From 6169e48e150378fcc19d9751b04fc24c2a67c193 Mon Sep 17 00:00:00 2001 From: sunag Date: Fri, 14 Jul 2023 13:03:06 -0300 Subject: [PATCH] NodeMaterial: unlit property (#26429) * NodeMaterial: unlit property * cleanup --- examples/jsm/nodes/materials/NodeMaterial.js | 27 ++++++++++---------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/examples/jsm/nodes/materials/NodeMaterial.js b/examples/jsm/nodes/materials/NodeMaterial.js index 0acc2dd93ca14f..61355c4896d66f 100644 --- a/examples/jsm/nodes/materials/NodeMaterial.js +++ b/examples/jsm/nodes/materials/NodeMaterial.js @@ -1,4 +1,4 @@ -import { Material, ShaderMaterial, NoColorSpace } from 'three'; +import { Material, ShaderMaterial, NoColorSpace, LinearSRGBColorSpace } from 'three'; import { getNodeChildren, getCacheKey } from '../core/NodeUtils.js'; import { attribute } from '../core/AttributeNode.js'; import { output, diffuseColor } from '../core/PropertyNode.js'; @@ -34,6 +34,7 @@ class NodeMaterial extends ShaderMaterial { this.lights = true; this.normals = true; + this.unlit = this.constructor === NodeMaterial.prototype.constructor; // Extended materials are not unlit by default this.lightsNode = null; this.envNode = null; @@ -78,7 +79,7 @@ class NodeMaterial extends ShaderMaterial { let outputNode; - if ( this.isUnlit === false ) { + if ( this.unlit === false ) { if ( this.normals === true ) this.constructNormal( builder ); @@ -89,6 +90,12 @@ class NodeMaterial extends ShaderMaterial { outputNode = this.constructOutput( builder, vec4( outgoingLightNode, diffuseColor.a ) ); + // OUTPUT NODE + + builder.stack.assign( output, outputNode ); + + // + if ( this.outputNode !== null ) outputNode = this.outputNode; } else { @@ -328,7 +335,11 @@ class NodeMaterial extends ShaderMaterial { } - if ( outputColorSpace !== NoColorSpace ) outputNode = outputNode.linearToColorSpace( outputColorSpace ); + if ( outputColorSpace !== LinearSRGBColorSpace && outputColorSpace !== NoColorSpace ) { + + outputNode = outputNode.linearToColorSpace( outputColorSpace ); + + } // FOG @@ -336,10 +347,6 @@ class NodeMaterial extends ShaderMaterial { if ( fogNode ) outputNode = vec4( fogNode.mixAssign( outputNode.rgb ), outputNode.a ); - // OUTPUT NODE - - builder.stack.assign( output, outputNode ); - return outputNode; } @@ -439,12 +446,6 @@ class NodeMaterial extends ShaderMaterial { } - get isUnlit() { - - return this.constructor === NodeMaterial.prototype.constructor; - - } - copy( source ) { this.lightsNode = source.lightsNode;