-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Open
Labels
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