Przeglądaj źródła

Pertubation code refactoring

arobertson0 6 lat temu
rodzic
commit
695c0844b8

Plik diff jest za duży
+ 60 - 46
build/three.js


+ 60 - 46
build/three.module.js

@@ -15446,15 +15446,56 @@ var normal_fragment_begin = /* glsl */ `
 #endif
 #endif
 `;
 `;
 
 
-var normal_fragment_maps = "#ifdef USE_NORMALMAP\n\t#ifdef OBJECTSPACE_NORMALMAP\n\t\tnormal = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\t\t#ifdef FLIP_SIDED\n\t\t\tnormal = - normal;\n\t\t#endif\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tnormal = normal * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\t#endif\n\t\tnormal = normalize( normalMatrix * normal );\n\t#else\n\t\t#ifdef USE_TANGENT\n\t\t\tmat3 vTBN = mat3( tangent, bitangent, normal );\n\t\t\tvec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\t\t\tmapN.xy = normalScale * mapN.xy;\n\t\t\tnormal = normalize( vTBN * mapN );\n\t\t#else\n\t\t\tnormal = perturbNormal2Arb( -vViewPosition, normal );\n\t\t#endif\n\t#endif\n#elif defined( USE_BUMPMAP )\n\tnormal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );\n#endif";
+var normal_fragment_maps = "#ifdef USE_NORMALMAP\n\t#ifdef OBJECTSPACE_NORMALMAP\n\t\tnormal = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\t\t#ifdef FLIP_SIDED\n\t\t\tnormal = - normal;\n\t\t#endif\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tnormal = normal * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\t#endif\n\t\tnormal = normalize( normalMatrix * normal );\n\t#else\n\t\t#ifdef USE_TANGENT\n\t\t\tmat3 vTBN = mat3( tangent, bitangent, normal );\n\t\t\tvec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\t\t\tmapN.xy = normalScale * mapN.xy;\n\t\t\tnormal = normalize( vTBN * mapN );\n\t\t#else\n\t\t\tnormal = perturbNormal2Arb( -vViewPosition, normal, normalScale, normalMap );\n\t\t#endif\n\t#endif\n#elif defined( USE_BUMPMAP )\n\tnormal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );\n#endif";
 
 
-var normalmap_pars_fragment = "#ifdef USE_NORMALMAP\n\tuniform sampler2D normalMap;\n\tuniform vec2 normalScale;\n\t#ifdef OBJECTSPACE_NORMALMAP\n\t\tuniform mat3 normalMatrix;\n\t#else\n\t\tvec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm ) {\n\t\t\tvec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );\n\t\t\tvec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );\n\t\t\tvec2 st0 = dFdx( vUv.st );\n\t\t\tvec2 st1 = dFdy( vUv.st );\n\t\t\tfloat scale = sign( st1.t * st0.s - st0.t * st1.s );\n\t\t\tvec3 S = normalize( ( q0 * st1.t - q1 * st0.t ) * scale );\n\t\t\tvec3 T = normalize( ( - q0 * st1.s + q1 * st0.s ) * scale );\n\t\t\tvec3 N = normalize( surf_norm );\n\t\t\tmat3 tsn = mat3( S, T, N );\n\t\t\tvec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\t\t\tmapN.xy *= normalScale;\n\t\t\tmapN.xy *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\t\treturn normalize( tsn * mapN );\n\t\t}\n\t#endif\n#endif";
+var normalmap_pars_fragment = /* glsl */ `
+#ifdef USE_NORMALMAP
 
 
-var clearcoat_normal_fragment_begin = /* glsl */ `
-#ifndef STANDARD
+	uniform sampler2D normalMap;
+	uniform vec2 normalScale;
+
+	#ifdef OBJECTSPACE_NORMALMAP
+
+		uniform mat3 normalMatrix;
+
+	#endif
+#endif
+
+#if defined ( USE_NORMALMAP ) || defined ( USE_CLEARCOAT_NORMALMAP )
+
+		// Per-Pixel Tangent Space Normal Mapping
+		// http://hacksoflife.blogspot.ch/2009/11/per-pixel-tangent-space-normal-mapping.html
+
+		vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec2 normalScale, in sampler2D normalMap ) {
+
+			// Workaround for Adreno 3XX dFd*( vec3 ) bug. See #9988
+
+			vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );
+			vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );
+			vec2 st0 = dFdx( vUv.st );
+			vec2 st1 = dFdy( vUv.st );
 
 
-vec3 clearCoatNormal = geometryNormal;
+			float scale = sign( st1.t * st0.s - st0.t * st1.s ); // we do not care about the magnitude
+
+			vec3 S = normalize( ( q0 * st1.t - q1 * st0.t ) * scale );
+			vec3 T = normalize( ( - q0 * st1.s + q1 * st0.s ) * scale );
+			vec3 N = normalize( surf_norm );
+			mat3 tsn = mat3( S, T, N );
+
+			vec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;
 
 
+			mapN.xy *= normalScale;
+			mapN.xy *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );
+
+			return normalize( tsn * mapN );
+
+		}
+#endif
+`;
+
+var clearcoat_normal_fragment_begin = /* glsl */ `
+#ifndef STANDARD
+  vec3 clearCoatNormal = geometryNormal;
 #endif
 #endif
 `;
 `;
 
 
@@ -15467,22 +15508,23 @@ vec3 clearCoatNormal = clearCoatGeometryNormals ?
 */
 */
 
 
 var clearcoat_normal_fragment_maps = /* glsl */ `
 var clearcoat_normal_fragment_maps = /* glsl */ `
-#if defined( USE_NORMALMAP ) || defined ( USE_CLEARCOAT_NORMALMAP )
+#ifndef STANDARD
+	#if defined( USE_NORMALMAP ) || defined ( USE_CLEARCOAT_NORMALMAP )
 
 
-	#ifdef USE_TANGENT
+		#ifdef USE_TANGENT
 
 
-		mat3 vTBN = mat3( tangent, bitangent, clearCoatNormal );
-		vec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;
-		mapN.xy = clearCoatNormalScale * mapN.xy;
-		clearCoatNormal = normalize( vTBN * mapN );
+			mat3 vTBN = mat3( tangent, bitangent, clearCoatNormal );
+			vec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;
+			mapN.xy = clearCoatNormalScale * mapN.xy;
+			clearCoatNormal = normalize( vTBN * mapN );
 
 
-	#else
+		#else
 
 
-	  clearCoatNormal = perturbClearCoatNormal2Arb( -vViewPosition, clearCoatNormal );
+			clearCoatNormal = perturbNormal2Arb( -vViewPosition, clearCoatNormal, clearCoatNormalScale, clearCoatNormalMap );
 
 
+		#endif
 	#endif
 	#endif
 #endif
 #endif
-
 `;
 `;
 /*
 /*
 #if defined( USE_NORMALMAP )
 #if defined( USE_NORMALMAP )
@@ -15547,43 +15589,15 @@ var clearcoat_normal_fragment_maps = /* glsl */ `
 */
 */
 
 
 var clearcoat_normalmap_pars_fragment = /* glsl */ `
 var clearcoat_normalmap_pars_fragment = /* glsl */ `
