processing / processing/p5.js

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

Open
#8,374 12 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Area:WebGL p5.js 2.0+
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:
  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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.