Attempting to assign COLOR in shader throws error: Constants cannot be modified.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By spotlessapple

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!

:bust_in_silhouette: Reply From: estebanmolca

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.

:bust_in_silhouette: Reply From: Wakatta

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