File tree Expand file tree Collapse file tree 6 files changed +86
-30
lines changed Expand file tree Collapse file tree 6 files changed +86
-30
lines changed Original file line number Diff line number Diff line change @@ -94,9 +94,7 @@ class ContextNode extends Node {
94
94
95
95
analyze ( builder ) {
96
96
97
- const previousContext = builder . getContext ( ) ;
98
-
99
- builder . setContext ( { ...builder . context , ...this . value } ) ;
97
+ const previousContext = builder . addContext ( this . value ) ;
100
98
101
99
this . node . build ( builder ) ;
102
100
@@ -106,9 +104,7 @@ class ContextNode extends Node {
106
104
107
105
setup ( builder ) {
108
106
109
- const previousContext = builder . getContext ( ) ;
110
-
111
- builder . setContext ( { ...builder . context , ...this . value } ) ;
107
+ const previousContext = builder . addContext ( this . value ) ;
112
108
113
109
this . node . build ( builder ) ;
114
110
@@ -118,9 +114,7 @@ class ContextNode extends Node {
118
114
119
115
generate ( builder , output ) {
120
116
121
- const previousContext = builder . getContext ( ) ;
122
-
123
- builder . setContext ( { ...builder . context , ...this . value } ) ;
117
+ const previousContext = builder . addContext ( this . value ) ;
124
118
125
119
const snippet = this . node . build ( builder , output ) ;
126
120
Original file line number Diff line number Diff line change @@ -899,6 +899,22 @@ class NodeBuilder {
899
899
900
900
}
901
901
902
+ /**
903
+ * Adds context data to the builder's current context.
904
+ *
905
+ * @param {Object } context - The context to add.
906
+ * @return {Object } The previous context.
907
+ */
908
+ addContext ( context ) {
909
+
910
+ const previousContext = this . getContext ( ) ;
911
+
912
+ this . setContext ( { ...this . context , ...context } ) ;
913
+
914
+ return previousContext ;
915
+
916
+ }
917
+
902
918
/**
903
919
* Gets a context used in shader construction that can be shared across different materials.
904
920
* This is necessary since the renderer cache can reuse shaders generated in one material and use them in another.
Original file line number Diff line number Diff line change @@ -261,15 +261,9 @@ class StackNode extends Node {
261
261
262
262
for ( const childNode of this . getChildren ( ) ) {
263
263
264
- if ( childNode . isVarNode && childNode . intent = == true ) {
264
+ if ( childNode . isVarNode && childNode . isAssign ( builder ) ! == true ) {
265
265
266
- const properties = builder . getNodeProperties ( childNode ) ;
267
-
268
- if ( properties . assign !== true ) {
269
-
270
- continue ;
271
-
272
- }
266
+ continue ;
273
267
274
268
}
275
269
@@ -302,15 +296,9 @@ class StackNode extends Node {
302
296
303
297
for ( const node of this . nodes ) {
304
298
305
- if ( node . isVarNode && node . intent = == true ) {
299
+ if ( node . isVarNode && node . isAssign ( builder ) ! == true ) {
306
300
307
- const properties = builder . getNodeProperties ( node ) ;
308
-
309
- if ( properties . assign !== true ) {
310
-
311
- continue ;
312
-
313
- }
301
+ continue ;
314
302
315
303
}
316
304
Original file line number Diff line number Diff line change @@ -146,14 +146,53 @@ class VarNode extends Node {
146
146
147
147
}
148
148
149
+ isAssign ( builder ) {
150
+
151
+ if ( this . intent !== true ) return true ;
152
+
153
+ //
154
+
155
+ const properties = builder . getNodeProperties ( this ) ;
156
+
157
+ let assign = properties . assign ;
158
+
159
+ if ( assign !== true ) {
160
+
161
+ if ( this . node . isShaderCallNodeInternal && this . node . shaderNode . getLayout ( ) === null ) {
162
+
163
+ if ( builder . context . fnCall && builder . context . fnCall . shaderNode ) {
164
+
165
+ const nodeType = this . node . getNodeType ( builder ) ;
166
+
167
+ if ( nodeType !== 'void' ) {
168
+
169
+ const shaderNodeData = builder . getDataFromNode ( this . node . shaderNode ) ;
170
+
171
+ if ( shaderNodeData . hasLoop ) {
172
+
173
+ assign = true ;
174
+
175
+ }
176
+
177
+ }
178
+
179
+ }
180
+
181
+ }
182
+
183
+ }
184
+
185
+ return assign ;
186
+
187
+ }
188
+
149
189
build ( ...params ) {
150
190
151
191
if ( this . intent === true ) {
152
192
153
193
const builder = params [ 0 ] ;
154
- const properties = builder . getNodeProperties ( this ) ;
155
194
156
- if ( properties . assign !== true ) {
195
+ if ( this . isAssign ( builder ) !== true ) {
157
196
158
197
return this . node . build ( ...params ) ;
159
198
Original file line number Diff line number Diff line change @@ -488,6 +488,7 @@ class ShaderCallNodeInternal extends Node {
488
488
//
489
489
490
490
const previousSubBuildFn = builder . subBuildFn ;
491
+ const previousContext = builder . addContext ( { fnCall : this } ) ;
491
492
492
493
builder . subBuildFn = subBuild ;
493
494
@@ -565,6 +566,7 @@ class ShaderCallNodeInternal extends Node {
565
566
}
566
567
567
568
builder . subBuildFn = previousSubBuildFn ;
569
+ builder . setContext ( previousContext ) ;
568
570
569
571
if ( shaderNode . once ) {
570
572
@@ -608,6 +610,8 @@ class ShaderCallNodeInternal extends Node {
608
610
const subBuildOutput = builder . getSubBuildOutput ( this ) ;
609
611
const outputNode = this . getOutputNode ( builder ) ;
610
612
613
+ const previousContext = builder . addContext ( { fnCall : this } ) ;
614
+
611
615
if ( buildStage === 'setup' ) {
612
616
613
617
const subBuildInitialized = builder . getSubBuildProperty ( 'initialized' , this ) ;
@@ -655,6 +659,8 @@ class ShaderCallNodeInternal extends Node {
655
659
656
660
}
657
661
662
+ builder . setContext ( previousContext ) ;
663
+
658
664
return result ;
659
665
660
666
}
@@ -788,9 +794,15 @@ class ShaderNodeInternal extends Node {
788
794
789
795
}
790
796
797
+ getLayout ( ) {
798
+
799
+ return this . layout ;
800
+
801
+ }
802
+
791
803
call ( rawInputs = null ) {
792
804
793
- return nodeObject ( new ShaderCallNodeInternal ( this , rawInputs ) ) ;
805
+ return new ShaderCallNodeInternal ( this , rawInputs ) ;
794
806
795
807
}
796
808
Original file line number Diff line number Diff line change 1
1
import Node from '../core/Node.js' ;
2
2
import { expression } from '../code/ExpressionNode.js' ;
3
- import { nodeObject , nodeArray , Fn } from '../tsl/TSLBase.js' ;
3
+ import { nodeArray , Fn } from '../tsl/TSLBase.js' ;
4
4
import { error } from '../../utils.js' ;
5
5
6
6
/**
@@ -139,6 +139,13 @@ class LoopNode extends Node {
139
139
140
140
this . getProperties ( builder ) ;
141
141
142
+ if ( builder . context . fnCall ) {
143
+
144
+ const shaderNodeData = builder . getDataFromNode ( builder . context . fnCall . shaderNode ) ;
145
+ shaderNodeData . hasLoop = true ;
146
+
147
+ }
148
+
142
149
}
143
150
144
151
generate ( builder ) {
@@ -333,7 +340,7 @@ export default LoopNode;
333
340
* @param {...any } params - A list of parameters.
334
341
* @returns {LoopNode }
335
342
*/
336
- export const Loop = ( ...params ) => nodeObject ( new LoopNode ( nodeArray ( params , 'int' ) ) ) . toStack ( ) ;
343
+ export const Loop = ( ...params ) => new LoopNode ( nodeArray ( params , 'int' ) ) . toStack ( ) ;
337
344
338
345
/**
339
346
* TSL function for creating a `Continue()` expression.
You can’t perform that action at this time.
0 commit comments