From 91b1864080f3dd15560c62cefb55a4a212919813 Mon Sep 17 00:00:00 2001 From: sunag Date: Sat, 31 Aug 2019 23:16:27 -0300 Subject: [PATCH] nodematerial revision --- examples/jsm/nodes/accessors/NormalNode.js | 12 ------ examples/jsm/nodes/accessors/ReflectNode.js | 9 ++-- examples/jsm/nodes/inputs/CubeTextureNode.js | 3 +- .../jsm/nodes/materials/nodes/StandardNode.js | 42 ++++++++++++------- 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/examples/jsm/nodes/accessors/NormalNode.js b/examples/jsm/nodes/accessors/NormalNode.js index 3724cbbbbf6450..e6fff40270effe 100644 --- a/examples/jsm/nodes/accessors/NormalNode.js +++ b/examples/jsm/nodes/accessors/NormalNode.js @@ -14,7 +14,6 @@ function NormalNode( scope ) { } NormalNode.LOCAL = 'local'; -NormalNode.BENT = 'bent'; NormalNode.WORLD = 'world'; NormalNode.prototype = Object.create( TempNode.prototype ); @@ -42,17 +41,6 @@ NormalNode.prototype.generate = function ( builder, output ) { break; - case NormalNode.BENT: - - if ( builder.isShader( 'fragment' ) ) { - if( builder.context.anisotropy ) result = 'getBentNormal( geometry, anisotropyFactor, roughnessFactor )'; - else result = 'geometry.normal'; - } else { - result = 'geometryNormal'; - } - - break; - case NormalNode.WORLD: if ( builder.isShader( 'vertex' ) ) { diff --git a/examples/jsm/nodes/accessors/ReflectNode.js b/examples/jsm/nodes/accessors/ReflectNode.js index 982bae1f6c0976..7f1d4aee6ceaa8 100644 --- a/examples/jsm/nodes/accessors/ReflectNode.js +++ b/examples/jsm/nodes/accessors/ReflectNode.js @@ -6,12 +6,11 @@ import { TempNode } from '../core/TempNode.js'; import { PositionNode } from './PositionNode.js'; import { NormalNode } from './NormalNode.js'; -function ReflectNode( scope, normal ) { +function ReflectNode( scope ) { TempNode.call( this, 'v3' ); this.scope = scope || ReflectNode.CUBE; - this.normal = normal || null; } @@ -55,7 +54,7 @@ ReflectNode.prototype.generate = function ( builder, output ) { case ReflectNode.VECTOR: - var viewNormalNode = this.normal || builder.context.viewNormal || new NormalNode(); + var viewNormalNode = builder.context.viewNormal || new NormalNode(); var roughnessNode = builder.context.roughness; var viewNormal = viewNormalNode.build( builder, 'v3' ); @@ -89,7 +88,7 @@ ReflectNode.prototype.generate = function ( builder, output ) { case ReflectNode.CUBE: - var reflectVec = new ReflectNode( ReflectNode.VECTOR, this.normal ).build( builder, 'v3' ); + var reflectVec = new ReflectNode( ReflectNode.VECTOR ).build( builder, 'v3' ); var code = 'vec3( -' + reflectVec + '.x, ' + reflectVec + '.yz )'; @@ -109,7 +108,7 @@ ReflectNode.prototype.generate = function ( builder, output ) { case ReflectNode.SPHERE: - var reflectVec = new ReflectNode( ReflectNode.VECTOR, this.normal ).build( builder, 'v3' ); + var reflectVec = new ReflectNode( ReflectNode.VECTOR ).build( builder, 'v3' ); var code = 'normalize( ( viewMatrix * vec4( ' + reflectVec + ', 0.0 ) ).xyz + vec3( 0.0, 0.0, 1.0 ) ).xy * 0.5 + 0.5'; diff --git a/examples/jsm/nodes/inputs/CubeTextureNode.js b/examples/jsm/nodes/inputs/CubeTextureNode.js index e378c530dcee76..16d5b8a431684e 100644 --- a/examples/jsm/nodes/inputs/CubeTextureNode.js +++ b/examples/jsm/nodes/inputs/CubeTextureNode.js @@ -6,14 +6,13 @@ import { InputNode } from '../core/InputNode.js'; import { ReflectNode } from '../accessors/ReflectNode.js'; import { ColorSpaceNode } from '../utils/ColorSpaceNode.js'; import { ExpressionNode } from '../core/ExpressionNode.js'; -import { NormalNode } from '../accessors/NormalNode.js'; function CubeTextureNode( value, uv, bias ) { InputNode.call( this, 'v4', { shared: true } ); this.value = value; - this.uv = uv || new ReflectNode( ReflectNode.CUBE, new NormalNode( NormalNode.BENT ) ); + this.uv = uv || new ReflectNode(); this.bias = bias; } diff --git a/examples/jsm/nodes/materials/nodes/StandardNode.js b/examples/jsm/nodes/materials/nodes/StandardNode.js index c0e9f69015a023..caba5528627388 100644 --- a/examples/jsm/nodes/materials/nodes/StandardNode.js +++ b/examples/jsm/nodes/materials/nodes/StandardNode.js @@ -12,7 +12,6 @@ import { ExpressionNode } from '../../core/ExpressionNode.js'; import { ColorNode } from '../../inputs/ColorNode.js'; import { FloatNode } from '../../inputs/FloatNode.js'; import { SpecularMIPLevelNode } from '../../utils/SpecularMIPLevelNode.js'; -import { NormalNode } from '../../accessors/NormalNode.js'; function StandardNode() { @@ -37,6 +36,7 @@ StandardNode.prototype.build = function ( builder ) { builder.define('STANDARD'); var useClearcoat = this.clearcoat || this.clearcoatRoughness || this.clearcoatNormal; + var useAnisotropy = !!this.anisotropy; if( useClearcoat ){ @@ -147,18 +147,11 @@ StandardNode.prototype.build = function ( builder ) { var specularRoughness = new ExpressionNode('material.specularRoughness', 'f' ); var clearcoatRoughness = new ExpressionNode('material.clearcoatRoughness', 'f' ); - if ( this.anisotropy ) this.anisotropy.analyze( builder ); - if ( this.anisotropyRotation ) this.anisotropyRotation.analyze( builder ); - - var anisotropy = this.anisotropy ? this.anisotropy.flow( builder, 'f' ) : undefined; - var anisotropyRotation = anisotropy && this.anisotropyRotation ? this.anisotropyRotation.flow( builder, 'f' ) : undefined; - var contextEnvironment = { roughness: specularRoughness, bias: new SpecularMIPLevelNode( specularRoughness ), - viewNormal: new ExpressionNode('normal', 'vec3'), - gamma: true, - anisotropy: !!anisotropy + viewNormal: useAnisotropy ? new ExpressionNode('getBentNormal( geometry, anisotropyFactor, roughnessFactor )', 'vec3') : new ExpressionNode('normal', 'vec3'), + gamma: true }; var contextGammaOnly = { @@ -188,6 +181,9 @@ StandardNode.prototype.build = function ( builder ) { if ( this.clearcoatRoughness ) this.clearcoatRoughness.analyze( builder ); if ( this.clearcoatNormal ) this.clearcoatNormal.analyze( builder ); + if ( useAnisotropy && this.anisotropy ) this.anisotropy.analyze( builder ); + if ( useAnisotropy && this.anisotropyRotation ) this.anisotropyRotation.analyze( builder ); + if ( this.reflectivity ) this.reflectivity.analyze( builder ); if ( this.light ) this.light.analyze( builder, { cache: 'light' } ); @@ -230,6 +226,9 @@ StandardNode.prototype.build = function ( builder ) { var clearcoatRoughness = this.clearcoatRoughness ? this.clearcoatRoughness.flow( builder, 'f' ) : undefined; var clearcoatNormal = this.clearcoatNormal ? this.clearcoatNormal.flow( builder, 'v3' ) : undefined; + var anisotropy = useAnisotropy ? this.anisotropy.flow( builder, 'f' ) : undefined; + var anisotropyRotation = useAnisotropy && this.anisotropyRotation ? this.anisotropyRotation.flow( builder, 'f' ) : undefined; + var reflectivity = this.reflectivity ? this.reflectivity.flow( builder, 'f' ) : undefined; var light = this.light ? this.light.flow( builder, 'v3', { cache: 'light' } ) : undefined; @@ -258,7 +257,7 @@ StandardNode.prototype.build = function ( builder ) { var clearcoatEnv = useClearcoat && environment ? this.environment.flow( builder, 'c', { cache: 'clearcoat', context: contextClearcoatEnvironment, slot: 'environment' } ) : undefined; var sheen = this.sheen ? this.sheen.flow( builder, 'c' ) : undefined; - builder.requires.uv[0] = builder.requires.uv[0] || !!anisotropy; // if tangents aren't available + builder.requires.uv[0] = builder.requires.uv[0] || useAnisotropy; // if tangents aren't available builder.requires.transparent = alpha !== undefined; @@ -387,10 +386,25 @@ StandardNode.prototype.build = function ( builder ) { } - if ( anisotropy ) { + if ( useAnisotropy ) { + + output.push( + anisotropy.code, + 'float anisotropyFactor = ' + anisotropy.result + ';' + ); - output.push( 'float anisotropyFactor = ' + anisotropy.result + ';' ); - output.push( 'float anisotropyRotationFactor = ' + ( anisotropyRotation ? anisotropyRotation.result : '0.' ) + ';' ); + if ( anisotropyRotation ) { + + output.push( + anisotropyRotation.code, + 'float anisotropyRotationFactor = ' + anisotropyRotation.result + ';' + ); + + } else { + + output.push( 'float anisotropyRotationFactor = 0.;' ); + + } }