processing/p5.js

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

クローズ

#8,200 opened on 2025/10/25

 (8 件のコメント) (0 件のリアクション) (0 人の担当者)JavaScript (3,178 件のフォーク)batch import
Area:WebGLHelp Wantedp5.js 2.0+

Repository metrics

Stars
 (20,784 個のスター)
PR merge metrics
 (平均マージ 8d 13h) (30d で 45 merged PRs)

説明

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.

コントリビューターガイド