learn-wgpu
learn-wgpu copied to clipboard
The "Color Correction" paragraph is incorrect (or misleading)
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).
What formula would you recommend?
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.
I've updated the tutorial in a recent commit