0 votes

In the official documentation, shaders are introduced by reassigning COLOR inside a fragment function:

void fragment() {
  COLOR = some_color;

In attempting to do this on a custom spatial shader, I receive the following error:

error: Constants can not be modified

The code I'm attempting to run is below:

shader_type spatial;

void fragment() {
    COLOR = vec4(UV.x, 1.0 - UV.y, 0.5, 1.0);

Is this the expected behavior? Other tutorials in Godot shaders I've found also introduce the topic by reassigning color, so I can't help but think I have something set funny or am misunderstanding something. Thanks in advance for any help!

Godot version 3.2.3
in Engine by (30 points)

2 Answers

+1 vote
Best answer

According to the documentation, COLOR has the prefix in, which means read-only. But in the vertex function it has the prefix inout. As I understand it, the color can be assigned in the vertex function, and it can be read from the fragment function.


by (2,058 points)
selected by
+2 votes

What you're looking for is ALBEDO which takes in a vec3(Vector3) and ALPHA which is kinda self explanatory. COLOR there represents what you'd get from the output of your vertex function

by (4,560 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.