From c63ea902f0e462f0d9afecebbc38a4bcb3b97cc0 Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Sun, 27 Feb 2022 12:06:03 -0800 Subject: [PATCH] Revert "Further refactoring attempt" This reverts commit 334ca8df73c2686ac1c793313fc70c97a6142bea. --- Source/Core/VideoCommon/LightingShaderGen.cpp | 55 ++++++++----------- 1 file changed, 23 insertions(+), 32 deletions(-) diff --git a/Source/Core/VideoCommon/LightingShaderGen.cpp b/Source/Core/VideoCommon/LightingShaderGen.cpp index af40cce48e..b5c7e36d9e 100644 --- a/Source/Core/VideoCommon/LightingShaderGen.cpp +++ b/Source/Core/VideoCommon/LightingShaderGen.cpp @@ -22,48 +22,25 @@ static void GenerateLightShader(ShaderCode& object, const LightingUidData& uid_d object.Write(" float3 ldir = " LIGHT_POS ".xyz - pos.xyz;\n", LIGHT_POS_PARAMS(index)); object.Write(" float dist2 = dot(ldir, ldir);\n" " float dist = sqrt(dist2);\n" - " ldir = ldir / dist;\n\n"); - - switch (diffuse_func) - { - case DiffuseFunc::None: - object.Write(" float diffuse = 1.0;\n\n"); - break; - case DiffuseFunc::Sign: - default: // Confirmed by hardware testing that invalid values use this - object.Write(" float diffuse = dot(ldir, _normal);\n\n"); - break; - case DiffuseFunc::Clamp: - object.Write(" float diffuse = max(0.0, dot(ldir, _normal));\n\n"); - break; - } + " ldir = ldir / dist;\n"); switch (attn_func) { case AttenuationFunc::None: - if (diffuse_func == DiffuseFunc::None) - { - object.Write(" float attn = 1.0;\n"); - break; - } - else - { - object.Write(" lacc.{} += int{}(round(255 * sign(diffuse)));\n", swizzle, - swizzle_components); - object.Write(" }}\n"); - return; // Return, not break! - } case AttenuationFunc::Dir: object.Write(" float attn = 1.0;\n"); break; case AttenuationFunc::Spec: object.Write(" float cosine = 0.0;\n" - " // Compute the cosine of the angle between the object normal\n" - " // and the half-angle direction for the viewer\n" - " // (assuming the half-angle direction is a unit vector)\n" - " cosine = max(0.0, dot(_normal, -" LIGHT_DIR ".xyz));\n", + " // Ensure that the object is facing the light\n" + " if (dot(_normal, ldir) >= 0.0) {{\n" + " // Compute the cosine of the angle between the object normal\n" + " // and the half-angle direction for the viewer\n" + " // (assuming the half-angle direction is a unit vector)\n" + " cosine = max(0.0, dot(_normal, " LIGHT_DIR ".xyz));\n", LIGHT_DIR_PARAMS(index)); - object.Write(" // Specular lights use the angle for the denominator as well\n" + object.Write(" }}\n" + " // Specular lights use the angle for the denominator as well\n" " dist = cosine;\n" " dist2 = dist * dist;\n"); break; @@ -99,6 +76,20 @@ static void GenerateLightShader(ShaderCode& object, const LightingUidData& uid_d " float attn = max(0.0f, numerator / denominator);\n"); } + switch (diffuse_func) + { + case DiffuseFunc::None: + object.Write(" float diffuse = 1.0;\n"); + break; + case DiffuseFunc::Sign: + default: // Confirmed by hardware testing that invalid values use this + object.Write(" float diffuse = dot(ldir, _normal);\n"); + break; + case DiffuseFunc::Clamp: + object.Write(" float diffuse = max(0.0, dot(ldir, _normal));\n"); + break; + } + object.Write(" lacc.{} += int{}(round(attn * diffuse * float{}(" LIGHT_COL ")));\n", swizzle, swizzle_components, swizzle_components, LIGHT_COL_PARAMS(index, swizzle)); object.Write(" }}\n");