playcanvas / engine

JavaScript game engine built on WebGL, WebGPU, WebXR and glTF
https://playcanvas.com
MIT License
9.64k stars 1.34k forks source link

Issues and possible improvements to transparency rendering #5943

Open mvaligursky opened 9 months ago

mvaligursky commented 9 months ago

The default framebuffer WebGL uses for rendering is RGB(A)8 buffer. The values written to it are expected to be in the display color space, which typically means sRGB. As this framebuffer is created by the canvas, we have no control over it, and it is not created with sRGB (EXT_sRGB) flag. Meaning the shader writing to it needs to manually encode values from linear to sRGB space.

LDR rendering

HDR rendering

References: https://github.com/KhronosGroup/WebGL/issues/2474 https://github.com/mrdoob/three.js/issues/23019 https://stackoverflow.com/questions/51032480/how-do-you-implement-a-gamma-correct-workflow-in-webgl2 https://groups.google.com/g/angleproject/c/5ITMg4_m8Ug https://github.com/playcanvas/engine/issues/5287

MAG-AdrianMeredith commented 3 months ago

its not necessarily srgb though right? https://ccameron-chromium.github.io/webgl-examples/p3.html. but I guess this would actually help here as we're letting the hardware do it

mvaligursky commented 3 months ago

True, but until we implement https://github.com/playcanvas/engine/issues/5287, it's sRGB. Handling P3 is part of that issue.

mvaligursky commented 3 months ago

Related Chromium issue I created exploring the sRGB in WebXR: https://partnerissuetracker.corp.google.com/issues/352345526?pli=1

mvaligursky commented 2 months ago

conclusion regarding WebXR, from the issue above:

The mechanism for specifying a texture format for WebXR is the Layers API, which is not yet supported by Chrome but does have support in the Meta Quest browser. WebXR is not compatible with buffers allocated by drawingBufferStorage.

mvaligursky commented 2 months ago

https://github.com/playcanvas/engine/pull/6838 implements support for sRGB framebuffer on WebGPU, but also support for sRGB render target on all platforms (just not the default framebuffer on WebGL), allowing linear rendering.

mvaligursky commented 2 months ago

Update on this.

mvaligursky commented 2 months ago

relevant topic: https://www.fractolog.com/2024/07/color-space-correctness-in-alpha-blending/