Add widescreen actor culling option (#652)

This commit is contained in:
Garrett Cox 2024-08-09 15:42:34 -05:00 committed by GitHub
parent 0ec23b34ba
commit 4a57bdbc5f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 18 deletions

View File

@ -562,11 +562,10 @@ void DrawEnhancementsMenu() {
{ .tooltip =
"Disables the distance check for scene geometry, allowing it to be drawn no matter how far "
"away it is from the player. This may have unintended side effects." });
// BENTODO: Not implemented yet
// UIWidgets::CVarCheckbox("Widescreen Actor Culling",
// "gEnhancements.Graphics.ActorCullingAccountsForWidescreen",
// { .tooltip = "Adjusts the culling planes to account for widescreen resolutions. "
// "This may have unintended side effects." });
UIWidgets::CVarCheckbox("Widescreen Actor Culling",
"gEnhancements.Graphics.ActorCullingAccountsForWidescreen",
{ .tooltip = "Adjusts the culling planes to account for widescreen resolutions. "
"This may have unintended side effects." });
if (UIWidgets::CVarSliderInt(
"Increase Actor Draw Distance: %dx", "gEnhancements.Graphics.IncreaseActorDrawDistance", 1, 5, 1,
{ .tooltip =

View File

@ -23,6 +23,7 @@
#include <string.h>
#include "2s2h/Enhancements/FrameInterpolation/FrameInterpolation.h"
#include "2s2h/Enhancements/GameInteractor/GameInteractor.h"
#include "2s2h/BenPort.h"
// bss
// FaultClient sActorFaultClient; // 2 funcs
@ -3084,24 +3085,38 @@ void Ship_CalcShouldDrawAndUpdate(PlayState* play, Actor* actor, Vec3f* projecte
(projectedPos->z < ((actor->uncullZoneForward * drawMulti) + (actor->uncullZoneScale * drawMulti)));
if (updateCheck || drawCheck) {
f32 phi_f12;
f32 phi_f2 = CLAMP_MIN(projectedW, 1.0f);
f32 phi_f14;
f32 phi_f16;
// Ensure the projected W value is at least 1.0
f32 clampedProjectedW = CLAMP_MIN(projectedW, 1.0f);
f32 uncullZoneScaleDiagonal;
f32 uncullZoneScaleVertical;
f32 uncullZoneDownwardAdjusted;
// Adjust calculations if the field of view is not the default 60 degrees
if (play->view.fovy != 60.0f) {
phi_f12 = actor->uncullZoneScale * play->projectionMtxFDiagonal.x * 0.76980036f; // sqrt(16/27)
uncullZoneScaleDiagonal =
actor->uncullZoneScale * play->projectionMtxFDiagonal.x * 0.76980036f; // sqrt(16/27)
phi_f14 = play->projectionMtxFDiagonal.y * 0.57735026f; // 1 / sqrt(3)
phi_f16 = actor->uncullZoneScale * phi_f14;
phi_f14 *= actor->uncullZoneDownward;
uncullZoneScaleVertical = play->projectionMtxFDiagonal.y * 0.57735026f; // 1 / sqrt(3)
uncullZoneDownwardAdjusted = actor->uncullZoneScale * uncullZoneScaleVertical;
uncullZoneScaleVertical *= actor->uncullZoneDownward;
} else {
phi_f16 = phi_f12 = actor->uncullZoneScale;
phi_f14 = actor->uncullZoneDownward;
uncullZoneDownwardAdjusted = uncullZoneScaleDiagonal = actor->uncullZoneScale;
uncullZoneScaleVertical = actor->uncullZoneDownward;
}
if (((fabsf(projectedPos->x) - phi_f12) < phi_f2) && ((-phi_f2 < (projectedPos->y + phi_f14))) &&
((projectedPos->y - phi_f16) < phi_f2)) {
if (CVarGetInteger("gEnhancements.Graphics.ActorCullingAccountsForWidescreen", 0)) {
float originalAspectRatio = 4.0f / 3.0f;
float currentAspectRatio = OTRGetAspectRatio();
float aspectRatioMultiplier = MAX(currentAspectRatio / originalAspectRatio, 1.0f);
clampedProjectedW *= aspectRatioMultiplier;
}
bool isWithinHorizontalCullZone = ((fabsf(projectedPos->x) - uncullZoneScaleDiagonal) < clampedProjectedW);
bool isAboveBottomOfCullZone = ((-clampedProjectedW < (projectedPos->y + uncullZoneScaleVertical)));
bool isBelowTopOfCullZone = ((projectedPos->y - uncullZoneDownwardAdjusted) < clampedProjectedW);
if (isWithinHorizontalCullZone && isAboveBottomOfCullZone && isBelowTopOfCullZone) {
*shouldDraw = drawCheck;
*shouldUpdate = updateCheck;
}
@ -3148,7 +3163,8 @@ void Actor_DrawAll(PlayState* play, ActorContext* actorCtx) {
bool shipShouldDraw = false;
bool shipShouldUpdate = false;
if (CVarGetInteger("gEnhancements.Graphics.IncreaseActorDrawDistance", 1) > 1 ||
CVarGetInteger("gEnhancements.Graphics.IncreaseActorUpdateDistance", 1) > 1) {
CVarGetInteger("gEnhancements.Graphics.IncreaseActorUpdateDistance", 1) > 1 ||
CVarGetInteger("gEnhancements.Graphics.ActorCullingAccountsForWidescreen", 0)) {
Ship_CalcShouldDrawAndUpdate(play, actor, &actor->projectedPos, actor->projectedW, &shipShouldDraw,
&shipShouldUpdate);