-#if defined( USE_NORMALMAP ) || defined ( USE_CLEARCOAT_NORMALMAP )
-
+#ifndef STANDARD
+	#if defined( USE_NORMALMAP ) || defined ( USE_CLEARCOAT_NORMALMAP )
+		uniform vec2 clearCoatNormalScale;
+	#endif
 	#ifdef USE_CLEARCOAT_NORMALMAP
 	#ifdef USE_CLEARCOAT_NORMALMAP
 		uniform sampler2D clearCoatNormalMap;
 		uniform sampler2D clearCoatNormalMap;
 	#else
 	#else
 		#define clearCoatNormalMap normalMap
 		#define clearCoatNormalMap normalMap
 	#endif
 	#endif
-	uniform vec2 clearCoatNormalScale;
-
-		// Per-Pixel Tangent Space Normal Mapping
-		// http://hacksoflife.blogspot.ch/2009/11/per-pixel-tangent-space-normal-mapping.html
-
-		vec3 perturbClearCoatNormal2Arb( vec3 eye_pos, vec3 surf_norm ) {
-
-			// Workaround for Adreno 3XX dFd*( vec3 ) bug. See #9988
-
-			vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );
-			vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );
-			vec2 st0 = dFdx( vUv.st );
-			vec2 st1 = dFdy( vUv.st );
-
-			float scale = sign( st1.t * st0.s - st0.t * st1.s ); // we do not care about the magnitude
-
-			vec3 S = normalize( ( q0 * st1.t - q1 * st0.t ) * scale );
-			vec3 T = normalize( ( - q0 * st1.s + q1 * st0.s ) * scale );
-			vec3 N = normalize( surf_norm );
-			mat3 tsn = mat3( S, T, N );
-
-			vec3 mapN = texture2D( clearCoatNormalMap, vUv ).xyz * 2.0 - 1.0;
-
-			mapN.xy *= clearCoatNormalScale;
-			mapN.xy *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );
-
-			return normalize( tsn * mapN );
-
-		}
-
 #endif
 #endif
 `;
 `;
 /*
 /*

+ 2 - 12
src/renderers/shaders/ShaderChunk/clearcoat_normal_fragment_begin.glsl.js

@@ -1,15 +1,5 @@
-export default /* glsl */ `
+export default /* glsl */`
 #ifndef STANDARD
 #ifndef STANDARD
