Browse Source

NodeMaterial: Add .fog and .colorSpace properties (#26440)

sunag 2 years ago
parent
commit
3d53596def

+ 2 - 0
examples/jsm/nodes/materials/MeshNormalNodeMaterial.js

@@ -17,6 +17,8 @@ class MeshNormalNodeMaterial extends NodeMaterial {
 
 
 		this.isMeshNormalNodeMaterial = true;
 		this.isMeshNormalNodeMaterial = true;
 
 
+		this.colorSpace = false;
+
 		this.setDefaultValues( defaultValues );
 		this.setDefaultValues( defaultValues );
 
 
 		this.setValues( parameters );
 		this.setValues( parameters );

+ 23 - 12
examples/jsm/nodes/materials/NodeMaterial.js

@@ -32,9 +32,12 @@ class NodeMaterial extends ShaderMaterial {
 
 
 		this.forceSinglePass = false;
 		this.forceSinglePass = false;
 
 
+		this.unlit = this.constructor === NodeMaterial.prototype.constructor; // Extended materials are not unlit by default
+
+		this.fog = true;
 		this.lights = true;
 		this.lights = true;
 		this.normals = true;
 		this.normals = true;
-		this.unlit = this.constructor === NodeMaterial.prototype.constructor; // Extended materials are not unlit by default
+		this.colorSpace = true;
 
 
 		this.lightsNode = null;
 		this.lightsNode = null;
 		this.envNode = null;
 		this.envNode = null;
@@ -321,29 +324,37 @@ class NodeMaterial extends ShaderMaterial {
 
 
 		// FOG
 		// FOG
 
 
-		const fogNode = builder.fogNode;
+		if ( this.fog === true ) {
 
 
-		if ( fogNode ) outputNode = vec4( fogNode.mixAssign( outputNode.rgb ), outputNode.a );
+			const fogNode = builder.fogNode;
+
+			if ( fogNode ) outputNode = vec4( fogNode.mixAssign( outputNode.rgb ), outputNode.a );
+
+		}
 
 
 		// ENCODING
 		// ENCODING
 
 
-		const renderTarget = renderer.getRenderTarget();
+		if ( this.colorSpace === true ) {
 
 
-		let outputColorSpace;
+			const renderTarget = renderer.getRenderTarget();
 
 
-		if ( renderTarget !== null ) {
+			let outputColorSpace;
 
 
-			outputColorSpace = renderTarget.texture.colorSpace;
+			if ( renderTarget !== null ) {
 
 
-		} else {
+				outputColorSpace = renderTarget.texture.colorSpace;
 
 
-			outputColorSpace = renderer.outputColorSpace;
+			} else {
 
 
-		}
+				outputColorSpace = renderer.outputColorSpace;
+
+			}
+
+			if ( outputColorSpace !== LinearSRGBColorSpace && outputColorSpace !== NoColorSpace ) {
 
 
-		if ( outputColorSpace !== LinearSRGBColorSpace && outputColorSpace !== NoColorSpace ) {
+				outputNode = outputNode.linearToColorSpace( outputColorSpace );
 
 
-			outputNode = outputNode.linearToColorSpace( outputColorSpace );
+			}
 
 
 		}
 		}