Skip to content

Commit 7a1f975

Browse files
committed
Updated builds.
1 parent 288461a commit 7a1f975

9 files changed

+360
-53
lines changed

build/three.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67148,7 +67148,7 @@ function WebGLShadowMap( renderer, objects, capabilities ) {
6714867148
// Set GL state for depth map.
6714967149
_state.setBlending( NoBlending );
6715067150

67151-
if ( _state.buffers.depth.getReversed() ) {
67151+
if ( _state.buffers.depth.getReversed() === true ) {
6715267152

6715367153
_state.buffers.color.setClear( 0, 0, 0, 0 );
6715467154

build/three.module.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8474,7 +8474,7 @@ function WebGLShadowMap( renderer, objects, capabilities ) {
84748474
// Set GL state for depth map.
84758475
_state.setBlending( NoBlending );
84768476

8477-
if ( _state.buffers.depth.getReversed() ) {
8477+
if ( _state.buffers.depth.getReversed() === true ) {
84788478

84798479
_state.buffers.color.setClear( 0, 0, 0, 0 );
84808480

build/three.module.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/three.tsl.js

Lines changed: 2 additions & 1 deletion
Large diffs are not rendered by default.

build/three.tsl.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/three.webgpu.js

Lines changed: 176 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,6 +1939,16 @@ class Node extends EventDispatcher {
19391939

19401940
}
19411941

1942+
if ( result === '' && output !== null && output !== 'void' && output !== 'OutputType' ) {
1943+
1944+
// if no snippet is generated, return a default value
1945+
1946+
console.error( `THREE.TSL: Invalid generated code, expected a "${ output }".` );
1947+
1948+
result = builder.generateConst( output );
1949+
1950+
}
1951+
19421952
}
19431953

19441954
builder.removeChain( this );
@@ -3528,25 +3538,57 @@ class ShaderCallNodeInternal extends Node {
35283538
let index = 0;
35293539

35303540
inputs = new Proxy( inputs, {
3541+
35313542
get: ( target, property, receiver ) => {
35323543

3544+
let value;
3545+
35333546
if ( target[ property ] === undefined ) {
35343547

3535-
return target[ index ++ ];
3548+
value = target[ index ++ ];
35363549

35373550
} else {
35383551

3539-
return Reflect.get( target, property, receiver );
3552+
value = Reflect.get( target, property, receiver );
35403553

35413554
}
35423555

3556+
return value;
3557+
35433558
}
3559+
35443560
} );
35453561

35463562
}
35473563

3564+
const secureNodeBuilder = new Proxy( builder, {
3565+
3566+
get: ( target, property, receiver ) => {
3567+
3568+
let value;
3569+
3570+
if ( Symbol.iterator === property ) {
3571+
3572+
value = function* () {
3573+
3574+
yield undefined;
3575+
3576+
};
3577+
3578+
} else {
3579+
3580+
value = Reflect.get( target, property, receiver );
3581+
3582+
}
3583+
3584+
return value;
3585+
3586+
}
3587+
3588+
} );
3589+
35483590
const jsFunc = shaderNode.jsFunc;
3549-
const outputNode = inputs !== null || jsFunc.length > 1 ? jsFunc( inputs || [], builder ) : jsFunc( builder );
3591+
const outputNode = inputs !== null || jsFunc.length > 1 ? jsFunc( inputs || [], secureNodeBuilder ) : jsFunc( secureNodeBuilder );
35503592

35513593
result = nodeObject( outputNode );
35523594

@@ -3732,6 +3774,18 @@ const ConvertType = function ( type, cacheMap = null ) {
37323774

37333775
return ( ...params ) => {
37343776

3777+
for ( const param of params ) {
3778+
3779+
if ( param === undefined ) {
3780+
3781+
console.error( `THREE.TSL: Invalid parameter for the type "${ type }".` );
3782+
3783+
return nodeObject( new ConstNode( 0, type ) );
3784+
3785+
}
3786+
3787+
}
3788+
37353789
if ( params.length === 0 || ( ! [ 'bool', 'float', 'int', 'uint' ].includes( type ) && params.every( param => {
37363790

37373791
const paramType = typeof param;
@@ -3913,7 +3967,7 @@ class FnNode extends Node {
39133967

39143968
const type = this.getNodeType( builder );
39153969

3916-
console.warn( 'THREE.TSL: "Fn()" was declared but not invoked. Try calling it like "Fn()( ...params )".' );
3970+
console.error( 'THREE.TSL: "Fn()" was declared but not invoked. Try calling it like "Fn()( ...params )".' );
39173971

39183972
return builder.generateConst( type );
39193973

@@ -4780,16 +4834,24 @@ class UniformNode extends InputNode {
47804834
*
47814835
* @tsl
47824836
* @function
4783-
* @param {any} arg1 - The value of this node. Usually a JS primitive or three.js object (vector, matrix, color, texture).
4784-
* @param {string} [arg2] - The node type. If no explicit type is defined, the node tries to derive the type from its value.
4837+
* @param {any|string} value - The value of this uniform or your type. Usually a JS primitive or three.js object (vector, matrix, color, texture).
4838+
* @param {string} [type] - The node type. If no explicit type is defined, the node tries to derive the type from its value.
47854839
* @returns {UniformNode}
47864840
*/
4787-
const uniform = ( arg1, arg2 ) => {
4841+
const uniform = ( value, type ) => {
4842+
4843+
const nodeType = getConstNodeType( type || value );
4844+
4845+
if ( nodeType === value ) {
4846+
4847+
// if the value is a type but no having a value
47884848

4789-
const nodeType = getConstNodeType( arg2 || arg1 );
4849+
value = getValueFromType( nodeType );
4850+
4851+
}
47904852

47914853
// @TODO: get ConstNode from .traverse() in the future
4792-
const value = ( arg1 && arg1.isNode === true ) ? ( arg1.node && arg1.node.value ) || arg1.value : arg1;
4854+
value = ( value && value.isNode === true ) ? ( value.node && value.node.value ) || value.value : value;
47934855

47944856
return nodeObject( new UniformNode( value, nodeType ) );
47954857

@@ -5055,11 +5117,10 @@ class AssignNode extends TempNode {
50555117

50565118
const needsSplitAssign = this.needsSplitAssign( builder );
50575119

5120+
const target = targetNode.build( builder );
50585121
const targetType = targetNode.getNodeType( builder );
50595122

5060-
const target = targetNode.build( builder );
50615123
const source = sourceNode.build( builder, targetType );
5062-
50635124
const sourceType = sourceNode.getNodeType( builder );
50645125

50655126
const nodeData = builder.getDataFromNode( this );
@@ -7309,10 +7370,12 @@ class ConditionalNode extends Node {
73097370

73107371
//
73117372

7373+
const isUniformFlow = builder.context.uniformFlow;
7374+
73127375
const properties = builder.getNodeProperties( this );
73137376
properties.condNode = condNode;
7314-
properties.ifNode = ifNode.context( { nodeBlock: ifNode } );
7315-
properties.elseNode = elseNode ? elseNode.context( { nodeBlock: elseNode } ) : null;
7377+
properties.ifNode = isUniformFlow ? ifNode : ifNode.context( { nodeBlock: ifNode } );
7378+
properties.elseNode = elseNode ? ( isUniformFlow ? elseNode : elseNode.context( { nodeBlock: elseNode } ) ) : null;
73167379

73177380
}
73187381

@@ -7337,6 +7400,20 @@ class ConditionalNode extends Node {
73377400
nodeData.nodeProperty = nodeProperty;
73387401

73397402
const nodeSnippet = condNode.build( builder, 'bool' );
7403+
const isUniformFlow = builder.context.uniformFlow;
7404+
7405+
if ( isUniformFlow && elseNode !== null ) {
7406+
7407+
const ifSnippet = ifNode.build( builder, type );
7408+
const elseSnippet = elseNode.build( builder, type );
7409+
7410+
const mathSnippet = builder.getTernary( nodeSnippet, ifSnippet, elseSnippet );
7411+
7412+
// TODO: If node property already exists return something else
7413+
7414+
return builder.format( mathSnippet, type, output );
7415+
7416+
}
73407417

73417418
builder.addFlowCode( `\n${ builder.tab }if ( ${ nodeSnippet } ) {\n\n` ).addFlowTab();
73427419

@@ -7550,6 +7627,16 @@ class ContextNode extends Node {
75507627
*/
75517628
const context = /*@__PURE__*/ nodeProxy( ContextNode ).setParameterLength( 1, 2 );
75527629

7630+
/**
7631+
* TSL function for defining a uniformFlow context value for a given node.
7632+
*
7633+
* @tsl
7634+
* @function
7635+
* @param {Node} node - The node whose dependencies should all execute within a uniform control-flow path.
7636+
* @returns {ContextNode}
7637+
*/
7638+
const uniformFlow = ( node ) => context( node, { uniformFlow: true } );
7639+
75537640
/**
75547641
* TSL function for defining a name for the context value for a given node.
75557642
*
@@ -7581,6 +7668,7 @@ function label( node, name ) {
75817668

75827669
addMethodChaining( 'context', context );
75837670
addMethodChaining( 'label', label );
7671+
addMethodChaining( 'uniformFlow', uniformFlow );
75847672
addMethodChaining( 'setName', setName );
75857673

75867674
/**
@@ -30936,13 +31024,13 @@ class StackNode extends Node {
3093631024

3093731025
getNodeType( builder ) {
3093831026

30939-
return this.outputNode ? this.outputNode.getNodeType( builder ) : 'void';
31027+
return this.hasOutput ? this.outputNode.getNodeType( builder ) : 'void';
3094031028

3094131029
}
3094231030

3094331031
getMemberType( builder, name ) {
3094431032

30945-
return this.outputNode ? this.outputNode.getMemberType( builder, name ) : 'void';
31033+
return this.hasOutput ? this.outputNode.getMemberType( builder, name ) : 'void';
3094631034

3094731035
}
3094831036

@@ -30954,6 +31042,13 @@ class StackNode extends Node {
3095431042
*/
3095531043
add( node ) {
3095631044

31045+
if ( node.isNode !== true ) {
31046+
31047+
console.error( 'THREE.TSL: Invalid node added to stack.' );
31048+
return this;
31049+
31050+
}
31051+
3095731052
this.nodes.push( node );
3095831053

3095931054
return this;
@@ -31047,7 +31142,7 @@ class StackNode extends Node {
3104731142

3104831143
} else {
3104931144

31050-
throw new Error( 'TSL: Invalid parameter length. Case() requires at least two parameters.' );
31145+
console.error( 'THREE.TSL: Invalid parameter length. Case() requires at least two parameters.' );
3105131146

3105231147
}
3105331148

@@ -31131,6 +31226,12 @@ class StackNode extends Node {
3113131226

3113231227
}
3113331228

31229+
get hasOutput() {
31230+
31231+
return this.outputNode && this.outputNode.isNode;
31232+
31233+
}
31234+
3113431235
build( builder, ...params ) {
3113531236

3113631237
const previousBuildStack = builder.currentStack;
@@ -31181,7 +31282,19 @@ class StackNode extends Node {
3118131282

3118231283
}
3118331284

31184-
const result = this.outputNode ? this.outputNode.build( builder, ...params ) : super.build( builder, ...params );
31285+
//
31286+
31287+
let result;
31288+
31289+
if ( this.hasOutput ) {
31290+
31291+
result = this.outputNode.build( builder, ...params );
31292+
31293+
} else {
31294+
31295+
result = super.build( builder, ...params );
31296+
31297+
}
3118531298

3118631299
setCurrentStack( previousStack );
3118731300

@@ -43380,6 +43493,7 @@ var TSL = /*#__PURE__*/Object.freeze({
4338043493
uniform: uniform,
4338143494
uniformArray: uniformArray,
4338243495
uniformCubeTexture: uniformCubeTexture,
43496+
uniformFlow: uniformFlow,
4338343497
uniformGroup: uniformGroup,
4338443498
uniformTexture: uniformTexture,
4338543499
unpremultiplyAlpha: unpremultiplyAlpha,
@@ -45781,6 +45895,22 @@ class NodeBuilder {
4578145895

4578245896
}
4578345897

45898+
/**
45899+
* Returns the native snippet for a ternary operation. E.g. GLSL would output
45900+
* a ternary op as `cond ? x : y` whereas WGSL would output it as `select(y, x, cond)`
45901+
*
45902+
* @abstract
45903+
* @param {string} condSnippet - The condition determining which expression gets resolved.
45904+
* @param {string} ifSnippet - The expression to resolve to if the condition is true.
45905+
* @param {string} elseSnippet - The expression to resolve to if the condition is false.
45906+
* @return {string} The resolved method name.
45907+
*/
45908+
getTernary( /* condSnippet, ifSnippet, elseSnippet*/ ) {
45909+
45910+
return null;
45911+
45912+
}
45913+
4578445914
/**
4578545915
* Returns a node for the given hash, see {@link NodeBuilder#setHashNode}.
4578645916
*
@@ -46097,7 +46227,6 @@ class NodeBuilder {
4609746227

4609846228
}
4609946229

46100-
4610146230
/**
4610246231
* Generates the shader string for the given type and value.
4610346232
*
@@ -47876,11 +48005,6 @@ class NodeBuilder {
4787648005

4787748006
}
4787848007

47879-
/**
47880-
* Prevents the node builder from being used as an iterable in TSL.Fn(), avoiding potential runtime errors.
47881-
*/
47882-
*[ Symbol.iterator ]() { }
47883-
4788448008
}
4788548009

4788648010
/**
@@ -56502,6 +56626,20 @@ class GLSLNodeBuilder extends NodeBuilder {
5650256626

5650356627
}
5650456628

56629+
/**
56630+
* Returns the native snippet for a ternary operation.
56631+
*
56632+
* @param {string} condSnippet - The condition determining which expression gets resolved.
56633+
* @param {string} ifSnippet - The expression to resolve to if the condition is true.
56634+
* @param {string} elseSnippet - The expression to resolve to if the condition is false.
56635+
* @return {string} The resolved method name.
56636+
*/
56637+
getTernary( condSnippet, ifSnippet, elseSnippet ) {
56638+
56639+
return `${condSnippet} ? ${ifSnippet} : ${elseSnippet}`;
56640+
56641+
}
56642+
5650556643
/**
5650656644
* Returns the output struct name. Not relevant for GLSL.
5650756645
*
@@ -69029,6 +69167,21 @@ ${ flowData.code }
6902969167

6903069168
}
6903169169

69170+
/**
69171+
* Returns the native snippet for a ternary operation.
69172+
*
69173+
* @param {string} condSnippet - The condition determining which expression gets resolved.
69174+
* @param {string} ifSnippet - The expression to resolve to if the condition is true.
69175+
* @param {string} elseSnippet - The expression to resolve to if the condition is false.
69176+
* @return {string} The resolved method name.
69177+
*/
69178+
getTernary( condSnippet, ifSnippet, elseSnippet ) {
69179+
69180+
return `select( ${elseSnippet}, ${ifSnippet}, ${condSnippet} )`;
69181+
69182+
}
69183+
69184+
6903269185
/**
6903369186
* Returns the WGSL type of the given node data type.
6903469187
*

build/three.webgpu.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)