How do I get the texture pixel location in a fragment shader?

I am writing a shader where based on time, a progress bar fills up. The way I want to do this is calculate if the pixel is in a specific range. For instance, I want to see if the pixel for the texture sampled is between x (50 and 100). How do I get the coordinates of the pixel where the sample is taken from in the fragment shader?

Thanks!

For a non-rotating plane, simpler to use UV.x (assuming the unwrap goes that way.) Greater than 50% full would be something like i.uv.x>0.5 (a standard plane unwrap has coords from 0 to 1, no matter how large/stretched the actual plane is.)

If you have to get the actual (world? model?) coords, I think you can’t(*). What you can do is add something like float3 pos2 to your v2f structure (vertex output, fragment input,) and assign to it in the vertex shader (copy it first thing if you want model coords.) Then can use it in the frag shader. Like anything else, it will be auto-interpolated to give correct numbers for each pixel.

(*)The “standard” v2f does have a “pos SV_POSITION” variable. This is the viewport(?) coords, so not useful, plus it’s normally used and eaten by the hardware, so the frag shader can’t read it anyway.

hey, i also wanted to have the space coordinates of a pixel in the fragment shader (that only manages a x,y screen position).

i used aditionnal TEXCOORDS to store the vertex position in the v2f , then could reuse it the frag function.

 	struct v2f {
      	float4 pos : SV_POSITION;
      	fixed4 color : COLOR;
      	float2 uv : TEXCOORD0; // stores uv
      	float3 pos1 : TEXCOORD1; // vertex position
  	};