Open SyntaxPartnership opened 5 years ago
COLOR is intended to be ~only~ primary used as an output. Related godotengine/godot#23179.
Try vec4 col = texture(TEXTURE, UV);
.
EDIT: COLOR is actually the output of the vertex shader. Unless you use vertex colors this will be white.
This is indeed expected as mentioned by @DavidSichma. Yet many users seem to be hit by this, so we should see if we can improve the UX, e.g. by getting a compilation error when trying to read COLOR
before it has been assigned.
@akien-mga In the fragment shader COLOR
is both an input and output. It is the vertex color output from the vertex shader into the fragment shader and it is the output color from the fragment shader. So it would not make sense to throw a compilation error when it is used. I think the best thing to do is just document COLOR
better and explain that it does not automatically read from the texture.
CC @Chaosus
By default, vertex color is always white so comparison like if (COLOR == target_color_1)
doesn't make much sense. More commonly, If you need to replace a texture pixel color in a fragment shader you should use texture(sampler, UV)
instead COLOR...
@akien-mga I don't understand what unintuitively
and wrong in this behavior. Do you want me to create a PR to warn users about this? Of course, I could :)
As I said above, I don't think there should be an editor warning. I think this is just a documentation issue.
Phew... Then I think so too. It's rather hard to implement such warn system anyways 😄
Transferred to godot-docs as this seems to be a documentation issue.
From a quick look at https://docs.godotengine.org/en/stable/tutorials/shading/shading_reference/canvas_item_shader.html#vertex-built-ins, I'd say that it might still not be crystal clear that one can't read from COLOR
in the vertex
function (it's specified as inout
, without particular caveat).
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:
And:
(Ignore the green pixel.)
Steps to reproduce: Run app.