Skip to content

Add color space alpha notes to Color documentation#104410

Merged
Repiteo merged 1 commit into
godotengine:masterfrom
aaronfranke:color-space-doc
Apr 9, 2025
Merged

Add color space alpha notes to Color documentation#104410
Repiteo merged 1 commit into
godotengine:masterfrom
aaronfranke:color-space-doc

Conversation

@aaronfranke

Copy link
Copy Markdown
Member

I discussed color spaces and blending with @allenwp in person at GDC and he mentioned these things, which I think should be explicitly stated in the documentation.

@beicause

beicause commented Mar 21, 2025

Copy link
Copy Markdown
Contributor

I have a question: doesn't the sRGB encoding ignore the alpha channel by nature? I don't heard of the difference of alpha between sRGB space and linear space and non-linear alpha encoding.

VK_FORMAT_R8G8B8A8_SRGB specifies a four-component, 32-bit unsigned normalized format that has an 8-bit R component stored with sRGB nonlinear encoding in byte 0, an 8-bit G component stored with sRGB nonlinear encoding in byte 1, an 8-bit B component stored with sRGB nonlinear encoding in byte 2, and an 8-bit A component in byte 3.

Vulkan VK_FORMAT_R8G8B8A8_SRGB doesn't use non-linear alpha, too. I doubt if non-linear alpha has any use cases.

@allenwp

allenwp commented Mar 21, 2025

Copy link
Copy Markdown
Contributor

I have a question: doesn't the sRGB encoding ignore the alpha channel by nature? I don't heard of the difference of alpha between sRGB space and linear space and non-linear alpha encoding.

VK_FORMAT_R8G8B8A8_SRGB specifies a four-component, 32-bit unsigned normalized format that has an 8-bit R component stored with sRGB nonlinear encoding in byte 0, an 8-bit G component stored with sRGB nonlinear encoding in byte 1, an 8-bit B component stored with sRGB nonlinear encoding in byte 2, and an 8-bit A component in byte 3.

Vulkan VK_FORMAT_R8G8B8A8_SRGB doesn't use non-linear alpha, too. I doubt if non-linear alpha has any use cases.

You are correct and this PR aims to explicitly state exactly what you described in your comment for those who are unaware of this.

@beicause

Copy link
Copy Markdown
Contributor

Since there is no other case about the alpha channel, why is it necessary to explicitly state it?

@allenwp allenwp left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alpha channel often does not exist in the concept of a [color] space (at least in the parts of colorimetry where nonlinear/linear sRGB are being discussed), so I believe it will be less confusing to use the term "linear encoding" than "linear space" when describing how the alpha channel is stored.

Comment thread doc/classes/Color.xml Outdated
Comment thread doc/classes/Color.xml Outdated
Comment thread doc/classes/Color.xml Outdated
@allenwp

allenwp commented Mar 21, 2025

Copy link
Copy Markdown
Contributor

Since there is no other case about the alpha channel, why is it necessary to explicitly state it?

Both Aaron and I were uncertain about what encoding was common or expected for the alpha channel of color data, especially because this Color data structure can hold either linear or nonlinear encoding for the RGB channels. Since both of us had this uncertainty, we expect that other users may similarly be unsure. Adding this explicit statement will help others have clarity on this point.

@allenwp

allenwp commented Mar 21, 2025

Copy link
Copy Markdown
Contributor

Since we're here, it might be also good to add something like this to the class description:

Color data may be stored in nonlinear sRGB encoding or linear RGB encoding. Use srgb_to_linear and linear_to_srgb to convert between these two color spaces.

@allenwp

allenwp commented Mar 22, 2025

Copy link
Copy Markdown
Contributor

Since we're here, it might be also good to add something like this to the class description:

Color data may be stored in nonlinear sRGB encoding or linear RGB encoding. Use srgb_to_linear and linear_to_srgb to convert between these two color spaces.

After thinking more about it, this text might make a problem with the ambiguity of Color encoding worse. Maybe the following text would be better?

Red, green, and blue values of Color use nonlinear sRGB encoding within Godot, unless stated otherwise by documentation.

If this is ever untrue a documentation issue should be opened.

Thoughts?

(I can make this sort of change a separate PR if you'd prefer.)

@allenwp

allenwp commented Mar 26, 2025

Copy link
Copy Markdown
Contributor

After thinking more about it, this text might make a problem with the ambiguity of Color encoding worse. Maybe the following text would be better?

Red, green, and blue values of Color use nonlinear sRGB encoding within Godot, unless stated otherwise by documentation.

Because this somewhat goes beyond the intended scope of this PR, I've created a new PR #104666 that builds on top of this one, adding more information about colour encoding of RGB properties. These two PRs can be merged separately or I can squash mine with @aaronfranke as a coauthor.

Comment thread doc/classes/Color.xml Outdated
@aaronfranke aaronfranke changed the title Add color space blend and alpha notes to Color documentation Add color space alpha notes to Color documentation Mar 28, 2025
Comment thread doc/classes/Color.xml Outdated
Comment thread doc/classes/Color.xml Outdated
Comment thread doc/classes/Color.xml Outdated
Comment thread doc/classes/Color.xml Outdated
@Repiteo Repiteo merged commit 604e1c1 into godotengine:master Apr 9, 2025
@Repiteo

Repiteo commented Apr 9, 2025

Copy link
Copy Markdown
Contributor

Thanks!

@aaronfranke aaronfranke deleted the color-space-doc branch April 9, 2025 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants