godotengine / godotengine/godot-docs
Accessing COLOR as input variable breaks shader unintuitively
- Dominant language
- reStructuredText
- Stars
- 5.7k
- Forks
- 3.8k
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 25
Description
**Godot version:**
3.1 Alpha 2
**OS/device including version:**
Windows 7 Professional Service Pack 1
**Issue description:**
Shader turns entire sprite white.
Tried both of the following shader coding:
```
shader_type canvas_item;
//Set target colors.
uniform vec4 target_color_1 : hint_color;
uniform vec4 target_color_2 : hint_color;
uniform vec4 target_color_3 : hint_color;
//Set replacement colors.
uniform vec4 replace_color_1 : hint_color;
uniform vec4 replace_color_2 : hint_color;
uniform vec4 replace_color_3 : hint_color;
void fragment() {
if (COLOR == target_color_1)
{
COLOR = replace_color_1
}
if (COLOR == target_color_2)
{
COLOR = replace_color_2
}
if (COLOR == target_color_3)
{
COLOR = replace_color_3
}
}
```
And:
```
shader_type canvas_item;
uniform float threshold : hint_range(0,1) = 0.01;
uniform vec4 T0:hint_color = vec4(0.058823, 0.058823, 0.058823, 1);
uniform vec4 T1:hint_color = vec4(0.254902, 0.254902, 0.254902, 1);
uniform vec4 T2:hint_color = vec4(0.45098, 0.45098, 0.45098, 1);
uniform vec4 R0 : hint_color;
uniform vec4 R1 : hint_color;
uniform vec4 R2 : hint_color;
void fragment() {
vec3 c = COLOR.rgb;
if (abs(T0.r-c.r) <= threshold && abs(T0.g-c.g) <= threshold && abs(T0.b-c.b) <= threshold) {COLOR.rgb = R0.rgb;}
if (abs(T1.r-c.r) <= threshold && abs(T1.g-c.g) <= threshold && abs(T1.b-c.b) <= threshold) {COLOR.rgb = R1.rgb;}
if (abs(T2.r-c.r) <= threshold && abs(T2.g-c.g) <= threshold && abs(T2.b-c.b) <= threshold) {COLOR.rgb = R2.rgb;}
}
```

(Ignore the green pixel.)
**Steps to reproduce:**
Run app.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.