Unexpected value in TEXTURE_PIXEL_SIZE

Godot Version

4.2.1

Question

I have a fragment shader in a ColorRect node with size 320x240 and the TEXTURE_PIXEL_SIZE is (1, 1). I thought it would be (1/320, 1/240). How is that TEXTURE_PIXEL_SIZE calculated?

How do you know it’s 1,1? I made a ColorRect that’s the same size and it appears to be 1/320, 1/240 for me.

I’ve used if statements to change the color depending on the value.

Can you post your code

This input gives you the pixel size of the first TEXTURE bound to the shader, not of the rect in which you are drawing. There is no standard way to get that data in a fragment shader because it’s usually not needed. If you want to have the size of the rect for some reason pass it in as a uniform.

This sounds like a good reason. I thought it would be derived from the size of the node since UV seems to have correct values. Thanks.

shader_type canvas_item;

void fragment() {
        if (TEXTURE_PIXEL_SIZE.x == 1.) {
	        COLOR.rgb = vec3(1, 0, 0);
        }
}

UV in GL typically goes from zero to one from one vertex to another, but I think godot does something special in canvas shaders and it gives you UV where an unit is a fragment or a pixel. Not sure how that works exactly.
If you use equals on a float you’re probably gonna get inconsistent results. Always do > and < with floats.

Yes, I know. I used those comparators until I narrowed it down to just 1.