From 1c19bce514473f536facf72844cc3b6dd3d2b75c Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Thu, 22 Nov 2018 08:31:32 -0800 Subject: [PATCH] GPU: Correct specular exponent zero. --- GPU/Directx9/VertexShaderGeneratorDX9.cpp | 9 +++++++-- GPU/GLES/VertexShaderGeneratorGLES.cpp | 9 +++++++-- GPU/Software/Lighting.cpp | 2 +- GPU/Vulkan/VertexShaderGeneratorVulkan.cpp | 9 +++++++-- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/GPU/Directx9/VertexShaderGeneratorDX9.cpp b/GPU/Directx9/VertexShaderGeneratorDX9.cpp index 1ca697ea0e..406816031e 100644 --- a/GPU/Directx9/VertexShaderGeneratorDX9.cpp +++ b/GPU/Directx9/VertexShaderGeneratorDX9.cpp @@ -589,7 +589,7 @@ void GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage WRITE(p, " if (u_matspecular.a == 0.0) {\n"); WRITE(p, " ldot = 1.0;\n"); WRITE(p, " } else {\n"); - WRITE(p, " ldot = pow(ldot, u_matspecular.a);\n"); + WRITE(p, " ldot = pow(max(ldot, 0.0), u_matspecular.a);\n"); WRITE(p, " }\n"); } @@ -621,8 +621,13 @@ void GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage if (doSpecular) { WRITE(p, " if (ldot >= 0.0) {\n"); WRITE(p, " ldot = dot(normalize(toLight + float3(0.0, 0.0, 1.0)), worldnormal);\n"); + WRITE(p, " if (u_matspecular.a == 0.0) {\n"); + WRITE(p, " ldot = 1.0;\n"); + WRITE(p, " } else {\n"); + WRITE(p, " ldot = pow(max(ldot, 0.0), u_matspecular.a);\n"); + WRITE(p, " }\n"); WRITE(p, " if (ldot > 0.0)\n"); - WRITE(p, " lightSum1 += u_lightspecular%i * %s * (pow(ldot, u_matspecular.a) %s);\n", i, specularStr, timesLightScale); + WRITE(p, " lightSum1 += u_lightspecular%i * %s * ldot %s;\n", i, specularStr, timesLightScale); WRITE(p, " }\n"); } WRITE(p, " lightSum0.rgb += (u_lightambient%i * %s.rgb + diffuse)%s;\n", i, ambientStr, timesLightScale); diff --git a/GPU/GLES/VertexShaderGeneratorGLES.cpp b/GPU/GLES/VertexShaderGeneratorGLES.cpp index 63ffab8e46..f8193617e0 100644 --- a/GPU/GLES/VertexShaderGeneratorGLES.cpp +++ b/GPU/GLES/VertexShaderGeneratorGLES.cpp @@ -683,7 +683,7 @@ void GenerateVertexShader(const VShaderID &id, char *buffer, uint32_t *attrMask, WRITE(p, " if (u_matspecular.a == 0.0) {\n"); WRITE(p, " ldot = 1.0;\n"); WRITE(p, " } else {\n"); - WRITE(p, " ldot = pow(ldot, u_matspecular.a);\n"); + WRITE(p, " ldot = pow(max(ldot, 0.0), u_matspecular.a);\n"); WRITE(p, " }\n"); } @@ -715,8 +715,13 @@ void GenerateVertexShader(const VShaderID &id, char *buffer, uint32_t *attrMask, if (doSpecular) { WRITE(p, " if (ldot >= 0.0) {\n"); WRITE(p, " ldot = dot(normalize(toLight + vec3(0.0, 0.0, 1.0)), worldnormal);\n"); + WRITE(p, " if (u_matspecular.a == 0.0) {\n"); + WRITE(p, " ldot = 1.0;\n"); + WRITE(p, " } else {\n"); + WRITE(p, " ldot = pow(max(ldot, 0.0), u_matspecular.a);\n"); + WRITE(p, " }\n"); WRITE(p, " if (ldot > 0.0)\n"); - WRITE(p, " lightSum1 += u_lightspecular%i * %s * (pow(ldot, u_matspecular.a) %s);\n", i, specularStr, timesLightScale); + WRITE(p, " lightSum1 += u_lightspecular%i * %s * ldot %s;\n", i, specularStr, timesLightScale); WRITE(p, " }\n"); } WRITE(p, " lightSum0.rgb += (u_lightambient%i * %s.rgb + diffuse)%s;\n", i, ambientStr, timesLightScale); diff --git a/GPU/Software/Lighting.cpp b/GPU/Software/Lighting.cpp index c9f58e7f82..5246d9124d 100644 --- a/GPU/Software/Lighting.cpp +++ b/GPU/Software/Lighting.cpp @@ -125,7 +125,7 @@ void Process(VertexData& vertex, bool hasColor) { float specular_factor = Dot(H.Normalized(), vertex.worldnormal); float k = gstate.getMaterialSpecularCoef(); - specular_factor = pow(specular_factor, k); + specular_factor = pspLightPow(specular_factor, k); if (specular_factor > 0.f) { specular_color += lsc * msc * specular_factor * att * spot; diff --git a/GPU/Vulkan/VertexShaderGeneratorVulkan.cpp b/GPU/Vulkan/VertexShaderGeneratorVulkan.cpp index 891d2ea723..c6aa3644bd 100644 --- a/GPU/Vulkan/VertexShaderGeneratorVulkan.cpp +++ b/GPU/Vulkan/VertexShaderGeneratorVulkan.cpp @@ -472,7 +472,7 @@ bool GenerateVulkanGLSLVertexShader(const VShaderID &id, char *buffer) { WRITE(p, " if (light.matspecular.a == 0.0) {\n"); WRITE(p, " dot%i = 1.0;\n", i); WRITE(p, " } else {\n"); - WRITE(p, " dot%i = pow(dot%i, light.matspecular.a);\n", i, i); + WRITE(p, " dot%i = pow(max(dot%i, 0.0), light.matspecular.a);\n", i, i); WRITE(p, " }\n"); } @@ -504,8 +504,13 @@ bool GenerateVulkanGLSLVertexShader(const VShaderID &id, char *buffer) { if (doSpecular) { WRITE(p, " if (dot%i >= 0.0) {\n", i); WRITE(p, " dot%i = dot(normalize(toLight + vec3(0.0, 0.0, 1.0)), worldnormal);\n", i); + WRITE(p, " if (light.matspecular.a == 0.0) {\n"); + WRITE(p, " dot%i = 1.0;\n", i); + WRITE(p, " } else {\n"); + WRITE(p, " dot%i = pow(max(dot%i, 0.0), light.matspecular.a);\n", i, i); + WRITE(p, " }\n"); WRITE(p, " if (dot%i > 0.0)\n", i); - WRITE(p, " lightSum1 += light.specular[%i] * %s * (pow(dot%i, light.matspecular.a) %s);\n", i, specularStr, i, timesLightScale); + WRITE(p, " lightSum1 += light.specular[%i] * %s * dot%i %s;\n", i, specularStr, i, timesLightScale); WRITE(p, " }\n"); } WRITE(p, " lightSum0.rgb += (light.ambient[%i] * %s.rgb + diffuse)%s;\n", i, ambientStr, timesLightScale);