Skip to content

[p5.js 2.0 Bug Report]: Instanced p5.strands shader doesn't work after first frame if you use only it #8374

@davepagurek

Description

@davepagurek

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:

  1. Create a model using buildGeometry so that we can draw it with an instance count
  2. Create a p5.strands shader that offsets position based on the instance number
  3. Draw a number of instances using the shader

It flickers showing all the instances, and then goes back to just showing one:

Image

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:

Image

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions