diff --git a/src/video_core/swrasterizer/rasterizer.cpp b/src/video_core/swrasterizer/rasterizer.cpp index 2ef91106f..c6fab6f53 100644 --- a/src/video_core/swrasterizer/rasterizer.cpp +++ b/src/video_core/swrasterizer/rasterizer.cpp @@ -163,14 +163,6 @@ std::tuple, Math::Vec4> 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> 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 { @@ -386,6 +369,23 @@ std::tuple, Math::Vec4> 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);