Skip to content

Commit d6f8635

Browse files
committed
fix: only skip uSampler override when user explicitly set it
Replace isUserFillShader check with _userSetSampler flag on Shader, tracking only explicit user calls to setUniform('uSampler', ...). Guarded by _settingFillUniforms on renderer to distinguish internal _setFillUniforms calls from user calls. Fixes the texture() does not remain bound test which uses baseMaterialShader().modify({}) with shader() — previously caught by isUserFillShader check, preventing uSampler reset to empty texture after pop().
1 parent f75f227 commit d6f8635

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

src/core/p5.Renderer3D.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,17 +1496,11 @@ export class Renderer3D extends Renderer {
14961496
fillShader.setUniform("uUseVertexColor", this._useVertexColor);
14971497
fillShader.setUniform("uMaterialColor", this.states.curFillColor);
14981498
fillShader.setUniform("isTexture", !!this.states._tex);
1499-
// We need to explicitly set uSampler back to an empty texture here.
1500-
// In general, we record the last set texture so we can re-apply it
1501-
// the next time a shader is used. However, the texture() function
1502-
// works differently and is global p5 state. If the p5 state has
1503-
// been cleared, we also need to clear the value in uSampler to match.
1504-
const isUserFillShader =
1505-
fillShader === this.states.userFillShader ||
1506-
fillShader === this.states.userImageShader;
1507-
if (this.states._tex || !isUserFillShader) {
1499+
this._settingFillUniforms = true;
1500+
if (this.states._tex || !fillShader._userSetSampler) {
15081501
fillShader.setUniform("uSampler", this.states._tex || empty);
15091502
}
1503+
this._settingFillUniforms = false;
15101504
fillShader.setUniform(
15111505
"uTint",
15121506
this.states.tint?._getRGBA([255, 255, 255, 255]) ?? [255, 255, 255, 255]

src/webgl/p5.Shader.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,13 @@ class Shader {
11031103
return;
11041104
}
11051105

1106+
// Track when the user explicitly sets uSampler so that
1107+
// _setFillUniforms knows not to override it with the empty texture
1108+
// when no texture is active via the p5 texture() API.
1109+
if (uniformName === 'uSampler' && !this._renderer._settingFillUniforms) {
1110+
this._userSetSampler = true;
1111+
}
1112+
11061113
// In p5.strands-related code, where some of the code may be in
11071114
// p5.webgpu.js instead of the main p5.js build, we generally use
11081115
// duck typing instead of instanceof to avoid accidentally importing

0 commit comments

Comments
 (0)