Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion examples/jsm/nodes/Nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export { default as ViewportDepthNode, viewZToOrthographicDepth, orthographicDep
export { default as ExpressionNode, expression } from './code/ExpressionNode.js';
export { default as CodeNode, code, js } from './code/CodeNode.js';
export { default as FunctionCallNode, call } from './code/FunctionCallNode.js';
export { default as FunctionNode, func, fn } from './code/FunctionNode.js';
export { default as FunctionNode, nativeFn, wgslFn, glslFn } from './code/FunctionNode.js';
export { default as ScriptableNode, scriptable, global } from './code/ScriptableNode.js';
export { default as ScriptableValueNode, scriptableValue } from './code/ScriptableValueNode.js';

Expand Down
8 changes: 4 additions & 4 deletions examples/jsm/nodes/accessors/SkinningNode.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Node, { addNodeClass } from '../core/Node.js';
import { NodeUpdateType } from '../core/constants.js';
import { ShaderNode, nodeProxy } from '../shadernode/ShaderNode.js';
import { fn, nodeProxy } from '../shadernode/ShaderNode.js';
import { attribute } from '../core/AttributeNode.js';
import { uniform } from '../core/UniformNode.js';
import { add } from '../math/OperatorNode.js';
Expand All @@ -9,7 +9,7 @@ import { normalLocal } from './NormalNode.js';
import { positionLocal } from './PositionNode.js';
import { tangentLocal } from './TangentNode.js';

const Skinning = new ShaderNode( ( inputs, {}, builder ) => {
const Skinning = fn( ( inputs, {}, builder ) => {

const { index, weight, bindMatrix, bindMatrixInverse, boneMatrices } = inputs;

Expand Down Expand Up @@ -80,14 +80,14 @@ class SkinningNode extends Node {

generate( builder ) {

/*return new ShaderNode( ( {}, stack, builder ) => Skinning.call( {
/*return fn( ( {}, stack, builder ) => Skinning( {
index: this.skinIndexNode,
weight: this.skinWeightNode,
bindMatrix: this.bindMatrixNode,
bindMatrixInverse: this.bindMatrixInverseNode,
boneMatrices: this.boneMatricesNode
}, stack, builder ) ).build( builder );*/
Skinning.call( {
Skinning( {
index: this.skinIndexNode,
weight: this.skinWeightNode,
bindMatrix: this.bindMatrixNode,
Expand Down
29 changes: 25 additions & 4 deletions examples/jsm/nodes/code/FunctionNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { nodeObject } from '../shadernode/ShaderNode.js';

class FunctionNode extends CodeNode {

constructor( code = '', includes = [] ) {
constructor( code = '', includes = [], language = '' ) {

super( code, includes );
super( code, includes, language );

this.keywords = {};

Expand Down Expand Up @@ -99,8 +99,29 @@ class FunctionNode extends CodeNode {

export default FunctionNode;

export const func = ( code, includes ) => nodeObject( new FunctionNode( code, includes ) );
export const nativeFn = ( code, includes, language = '' ) => {

export const fn = ( code, includes ) => func( code, includes ).call;
let functionNode = null;

return ( ...params ) => {

if ( functionNode === null ) functionNode = nodeObject( new FunctionNode( code, includes, language ) );

return functionNode.call( ...params );

};

};

export const glslFn = ( code, includes ) => nativeFn( code, includes, 'glsl' );
export const wgslFn = ( code, includes ) => nativeFn( code, includes, 'wgsl' );

export const func = ( code, includes ) => {

console.warn( 'FunctionNode: func() is deprecated. Use nativeFn(), wgslFn() or glslFn() instead.' );

return nodeObject( new FunctionNode( code, includes ) );

};

addNodeClass( FunctionNode );
18 changes: 9 additions & 9 deletions examples/jsm/nodes/display/BlendModeNode.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
import TempNode from '../core/TempNode.js';
import { EPSILON } from '../math/MathNode.js';
import { addNodeClass } from '../core/Node.js';
import { addNodeElement, ShaderNode, nodeProxy, vec3 } from '../shadernode/ShaderNode.js';
import { addNodeElement, fn, nodeProxy, vec3 } from '../shadernode/ShaderNode.js';

export const BurnNode = new ShaderNode( ( { base, blend } ) => {
export const BurnNode = fn( ( { base, blend } ) => {

const fn = ( c ) => blend[ c ].lessThan( EPSILON ).cond( blend[ c ], base[ c ].oneMinus().div( blend[ c ] ).oneMinus().max( 0 ) );

return vec3( fn( 'x' ), fn( 'y' ), fn( 'z' ) );

} );

export const DodgeNode = new ShaderNode( ( { base, blend } ) => {
export const DodgeNode = fn( ( { base, blend } ) => {

const fn = ( c ) => blend[ c ].equal( 1.0 ).cond( blend[ c ], base[ c ].div( blend[ c ].oneMinus() ).max( 0 ) );

return vec3( fn( 'x' ), fn( 'y' ), fn( 'z' ) );

} );

export const ScreenNode = new ShaderNode( ( { base, blend } ) => {
export const ScreenNode = fn( ( { base, blend } ) => {

const fn = ( c ) => base[ c ].oneMinus().mul( blend[ c ].oneMinus() ).oneMinus();

return vec3( fn( 'x' ), fn( 'y' ), fn( 'z' ) );

} );

export const OverlayNode = new ShaderNode( ( { base, blend } ) => {
export const OverlayNode = fn( ( { base, blend } ) => {

const fn = ( c ) => base[ c ].lessThan( 0.5 ).cond( base[ c ].mul( blend[ c ], 2.0 ), base[ c ].oneMinus().mul( blend[ c ].oneMinus() ).oneMinus() );

Expand Down Expand Up @@ -57,19 +57,19 @@ class BlendModeNode extends TempNode {

if ( blendMode === BlendModeNode.BURN ) {

outputNode = BurnNode.call( params );
outputNode = BurnNode( params );

} else if ( blendMode === BlendModeNode.DODGE ) {

outputNode = DodgeNode.call( params );
outputNode = DodgeNode( params );

} else if ( blendMode === BlendModeNode.SCREEN ) {

outputNode = ScreenNode.call( params );
outputNode = ScreenNode( params );

} else if ( blendMode === BlendModeNode.OVERLAY ) {

outputNode = OverlayNode.call( params );
outputNode = OverlayNode( params );

}

Expand Down
14 changes: 7 additions & 7 deletions examples/jsm/nodes/display/ColorAdjustmentNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import TempNode from '../core/TempNode.js';
import { dot, mix } from '../math/MathNode.js';
import { add } from '../math/OperatorNode.js';
import { addNodeClass } from '../core/Node.js';
import { addNodeElement, ShaderNode, nodeProxy, float, vec3, mat3 } from '../shadernode/ShaderNode.js';
import { addNodeElement, fn, nodeProxy, float, vec3, mat3 } from '../shadernode/ShaderNode.js';

const saturationNode = new ShaderNode( ( { color, adjustment } ) => {
const saturationNode = fn( ( { color, adjustment } ) => {

return adjustment.mix( luminance( color ), color );

} );

const vibranceNode = new ShaderNode( ( { color, adjustment } ) => {
const vibranceNode = fn( ( { color, adjustment } ) => {

const average = add( color.r, color.g, color.b ).div( 3.0 );

Expand All @@ -21,7 +21,7 @@ const vibranceNode = new ShaderNode( ( { color, adjustment } ) => {

} );

const hueNode = new ShaderNode( ( { color, adjustment } ) => {
const hueNode = fn( ( { color, adjustment } ) => {

const RGBtoYIQ = mat3( 0.299, 0.587, 0.114, 0.595716, - 0.274453, - 0.321263, 0.211456, - 0.522591, 0.311135 );
const YIQtoRGB = mat3( 1.0, 0.9563, 0.6210, 1.0, - 0.2721, - 0.6474, 1.0, - 1.107, 1.7046 );
Expand Down Expand Up @@ -58,15 +58,15 @@ class ColorAdjustmentNode extends TempNode {

if ( method === ColorAdjustmentNode.SATURATION ) {

outputNode = saturationNode.call( callParams );
outputNode = saturationNode( callParams );

} else if ( method === ColorAdjustmentNode.VIBRANCE ) {

outputNode = vibranceNode.call( callParams );
outputNode = vibranceNode( callParams );

} else if ( method === ColorAdjustmentNode.HUE ) {

outputNode = hueNode.call( callParams );
outputNode = hueNode( callParams );

} else {

Expand Down
8 changes: 4 additions & 4 deletions examples/jsm/nodes/display/ColorSpaceNode.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import TempNode from '../core/TempNode.js';
import { mix } from '../math/MathNode.js';
import { addNodeClass } from '../core/Node.js';
import { addNodeElement, ShaderNode, nodeObject, nodeProxy, vec4 } from '../shadernode/ShaderNode.js';
import { addNodeElement, fn, nodeObject, nodeProxy, vec4 } from '../shadernode/ShaderNode.js';

import { LinearSRGBColorSpace, SRGBColorSpace } from 'three';

const sRGBToLinearShader = new ShaderNode( ( inputs ) => {
const sRGBToLinearShader = fn( ( inputs ) => {

const { value } = inputs;
const { rgb } = value;
Expand All @@ -20,7 +20,7 @@ const sRGBToLinearShader = new ShaderNode( ( inputs ) => {

} );

const LinearTosRGBShader = new ShaderNode( ( inputs ) => {
const LinearTosRGBShader = fn( ( inputs ) => {

const { value } = inputs;
const { rgb } = value;
Expand Down Expand Up @@ -77,7 +77,7 @@ class ColorSpaceNode extends TempNode {
if ( method === ColorSpaceNode.LINEAR_TO_LINEAR )
return node;

return Methods[ method ].call( { value: node } );
return Methods[ method ]( { value: node } );

}

Expand Down
6 changes: 3 additions & 3 deletions examples/jsm/nodes/display/NormalMapNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import { tangentView } from '../accessors/TangentNode.js';
import { uv } from '../accessors/UVNode.js';
import { faceDirection } from './FrontFacingNode.js';
import { addNodeClass } from '../core/Node.js';
import { ShaderNode, nodeProxy, vec3, mat3 } from '../shadernode/ShaderNode.js';
import { fn, nodeProxy, vec3, mat3 } from '../shadernode/ShaderNode.js';

import { TangentSpaceNormalMap, ObjectSpaceNormalMap } from 'three';

// Normal Mapping Without Precomputed Tangents
// http://www.thetenthplanet.de/archives/1180

const perturbNormal2ArbNode = new ShaderNode( ( inputs ) => {
const perturbNormal2ArbNode = fn( ( inputs ) => {

const { eye_pos, surf_norm, mapN, uv } = inputs;

Expand Down Expand Up @@ -80,7 +80,7 @@ class NormalMapNode extends TempNode {

} else {

outputNode = perturbNormal2ArbNode.call( {
outputNode = perturbNormal2ArbNode( {
eye_pos: positionView,
surf_norm: normalView,
mapN: normalMap,
Expand Down
16 changes: 8 additions & 8 deletions examples/jsm/nodes/display/ToneMappingNode.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import TempNode from '../core/TempNode.js';
import { addNodeClass } from '../core/Node.js';
import { ShaderNode, nodeObject, float, mat3 } from '../shadernode/ShaderNode.js';
import { fn, nodeObject, float, mat3 } from '../shadernode/ShaderNode.js';

import { NoToneMapping, LinearToneMapping, ReinhardToneMapping, CineonToneMapping, ACESFilmicToneMapping } from 'three';

// exposure only
const LinearToneMappingNode = new ShaderNode( ( { color, exposure } ) => {
const LinearToneMappingNode = fn( ( { color, exposure } ) => {

return color.mul( exposure ).clamp();

} );

// source: https://www.cs.utah.edu/docs/techreports/2002/pdf/UUCS-02-001.pdf
const ReinhardToneMappingNode = new ShaderNode( ( { color, exposure } ) => {
const ReinhardToneMappingNode = fn( ( { color, exposure } ) => {

color = color.mul( exposure );

Expand All @@ -21,7 +21,7 @@ const ReinhardToneMappingNode = new ShaderNode( ( { color, exposure } ) => {
} );

// source: http://filmicworlds.com/blog/filmic-tonemapping-operators/
const OptimizedCineonToneMappingNode = new ShaderNode( ( { color, exposure } ) => {
const OptimizedCineonToneMappingNode = fn( ( { color, exposure } ) => {

// optimized filmic operator by Jim Hejl and Richard Burgess-Dawson
color = color.mul( exposure );
Expand All @@ -35,7 +35,7 @@ const OptimizedCineonToneMappingNode = new ShaderNode( ( { color, exposure } ) =
} );

// source: https://github.com/selfshadow/ltc_code/blob/master/webgl/shaders/ltc/ltc_blit.fs
const RRTAndODTFit = new ShaderNode( ( { color } ) => {
const RRTAndODTFit = fn( ( { color } ) => {

const a = color.mul( color.add( 0.0245786 ) ).sub( 0.000090537 );
const b = color.mul( color.add( 0.4329510 ).mul( 0.983729 ) ).add( 0.238081 );
Expand All @@ -45,7 +45,7 @@ const RRTAndODTFit = new ShaderNode( ( { color } ) => {
} );

// source: https://github.com/selfshadow/ltc_code/blob/master/webgl/shaders/ltc/ltc_blit.fs
const ACESFilmicToneMappingNode = new ShaderNode( ( { color, exposure } ) => {
const ACESFilmicToneMappingNode = fn( ( { color, exposure } ) => {

// sRGB => XYZ => D65_2_D60 => AP1 => RRT_SAT
const ACESInputMat = mat3(
Expand All @@ -66,7 +66,7 @@ const ACESFilmicToneMappingNode = new ShaderNode( ( { color, exposure } ) => {
color = ACESInputMat.mul( color );

// Apply RRT and ODT
color = RRTAndODTFit.call( { color } );
color = RRTAndODTFit( { color } );

color = ACESOutputMat.mul( color );

Expand Down Expand Up @@ -118,7 +118,7 @@ class ToneMappingNode extends TempNode {

if ( toneMappingNode ) {

outputNode = toneMappingNode.call( toneMappingParams );
outputNode = toneMappingNode( toneMappingParams );

} else {

Expand Down
10 changes: 5 additions & 5 deletions examples/jsm/nodes/functions/BSDF/BRDF_BlinnPhong.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@ import F_Schlick from './F_Schlick.js';
import { shininess, specularColor } from '../../core/PropertyNode.js';
import { transformedNormalView } from '../../accessors/NormalNode.js';
import { positionViewDirection } from '../../accessors/PositionNode.js';
import { ShaderNode, float } from '../../shadernode/ShaderNode.js';
import { fn, float } from '../../shadernode/ShaderNode.js';

const G_BlinnPhong_Implicit = () => float( 0.25 );

const D_BlinnPhong = new ShaderNode( ( { dotNH } ) => {
const D_BlinnPhong = fn( ( { dotNH } ) => {

return shininess.mul( 0.5 / Math.PI ).add( 1.0 ).mul( dotNH.pow( shininess ) );

} );

const BRDF_BlinnPhong = new ShaderNode( ( { lightDirection } ) => {
const BRDF_BlinnPhong = fn( ( { lightDirection } ) => {

const halfDir = lightDirection.add( positionViewDirection ).normalize();

const dotNH = transformedNormalView.dot( halfDir ).clamp();
const dotVH = positionViewDirection.dot( halfDir ).clamp();

const F = F_Schlick.call( { f0: specularColor, f90: 1.0, dotVH } );
const F = F_Schlick( { f0: specularColor, f90: 1.0, dotVH } );
const G = G_BlinnPhong_Implicit();
const D = D_BlinnPhong.call( { dotNH } );
const D = D_BlinnPhong( { dotNH } );

return F.mul( G ).mul( D );

Expand Down
10 changes: 5 additions & 5 deletions examples/jsm/nodes/functions/BSDF/BRDF_GGX.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import V_GGX_SmithCorrelated from './V_GGX_SmithCorrelated.js';
import D_GGX from './D_GGX.js';
import { transformedNormalView } from '../../accessors/NormalNode.js';
import { positionViewDirection } from '../../accessors/PositionNode.js';
import { ShaderNode } from '../../shadernode/ShaderNode.js';
import { fn } from '../../shadernode/ShaderNode.js';

// GGX Distribution, Schlick Fresnel, GGX_SmithCorrelated Visibility
const BRDF_GGX = new ShaderNode( ( inputs ) => {
const BRDF_GGX = fn( ( inputs ) => {

const { lightDirection, f0, f90, roughness } = inputs;

Expand All @@ -21,9 +21,9 @@ const BRDF_GGX = new ShaderNode( ( inputs ) => {
const dotNH = normalView.dot( halfDir ).clamp();
const dotVH = positionViewDirection.dot( halfDir ).clamp();

const F = F_Schlick.call( { f0, f90, dotVH } );
const V = V_GGX_SmithCorrelated.call( { alpha, dotNL, dotNV } );
const D = D_GGX.call( { alpha, dotNH } );
const F = F_Schlick( { f0, f90, dotVH } );
const V = V_GGX_SmithCorrelated( { alpha, dotNL, dotNV } );
const D = D_GGX( { alpha, dotNH } );

return F.mul( V ).mul( D );

Expand Down
4 changes: 2 additions & 2 deletions examples/jsm/nodes/functions/BSDF/BRDF_Lambert.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ShaderNode } from '../../shadernode/ShaderNode.js';
import { fn } from '../../shadernode/ShaderNode.js';

const BRDF_Lambert = new ShaderNode( ( inputs ) => {
const BRDF_Lambert = fn( ( inputs ) => {

return inputs.diffuseColor.mul( 1 / Math.PI ); // punctual light

Expand Down
Loading