spatial fragment shader: half one color, half another color

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

I’m attempting to write a spatial fragment shader that makes half of an object one color, and the other half another color. I’ve tried the following below, but the results aren’t what I expected:

shader_type spatial;

void fragment() {
	if(UV.x < 0.5) {
		ALBEDO = vec3(0.35, 0.83, 0.32);
		ALPHA = 0.75;
		EMISSION = vec3(0.35, 0.83, 0.32);
	}
	else {
		ALBEDO = vec3(250, 250, 0);
	}
}

This resulted in the following:
enter image description here

Now, I want the color of this green rectangle to match the exact color of the one further back in the picture. The albedo, alpha, and emission colors are set exactly the same, but the image is still not the same color.

In addition to this, the color is not split evenly across the rectangle. You’ll notice the front strip of the rectangle is green instead of half green and half yellow.

For some additional context, the green rectangle in the background has the follow properties set (not with a custom spatial shader, just through the GUI):

Flags Transparent: True
Albedo RGBA: (0.35, 0.83, 0.32, 0.75)
Emission Enabled: True
Emission RGB: (0.35, 0.83, 0.32)

Any help is greatly appreciated, thanks!

:bust_in_silhouette: Reply From: spotlessapple

Another person from a separate chat client suggested this solution and it ended up working.

Assigning ALBEDO a vec3 of 88, 211, 81 caused the color to immediately turn white (I believe this is because I should’ve been using the raw values bounded between [0, 1], though these weren’t generating the correct colors either), but using the newly declared color variable’s r,g,b,a members and setting them to the values (not-raw) that I selected for the green rectangle in the background got the colors to match.

Also, switching from UV to VERTEX worked for me since my camera doesn’t move and is focused/centered on the 0 line of the x axis:

shader_type spatial;

uniform vec4 color : hint_color = vec4(88, 211, 81, 190);

void fragment() {
	if(VERTEX.x < 0.0) {
		vec3 oricol = vec3(color.r, color.g, color.b);
		ALBEDO = oricol;
		EMISSION = oricol;
		ALPHA = color.a;
	}
	else {
		ALBEDO = vec3(250, 250, 0);
	}
}

enter image description here