Most appropriate sub-area of p5.js?
p5.js version
2.1.2
Web browser and version
Firefox
Operating system
MacOS
Steps to reproduce this
Steps:
- Create a model using
buildGeometry so 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
Most appropriate sub-area of p5.js?
p5.js version
2.1.2
Web browser and version
Firefox
Operating system
MacOS
Steps to reproduce this
Steps:
buildGeometryso that we can draw it with an instance countIt 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()andpop()and then drawing another shape without a custom shader, then all the instances show up like they're supposed to:Snippet:
Live: https://editor.p5js.org/davepagurek/sketches/4pTh3thfJ