Browse Source

Implemented normalmaps

arobertson0 6 years ago
parent
commit
cf95c7e167

File diff suppressed because it is too large
+ 18 - 9
build/three.js


+ 18 - 9
build/three.module.js

@@ -15109,18 +15109,23 @@ float clearCoatDHRApprox( const in float roughness, const in float dotNL ) {
 void RE_Direct_Physical( const in IncidentLight directLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {
 void RE_Direct_Physical( const in IncidentLight directLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {
 
 
 	float dotNL = saturate( dot( geometry.normal, directLight.direction ) );
 	float dotNL = saturate( dot( geometry.normal, directLight.direction ) );
-
 	vec3 irradiance = dotNL * directLight.color;
 	vec3 irradiance = dotNL * directLight.color;
 
 
+	#ifndef STANDARD
+		float ccDotNV = saturate( dot( geometry.clearCoatNormal, geometry.viewDir ) );
+		float ccDotNL = ccDotNV;
+		vec3 ccIrradiance= ccDotNL * directLight.color;
+	#endif
+
 	#ifndef PHYSICALLY_CORRECT_LIGHTS
 	#ifndef PHYSICALLY_CORRECT_LIGHTS
 
 
 		irradiance *= PI; // punctual light
 		irradiance *= PI; // punctual light
-
+		#ifndef STANDARD
+			ccIrradiance *= PI; // punctual light
+		#endif
 	#endif
 	#endif
 
 
 	#ifndef STANDARD
 	#ifndef STANDARD
-		float ccDotNV = saturate( dot( geometry.clearCoatNormal, geometry.viewDir ) );
-		float ccDotNL = ccDotNV;
 		float clearCoatDHR = material.clearCoat * clearCoatDHRApprox( material.clearCoatRoughness, ccDotNL );
 		float clearCoatDHR = material.clearCoat * clearCoatDHRApprox( material.clearCoatRoughness, ccDotNL );
 	#else
 	#else
 		float clearCoatDHR = 0.0;
 		float clearCoatDHR = 0.0;
@@ -15132,7 +15137,7 @@ void RE_Direct_Physical( const in IncidentLight directLight, const in GeometricC
 
 
 	#ifndef STANDARD
 	#ifndef STANDARD
 
 
-		reflectedLight.directSpecular += irradiance * material.clearCoat * BRDF_ClearCoat_GGX( directLight, geometry, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );
+		reflectedLight.directSpecular += ccIrradiance * material.clearCoat * BRDF_ClearCoat_GGX( directLight, geometry, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );
 
 
 	#endif
 	#endif
 
 
@@ -15462,7 +15467,7 @@ vec3 clearCoatNormal = clearCoatGeometryNormals ?
 */
 */
 
 
 var clearcoat_normal_fragment_maps = /* glsl */ `
 var clearcoat_normal_fragment_maps = /* glsl */ `
-#if defined( USE_NORMALMAP )
+#if defined( USE_NORMALMAP ) || defined ( USE_CLEARCOAT_NORMALMAP )
 
 
 	#ifdef USE_TANGENT
 	#ifdef USE_TANGENT
 
 
@@ -15542,9 +15547,13 @@ var clearcoat_normal_fragment_maps = /* glsl */ `
 */
 */
 
 
 var clearcoat_normalmap_pars_fragment = /* glsl */ `
 var clearcoat_normalmap_pars_fragment = /* glsl */ `
-#ifdef USE_NORMALMAP
+#if defined( USE_NORMALMAP ) || defined ( USE_CLEARCOAT_NORMALMAP )
 
 
-	//uniform sampler2D normalMap;
+	#ifdef USE_CLEARCOAT_NORMALMAP
+		uniform sampler2D clearCoatNormalMap;
+	#else
+		#define clearCoatNormalMap normalMap
+	#endif
 	uniform vec2 clearCoatNormalScale;
 	uniform vec2 clearCoatNormalScale;
 
 
 		// Per-Pixel Tangent Space Normal Mapping
 		// Per-Pixel Tangent Space Normal Mapping
@@ -15566,7 +15575,7 @@ var clearcoat_normalmap_pars_fragment = /* glsl */ `
 			vec3 N = normalize( surf_norm );
 			vec3 N = normalize( surf_norm );
 			mat3 tsn = mat3( S, T, N );
 			mat3 tsn = mat3( S, T, N );
 
 
-			vec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;
+			vec3 mapN = texture2D( clearCoatNormalMap, vUv ).xyz * 2.0 - 1.0;
 
 
 			mapN.xy *= clearCoatNormalScale;
 			mapN.xy *= clearCoatNormalScale;
 			mapN.xy *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );
 			mapN.xy *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );

+ 4 - 4
examples/_.html

@@ -73,7 +73,7 @@
 		const sphereSpacing = 1.25 * sphereSize * 2;
 		const sphereSpacing = 1.25 * sphereSize * 2;
 
 
 		const variationsX = [
 		const variationsX = [
-			(mat, scale, map) => { mat.clearCoatNormalScale.copy(	mat.normalScale); },
+			(mat, scale, map) => { mat.clearCoatNormalScale.copy(mat.normalScale); },
 			(mat, scale, map) => { mat.clearCoatNormalScale = new THREE.Vector2(scale, scale); },
 			(mat, scale, map) => { mat.clearCoatNormalScale = new THREE.Vector2(scale, scale); },
 			(mat, scale, map) => {
 			(mat, scale, map) => {
 				mat.clearCoatNormalScale = new THREE.Vector2(scale, scale);
 				mat.clearCoatNormalScale = new THREE.Vector2(scale, scale);
@@ -168,7 +168,7 @@
 							variationsX[ii](mat, 1, normalMaps.tentacle);
 							variationsX[ii](mat, 1, normalMaps.tentacle);
 							variationsY[jj](mat, 1, normalMaps.face);
 							variationsY[jj](mat, 1, normalMaps.face);
 							var mesh = new THREE.Mesh(geometry, mat);
 							var mesh = new THREE.Mesh(geometry, mat);
-
+							meshes.push(mesh);
 							mesh.position.x = (ii - (maxI - 1) / 2) * sphereSpacing;
 							mesh.position.x = (ii - (maxI - 1) / 2) * sphereSpacing;
 							mesh.position.y = (jj - (maxJ - 1) / 2) * sphereSpacing;
 							mesh.position.y = (jj - (maxJ - 1) / 2) * sphereSpacing;
 							scene.add(mesh);
 							scene.add(mesh);
@@ -266,9 +266,9 @@
 
 
 
 
 			gui.add(guiMatParams, 'normalMap', guiNormalMapNames);
 			gui.add(guiMatParams, 'normalMap', guiNormalMapNames);
-			gui.add(guiMatParams, 'normalScale', 0, 10, 0.01);
+			gui.add(guiMatParams, 'normalScale', 0, 1, 0.01);
 			gui.add(guiMatParams, 'clearCoatNormalMap', guiNormalMapNames);
 			gui.add(guiMatParams, 'clearCoatNormalMap', guiNormalMapNames);
-			gui.add(guiMatParams, 'clearCoatNormalScale', 0, 10, 0.01);
+			gui.add(guiMatParams, 'clearCoatNormalScale', 0, 1, 0.01);
 
 
 			gui.open();
 			gui.open();
 		}
 		}

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

@@ -1,5 +1,5 @@
 export default /* glsl */ `
 export default /* glsl */ `
-#if defined( USE_NORMALMAP )
+#if defined( USE_NORMALMAP ) || defined ( USE_CLEARCOAT_NORMALMAP )
 
 
 	#ifdef USE_TANGENT
 	#ifdef USE_TANGENT
 
 

+ 7 - 3
src/renderers/shaders/ShaderChunk/clearcoat_normalmap_pars_fragment.glsl.js

@@ -1,7 +1,11 @@
 export default /* glsl */ `
 export default /* glsl */ `
-#ifdef USE_NORMALMAP
+#if defined( USE_NORMALMAP ) || defined ( USE_CLEARCOAT_NORMALMAP )
 
 
-	//uniform sampler2D normalMap;
+	#ifdef USE_CLEARCOAT_NORMALMAP
+		uniform sampler2D clearCoatNormalMap;
+	#else
+		#define clearCoatNormalMap normalMap
+	#endif
 	uniform vec2 clearCoatNormalScale;
 	uniform vec2 clearCoatNormalScale;
 
 
 		// Per-Pixel Tangent Space Normal Mapping
 		// Per-Pixel Tangent Space Normal Mapping
@@ -23,7 +27,7 @@ export default /* glsl */ `
 			vec3 N = normalize( surf_norm );
 			vec3 N = normalize( surf_norm );
 			mat3 tsn = mat3( S, T, N );
 			mat3 tsn = mat3( S, T, N );
 
 
-			vec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;
+			vec3 mapN = texture2D( clearCoatNormalMap, vUv ).xyz * 2.0 - 1.0;
 
 
 			mapN.xy *= clearCoatNormalScale;
 			mapN.xy *= clearCoatNormalScale;
 			mapN.xy *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );
 			mapN.xy *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );

Some files were not shown because too many files changed in this diff