Kaynağa Gözat

NodeMaterial - clearCoatNormal

sunag 6 yıl önce
ebeveyn
işleme
0519f53208

+ 1 - 1
examples/jsm/nodes/accessors/NormalNode.js

@@ -36,7 +36,7 @@ NormalNode.prototype.generate = function ( builder, output ) {
 
 		case NormalNode.LOCAL:
 
-			result = 'normal';
+			result = 'geometryNormal';
 
 			break;
 

+ 1 - 0
examples/jsm/nodes/materials/StandardNodeMaterial.js

@@ -27,6 +27,7 @@ NodeUtils.addShortcuts( StandardNodeMaterial.prototype, 'fragment', [
 	'reflectivity',
 	'clearCoat',
 	'clearCoatRoughness',
+	'clearCoatNormal',
 	'normal',
 	'emissive',
 	'ambient',

+ 13 - 1
examples/jsm/nodes/materials/nodes/StandardNode.js

@@ -32,7 +32,7 @@ StandardNode.prototype.build = function ( builder ) {
 
 	var code;
 
-	builder.define( this.clearCoat || this.clearCoatRoughness ? 'PHYSICAL' : 'STANDARD' );
+	builder.define( this.clearCoat || this.clearCoatRoughness || this.clearCoatNormal ? 'PHYSICAL' : 'STANDARD' );
 
 	builder.requires.lights = true;
 
@@ -145,6 +145,7 @@ StandardNode.prototype.build = function ( builder ) {
 
 		if ( this.clearCoat ) this.clearCoat.analyze( builder );
 		if ( this.clearCoatRoughness ) this.clearCoatRoughness.analyze( builder );
+		if ( this.clearCoatNormal ) this.clearCoatNormal.analyze( builder );
 
 		if ( this.reflectivity ) this.reflectivity.analyze( builder );
 
@@ -184,6 +185,7 @@ StandardNode.prototype.build = function ( builder ) {
 
 		var clearCoat = this.clearCoat ? this.clearCoat.flow( builder, 'f' ) : undefined;
 		var clearCoatRoughness = this.clearCoatRoughness ? this.clearCoatRoughness.flow( builder, 'f' ) : undefined;
+		var clearCoatNormal = this.clearCoatNormal ? this.clearCoatNormal.flow( builder, 'v3' ) : undefined;
 
 		var reflectivity = this.reflectivity ? this.reflectivity.flow( builder, 'f' ) : undefined;
 
@@ -238,6 +240,7 @@ StandardNode.prototype.build = function ( builder ) {
 
 			// add before: prevent undeclared normal
 			"	#include <normal_fragment_begin>",
+			"	#include <clearcoat_normal_fragment_begin>",
 
 			// add before: prevent undeclared material
 			"	PhysicalMaterial material;",
@@ -289,6 +292,15 @@ StandardNode.prototype.build = function ( builder ) {
 
 		}
 
+		if ( clearCoatNormal ) {
+
+			output.push(
+				clearCoatNormal.code,
+				'clearCoatNormal = ' + clearCoatNormal.result + ';'
+			);
+
+		}
+
 		// optimization for now
 
 		output.push(

+ 17 - 0
examples/webgl_materials_nodes.html

@@ -49,6 +49,7 @@
 				decalDiffuse: { url: 'textures/decal/decal-diffuse.png' },
 				decalNormal: { url: 'textures/decal/decal-normal.jpg' },
 				cloud: { url: 'textures/lava/cloud.png' },
+				carbonNormal: { url: 'textures/carbon/Carbon_Normal.png' },
 				spherical: { url: 'textures/envmap.png' }
 			};
 
@@ -742,6 +743,7 @@
 						//mtl.reflectivity = // reflectivity (float)
 						//mtl.clearCoat = // clearCoat (float)
 						//mtl.clearCoatRoughness = // clearCoatRoughness (float)
+						//mtl.clearCoatNormal = // clearCoatNormal (vec3)
 						//mtl.normal = // normal (vec3)
 						//mtl.emissive = // emissive color (vec3)
 						//mtl.ambient = // ambient color (vec3)
@@ -754,6 +756,7 @@
 						var mask = new Nodes.SwitchNode( new Nodes.TextureNode( getTexture( "decalDiffuse" ) ), 'w' );
 
 						var normalScale = new Nodes.FloatNode( .3 );
+						var clearCoatNormalScale = new Nodes.FloatNode( .1 );
 
 						var roughnessA = new Nodes.FloatNode( .5 );
 						var metalnessA = new Nodes.FloatNode( .5 );
@@ -785,12 +788,20 @@
 							Nodes.OperatorNode.MUL
 						);
 
+						var clearCoatNormalMask = new Nodes.OperatorNode(
+							mask,
+							clearCoatNormalScale,
+							Nodes.OperatorNode.MUL
+						);
+
 						mtl.color = new Nodes.ColorNode( 0xEEEEEE );
 						mtl.roughness = roughness;
 						mtl.metalness = metalness;
 						mtl.reflectivity = reflectivity;
 						mtl.clearCoat = clearCoat;
 						mtl.clearCoatRoughness = clearCoatRoughness;
+						mtl.clearCoatNormal = new Nodes.NormalMapNode( new Nodes.TextureNode( getTexture( "grassNormal" ) ) );
+						mtl.clearCoatNormal.scale = clearCoatNormalMask;
 						mtl.environment = new Nodes.CubeTextureNode( cubemap );
 						mtl.normal = new Nodes.NormalMapNode( new Nodes.TextureNode( getTexture( "grassNormal" ) ) );
 						mtl.normal.scale = normalMask;
@@ -821,6 +832,12 @@
 
 						}, false, 0, 1 );
 
+						addGui( 'clearCoatNormalScale', clearCoatNormalScale.value, function ( val ) {
+
+							clearCoatNormalScale.value = val;
+
+						}, false, 0, 1 );
+
 						addGui( 'roughnessA', roughnessA.value, function ( val ) {
 
 							roughnessA.value = val;

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

@@ -1,7 +1,7 @@
 export default /* glsl */`
-#ifdef USE_CLEARCOAT_NORMALMAP
+#ifdef PHYSICAL
 
-  vec3 clearCoatNormal = geometryNormal;
+	vec3 clearCoatNormal = geometryNormal;
 
 #endif
 `;

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

@@ -20,14 +20,10 @@ geometry.position = - vViewPosition;
 geometry.normal = normal;
 geometry.viewDir = normalize( vViewPosition );
 
-#ifdef USE_CLEARCOAT_NORMALMAP
+#ifdef PHYSICAL
 
 	geometry.clearCoatNormal = clearCoatNormal;
 
-#else
-
-	geometry.clearCoatNormal = geometryNormal;
-
 #endif
 
 IncidentLight directLight;

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

@@ -33,7 +33,7 @@ export default /* glsl */`
 
 #endif
 
-// non perturbed normal for clearcoat
+// non perturbed normal for clearcoat among others
 
 vec3 geometryNormal = normal;