processing/p5.js

[p5.js 2.0 Bug Report]: p5.js overrides uSampler uniform for user shaders

Open

#8200 opened on Oct 25, 2025

View on GitHub
 (7 comments) (0 reactions) (0 assignees)JavaScript (20,784 stars) (3,178 forks)batch import
Area:WebGLHelp Wantedp5.js 2.0+

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.0.5 (2.0+)

Web browser and version

All

Operating system

All

Steps to reproduce this

Steps:

  1. Create a shader using a uniform called uSampler
  2. Set a value for it on the shader
  3. Draw something using the shader Instead of using the provided sampler value, it gets reset to be empty.

Snippet:

In 1.11.0 this draws a red rectangle. In 2.0.5 this is an empty canvas:

function setup() {
  createCanvas(400, 400, WEBGL);
  let myShader = createFilterShader(`precision highp float;
uniform sampler2D uSampler;
varying vec2 vTexCoord;

void main() {
  gl_FragColor = texture2D(uSampler, vTexCoord);
}
  `)

  let fbo = createFramebuffer()
  fbo.draw(() => background('red'))
  
  shader(myShader)
  myShader.setUniform('uSampler', fbo)
  noStroke()
  plane(width, height)
}

https://editor.p5js.org/davepagurek/sketches/kF84pt-Am

That's because this code gets run after the user's setUniform, overriding it: https://github.com/processing/p5.js/blob/f78009a93d896daa670e7199c9737063a0c6bedb/src/webgl/p5.RendererGL.js#L2378-L2383

It's being set back to an empty texture for good reason, as mentioned in the comments in the code, but we shouldn't do that if it's a user shader and has already had a value set.

Contributor guide