Skip to content

[p5.js 2.0 Bug Report]: p5.strands uniformVector* calls are broken due to callbacks getting converted into nodes #7960

@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.0.3

Web browser and version

Firefox

Operating system

MacOS

Steps to reproduce this

Steps:

  1. Create a p5.strands shader
  2. Create a uniform vector with a default value, e.g. uniformVector2(() => [width, height])
  3. Use the shader in draw
  4. Try to run the sketch, and an error will occur

I tried putting a debugger statement after the call and running the sketch with the debugger open. You can see that the array is mistakenly getting wrapped in dynamicNode:

const size = uniformVector2('size', () => dynamicNode([
    width,
    height
]))

We should not wrap arrays in dynamicNode if the array is the callback to a uniform function.

Snippet:

let myShader

function setup() {
  createCanvas(400, 400, WEBGL);
  myShader = baseMaterialShader().modify(() => {
    const size = uniformVector2(() => [width, height])
    debugger
    getPixelInputs((inputs) => {
      inputs.color = [
        size / 1000,
        0,
        1
      ]
      return inputs
    })
  })
}

function draw() {
  background(220)
  shader(myShader)
  plane(width, height)
}

Live: https://editor.p5js.org/davepagurek/sketches/McwMGHEFf

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions