Correct Light radius calculation

This commit is contained in:
Phillip Stephens 2021-05-06 10:51:54 -07:00
parent e0e88a88bc
commit 5e0604f101
1 changed files with 14 additions and 11 deletions

View File

@ -8,19 +8,22 @@ constexpr zeus::CVector3f kDefaultPosition(0.f, 0.f, 0.f);
constexpr zeus::CVector3f kDefaultDirection(0.f, -1.f, 0.f); constexpr zeus::CVector3f kDefaultDirection(0.f, -1.f, 0.f);
float CLight::CalculateLightRadius() const { float CLight::CalculateLightRadius() const {
if (x28_distL < FLT_EPSILON && x2c_distQ < FLT_EPSILON) if (FLT_EPSILON > x28_distL && FLT_EPSILON > x2c_distQ) {
return FLT_MAX; return 0.f;
float intens = GetIntensity();
if (x2c_distQ > FLT_EPSILON) {
if (intens <= FLT_EPSILON)
return 0.f;
return std::sqrt(intens / (0.0588235f * x2c_distQ));
} }
if (x28_distL > FLT_EPSILON) float intensity = GetIntensity();
return intens / (0.0588235f * x28_distL); if (x2c_distQ <= FLT_EPSILON) {
constexpr float mulVal = std::min(0.05882353f, 0.2f); // Yes, retro really did do this
if (x28_distL > FLT_EPSILON) {
return intensity / (mulVal * x28_distL);
}
} else {
constexpr float mulVal = std::min(0.05882353f, 0.2f); // See above comment
if (intensity > FLT_EPSILON) {
return std::sqrt(intensity / (mulVal * x2c_distQ));
}
}
return 0.f; return 0.f;
} }