ifcviewer-web: render through an sRGB surface view (fix dark colors)

The fragment shader pre-decodes sRGB→linear to cancel the surface's
automatic linear→sRGB write encoding, so the final bytes match the GL
backend. That only holds when the render target is an sRGB format. On
desktop the surface's preferred format already is (e.g. BGRA8UnormSrgb),
but the browser canvas only offers plain BGRA8Unorm — so nothing
re-encoded and the whole image (background + models) rendered ~3× too
dark (authored bg 0.125,0.137,0.161 → ~32,35,41 collapsed to ~3,4,6).

Fix: when the surface format isn't sRGB, render through an sRGB *view* of
it — the standard WebGPU canvas pattern. surface_view_format_ is the sRGB
sibling of surface_format_ (unchanged when already sRGB, so desktop is a
no-op); configureSurface advertises it via viewFormats, the colour
pipelines (main, MSAA target, edge) target it, and render() creates the
surface view with it. The screenshot path still reads the base texture, so
its BGRA byte-order check stays on surface_format_.

Regression test: sample a 1x1 background pixel and assert it isn't crushed
dark (R,B > 20). Verified visually too — bg is now the correct dark
blue-gray and the cube is properly lit. 5/5 web smoke + 107/107 unit pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Dion Moult
2026-06-30 11:08:30 +10:00
parent 3cc759d72b
commit a6cfb2651a
3 changed files with 93 additions and 8 deletions
+4
View File
@@ -682,6 +682,10 @@ private:
WGPUQueue queue_ = nullptr;
WGPUSurface surface_ = nullptr;
WGPUTextureFormat surface_format_ = WGPUTextureFormat_Undefined;
// Format the colour pipelines + surface view actually render through. Equals
// surface_format_ on desktop (already sRGB); on web it's the sRGB sibling of
// the plain-Unorm canvas format so the shader's sRGB encode-cancel works.
WGPUTextureFormat surface_view_format_ = WGPUTextureFormat_Undefined;
bool surface_configured_ = false;
// ---- Pipelines + bind-group layouts (built once after init) -------------