From 2238fab6019eebf7ed2c6ee4735658bf2f0a5751 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 20 Dec 2023 14:47:49 +0100 Subject: [PATCH] Minor lighting optimization in vshader --- GPU/Common/VertexShaderGenerator.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/GPU/Common/VertexShaderGenerator.cpp b/GPU/Common/VertexShaderGenerator.cpp index c85249216b..15725f652f 100644 --- a/GPU/Common/VertexShaderGenerator.cpp +++ b/GPU/Common/VertexShaderGenerator.cpp @@ -1069,16 +1069,14 @@ bool GenerateVertexShader(const VShaderID &id, char *buffer, const ShaderLanguag p.C(" ldot = u_matspecular.a > 0.0 ? pow(max(ldot, 0.0), u_matspecular.a) : 1.0;\n"); p.C(" }\n"); p.F(" diffuse = (u_lightdiffuse%s * diffuseColor) * max(ldot, 0.0);\n", iStr); - p.C(" if (comp == 0x1u) {\n"); // do specular - p.C(" if (ldot >= 0.0) {\n"); - p.C(" if (u_matspecular.a > 0.0) {\n"); - p.C(" ldot = dot(normalize(toLight + vec3(0.0, 0.0, 1.0)), worldnormal);\n"); - p.C(" ldot = pow(max(ldot, 0.0), u_matspecular.a);\n"); - p.C(" } else {\n"); - p.C(" ldot = 1.0;\n"); - p.C(" }\n"); - p.F(" lightSum1 += u_lightspecular%s * specularColor * ldot * lightScale;\n", iStr); + p.C(" if (comp == 0x1u && ldot > 0.0) {\n"); // do specular + p.C(" if (u_matspecular.a > 0.0) {\n"); + p.C(" ldot = dot(normalize(toLight + vec3(0.0, 0.0, 1.0)), worldnormal);\n"); + p.C(" ldot = pow(ldot, u_matspecular.a);\n"); + p.C(" } else {\n"); + p.C(" ldot = 1.0;\n"); p.C(" }\n"); + p.F(" lightSum1 += u_lightspecular%s * specularColor * ldot * lightScale;\n", iStr); p.C(" }\n"); p.F(" lightSum0.rgb += (u_lightambient%s * ambientColor.rgb + diffuse) * lightScale;\n", iStr); p.C(" }\n"); @@ -1149,7 +1147,7 @@ bool GenerateVertexShader(const VShaderID &id, char *buffer, const ShaderLanguag p.C(" if (ldot >= 0.0) {\n"); p.C(" if (u_matspecular.a > 0.0) {\n"); p.C(" ldot = dot(normalize(toLight + vec3(0.0, 0.0, 1.0)), worldnormal);\n"); - p.C(" ldot = pow(max(ldot, 0.0), u_matspecular.a);\n"); + p.C(" ldot = pow(ldot, u_matspecular.a);\n"); p.C(" } else {\n"); p.C(" ldot = 1.0;\n"); p.C(" }\n");