Skip to content

Commit

Permalink
Fix logic errors and exception in SpecGloss pipeline
Browse files Browse the repository at this point in the history
This PR addresses this issue: 
#2386 
And then I also found another critical logic error in the spec gloss pipeline that was likely there even before riccardo adapted the shader to use structs:

It looks like the specular value taken from specularMaps was being totally ignored and not used in the roughness calculation. The code further down in the shader was calculating the roughness solely based on m_Glossiness with no regard for the glossiness texture maps, which is incorrect.

The logic error and exception should all be fixed in this PR now, but it will need testing from a spec gloss model with packed specularGlossinesMap as well as a model with seperate specular and glossiness maps in order to ensure everything works properly now.
  • Loading branch information
yaRnMcDonuts authored Mar 6, 2025
1 parent 75f0b73 commit b846c6a
Showing 1 changed file with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -384,28 +384,27 @@
//spec gloss tex reads:

#ifdef SPECGLOSSPIPELINE
flota glossiness = m_Glossiness;
#ifdef USE_PACKED_SG
vec4 specularColor = texture2D(m_SpecularGlossinessMap, newTexCoord);
float glossiness = specularColor.a * m_Glossiness;
glossiness *= specularColor.a;
specularColor *= m_Specular;
surface.specularColor = specularColor.rgb;
#else
#ifdef SPECULARMAP
vec4 specularColor = texture2D(m_SpecularMap, newTexCoord);
#else
vec4 specularColor = vec4(1.0);
#endif
#ifdef GLOSSINESSMAP
float glossiness = texture2D(m_GlossinesMap, newTexCoord).r * m_Glossiness;
#else
float glossiness = m_Glossiness;
glossiness *= texture2D(m_GlossinesMap, newTexCoord).r;
#endif
specularColor *= m_Specular;
surface.specularColor = specularColor;
surface.specularColor = specularColor.rgb;
surface.roughness = 1.0 - glossiness;
#endif
#endif



vec3 ao = vec3(1.0);
#ifdef LIGHTMAP
vec3 lightMapColor;
Expand Down Expand Up @@ -475,7 +474,6 @@

#ifdef SPECGLOSSPIPELINE
surface.diffuseColor = surface.albedo;// * (1.0 - max(max(specularColor.r, specularColor.g), specularColor.b));
surface.roughness = 1.0 - m_Glossiness;
surface.fZero = surface.specularColor.xyz;
#else
surface.specularColor = (0.04 - 0.04 * surface.metallic) + surface.albedo * surface.metallic; // 0.04 is the standard base specular reflectance for non-metallic surfaces in PBR. While values like 0.08 can be used for different implementations, 0.04 aligns with Khronos' PBR specification.
Expand Down

0 comments on commit b846c6a

Please sign in to comment.