File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -48,9 +48,15 @@ function shadergen(p5, fn) {
48
48
}
49
49
50
50
const ASTCallbacks = {
51
- // TODO: automatically making uniforms
52
-
53
-
51
+ VariableDeclarator ( node ) {
52
+ if ( node . init . callee && node . init . callee . name . slice ( 0 , 7 ) === 'uniform' ) {
53
+ const uniformNameLiteral = {
54
+ type : 'Literal' ,
55
+ value : node . id . name
56
+ }
57
+ node . init . arguments . unshift ( uniformNameLiteral ) ;
58
+ }
59
+ } ,
54
60
// The callbacks for AssignmentExpression and BinaryExpression handle
55
61
// operator overloading including +=, *= assignment expressions
56
62
AssignmentExpression ( node ) {
@@ -632,7 +638,8 @@ function shadergen(p5, fn) {
632
638
const uniformFnVariant = `uniform${ uniformFns [ type ] } ` ;
633
639
ShaderGenerator . prototype [ uniformFnVariant ] = function ( name , defaultValue ) {
634
640
this . output . uniforms [ `${ type } ${ name } ` ] = defaultValue ;
635
- return new VariableNode ( name , type ) ;
641
+ let safeType = type === 'sampler2D' ? 'vec4' : type ;
642
+ return new VariableNode ( name , safeType ) ;
636
643
} ;
637
644
fn [ uniformFnVariant ] = function ( name , value ) {
638
645
return GLOBAL_SHADER [ uniformFnVariant ] ( name , value ) ;
You can’t perform that action at this time.
0 commit comments