From 7e53bb50590a243e16e6b0c722e6467f8675c4d6 Mon Sep 17 00:00:00 2001 From: Brian Hursey Date: Sat, 28 Nov 2026 06:40:25 +0000 Subject: [PATCH] Keep the proof cube off the graded image's texture unit. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The finish shader gained a sampler3D for ICC soft proofing, but that sampler was only assigned when proofing was on; unset it defaulted to unit 0, where the graded image is bound, and WebGL rejects a draw whose samplers mix types on one unit. Every frame then failed and photo after photo showed a black canvas with no console error. Assign the proof sampler on every draw and bind a 1x1x1 placeholder while proofing is off. 🤖 Generated with Codebuff Co-Authored-By: Codebuff --- src/gl/renderer.ts | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/gl/renderer.ts b/src/gl/renderer.ts index 2239356..a659a2f 100644 --- a/src/gl/renderer.ts +++ b/src/gl/renderer.ts @@ -1247,6 +1247,8 @@ export class Renderer { private srcW = 1; private srcH = 1; private proofTex: WebGLTexture | null = null; + /** Bound to the proof sampler while soft proofing is off. */ + private proofFallback: WebGLTexture | null = null; private proofLutOn = 0; /** Identity guard: the cube is uploaded once per profile, not per frame. */ private proofCube: SoftProofCube | null = null; @@ -1485,6 +1487,28 @@ export class Renderer { * approximation. Uploading happens here rather than per frame: the table is * built once from a printer profile. */ + /** + * The finish shader always declares a sampler3D, and an unassigned sampler + * reads as texture unit 0, where the graded image lives. WebGL rejects a + * draw whose samplers mix types on one unit, so the proof unit must always + * carry a 3D texture of its own, even when proofing is off. + */ + private proofFallbackTex(): WebGLTexture | null { + if (this.proofFallback) return this.proofFallback; + const gl = this.gl; + const tex = gl.createTexture(); + if (!tex) return null; + gl.bindTexture(gl.TEXTURE_3D, tex); + gl.texParameteri(gl.TEXTURE_3D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); + gl.texParameteri(gl.TEXTURE_3D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); + gl.texParameteri(gl.TEXTURE_3D, gl.TEXTURE_WRAP_R, gl.CLAMP_TO_EDGE); + gl.texParameteri(gl.TEXTURE_3D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); + gl.texParameteri(gl.TEXTURE_3D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); + gl.texImage3D(gl.TEXTURE_3D, 0, gl.RGBA8, 1, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array([0, 0, 0, 255])); + this.proofFallback = tex; + return tex; + } + setProofLut(lut: SoftProofCube | null) { if (lut === this.proofCube) return; this.proofCube = lut; @@ -1502,6 +1526,10 @@ export class Renderer { if (!tex) return; this.proofTex = tex; } + // The cube belongs to the proof unit only; binding it on whatever unit the + // last pass left active would put a 3D texture on the graded image's unit. + const activeUnit = gl.getParameter(gl.ACTIVE_TEXTURE) as number; + gl.activeTexture(gl.TEXTURE7); gl.bindTexture(gl.TEXTURE_3D, this.proofTex); gl.texParameteri(gl.TEXTURE_3D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); gl.texParameteri(gl.TEXTURE_3D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); @@ -1543,6 +1571,7 @@ export class Renderer { bytes, ); } + gl.activeTexture(activeUnit); this.proofLutOn = 1; } @@ -1997,7 +2026,10 @@ export class Renderer { this.finish.f('u_proofBlack', edits.proof.blackPoint); this.finish.f('u_gamut', edits.proof.gamut ? 1 : 0); this.finish.f('u_proofLutOn', this.proofLutOn); - if (this.proofTex && this.proofLutOn > 0.5) this.finish.tex3d('u_proofLut', this.proofTex, 7); + // Always assigned: an unset sampler3D defaults to unit 0 and collides + // with u_graded, which makes every draw fail and the view go black. + const proofTex = this.proofTex && this.proofLutOn > 0.5 ? this.proofTex : this.proofFallbackTex(); + if (proofTex) this.finish.tex3d('u_proofLut', proofTex, 7); this.finish.f('u_nr', edits.noise.luminance); this.finish.f('u_chroma', edits.noise.chroma); this.finish.f('u_chromaDetail', edits.noise.chromaDetail);