p5.js icon indicating copy to clipboard operation
p5.js copied to clipboard

[p5.js 2.0 Beta Bug Report]: vertexProperty() breaks if drawing with strokes

Open davepagurek opened this issue 1 year ago • 2 comments

Most appropriate sub-area of p5.js?

  • [ ] Accessibility
  • [ ] Color
  • [ ] Core/Environment/Rendering
  • [ ] Data
  • [ ] DOM
  • [ ] Events
  • [ ] Image
  • [ ] IO
  • [ ] Math
  • [ ] Typography
  • [ ] Utilities
  • [x] WebGL
  • [ ] Build process
  • [ ] Unit testing
  • [ ] Internationalization
  • [ ] Friendly errors
  • [ ] Other (specify if possible)

p5.js version

2.0 beta 1

Web browser and version

Firefox

Operating system

MacOS

Steps to reproduce this

When drawing strokes, we don't duplicate custom vertex properties to the different parts of strokes. When you try to draw strokes with per-vertex properties and use a shader that reads it, you get this warning in the browser console (not the p5 editor console though! open the browser one):

WebGL warning: drawArraysInstanced: Vertex fetch requires 51780, but attribs only supply 11526.
let snake
let snakeShader

function setup() {
  createCanvas(400, 400, WEBGL);
  
  snakeShader = baseMaterialShader().modify({
    vertexDeclarations: 'in float len;'
  })
  
  const pts = []
  for (let i = 0; i < 50; i++) {
      pts.push(createVector(random(width), random(height)))
  }
  
 snake = buildGeometry(() => {
    noFill()
    beginShape()
    for (const [i, { x, y }] of pts.entries()) {
        vertexProperty('len', [i/(pts.length-1)])
        splineVertex(x, y)
    }
    endShape()
  })
}

function draw() {
  clear()
  strokeShader(snakeShader)
  model(snake)
}

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

davepagurek avatar Feb 01 '25 21:02 davepagurek

Hi @davepagurek,

I'd like to work on this issue. Based on your feedback, I plan to duplicate user-defined vertex properties similarly to how per-vertex stroke colours are handled in p5.Geometry.js.

Would you be open to me working on this?

Thanks!

ImRAJAS-SAMSE avatar Feb 28 '25 04:02 ImRAJAS-SAMSE

Thanks @ImRAJAS-SAMSE! I'll assign this to you.

davepagurek avatar Mar 02 '25 15:03 davepagurek