From 4e06ea1bb538a4049e9cce6e3d0c701c14ac0fda Mon Sep 17 00:00:00 2001 From: Luke Street Date: Thu, 12 May 2022 01:10:06 -0400 Subject: [PATCH] Various lighting fixes --- Runtime/Character/CActorLights.cpp | 23 +++++++++-------------- Runtime/Graphics/CLight.cpp | 6 +++--- Runtime/Graphics/CLight.hpp | 10 +++++----- Runtime/Weapon/CPlayerGun.cpp | 2 +- Runtime/World/CWorldLight.cpp | 2 +- aurora/lib/gfx/gx.cpp | 18 ++++++++---------- 6 files changed, 27 insertions(+), 34 deletions(-) diff --git a/Runtime/Character/CActorLights.cpp b/Runtime/Character/CActorLights.cpp index 114d0d5c7..f44ab053d 100644 --- a/Runtime/Character/CActorLights.cpp +++ b/Runtime/Character/CActorLights.cpp @@ -135,7 +135,7 @@ void CActorLights::AddOverflowToLights(const CLight& light, const zeus::CColor& } void CActorLights::MoveAmbienceToLights(const zeus::CColor& color) { - if (x298_29_ambienceGenerated) { + if (x298_29_ambienceGenerated || x0_areaLights.empty()) { x288_ambientColor += color * 0.333333f; x288_ambientColor.a() = 1.f; return; @@ -187,6 +187,7 @@ bool CActorLights::BuildAreaLightList(const CStateManager& mgr, const CGameArea& /* Early return if not ready for update */ if (mgr.GetInputFrameIdx() - x2a4_lastUpdateFrame < x2a8_areaUpdateFramePeriod) return false; + x2a4_lastUpdateFrame = mgr.GetInputFrameIdx(); vec = aabb.center() + x2ac_actorPosBias; if (x2d4_worldLightingLevel == worldLightingLevel) if ((x2c0_lastActorPos - vec).magSquared() < x2cc_actorPositionDeltaUpdateThreshold) @@ -243,19 +244,13 @@ bool CActorLights::BuildAreaLightList(const CStateManager& mgr, const CGameArea& x288_ambientColor = light.GetNormalIndependentLightingAtPoint(vec); } else { EPVSVisSetState visible = EPVSVisSetState::OutOfBounds; - if (area.GetAreaVisSet()) { - if (lightIt->DoesCastShadows()) { - u32 pvsIdx; - if (use2ndLayer) - pvsIdx = area.Get2ndPVSLightFeature(lightIdx); - else - pvsIdx = area.Get1stPVSLightFeature(lightIdx); - visible = sets[0].GetVisible(pvsIdx); - if (visible != EPVSVisSetState::OutOfBounds) - visible = std::max(visible, sets[1].GetVisible(pvsIdx)); - if (visible != EPVSVisSetState::OutOfBounds) - visible = std::max(visible, sets[2].GetVisible(pvsIdx)); - } + if (area.GetAreaVisSet() && lightIt->DoesCastShadows()) { + u32 pvsIdx = use2ndLayer ? area.Get2ndPVSLightFeature(lightIdx) : area.Get1stPVSLightFeature(lightIdx); + visible = sets[0].GetVisible(pvsIdx); + if (visible != EPVSVisSetState::OutOfBounds) + visible = std::max(visible, sets[1].GetVisible(pvsIdx)); + if (visible != EPVSVisSetState::OutOfBounds) + visible = std::max(visible, sets[2].GetVisible(pvsIdx)); } if (visible != EPVSVisSetState::EndOfTree) { zeus::CSphere sphere(light.GetPosition(), light.GetRadius() * 2.f); diff --git a/Runtime/Graphics/CLight.cpp b/Runtime/Graphics/CLight.cpp index 4ebf58ca7..bd81256ae 100644 --- a/Runtime/Graphics/CLight.cpp +++ b/Runtime/Graphics/CLight.cpp @@ -9,7 +9,7 @@ constexpr zeus::CVector3f kDefaultDirection(0.f, -1.f, 0.f); float CLight::CalculateLightRadius() const { if (FLT_EPSILON > x28_distL && FLT_EPSILON > x2c_distQ) { - return 0.f; + return FLT_MAX; } float intensity = GetIntensity(); @@ -77,8 +77,8 @@ CLight CLight::BuildDirectional(const zeus::CVector3f& dir, const zeus::CColor& } CLight CLight::BuildSpot(const zeus::CVector3f& pos, const zeus::CVector3f& dir, const zeus::CColor& color, - float angle) { - return CLight(ELightType::Spot, pos, dir, color, angle); + float cutoff) { + return CLight(ELightType::Spot, pos, dir, color, cutoff); } CLight CLight::BuildPoint(const zeus::CVector3f& pos, const zeus::CColor& color) { diff --git a/Runtime/Graphics/CLight.hpp b/Runtime/Graphics/CLight.hpp index fbf60e1f4..5a31628e1 100644 --- a/Runtime/Graphics/CLight.hpp +++ b/Runtime/Graphics/CLight.hpp @@ -27,11 +27,11 @@ class CLight { zeus::CColor x18_color = zeus::skClear; ELightType x1c_type = ELightType::Custom; float x20_spotCutoff = 0.f; - float x24_distC = 1.f; - float x28_distL = 0.f; + float x24_distC = 0.f; + float x28_distL = 1.f; float x2c_distQ = 0.f; - float x30_angleC = 1.f; - float x34_angleL = 0.f; + float x30_angleC = 0.f; + float x34_angleL = 1.f; float x38_angleQ = 0.f; u32 x3c_priority = 0; u32 x40_lightId = 0; // Serves as unique key @@ -97,7 +97,7 @@ public: static CLight BuildDirectional(const zeus::CVector3f& dir, const zeus::CColor& color); static CLight BuildSpot(const zeus::CVector3f& pos, const zeus::CVector3f& dir, const zeus::CColor& color, - float angle); + float cutoff); static CLight BuildPoint(const zeus::CVector3f& pos, const zeus::CColor& color); static CLight BuildCustom(const zeus::CVector3f& pos, const zeus::CVector3f& dir, const zeus::CColor& color, float distC, float distL, float distQ, float angleC, float angleL, float angleQ); diff --git a/Runtime/Weapon/CPlayerGun.cpp b/Runtime/Weapon/CPlayerGun.cpp index 43509bd53..28a38ded3 100644 --- a/Runtime/Weapon/CPlayerGun.cpp +++ b/Runtime/Weapon/CPlayerGun.cpp @@ -124,7 +124,7 @@ float CPlayerGun::CMotionState::gGunExtendDistance = 0.125f; float CPlayerGun::skTractorBeamFactor = 0.5f / CPlayerState::GetMissileComboChargeFactor(); CPlayerGun::CPlayerGun(TUniqueId playerId) -: x0_lights(8, zeus::CVector3f{-30.f, 0.f, 30.f}, 4, 4, false, false, false, 0.1f) +: x0_lights(8, zeus::skZero3f, 4, 4, false, false, false, 0.1f) , x538_playerId(playerId) , x550_camBob(CPlayerCameraBob::ECameraBobType::One, CPlayerCameraBob::GetCameraBobExtent(), CPlayerCameraBob::GetCameraBobPeriod()) diff --git a/Runtime/World/CWorldLight.cpp b/Runtime/World/CWorldLight.cpp index 0a96da65f..400307ccf 100644 --- a/Runtime/World/CWorldLight.cpp +++ b/Runtime/World/CWorldLight.cpp @@ -64,7 +64,7 @@ CLight CWorldLight::GetAsCGraphicsLight() const { } const auto [distC, distL, distQ] = CalculateLightFalloff(x3c_falloff, x28_q); - return CLight::BuildCustom(x10_position, zeus::CVector3f{0.f, 1.f, 0.f}, + return CLight::BuildCustom(x10_position, zeus::CVector3f{1.f, 0.f, 0.f}, zeus::CColor{x4_color.x(), x4_color.y(), x4_color.z(), 1.f}, distC, distL, distQ, 1.f, 0.f, 0.f); } diff --git a/aurora/lib/gfx/gx.cpp b/aurora/lib/gfx/gx.cpp index 39ce771fe..05c2bcabd 100644 --- a/aurora/lib/gfx/gx.cpp +++ b/aurora/lib/gfx/gx.cpp @@ -224,19 +224,16 @@ void GXInitLightAttnK(GX::LightObj* light, float k0, float k1, float k2) { } void GXInitLightSpot(GX::LightObj* light, float cutoff, GX::SpotFn spotFn) { - if (cutoff < 0.f || cutoff > 90.f) { + if (cutoff <= 0.f || cutoff > 90.f) { spotFn = GX::SP_OFF; } - float cr = (cutoff * M_PIF) / 180.f; + float cr = std::cos((cutoff * M_PIF) / 180.f); float a0 = 1.f; float a1 = 0.f; float a2 = 0.f; switch (spotFn) { - case GX::SP_OFF: - a0 = 1.f; - a1 = 0.f; - a2 = 0.f; + default: break; case GX::SP_FLAT: a0 = -1000.f * cr; @@ -249,7 +246,7 @@ void GXInitLightSpot(GX::LightObj* light, float cutoff, GX::SpotFn spotFn) { a2 = 0.f; break; case GX::SP_COS2: - a0 = 0.0f; + a0 = 0.f; a1 = -cr / (1.f - cr); a2 = 1.f / (1.f - cr); break; @@ -323,10 +320,11 @@ void GXInitLightPos(GX::LightObj* light, float x, float y, float z) { } void GXInitLightDir(GX::LightObj* light, float nx, float ny, float nz) { - light->nx = nx; - light->ny = ny; - light->nz = nz; + light->nx = -nx; + light->ny = -ny; + light->nz = -nz; } + void GXInitSpecularDir(GX::LightObj* light, float nx, float ny, float nz) { float hx = -nx; float hy = -ny;