godot icon indicating copy to clipboard operation
godot copied to clipboard

Add `srgb_color` shader hint.

Open basicer opened this issue 1 year ago • 6 comments

Sometimes shaders want to accept a color as input that is always in the srgb color space. This adds a hint to vec3/vec4 to enable the color picker popup for those vectors but disable color space conversion.

basicer avatar Oct 04 '24 07:10 basicer

Hey @basicer , can you list usecases for this?

QbieShay avatar Dec 09 '24 18:12 QbieShay

@QbieShay This is something that has come up a few times. I thought there was a proposal, but all I can find is https://github.com/godotengine/godot-proposals/issues/2323

Basically, people want to use the color picker, but they want to keep colors in sRGB space. When using the source_color hint, Godot will automatically convert the color to linear in 3D shaders and in 2D shaders when using HDR. So we need a hint that tells Godot to use a color picker without giving Godot permission to do color space operations

clayjohn avatar Dec 09 '24 18:12 clayjohn

Discussed this in the rendering meeting. It's clear to me now why the feature is wanted, but we discussed a different API:

  • Support for source_color should be extended to vec3
  • This new hint should work together with source color, and just disable the unwanted operation.

For example

uniform vec3 albedo_color: source_color // shows color picker, performs conversion
unifomr vec3 albedo_color1:  source_color, disable_color_conversion // shows color picker, but disables extra logic
uniform vec3 albedo_color2: disable_color_conversion // behaves like the previous one

This expands using color for vec3 (which is something that we should have already) and add an extra option, allows for compact syntax for advanced users, so everyone should be happy with this solution ^^

QbieShay avatar Dec 10 '24 15:12 QbieShay

NOTE: I called it "disable color conversion" but we can find something better. But it should still be clear.

QbieShay avatar Dec 10 '24 19:12 QbieShay

NOTE: I called it "disable color conversion" but we can find something better. But it should still be clear.

I like it, but its a bit long? Maybe no_color_conversion ?

basicer avatar Dec 14 '24 20:12 basicer

Judging by the existing uniform hints and render modes, the most idiomatic name here is either color_conversion_disable or color_conversion_disabled.

color_conversion_disable matches existing hints more closely, but there is only one existing example: repeat_disable. color_conversion_disabled matches the multiple examples of render modes (cull_disabled, depth_test_disabled, specular_disabled, etc.). My preference personally is color_conversion_disabled.

The name is a little on the long side, but we already have some verbose hints like hint_normal_roughness_texture or alpha_to_coverage_and_one, so it's probably fine.

disable_color_conversion is not idiomatic because the order is wrong. To use an analogy with properties, idiomatically the "property name" comes first, then the "property value".

tetrapod00 avatar Dec 16 '24 00:12 tetrapod00

@tetrapod00 Might be idiomatic but is too long imo.

Zireael07 avatar Dec 16 '24 08:12 Zireael07

We discussed again in the rendering meeting and have settled on color_conversion_disabled as suggested by tetrapod. The one difference from Qbie's suggestion is that we agree that it should be an error to use it by itself

clayjohn avatar Jan 30 '25 04:01 clayjohn

I'm not sure I follow your comments @clayjohn .

When the parser sees color_conversion_disabled it checks that the existing hint is HINT_SOURCE_COLOR and then replaces it with HINT_COLOR_CONVERSION_DISABLED since there can only be one hint set. So the conditions do trigger.

basicer avatar Apr 11 '25 04:04 basicer

I'm not sure I follow your comments @clayjohn .

When the parser sees color_conversion_disabled it checks that the existing hint is HINT_SOURCE_COLOR and then replaces it with HINT_COLOR_CONVERSION_DISABLED since there can only be one hint set. So the conditions do trigger.

Oh, interesting. I see what you mean. Each hint overwrites the previous one. In cases where multiple hints are valid we have edge case handling. I really don't like that approach, but its not your fault. Its best to stick with the patterns that are there.

That just leaves my comment about the code completion.

clayjohn avatar Apr 11 '25 04:04 clayjohn

I'm not sure I follow your comments @clayjohn . When the parser sees color_conversion_disabled it checks that the existing hint is HINT_SOURCE_COLOR and then replaces it with HINT_COLOR_CONVERSION_DISABLED since there can only be one hint set. So the conditions do trigger.

Oh, interesting. I see what you mean. Each hint overwrites the previous one. In cases where multiple hints are valid we have edge case handling. I really don't like that approach, but its not your fault. Its best to stick with the patterns that are there.

That just leaves my comment about the code completion.

Yeah, I don't like it either, but It didn't seem worth refactoring into a bitset or something just for this.

basicer avatar Apr 11 '25 21:04 basicer

Thanks!

Repiteo avatar Apr 15 '25 00:04 Repiteo