Skip to content

Commit d4f6cef

Browse files
committed
add toFloat() for ease of use with instanceID()
1 parent 65ea279 commit d4f6cef

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/webgl/ShaderGenerator.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,16 @@ function shadergenerator(p5, fn) {
274274
}
275275
}
276276

277+
toFloat() {
278+
if (isFloatNode(this)) {
279+
return this;
280+
} else if (isIntNode(this)) {
281+
return new FloatNode(this);
282+
} else {
283+
throw new TypeError(`Can't convert from type '${this.type}' to 'float'.`)
284+
}
285+
}
286+
277287
toGLSL(context){
278288
throw new TypeError("Not supposed to call this function on BaseNode, which is an abstract class.");
279289
}
@@ -373,11 +383,13 @@ function shadergenerator(p5, fn) {
373383
}
374384

375385
deconstructArgs(context) {
376-
if (Array.isArray(this.args)) {
377-
return this.args.map((argNode) => argNode.toGLSLBase(context)).join(', ');
378-
} else {
379-
return `${this.args.toGLSLBase(context)}`;
380-
}
386+
let argsString = this.args.map((argNode, i) => {
387+
if (isIntNode(argNode) && this.argumentTypes[i] != 'float') {
388+
argNode = argNode.toFloat();
389+
}
390+
return argNode.toGLSLBase(context);
391+
}).join(', ');
392+
return argsString;
381393
}
382394

383395
toGLSL(context) {

0 commit comments

Comments
 (0)