-
-vec3 clearCoatNormal = geometryNormal;
-
+  vec3 clearCoatNormal = geometryNormal;
 #endif
 #endif
 `;
 `;
-
-/*
-
-vec3 clearCoatNormal = clearCoatGeometryNormals ?
-  geometryNormal: // use the unperturbed normal of the geometry
-  normal; // Use the (maybe) perturbed normal
-
-*/

+ 10 - 9
src/renderers/shaders/ShaderChunk/clearcoat_normal_fragment_maps.glsl.js

@@ -1,20 +1,21 @@
 export default /* glsl */ `
 export default /* glsl */ `
-#if defined( USE_NORMALMAP ) || defined ( USE_CLEARCOAT_NORMALMAP )
+#ifndef STANDARD
+	#if defined( USE_NORMALMAP ) || defined ( USE_CLEARCOAT_NORMALMAP )
 
 
-	#ifdef USE_TANGENT
+		#ifdef USE_TANGENT
 
 
-		mat3 vTBN = mat3( tangent, bitangent, clearCoatNormal );
-		vec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;
-		mapN.xy = clearCoatNormalScale * mapN.xy;
-		clearCoatNormal = normalize( vTBN * mapN );
+			mat3 vTBN = mat3( tangent, bitangent, clearCoatNormal );
+			vec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;
+			mapN.xy = clearCoatNormalScale * mapN.xy;
+			clearCoatNormal = normalize( vTBN * mapN );
 
 
-	#else
+		#else
 
 
-	  clearCoatNormal = perturbClearCoatNormal2Arb( -vViewPosition, clearCoatNormal );
+			clearCoatNormal = perturbNormal2Arb( -vViewPosition, clearCoatNormal, clearCoatNormalScale, clearCoatNormalMap );
 
 
+		#endif
 	#endif
 	#endif
 #endif
 #endif
-
 `;
 `;
 /*
 /*
 #if defined( USE_NORMALMAP )
 #if defined( USE_NORMALMAP )

+ 4 - 32
src/renderers/shaders/ShaderChunk/clearcoat_normalmap_pars_fragment.glsl.js

@@ -1,41 +1,13 @@
 export default /* glsl */ `
 export default /* glsl */ `
