Browse Source

ShaderChunk: Clarified isFrontFacing code.

Mr.doob 4 years ago
parent
commit
779c811206

+ 5 - 1
src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl.js

@@ -35,7 +35,11 @@ export default /* glsl */`
 
 		float fDet = dot( vSigmaX, R1 );
 
-		fDet *= ( float( isFrontFacing ) * 2.0 - 1.0 );
+		#ifdef DOUBLE_SIDED
+
+			fDet *= ( float( isFrontFacing ) * 2.0 - 1.0 );
+
+		#endif
 
 		vec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );
 		return normalize( abs( fDet ) * surf_norm - vGrad );

+ 15 - 9
src/renderers/shaders/ShaderChunk/normal_fragment_begin.glsl.js

@@ -1,25 +1,31 @@
 export default /* glsl */`
-// Workaround for Adreno GPUs not able to do dFdx( vViewPosition )
-
-vec3 fdx = vec3( dFdx( vViewPosition.x ), dFdx( vViewPosition.y ), dFdx( vViewPosition.z ) );
-vec3 fdy = vec3( dFdy( vViewPosition.x ), dFdy( vViewPosition.y ), dFdy( vViewPosition.z ) );
+bool isFrontFacing = true;
 
 #ifdef FLAT_SHADED
 
+	// Workaround for Adreno GPUs not able to do dFdx( vViewPosition )
+
+	vec3 fdx = vec3( dFdx( vViewPosition.x ), dFdx( vViewPosition.y ), dFdx( vViewPosition.z ) );
+	vec3 fdy = vec3( dFdy( vViewPosition.x ), dFdy( vViewPosition.y ), dFdy( vViewPosition.z ) );
 	vec3 normal = normalize( cross( fdx, fdy ) );
 
-	bool isFrontFacing = dot( vec3( 0, 0, 1 ), normal ) > 0.0;
+	isFrontFacing = dot( vec3( 0, 0, 1 ), normal ) > 0.0;
 
 #else
 
 	vec3 normal = normalize( vNormal );
 
-	// Workaround for Adreno GPUs broken gl_FrontFacing implementation
-	// https://stackoverflow.com/a/32621243
+	#ifdef DOUBLE_SIDED
+
+		// Workaround for Adreno GPUs not able to do dFdx( vViewPosition )
 
-	bool isFrontFacing = dot( normal, normalize( cross( fdx, fdy ) ) ) > 0.0;
+		vec3 fdx = vec3( dFdx( vViewPosition.x ), dFdx( vViewPosition.y ), dFdx( vViewPosition.z ) );
+		vec3 fdy = vec3( dFdy( vViewPosition.x ), dFdy( vViewPosition.y ), dFdy( vViewPosition.z ) );
 
-	#ifdef DOUBLE_SIDED
+		// Workaround for Adreno GPUs broken gl_FrontFacing implementation
+		// https://stackoverflow.com/a/32621243
+
+		isFrontFacing = dot( normal, normalize( cross( fdx, fdy ) ) ) > 0.0;
 
 		normal = normal * ( float( isFrontFacing ) * 2.0 - 1.0 );
 

+ 5 - 1
src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl.js

@@ -34,7 +34,11 @@ export default /* glsl */`
 
 		mat3 tsn = mat3( S, T, N );
 
-		mapN.xy *= ( float( isFrontFacing ) * 2.0 - 1.0 );
+		#ifdef DOUBLE_SIDED
+
+			mapN.xy *= ( float( isFrontFacing ) * 2.0 - 1.0 );
+
+		#endif
 
 		return normalize( tsn * mapN );
 

+ 5 - 1
src/renderers/shaders/ShaderLib/normal_frag.glsl.js

@@ -3,7 +3,11 @@ export default /* glsl */`
 
 uniform float opacity;
 
-varying vec3 vViewPosition;
+#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )
+
+	varying vec3 vViewPosition;
+
+#endif
 
 #ifndef FLAT_SHADED
 

+ 5 - 1
src/renderers/shaders/ShaderLib/normal_vert.glsl.js

@@ -1,7 +1,11 @@
 export default /* glsl */`
 #define NORMAL
 
-varying vec3 vViewPosition;
+#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )
+
+	varying vec3 vViewPosition;
+
+#endif
 
 #ifndef FLAT_SHADED