@@ -82,23 +82,23 @@ Object.assign(NodeMaterial.prototype, {
82
82
var graphVar = this . graphData . graphVars [ n ] ;
83
83
84
84
if ( graphVar . name . startsWith ( 'IN_' ) || ( graphVar . name . startsWith ( 'CONST_' ) && graphVar . type === 'sampler2D' ) ) {
85
- var g_id = '_' + this . id ;
85
+ var matId = '_' + this . id ;
86
86
87
87
switch ( graphVar . type ) {
88
88
case 'sampler2D' :
89
- this . setParameter ( graphVar . name + g_id , graphVar . valueTex ) ;
89
+ this . setParameter ( graphVar . name + matId , graphVar . valueTex ) ;
90
90
break ;
91
91
case 'float' :
92
- this . setParameter ( graphVar . name + g_id , graphVar . valueX ) ;
92
+ this . setParameter ( graphVar . name + matId , graphVar . valueX ) ;
93
93
break ;
94
94
case 'vec2' :
95
- this . setParameter ( graphVar . name + g_id , [ graphVar . valueX , graphVar . valueY ] ) ;
95
+ this . setParameter ( graphVar . name + matId , [ graphVar . valueX , graphVar . valueY ] ) ;
96
96
break ;
97
97
case 'vec3' :
98
- this . setParameter ( graphVar . name + g_id , [ graphVar . valueX , graphVar . valueY , graphVar . valueZ ] ) ;
98
+ this . setParameter ( graphVar . name + matId , [ graphVar . valueX , graphVar . valueY , graphVar . valueZ ] ) ;
99
99
break ;
100
100
case 'vec4' :
101
- this . setParameter ( graphVar . name + g_id , [ graphVar . valueX , graphVar . valueY , graphVar . valueZ , graphVar . valueW ] ) ;
101
+ this . setParameter ( graphVar . name + matId , [ graphVar . valueX , graphVar . valueY , graphVar . valueZ , graphVar . valueW ] ) ;
102
102
break ;
103
103
case 'samplerCube' :
104
104
default :
@@ -107,16 +107,6 @@ Object.assign(NodeMaterial.prototype, {
107
107
}
108
108
}
109
109
}
110
- //
111
- // if (this._depGraphTextureList)
112
- // {
113
- // for (var i = 0; i < this._depGraphTextureList.length; i++)
114
- // {
115
- // var depGraphTexture=this._depGraphTextureList[i];
116
- //
117
- // this.setParameter(depGraphTexture.name, depGraphTexture.valueTex);
118
- // }
119
- // }
120
110
121
111
if ( this . dirtyShader || ! this . _scene ) {
122
112
this . shader = null ;
@@ -125,26 +115,6 @@ Object.assign(NodeMaterial.prototype, {
125
115
} ,
126
116
127
117
updateShader : function ( device , scene , objDefs , staticLightList , pass , sortedLights ) {
128
- // update dynamic lighting - for now main light is first directional light in slot 0 of 32 slots
129
- //
130
- // var dynamicLightlist = [];
131
- // var mainLight;
132
- //
133
- // for (i = 0; i < sortedLights[LIGHTTYPE_DIRECTIONAL].length; i++)
134
- // {
135
- // var light = sortedLights[LIGHTTYPE_DIRECTIONAL][i];
136
- // if (light.enabled && light. ) {
137
- // if (light.mask & mask) {
138
- // if (lType !== LIGHTTYPE_DIRECTIONAL) {
139
- // if (light.isStatic) {
140
- // continue;
141
- // }
142
- // }
143
- // lightsFiltered.push(light);
144
- // }
145
- // }
146
- // }
147
- //
148
118
if ( this . hasValidGraphData ( ) ) {
149
119
this . initShader ( device ) ;
150
120
this . dirtyShader = false ;
@@ -308,28 +278,28 @@ Object.assign(NodeMaterial.prototype, {
308
278
var functionString = this . graphData . customFuncGlsl . trim ( ) ;
309
279
310
280
var head = functionString . split ( ")" ) [ 0 ] ;
311
- var rettype_funcname = head . split ( "(" ) [ 0 ] ;
312
- var rettype = rettype_funcname . split ( " " ) [ 0 ] ;
281
+ var retTypeAndFuncName = head . split ( "(" ) [ 0 ] ;
282
+ var retType = retTypeAndFuncName . split ( " " ) [ 0 ] ;
313
283
var params = head . split ( "(" ) [ 1 ] . split ( "," ) ;
314
284
315
- this . name = rettype_funcname . split ( " " ) [ 1 ] ;
285
+ this . name = retTypeAndFuncName . split ( " " ) [ 1 ] ;
316
286
// TODO check for function name clashes - maybe replace func name in function string with hash key?
317
287
318
- if ( rettype != "void" ) {
319
- this . addOutput ( rettype , 'ret' ) ;
288
+ if ( retType != "void" ) {
289
+ this . addOutput ( retType , 'ret' ) ;
320
290
}
321
291
322
292
for ( var p = 0 ; p < params . length ; p ++ ) {
323
- var io_type_name = params [ p ] . split ( " " ) ;
293
+ var inOrOutAndTypeAndName = params [ p ] . split ( " " ) ;
324
294
325
- if ( io_type_name [ 0 ] === "" ) io_type_name . shift ( ) ;
295
+ if ( inOrOutAndTypeAndName [ 0 ] === "" ) inOrOutAndTypeAndName . shift ( ) ;
326
296
327
- if ( io_type_name [ 0 ] === "out" ) {
328
- this . addOutput ( io_type_name [ 1 ] , io_type_name [ 2 ] ) ;
297
+ if ( inOrOutAndTypeAndName [ 0 ] === "out" ) {
298
+ this . addOutput ( inOrOutAndTypeAndName [ 1 ] , inOrOutAndTypeAndName [ 2 ] ) ;
329
299
// this.defineOuputGetter(this.outputName[this.outputName.length - 1], this.outputName.length - 1);
330
300
}
331
- if ( io_type_name [ 0 ] === "in" ) {
332
- this . addInput ( io_type_name [ 1 ] , io_type_name [ 2 ] ) ;
301
+ if ( inOrOutAndTypeAndName [ 0 ] === "in" ) {
302
+ this . addInput ( inOrOutAndTypeAndName [ 1 ] , inOrOutAndTypeAndName [ 2 ] ) ;
333
303
// this.defineInputSetter(this.inputName[this.inputName.length - 1], this.inputName.length - 1);
334
304
} else {
335
305
// unsupported parameter !!! TODO add support for more parameter types?
@@ -462,10 +432,10 @@ Object.assign(NodeMaterial.prototype, {
462
432
var generatedGlsl = '' ;
463
433
// run through inputs (and const sampler2Ds) to declare uniforms - (default) values are set elsewhere
464
434
for ( i = 0 ; i < this . graphData . graphVars . length ; i ++ ) {
465
- var g_id = '_' + this . id ;
435
+ var matId = '_' + this . id ;
466
436
graphVar = this . graphData . graphVars [ i ] ;
467
437
if ( graphVar . name . startsWith ( 'IN_' ) || ( graphVar . name . startsWith ( 'CONST_' ) && graphVar . type === 'sampler2D' ) ) {
468
- generatedGlsl += 'uniform ' + graphVar . type + ' ' + graphVar . name + g_id + ';\n' ;
438
+ generatedGlsl += 'uniform ' + graphVar . type + ' ' + graphVar . name + matId + ';\n' ;
469
439
}
470
440
}
471
441
// run through constants values are set here (except for textures - which have to be uniforms)
@@ -515,8 +485,8 @@ Object.assign(NodeMaterial.prototype, {
515
485
516
486
depGraphList . push ( funcString ) ;
517
487
}
518
- var t_len = depGraphList . length ; // need this because pop() reduces array length!
519
- for ( i = 0 ; i < t_len ; i ++ ) {
488
+ var tLen = depGraphList . length ; // need this because pop() reduces array length!
489
+ for ( i = 0 ; i < tLen ; i ++ ) {
520
490
generatedGlsl += depGraphList . pop ( ) ;
521
491
}
522
492
@@ -531,10 +501,10 @@ Object.assign(NodeMaterial.prototype, {
531
501
var outNames = { } ;
532
502
533
503
for ( var i = 0 ; i < this . graphData . graphVars . length ; i ++ ) {
534
- var g_id = '_' + this . id ;
504
+ var matId = '_' + this . id ;
535
505
var graphVar = this . graphData . graphVars [ i ] ;
536
506
if ( graphVar . name . startsWith ( 'IN_' ) ) {
537
- inNames [ graphVar . name ] = graphVar . name + g_id ;
507
+ inNames [ graphVar . name ] = graphVar . name + matId ;
538
508
}
539
509
if ( graphVar . name . startsWith ( 'OUT_' ) ) {
540
510
generatedGlsl += graphVar . type + ' ' + graphVar . name + ';\n' ;
@@ -559,18 +529,17 @@ Object.assign(NodeMaterial.prototype, {
559
529
} else if ( this . graphData . subGraphs ) {
560
530
// graph
561
531
// function head
562
- var ret_used = false ;
532
+ var retUsed = false ;
563
533
564
534
for ( i = 0 ; i < this . graphData . graphVars . length ; i ++ ) {
565
535
graphVar = this . graphData . graphVars [ i ] ;
566
536
if ( graphVar . name . startsWith ( 'OUT_ret' ) ) {
567
- // graphVarNameToIndexMap[graphVar.name]={type:graphVar.type, value:graphVar.value};
568
537
generatedGlsl = graphVar . type + ' ' ;
569
- ret_used = true ;
538
+ retUsed = true ;
570
539
}
571
540
}
572
541
573
- if ( ret_used === true ) {
542
+ if ( retUsed === true ) {
574
543
generatedGlsl += this . name + '_' + this . id + '( ' ;
575
544
} else {
576
545
generatedGlsl = 'void ' + this . name + '_' + this . id + '( ' ;
@@ -579,8 +548,6 @@ Object.assign(NodeMaterial.prototype, {
579
548
for ( i = 0 ; i < this . graphData . graphVars . length ; i ++ ) {
580
549
graphVar = this . graphData . graphVars [ i ] ;
581
550
if ( graphVar . name . startsWith ( 'IN_' ) ) {
582
- // graphVarNameToIndexMap[graphVar.name]={type:graphVar.type, value:graphVar.value};
583
-
584
551
generatedGlsl += 'in ' + graphVar . type + ' ' + graphVar . name + ', ' ;
585
552
}
586
553
}
@@ -589,7 +556,6 @@ Object.assign(NodeMaterial.prototype, {
589
556
graphVar = this . graphData . graphVars [ i ] ;
590
557
if ( graphVar . name . startsWith ( 'OUT_' ) ) {
591
558
if ( ! graphVar . name . startsWith ( 'OUT_ret' ) ) {
592
- // graphVarNameToIndexMap[graphVar.name]={type:graphVar.type, value:graphVar.value};
593
559
generatedGlsl += 'out ' + graphVar . type + ' ' + graphVar . name + ', ' ;
594
560
}
595
561
}
@@ -657,10 +623,11 @@ Object.assign(NodeMaterial.prototype, {
657
623
var subGraphOnListFlags = [ ] ;
658
624
var subGraphList = [ ] ;
659
625
660
- var while_loop_count = 0 ; // it should not be possible for the the number of iterations to exceeds the number of connections - unless there is a cyclic dependency
626
+ // it should not be possible for the the number of iterations to exceeds the number of connections - unless there is a cyclic dependency
627
+ var whileLoopCount = 0 ;
661
628
662
- while ( subGraphList . length < this . graphData . subGraphs . length || while_loop_count < this . graphData . connections . length ) {
663
- while_loop_count ++ ;
629
+ while ( subGraphList . length < this . graphData . subGraphs . length || whileLoopCount < this . graphData . connections . length ) {
630
+ whileLoopCount ++ ;
664
631
665
632
for ( i = 0 ; i < this . graphData . subGraphs . length ; i ++ ) {
666
633
if ( subGraphOnListFlags [ i ] != true ) {
0 commit comments