SwRasterizer/Lighting: Move the clamp highlight calculation to the end of the per-light loop body.

This commit is contained in:
Subv 2017-06-28 12:43:00 -05:00 committed by wwylele
parent 7526af5e52
commit 9906feefbd

View file

@ -163,14 +163,6 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(
light_vector.Normalize();
auto LV_N = Math::Dot(light_vector, normal);
auto dot_product = LV_N;
if (light_config.config.two_sided_diffuse)
dot_product = std::abs(dot_product);
else
dot_product = std::max(dot_product, 0.0f);
float dist_atten = 1.0f;
if (!lighting.IsDistAttenDisabled(num)) {
auto distance = (-view - position).Length();
@ -187,15 +179,6 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(
dist_atten = LookupLightingLut(g_state.lighting, lut, lutindex, delta);
}
float clamp_highlights = 1.0f;
if (lighting.config0.clamp_highlights) {
if (LV_N <= 0.f)
clamp_highlights = 0.f;
else
clamp_highlights = 1.f;
}
auto GetLutIndex = [&](unsigned num, LightingRegs::LightingLutInput input,
bool abs) -> std::tuple<u8, float> {
@ -386,6 +369,23 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(
}
}
auto dot_product = Math::Dot(light_vector, normal);
// Calculate clamp highlights before applying the two-sided diffuse configuration to the dot
// product.
float clamp_highlights = 1.0f;
if (lighting.config0.clamp_highlights) {
if (dot_product <= 0.f)
clamp_highlights = 0.f;
else
clamp_highlights = 1.f;
}
if (light_config.config.two_sided_diffuse)
dot_product = std::abs(dot_product);
else
dot_product = std::max(dot_product, 0.0f);
auto diffuse =
light_config.diffuse.ToVec3f() * dot_product + light_config.ambient.ToVec3f();
diffuse_sum += Math::MakeVec(diffuse * dist_atten, 0.0f);