From 770a460bb9a0611a21d807f7a9fa8fbf47630278 Mon Sep 17 00:00:00 2001 From: sunag Date: Sun, 4 Dec 2022 06:55:49 -0300 Subject: [PATCH 1/9] ToneMappingNode: Fix property name --- examples/jsm/nodes/display/ToneMappingNode.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/jsm/nodes/display/ToneMappingNode.js b/examples/jsm/nodes/display/ToneMappingNode.js index 7efc6d43b1b213..ac75804bd5f620 100644 --- a/examples/jsm/nodes/display/ToneMappingNode.js +++ b/examples/jsm/nodes/display/ToneMappingNode.js @@ -25,7 +25,7 @@ class ToneMappingNode extends TempNode { construct( builder ) { - const colorNode = this.color || builder.context.color; + const colorNode = this.colorNode || builder.context.color; const toneMapping = this.toneMapping; const toneMappingParams = { exposure: this.exposureNode, color: colorNode }; @@ -38,7 +38,7 @@ class ToneMappingNode extends TempNode { } else { - outputNode = this.colorNode; + outputNode = colorNode; } From 8590cfb8f6be3081a828f351a53d52c9ac00f8f4 Mon Sep 17 00:00:00 2001 From: sunag Date: Sun, 4 Dec 2022 06:56:41 -0300 Subject: [PATCH 2/9] ShaderNode: Improve syntax --- examples/jsm/nodes/shadernode/ShaderNode.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/examples/jsm/nodes/shadernode/ShaderNode.js b/examples/jsm/nodes/shadernode/ShaderNode.js index d2b8fac91b9f6b..36e6897bad5442 100644 --- a/examples/jsm/nodes/shadernode/ShaderNode.js +++ b/examples/jsm/nodes/shadernode/ShaderNode.js @@ -7,6 +7,8 @@ import ConstNode from '../core/ConstNode.js'; import StackNode from '../core/StackNode.js'; import { getValueFromType } from '../core/NodeUtils.js'; +import * as NodeElements from './ShaderNodeElements.js'; + const shaderNodeHandler = { construct( NodeClosure, params ) { @@ -17,7 +19,7 @@ const shaderNodeHandler = { }, - get: function ( node, prop ) { + get: function ( node, prop, nodeObj ) { if ( typeof prop === 'string' && node[ prop ] === undefined ) { @@ -39,6 +41,12 @@ const shaderNodeHandler = { return nodeObject( new ArrayElementNode( node, new ConstNode( Number( prop ), 'uint' ) ) ); + } else if ( NodeElements[ prop ] ) { + + const nodeElement = NodeElements[ prop ]; + + return ( ...params ) => nodeElement( nodeObj, ...params ); + } } From 915d5b83be0944131910c426f106902dd3b6713d Mon Sep 17 00:00:00 2001 From: sunag Date: Sun, 4 Dec 2022 06:57:25 -0300 Subject: [PATCH 3/9] update some nodes using new syntax --- examples/jsm/nodes/functions/BSDF/DFGApprox.js | 2 +- examples/jsm/nodes/functions/BSDF/F_Schlick.js | 4 ++-- examples/jsm/nodes/lighting/EnvironmentNode.js | 10 +++++----- examples/webgpu_compute.html | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/jsm/nodes/functions/BSDF/DFGApprox.js b/examples/jsm/nodes/functions/BSDF/DFGApprox.js index a2a1b3916f8105..160bf8f4fb3efe 100644 --- a/examples/jsm/nodes/functions/BSDF/DFGApprox.js +++ b/examples/jsm/nodes/functions/BSDF/DFGApprox.js @@ -14,7 +14,7 @@ const DFGApprox = new ShaderNode( ( inputs ) => { const c1 = vec4( 1, 0.0425, 1.04, - 0.04 ); - const r = add( mul( roughness, c0 ), c1 ); + const r = roughness.mul( c0 ).add( c1 ); const a004 = add( mul( min( mul( r.x, r.x ), exp2( mul( - 9.28, dotNV ) ) ), r.x ), r.y ); diff --git a/examples/jsm/nodes/functions/BSDF/F_Schlick.js b/examples/jsm/nodes/functions/BSDF/F_Schlick.js index 409d0a5d2211d6..45fe6a4932f7a6 100644 --- a/examples/jsm/nodes/functions/BSDF/F_Schlick.js +++ b/examples/jsm/nodes/functions/BSDF/F_Schlick.js @@ -9,9 +9,9 @@ const F_Schlick = new ShaderNode( ( inputs ) => { // Optimized variant (presented by Epic at SIGGRAPH '13) // https://cdn2.unrealengine.com/Resources/files/2013SiggraphPresentationsNotes-26915738.pdf - const fresnel = exp2( mul( sub( mul( - 5.55473, dotVH ), 6.98316 ), dotVH ) ); + const fresnel = exp2( mul( - 5.55473, dotVH ).sub( 6.98316 ).mul( dotVH ) ); - return add( mul( f0, sub( 1.0, fresnel ) ), mul( f90, fresnel ) ); + return f0.mul( sub( 1.0, fresnel ) ).add( f90.mul( fresnel ) ); } ); // validated diff --git a/examples/jsm/nodes/lighting/EnvironmentNode.js b/examples/jsm/nodes/lighting/EnvironmentNode.js index ef1c0448a1cb83..59c732136eb2a2 100644 --- a/examples/jsm/nodes/lighting/EnvironmentNode.js +++ b/examples/jsm/nodes/lighting/EnvironmentNode.js @@ -30,9 +30,9 @@ class EnvironmentNode extends LightingNode { if ( reflectVec === undefined ) { - reflectVec = reflect( negate( positionViewDirection ), transformedNormalView ); - reflectVec = normalize( mix( reflectVec, transformedNormalView, mul( roughness, roughness ) ) ); - reflectVec = transformDirection( reflectVec, cameraViewMatrix ); + reflectVec = positionViewDirection.negate().reflect( transformedNormalView ); + reflectVec = reflectVec.mix( transformedNormalView, roughness.mul( roughness ) ).normalize(); + reflectVec = reflectVec.transformDirection( cameraViewMatrix ); } @@ -47,7 +47,7 @@ class EnvironmentNode extends LightingNode { // @TODO: Needed PMREM radianceTextureUVNode = equirectUV( reflectVec ); - radianceTextureUVNode = vec2( radianceTextureUVNode.x, invert( radianceTextureUVNode.y ) ); + radianceTextureUVNode = vec2( radianceTextureUVNode.x, radianceTextureUVNode.y.invert() ); } @@ -86,7 +86,7 @@ class EnvironmentNode extends LightingNode { // @TODO: Needed PMREM irradianceTextureUVNode = equirectUV( transformedNormalWorld ); - irradianceTextureUVNode = vec2( irradianceTextureUVNode.x, invert( irradianceTextureUVNode.y ) ); + irradianceTextureUVNode = vec2( irradianceTextureUVNode.x, irradianceTextureUVNode.y.invert() ); } diff --git a/examples/webgpu_compute.html b/examples/webgpu_compute.html index 19f01ed5e3b09e..86a84263ee7277 100644 --- a/examples/webgpu_compute.html +++ b/examples/webgpu_compute.html @@ -97,7 +97,7 @@ stack.assign( position, max( negate( limit ), min( limit, position ) ) ); const pointerSize = 0.1; - const distanceFromPointer = length( sub( pointer, position ) ); + const distanceFromPointer = pointer.sub( position ).length(); stack.assign( particle, cond( lessThanEqual( distanceFromPointer, pointerSize ), vec3(), position ) ); From 24a06fdbe91d0aed4c86d64df12680214e8f9780 Mon Sep 17 00:00:00 2001 From: sunag Date: Sun, 4 Dec 2022 07:10:51 -0300 Subject: [PATCH 4/9] cleanup --- examples/jsm/nodes/functions/BSDF/F_Schlick.js | 2 +- examples/jsm/nodes/lighting/EnvironmentNode.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/jsm/nodes/functions/BSDF/F_Schlick.js b/examples/jsm/nodes/functions/BSDF/F_Schlick.js index 45fe6a4932f7a6..ccde2e3cadcca3 100644 --- a/examples/jsm/nodes/functions/BSDF/F_Schlick.js +++ b/examples/jsm/nodes/functions/BSDF/F_Schlick.js @@ -1,4 +1,4 @@ -import { ShaderNode, add, sub, mul, exp2 } from '../../shadernode/ShaderNodeBaseElements.js'; +import { ShaderNode, sub, mul, exp2 } from '../../shadernode/ShaderNodeBaseElements.js'; const F_Schlick = new ShaderNode( ( inputs ) => { diff --git a/examples/jsm/nodes/lighting/EnvironmentNode.js b/examples/jsm/nodes/lighting/EnvironmentNode.js index 59c732136eb2a2..c5b9ac62905d5f 100644 --- a/examples/jsm/nodes/lighting/EnvironmentNode.js +++ b/examples/jsm/nodes/lighting/EnvironmentNode.js @@ -2,7 +2,7 @@ import LightingNode from './LightingNode.js'; import ContextNode from '../core/ContextNode.js'; import CacheNode from '../core/CacheNode.js'; import SpecularMIPLevelNode from '../utils/SpecularMIPLevelNode.js'; -import { float, mul, roughness, reflect, mix, positionViewDirection, negate, normalize, transformedNormalView, transformedNormalWorld, transformDirection, cameraViewMatrix, equirectUV, vec2, invert } from '../shadernode/ShaderNodeElements.js'; +import { float, mul, roughness, positionViewDirection, normalize, transformedNormalView, transformedNormalWorld, cameraViewMatrix, equirectUV, vec2 } from '../shadernode/ShaderNodeElements.js'; class EnvironmentNode extends LightingNode { From 12b134153d73a8600ae5074bf63c4be2862945f4 Mon Sep 17 00:00:00 2001 From: sunag Date: Sun, 4 Dec 2022 07:13:11 -0300 Subject: [PATCH 5/9] cleanup(2) --- examples/jsm/nodes/lighting/EnvironmentNode.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/jsm/nodes/lighting/EnvironmentNode.js b/examples/jsm/nodes/lighting/EnvironmentNode.js index c5b9ac62905d5f..7f7d21a1b64bbf 100644 --- a/examples/jsm/nodes/lighting/EnvironmentNode.js +++ b/examples/jsm/nodes/lighting/EnvironmentNode.js @@ -2,7 +2,7 @@ import LightingNode from './LightingNode.js'; import ContextNode from '../core/ContextNode.js'; import CacheNode from '../core/CacheNode.js'; import SpecularMIPLevelNode from '../utils/SpecularMIPLevelNode.js'; -import { float, mul, roughness, positionViewDirection, normalize, transformedNormalView, transformedNormalWorld, cameraViewMatrix, equirectUV, vec2 } from '../shadernode/ShaderNodeElements.js'; +import { float, mul, roughness, positionViewDirection, transformedNormalView, transformedNormalWorld, cameraViewMatrix, equirectUV, vec2 } from '../shadernode/ShaderNodeElements.js'; class EnvironmentNode extends LightingNode { From 7fd5325afb51b06c51fc4c5d898f83ab8b4446e3 Mon Sep 17 00:00:00 2001 From: sunag Date: Mon, 5 Dec 2022 02:55:32 -0300 Subject: [PATCH 6/9] update a few more lines --- examples/jsm/nodes/functions/BSDF/DFGApprox.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/jsm/nodes/functions/BSDF/DFGApprox.js b/examples/jsm/nodes/functions/BSDF/DFGApprox.js index 160bf8f4fb3efe..164a2f9c94bd83 100644 --- a/examples/jsm/nodes/functions/BSDF/DFGApprox.js +++ b/examples/jsm/nodes/functions/BSDF/DFGApprox.js @@ -16,9 +16,9 @@ const DFGApprox = new ShaderNode( ( inputs ) => { const r = roughness.mul( c0 ).add( c1 ); - const a004 = add( mul( min( mul( r.x, r.x ), exp2( mul( - 9.28, dotNV ) ) ), r.x ), r.y ); + const a004 = min( mul( r.x, r.x ), dotNV.mul( -9.28 ).exp2() ).mul( r.x ).add( r.y ); - const fab = add( mul( vec2( - 1.04, 1.04 ), a004 ), r.zw ); + const fab = vec2( - 1.04, 1.04 ).mul( a004 ).add( r.zw ); return fab; From 04f40aa892ce564a0e22ead706cb3651464d346f Mon Sep 17 00:00:00 2001 From: sunag Date: Mon, 5 Dec 2022 02:58:27 -0300 Subject: [PATCH 7/9] cleanup --- examples/jsm/nodes/functions/BSDF/DFGApprox.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/jsm/nodes/functions/BSDF/DFGApprox.js b/examples/jsm/nodes/functions/BSDF/DFGApprox.js index 164a2f9c94bd83..bede92738f5ba7 100644 --- a/examples/jsm/nodes/functions/BSDF/DFGApprox.js +++ b/examples/jsm/nodes/functions/BSDF/DFGApprox.js @@ -1,5 +1,5 @@ import { - ShaderNode, dotNV, vec2, vec4, add, mul, min, exp2 + ShaderNode, dotNV, vec2, vec4, mul, min } from '../../shadernode/ShaderNodeElements.js'; // Analytical approximation of the DFG LUT, one half of the From 5a9224f5029612c112f74a029e3c1059f18c8486 Mon Sep 17 00:00:00 2001 From: sunag Date: Mon, 5 Dec 2022 10:06:51 -0300 Subject: [PATCH 8/9] updates --- examples/jsm/nodes/functions/BSDF/F_Schlick.js | 2 +- examples/webgpu_compute.html | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/jsm/nodes/functions/BSDF/F_Schlick.js b/examples/jsm/nodes/functions/BSDF/F_Schlick.js index ccde2e3cadcca3..9dbdbb499a544b 100644 --- a/examples/jsm/nodes/functions/BSDF/F_Schlick.js +++ b/examples/jsm/nodes/functions/BSDF/F_Schlick.js @@ -9,7 +9,7 @@ const F_Schlick = new ShaderNode( ( inputs ) => { // Optimized variant (presented by Epic at SIGGRAPH '13) // https://cdn2.unrealengine.com/Resources/files/2013SiggraphPresentationsNotes-26915738.pdf - const fresnel = exp2( mul( - 5.55473, dotVH ).sub( 6.98316 ).mul( dotVH ) ); + const fresnel = dotVH.mul( - 5.55473 ).sub( 6.98316 ).mul( dotVH ).exp2(); return f0.mul( sub( 1.0, fresnel ) ).add( f90.mul( fresnel ) ); diff --git a/examples/webgpu_compute.html b/examples/webgpu_compute.html index 86a84263ee7277..9c38837d2e473c 100644 --- a/examples/webgpu_compute.html +++ b/examples/webgpu_compute.html @@ -91,15 +91,15 @@ const position = add( particle, velocity ); - stack.assign( velocity.x, cond( greaterThanEqual( abs( position.x ), limit.x ), negate( velocity.x ), velocity.x ) ); - stack.assign( velocity.y, cond( greaterThanEqual( abs( position.y ), limit.y ), negate( velocity.y ), velocity.y ) ); + stack.assign( velocity.x, abs( position.x ).greaterThanEqual( limit.x ).cond( velocity.x.negate(), velocity.x ) ); + stack.assign( velocity.y, abs( position.y ).greaterThanEqual( limit.y ).cond( velocity.y.negate(), velocity.y ) ); - stack.assign( position, max( negate( limit ), min( limit, position ) ) ); + stack.assign( position, max( limit.negate(), min( limit, position ) ) ); const pointerSize = 0.1; const distanceFromPointer = pointer.sub( position ).length(); - stack.assign( particle, cond( lessThanEqual( distanceFromPointer, pointerSize ), vec3(), position ) ); + stack.assign( particle, cond( distanceFromPointer.lessThanEqual( pointerSize ), vec3(), position ) ); } ); From f1eaa009898a7e4506aba9e47d4d558aa310e902 Mon Sep 17 00:00:00 2001 From: sunag Date: Mon, 5 Dec 2022 11:34:28 -0300 Subject: [PATCH 9/9] cleanup --- examples/jsm/nodes/functions/BSDF/F_Schlick.js | 2 +- examples/webgpu_compute.html | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/jsm/nodes/functions/BSDF/F_Schlick.js b/examples/jsm/nodes/functions/BSDF/F_Schlick.js index 9dbdbb499a544b..2ebdea59331c40 100644 --- a/examples/jsm/nodes/functions/BSDF/F_Schlick.js +++ b/examples/jsm/nodes/functions/BSDF/F_Schlick.js @@ -1,4 +1,4 @@ -import { ShaderNode, sub, mul, exp2 } from '../../shadernode/ShaderNodeBaseElements.js'; +import { ShaderNode, sub } from '../../shadernode/ShaderNodeBaseElements.js'; const F_Schlick = new ShaderNode( ( inputs ) => { diff --git a/examples/webgpu_compute.html b/examples/webgpu_compute.html index 9c38837d2e473c..e7a88748052469 100644 --- a/examples/webgpu_compute.html +++ b/examples/webgpu_compute.html @@ -31,8 +31,7 @@ import { ShaderNode, compute, uniform, element, storage, attribute, mul, sin, cos, - add, sub, cond, abs, negate, max, min, length, float, vec2, vec3, color, - greaterThanEqual, lessThanEqual, instanceIndex + add, cond, abs, max, min, float, vec2, vec3, color, instanceIndex } from 'three/nodes'; import { GUI } from 'three/addons/libs/lil-gui.module.min.js';