[p5.js 2.0 Bug Report]: Instanced p5.strands shader doesn't work after first frame if you use only it
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 24k
- Forks
- 3.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 25
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.1.2
Web browser and version
Firefox
Operating system
MacOS
Steps to reproduce this
Steps:
- Create a model using
buildGeometryso that we can draw it with an instance count - Create a p5.strands shader that offsets position based on the instance number
- Draw a number of instances using the shader
It flickers showing all the instances, and then goes back to just showing one:
But weirdly, if you switch to using another shader in the same frame, e.g. by doing the instanced rendering within a push() and pop() and then drawing another shape without a custom shader, then all the instances show up like they're supposed to:
Snippet:
let instanceShader
let instance
function setup() {
createCanvas(400, 400, WEBGL)
instanceShader = baseMaterialShader().modify(() => {
getWorldInputs((inputs) => {
inputs.position.x += (instanceID() - 2) * 50
return inputs
})
})
instance = buildGeometry(() => sphere(20))
}
function draw() {
background(220)
push()
noStroke()
shader(instanceShader)
model(instance, 5)
pop()
// Works when you uncomment this?
// push()
// sphere(20)
// pop()
}
Live: https://editor.p5js.org/davepagurek/sketches/4pTh3thfJ
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the linked live sketch and the provided buildGeometry, baseMaterialShader, instanceID, and model calls. Start by tracing the WebGL instanced rendering and shader behavior across frames; done means the five instances remain visible when only the custom p5.strands shader is used, without the push/pop workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- computer-graphics
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100