Most appropriate sub-area of p5.js?
p5.js version
2.2.3
Web browser and version
All
Operating system
All
Steps to reproduce this
Steps:
- Create a strands shader
- Create a uniform that has a default value callback
- In the callback, include an if statement
It throws an error because p5.strands is trying to transpile the ifs and such within the callback function. Generally, we try not to transpile anything in a function used in a uniform callback, but that seems to not be applied for control flow right now.
Snippet:
let myShader
function setup() {
createCanvas(400, 400, WEBGL);
myShader = buildFilterShader(testFilter)
}
function testFilter() {
let pastOneSecond = uniformFloat(() => {
debugger
if (millis() > 1000) {
return 1
}
return 0
})
filterColor.begin()
filterColor.set(mix([1, 0, 0, 1], [0, 1, 0, 1], pastOneSecond))
filterColor.end()
}
function draw() {
background(220);
filter(myShader)
}
If you run this with the console open, it hits the debugger and you can see that it has transpiled testFilter into:
function anonymous(__p5
) {
let pastOneSecond = uniformFloat('pastOneSecond', () => {
debugger;
__p5.strandsIf(millis() > 1000, () => {
__p5.strandsEarlyReturn(1);
}).Else(() => {
});
return 0;
});
filterColor.begin();
filterColor.set(mix(__p5.strandsNode([
1,
0,
0,
1
]), __p5.strandsNode([
0,
1,
0,
1
]), pastOneSecond));
filterColor.end();
}
It should not have touched anything in the callback. This is likely because we need to transpile helper functions to find early returns, but we should not be doing so in uniform callback functions.
Most appropriate sub-area of p5.js?
p5.js version
2.2.3
Web browser and version
All
Operating system
All
Steps to reproduce this
Steps:
It throws an error because p5.strands is trying to transpile the ifs and such within the callback function. Generally, we try not to transpile anything in a function used in a uniform callback, but that seems to not be applied for control flow right now.
Snippet:
If you run this with the console open, it hits the
debuggerand you can see that it has transpiledtestFilterinto:It should not have touched anything in the callback. This is likely because we need to transpile helper functions to find early returns, but we should not be doing so in uniform callback functions.