Struggling to cast a uvec4 to vec4

4.3

Hello! Super Shader noob here, likely stuck in the “don’t know what questions to ask” phase. I’m trying to make a shader that references the uint values of a source texture, but I am unsure how to convert that information back to something that can be rendered. Or something of that nature:

shader_type canvas_item;

uniform usampler2D base;

void fragment() {
	uvec4 current_pixel = texture(base, UV);
	uint p_color = current_pixel.r;
	if (p_color > 120u){
		current_pixel = uvec4(0, 255, 255, 255);
	} 
	COLOR = vec4(current_pixel);
}

When the above code is run on any sprite, it returns a solid cyan sprite, when I think it should only return a sprite that is cyan for pixels with a red channel higher than 120, (I primarily am testing it on a red gradient, but have tried others for the same results.) I am also assuming a u8 scale, is that incorrect, perhaps? I’ve seen recommendations to divide the result by 255.0 or 4294967295.0, but both of those rendered the sprite blank…

I’m at a loss for what could even be occurring, and I have hit the limit of my language in asking intelligent questions. Any insight would be appreciated.

Are you positive that your texture uses unsigned integers? It’s much much more common for textures to use float values of 0-1.
I’d try just converting all the variables to floats and see if that fixes your problem.

One thing that is very helpful when working with shaders is converting StandardMaterial3D to a ShaderMaterial and then copying the parts you need.

Instructions