Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ShaderNode: Improve syntax (Fluent interface) #25074

Merged
merged 9 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/jsm/nodes/display/ToneMappingNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand All @@ -38,7 +38,7 @@ class ToneMappingNode extends TempNode {

} else {

outputNode = this.colorNode;
outputNode = colorNode;

}

Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/nodes/functions/BSDF/DFGApprox.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
sunag marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
6 changes: 3 additions & 3 deletions examples/jsm/nodes/functions/BSDF/F_Schlick.js
Original file line number Diff line number Diff line change
@@ -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 ) => {

Expand All @@ -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 ) );
sunag marked this conversation as resolved.
Show resolved Hide resolved

return add( mul( f0, sub( 1.0, fresnel ) ), mul( f90, fresnel ) );
return f0.mul( sub( 1.0, fresnel ) ).add( f90.mul( fresnel ) );

} ); // validated

Expand Down
12 changes: 6 additions & 6 deletions examples/jsm/nodes/lighting/EnvironmentNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, transformedNormalView, transformedNormalWorld, cameraViewMatrix, equirectUV, vec2 } from '../shadernode/ShaderNodeElements.js';

class EnvironmentNode extends LightingNode {

Expand Down Expand Up @@ -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 );

}

Expand All @@ -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() );

}

Expand Down Expand Up @@ -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() );

}

Expand Down
10 changes: 9 additions & 1 deletion examples/jsm/nodes/shadernode/ShaderNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand All @@ -17,7 +19,7 @@ const shaderNodeHandler = {

},

get: function ( node, prop ) {
get: function ( node, prop, nodeObj ) {

if ( typeof prop === 'string' && node[ prop ] === undefined ) {

Expand All @@ -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 );

}

}
Expand Down
2 changes: 1 addition & 1 deletion examples/webgpu_compute.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
sunag marked this conversation as resolved.
Show resolved Hide resolved

Expand Down