-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Description
Most appropriate sub-area of p5.js?
- Accessibility
- Color
- Core/Environment/Rendering
- Data
- DOM
- Events
- Image
- IO
- Math
- Typography
- Utilities
- WebGL
- Build process
- Unit testing
- Internationalization
- Friendly errors
- Other (specify if possible)
p5.js version
2.2-rc2
Web browser and version
Chrome 143
Operating system
MacOS 15.2
Steps to reproduce this
Steps:
- Create a WebGPU canvas
- Draw something
- Try to apply a filter shader, e.g. `filter(BLUR)
The issue is that it's failing to go through any of the conditions in this if when the node is a reference to the current canvas texture:
p5.js/src/strands/ir_builders.js
Lines 205 to 229 in db2ceae
| if (dep instanceof StrandsNode) { | |
| const node = DAG.getNodeDataFromID(dag, dep.id); | |
| originalNodeID = dep.id; | |
| baseType = node.baseType; | |
| if (node.opCode === OpCode.Nary.CONSTRUCTOR) { | |
| for (const inner of node.dependsOn) { | |
| mappedDependencies.push(inner); | |
| } | |
| } else { | |
| mappedDependencies.push(dep.id); | |
| } | |
| calculatedDimensions += node.dimension; | |
| continue; | |
| } | |
| else if (typeof dep === 'number') { | |
| const { id, dimension } = scalarLiteralNode(strandsContext, { dimension: 1, baseType }, dep); | |
| mappedDependencies.push(id); | |
| calculatedDimensions += dimension; | |
| continue; | |
| } | |
| else { | |
| FES.userError('type error', `You've tried to construct a scalar or vector type with a non-numeric value: ${dep}`); | |
| } |
The problem is that while the node is a StrandsNode, it's not the same StrandsNode! When you build p5.webgpu.js, it's currently including the p5.strands module, even though it is also included in the base p5.js build. So a StrandsNode created from p5.js will not pass the node instanceof StrandsNode check in p5.webgpu.js.
The fix is maybe to not use instanceof StrandsNode, and instead use duck typing to determine if something is a strands node by giving them a property like isStrandsNode: true. So then if we see an object where object.isStrandsNode is true, we can just assume it's a StrandsNode, regardless of what script it came from.
Snippet:
async function setup() {
await createCanvas(400, 400, WEBGPU)
// This works
// createCanvas(400, 400, WEBGL)
}
function draw() {
background(255)
fill('red')
noStroke()
circle(0, 0, 100)
filter(BLUR, 10)
}