godotengine / godotengine/godot

Shader globals do not respect `source_color` hint

Open
#106,922 3 comments 0 reactions 0 assignees View on GitHub
bug needs testing topic:shaders
Dominant language
C++
Stars
117k
Forks
26.8k
PR merge metrics
PR metrics pending

Description

### Tested versions

v4.4.1.stable.official, v4.5.dev4.official [209a446e3]

### System information

Godot v4.4.1.stable - Windows 10 (build 19045) - Vulkan (Forward+)

### Issue description

From my understanding, `source_color` enforces some kind of conversion from sRGB to linear color space.
This conversion is also necessary when using regular vector uniforms as color input, which in itself seems highly counterintuitive (and is a fact that appears to be undocumented).
(Related? #48039)
```
shader_type spatial;
render_mode unshaded;

uniform vec3 color : source_color = vec3(0.5);

void fragment() {
ALBEDO = color;
}
```
If `source_color` were to be omitted from this shader, the result would be incorrect, appearing too bright.

If `color` is intended to be one of the newly introduced shader globals, it appears there is currently no way to enforce the correct color space transformation (except for transforming the intended color from sRGB to linear before applying it to the global).

Neither using `Vector3` or `Color` as the global's type results in the correct color being applied, independently of any supplied hints.

Since I assume that the hints of one global cannot vary between different shaders, it should likely be made illegal to specify any hints for global variables within shaders (as well as a default value, as these are similarly ignored).
Instead, there should be a way to specify all hints to be applied to the global in their interface.

### Steps to reproduce

N/A

### Minimal reproduction project (MRP)

[repro-global-hint.zip](https://github.com/user-attachments/files/20497912/repro-global-hint.zip)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.