Godot Version
v4.6.beta3.official [76dda5c6c]
Question
Taking my first steps into shader language in Godot.
This code is on a shadermaterial in a ColorRect. The ColorRect color is 00fefe
In RGB this is red = 0.
The following shader is supposed to only color red pixels that are already red but it colors the whole rect red (it shouldn’t be coloring any of the rect).
Why? Why is texture_color.r = 1 when my ColorRect has no red in it?
shader_type canvas_item;
uniform vec4 color : source_color = vec4(1.0);
void fragment() {
vec4 texture_color = texture(TEXTURE, UV);
if (texture_color.r >= 1.0){
COLOR = vec4(1, 0,0,1);
}
}
ColorRects don’t actually have textures for shaders to read, you would need a Sprite2D or TextureRect for that to work.
1 Like
Is there a way to read the pixels of a ColorRect?
I guess you could use a screen-reading shader on a node that’s rendered after the ColorRect… but since ColorRects only have a single color, I would just make another uniform variable for that color on the shader.
1 Like
Reading TEXTURE when no texture is assigned will return default white color where all components are 1.0
What are you actually trying to do with this?
Experiments, just experiments to get to the 1st stage of understanding.
Thanks.
I hit solution on @paintsimmon post but it didn’t seem to register.
1 Like