-#if defined( USE_NORMALMAP ) || defined ( USE_CLEARCOAT_NORMALMAP )
-
+#ifndef STANDARD
+	#if defined( USE_NORMALMAP ) || defined ( USE_CLEARCOAT_NORMALMAP )
+		uniform vec2 clearCoatNormalScale;
+	#endif
 	#ifdef USE_CLEARCOAT_NORMALMAP
 	#ifdef USE_CLEARCOAT_NORMALMAP
 		uniform sampler2D clearCoatNormalMap;
 		uniform sampler2D clearCoatNormalMap;
 	#else
 	#else
 		#define clearCoatNormalMap normalMap
 		#define clearCoatNormalMap normalMap
 	#endif
 	#endif
-	uniform vec2 clearCoatNormalScale;
-
-		// Per-Pixel Tangent Space Normal Mapping
-		// http://hacksoflife.blogspot.ch/2009/11/per-pixel-tangent-space-normal-mapping.html
-
-		vec3 perturbClearCoatNormal2Arb( vec3 eye_pos, vec3 surf_norm ) {
-
-			// Workaround for Adreno 3XX dFd*( vec3 ) bug. See #9988
-
-			vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );
-			vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );
-			vec2 st0 = dFdx( vUv.st );
-			vec2 st1 = dFdy( vUv.st );
-
-			float scale = sign( st1.t * st0.s - st0.t * st1.s ); // we do not care about the magnitude
-
-			vec3 S = normalize( ( q0 * st1.t - q1 * st0.t ) * scale );
-			vec3 T = normalize( ( - q0 * st1.s + q1 * st0.s ) * scale );
-			vec3 N = normalize( surf_norm );
-			mat3 tsn = mat3( S, T, N );
-
-			vec3 mapN = texture2D( clearCoatNormalMap, vUv ).xyz * 2.0 - 1.0;
-
-			mapN.xy *= clearCoatNormalScale;
-			mapN.xy *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );
-
-			return normalize( tsn * mapN );
-
-		}
-
 #endif
 #endif
 `;
 `;
 /*
 /*

+ 1 - 1
src/renderers/shaders/ShaderChunk/normal_fragment_maps.glsl.js

@@ -30,7 +30,7 @@ export default /* glsl */`
 
 
 		#else
 		#else
 
 
-			normal = perturbNormal2Arb( -vViewPosition, normal );
+			normal = perturbNormal2Arb( -vViewPosition, normal, normalScale, normalMap );
 
 
 		#endif
 		#endif
 
 

+ 6 - 6
src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl.js

@@ -1,4 +1,4 @@
-export default /* glsl */`
+export default /* glsl */ `
 #ifdef USE_NORMALMAP
 #ifdef USE_NORMALMAP
 
 
 	uniform sampler2D normalMap;
 	uniform sampler2D normalMap;
@@ -8,12 +8,15 @@ export default /* glsl */`
 
 
 		uniform mat3 normalMatrix;
 		uniform mat3 normalMatrix;
 
 
-	#else
+	#endif
+#endif
+
+#if defined ( USE_NORMALMAP ) || defined ( USE_CLEARCOAT_NORMALMAP )
 
 
 		// Per-Pixel Tangent Space Normal Mapping
 		// Per-Pixel Tangent Space Normal Mapping
 		// http://hacksoflife.blogspot.ch/2009/11/per-pixel-tangent-space-normal-mapping.html
 		// http://hacksoflife.blogspot.ch/2009/11/per-pixel-tangent-space-normal-mapping.html
 
 
-		vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm ) {
+		vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec2 normalScale, in sampler2D normalMap ) {
 
 
 			// Workaround for Adreno 3XX dFd*( vec3 ) bug. See #9988
 			// Workaround for Adreno 3XX dFd*( vec3 ) bug. See #9988
 
 
@@ -37,8 +40,5 @@ export default /* glsl */`
 			return normalize( tsn * mapN );
 			return normalize( tsn * mapN );
 
 
 		}
 		}
-
-	#endif
-
 #endif
 #endif
 `;
 `;

Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików