Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug? Colors are specified in linear color space #1033

Closed
code-monkey-101 opened this issue Jul 10, 2022 · 4 comments
Closed

Bug? Colors are specified in linear color space #1033

code-monkey-101 opened this issue Jul 10, 2022 · 4 comments
Assignees
Milestone

Comments

@code-monkey-101
Copy link

code-monkey-101 commented Jul 10, 2022

I've noticed that all given colors are linear (non-SRGB).

I don't know if this is intentional, but usually colors are assumed to be SRGB colors and must be linearized before you make any calculations with them.

See for example Unity:
https://docs.unity3d.com/ScriptReference/Color-linear.html
https://docs.unity3d.com/ScriptReference/MaterialPropertyBlock.SetColor.html

@trevordblack
Copy link
Collaborator

Sort of.

Colors given are stated as-is, without any intent of being linear or sRGB. We don't discuss the difference between linear color spaces and gamma color spaces too much. And ultimately that's not the point of the book.

We could add some text specifying if a designated color is in linear or in sRGB.

What exactly would you recommend?

Keep on mind that it's ultimately more important that the book be a good learning tool than perfectly correct

@code-monkey-101
Copy link
Author

Since there is a chapter about gamma correction (book 1, chapter 8.3), I would at least mention it.

You are switching from a gamma workflow (sRGB colors in -> calculations in nonlinear space-> sRGB colors out) to a linear workflow without changing the values of the colors (sRGB colors in -> [missing linearization] -> calculations in linear space -> gamma conversion -> sRGB colors out). You can do "linear colors in -> calculations in linear space -> gamma conversion -> sRGB colors out", but the problem is that before chapter 8.3 you are interpreting the values as sRGB colors and after chapter 8.3 you are interpreting the same values as linear colors.

However, to do it correctly, you'd have to either adjust all the color values after chapter 8.3 or change all the pictures (everything becomes darker). So maybe just add a paragraph and mention that it's not entirely correct.

@code-monkey-101
Copy link
Author

code-monkey-101 commented Jul 10, 2022

By the way, the problem is even more obvious when sampling the texture in book 2, chapter 6.1.

jpegs are usually in sRGB color space. For example, with DirectX, you'd usually load the texture as DXGI_FORMAT_R8G8B8A8_UNORM_SRGB format and the hardware would to the linearization for you when sampling it in the shader. But since you are doing it in software, you'd have to do it manually (or just use stbi_loadf instead of stbi_load).

@trevordblack
Copy link
Collaborator

Closing this out. There is a separate issue to track fixing this in book 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants