learn-wgpu icon indicating copy to clipboard operation
learn-wgpu copied to clipboard

The "Color Correction" paragraph is incorrect (or misleading)

Open Desour opened this issue 1 year ago • 2 comments

https://github.com/sotrh/learn-wgpu/blob/11820796f5e1dbce42fb1119f04ddeb4b167d2a0/docs/beginner/tutorial4-buffer/README.md?plain=1#L432

Web colors are in srgb. So #BC00BC is not decimal (188, 0, 188) in rgb, but in srgb. The shown formula for transformation transforms srgb to linear rgb.

Note also: The TextureFormat for the surface is chosen in the tutorial such that it satisfies .is_srgb(), so it's e.g. Bgra8UnormSrgb. The srgb suffix means that rgb-to-srgb conversions are done automatically (see https://gpuweb.github.io/gpuweb/#enumdef-gputextureformat).

Desour avatar Jul 04 '23 16:07 Desour

What formula would you recommend?

sotrh avatar Jul 29 '23 19:07 sotrh

It's not about the formula (though, it's missing the conditional for small values https://en.wikipedia.org/wiki/SRGB#Transformation, but whatever). The issue is that the color values in the shader are already in linear colorspace. The gpu does the conversion automatically because we specified that it's an srgb texture.

https://gpuweb.github.io/gpuweb/#texture-formats

If the format has the -srgb suffix, then sRGB conversions from gamma to linear and vice versa are applied during the reading and writing of color values in the shader.

Desour avatar Jul 29 '23 20:07 Desour

I've updated the tutorial in a recent commit

sotrh avatar May 18 '24 16:05 sotrh