Repository navigation
|
Feel free to point me to relevant prior art / ongoing discussion if necessary. ContextThere are two kinds of textures and render targets: sRGB and linear. sRGB is effectively a curve encoding for linear colors, which helps better hide perceptual differences. The typical way this works in a graphics pipeline: the GPU hardware has special support to encode from linear to this curve, and decode from this curve back to linear. Encoding happens when selecting an sRGB format render target: when the shader code writes linear colors, GPU hardware encodes it from linear quantities into the sRGB curve, and writes the encoded sRGB value into the render target. Decoding happens when selecting an sRGB format texture: when the shader code samples an sRGB texture, GPU hardware decodes it from the sRGB sample values into linear quantiites, and returns the decoded linear value to the shader. Note that it is traditional for most display systems to use curve-encoded quantities. This is because it is the format understood by most display hardware (classically CRTs, but now most televisions and monitors expect curve-encoded quantities), so anything outputting directly to the screen needs to use curve-encoded quantities. For instance, the Direct3D 11 documentation tells us:
One way to imagine this is that the Windows compositor always reads a texture with a sRGB texture format. If the app chooses to use an sRGB format for its rendering, then it gets the automatic curve-encoding behavior of the GPU. Otherwise, it will put linear quantities into what should be sRGB curve-encoded colors, which is a classic mistake (sometimes called "gamma-space rendering", or "gamma-space lighting") Of course, browser composition pipelines are more complicated than just the Windows compositor on its own. So, some questions:
|
Replies: 2 comments 5 replies
|
The canvas swap chain's color space is configurable via GPUCanvasConfiguration.colorSpace. At this time, that can only be
Previously the spec said it was possible to specify both
It's tested: https://github.com/gpuweb/cts/blob/main/src/webgpu/web_platform/reftests/canvas_complex.html.ts As for the spec, it's not fully specified yet, but it will be when we define exactly what |
|
Hold up, "srgb" here is not an srgb texture format, and is therefore not srgb-encoded. (Can you see why I generally have been objecting to these names? :)) I believe this is still largely correct: https://hackmd.io/qkU7CRnkR1iKBDQwNj570w "srgb" in this case means srgb-gamut with perceptually-linear gamma curve. (0.5 "feels" like half way between the brightness of 0.0 and 1.0, but it's only ~21% of the photons) srgb formats are this other thing, where 0.5 encodes as 0xbc intead of 0x80. The reason you want to use a srgb format is because if you encode to physical-/photon-uniformly unorm8, you get low perceptual resolution in lows (blacks) and wasted perceptual resolution in highs (whites). So you use "srgb formats" when you're doing (physically-)linear color work to preserve good perceptual gradients. So the happy paths are:
This space ends up as a layer-cake of cancelling curves. But that's the story of how GL called perceptual "linear" and linear "srgb". |
The canvas swap chain's color space is configurable via GPUCanvasConfiguration.colorSpace. At this time, that can only be
"srgb", which means yes, the data in the canvas is sRGB encoded - equivalent to 2d and webgl canvas defaults. In the future it should have options like"srgb-linear"(intended for use with higher bit depths) and"display-p3". In all cases the canvas is then supposed to be color managed, though it's browser dependent whether this actually take the physical display's color space/calibration into account.(Note:
"srgb"here refers to the sRGB color space, not the-srgbtexture formats.)