Skip to content

Make instanceID() work in both vertex and fragment shaders #8691

@davepagurek

Description

@davepagurek

Increasing access

Currently, instanceID() only works in p5.strands vertex shader hooks because the GLSL gl_instanceID is only available globally in vertex shaders. However, the distinction between vertex and fragment shaders is intentionally not made upfront, so it can be confusing when you try to use instanceID() in, for example, a finalColor block and it doesn't work. Arguably we should do some work under the hood to make that work to add some more scaffolding to our teaching of vertex/fragment shaders, letting their explanation be deferred further without unblocking learners of, for example, compute shaders, who already have a lot of new things to be focusing on.

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)

Feature enhancement details

Basically, to make this work, we'd have to notice when instanceID() has been called in fragment shader hooks, and bridge its value from the vertex shader automatically via a varying variable. This would need to happen in a way that works for both GLSL and WGSL.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions