sebavan 4 years ago
parent
commit
2ca086ce65
2 changed files with 8 additions and 2 deletions
  1. 5 2
      src/Shaders/ShadersInclude/pbrBlockClearcoat.fx
  2. 3 0
      src/Shaders/pbr.fragment.fx

+ 5 - 2
src/Shaders/ShadersInclude/pbrBlockClearcoat.fx

@@ -95,6 +95,9 @@ struct clearcoatOutParams
             const in float ambientMonochrome,
         #endif
     #endif
+    #if defined(CLEARCOAT_BUMP) || defined(TWOSIDEDLIGHTING)
+        const in float frontFacingMultiplier,
+    #endif
         out clearcoatOutParams outParams
     )
     {
@@ -166,7 +169,7 @@ struct clearcoatOutParams
                 mat3 TBNClearCoat = vTBN;
             #else
                 // flip the uv for the backface
-                vec2 TBNClearCoatUV = gl_FrontFacing ? vClearCoatBumpUV : -vClearCoatBumpUV;
+                vec2 TBNClearCoatUV = vClearCoatBumpUV * frontFacingMultiplier;
                 mat3 TBNClearCoat = cotangent_frame(clearCoatNormalW * clearCoatNormalScale, vPositionW, TBNClearCoatUV, vClearCoatTangentSpaceParams);
             #endif
 
@@ -187,7 +190,7 @@ struct clearcoatOutParams
         #endif
 
         #if defined(TWOSIDEDLIGHTING) && defined(NORMAL)
-            clearCoatNormalW = gl_FrontFacing ? clearCoatNormalW : -clearCoatNormalW;
+            clearCoatNormalW = clearCoatNormalW * frontFacingMultiplier;
         #endif
 
         outParams.clearCoatNormalW = clearCoatNormalW;

+ 3 - 0
src/Shaders/pbr.fragment.fx

@@ -421,6 +421,9 @@ void main(void) {
             #ifdef RADIANCEOCCLUSION
                 ambientMonochrome,
             #endif
+        #endif,
+        #if defined(CLEARCOAT_BUMP) || defined(TWOSIDEDLIGHTING)
+            gl_FrontFacing ? 1. : -1.,
         #endif
             clearcoatOut
         );