File tree 2 files changed +29
-8
lines changed
2 files changed +29
-8
lines changed Original file line number Diff line number Diff line change @@ -99,17 +99,28 @@ class FunctionNode extends CodeNode {
99
99
100
100
export default FunctionNode ;
101
101
102
- const nativeFn = ( code , includes , language = '' ) => {
102
+ const nativeFn = ( code , includes = [ ] , language = '' ) => {
103
103
104
- let functionNode = null ;
104
+ for ( let i = 0 ; i < includes . length ; i ++ ) {
105
105
106
- return ( ... params ) => {
106
+ const include = includes [ i ] ;
107
107
108
- if ( functionNode === null ) functionNode = nodeObject ( new FunctionNode ( code , includes , language ) ) ;
108
+ // TSL Function: glslFn, wgslFn
109
109
110
- return functionNode . call ( ... params ) ;
110
+ if ( typeof include === 'function' ) {
111
111
112
- } ;
112
+ includes [ i ] = include . functionNode ;
113
+
114
+ }
115
+
116
+ }
117
+
118
+ const functionNode = nodeObject ( new FunctionNode ( code , includes , language ) ) ;
119
+
120
+ const fn = ( ...params ) => functionNode . call ( ...params ) ;
121
+ fn . functionNode = functionNode ;
122
+
123
+ return fn ;
113
124
114
125
} ;
115
126
Original file line number Diff line number Diff line change 166
166
167
167
// Custom WGSL ( desaturate filter )
168
168
169
- const desaturateWGSLNode = wgslFn ( `
169
+ const desaturateWGSLFn = wgslFn ( `
170
170
fn desaturate( color:vec3<f32> ) -> vec3<f32> {
171
171
172
172
let lum = vec3<f32>( 0.299, 0.587, 0.114 );
176
176
}
177
177
` ) ;
178
178
179
+ // include example
180
+
181
+ const someWGSLFn = wgslFn ( `
182
+ fn someFn( color:vec3<f32> ) -> vec3<f32> {
183
+
184
+ return desaturate( color );
185
+
186
+ }
187
+ ` , [ desaturateWGSLFn ] ) ;
188
+
179
189
material = new MeshBasicNodeMaterial ( ) ;
180
- material . colorNode = desaturateWGSLNode ( { color : texture ( uvTexture ) } ) ;
190
+ material . colorNode = someWGSLFn ( { color : texture ( uvTexture ) } ) ;
181
191
materials . push ( material ) ;
182
192
183
193
// Custom WGSL ( get texture from keywords )
You can’t perform that action at this time.
0 commit comments