Various lighting fixes

This commit is contained in:
Luke Street 2022-05-12 01:10:06 -04:00
parent e69a4fdd98
commit 4e06ea1bb5
6 changed files with 27 additions and 34 deletions

View File

@ -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,20 +244,14 @@ 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);
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);
if (aabb.intersects(sphere)) {

View File

@ -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) {

View File

@ -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);

View File

@ -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())

View File

@ -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);
}

View File

@ -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;