processing / processing/p5.js

Error when passing sampler2D array uniforms to shader

Open
#8,032 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Area:WebGL Bug
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
  • p5.strands
  • WebGL
  • DevOps, Build process, Unit testing
  • Internationalization (i18n)
  • Friendly Errors
  • Other (specify if possible)
p5.js version

1.11.10

Web browser and version

138.0.7204.184

Operating system

macOS

Steps to reproduce this

In GLSL #version 100 shaders, we should be able to pass an array of textures as uniform sampler2D textures[NUM_TEXTURES];. Right now, adding that line causes p5 to throw an error when calling unbindTextures.

Looking through p5.Shader, it seems like that kind of uniform is just not supported. For example, the gl.SAMPLER_2D uniform type is the only one that doesn't check for uniform.size in setUniform().

I haven't tested in p5 2.0 so I'm not sure if it's any different there.

Test sketch to repro: https://editor.p5js.org/araid/sketches/DkFW006mD

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

Start in src/webgl/p5.Shader.js at unbindTextures and setUniform, especially the referenced lines handling sampler2D uniforms. Reproduce the failure with the linked test sketch, then verify that a GLSL #version 100 sampler2D array uniform no longer throws when textures are unbound and assigned.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
computer-graphics
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.