How to get precise pixel values form a Texture2D using uv coordinates.

I’m having a piece of geometry where several polygons share the same uv coordinate. Each of vertices of the polygons have coordinates that are mapped to a single pixel in the Texture2D (128x128).

This is the result:


Note that the Texture2D i’m using only contains fully red or blue pixels. The left image is filterMode set to Point, and the right is filterMode set to Billinear.

It seems to start interpolating, which I would believe is a result of inpresice uv-coordinates, but I don’t understand why, mipmap is disabled and the UVs map to the exact pixel coordinate. What is strange is that if I “manually” define a float2( u, v ) inside the shader, the precise mapping seems to work.

Any ideas what causing this?

Figured this out, I wasn’t sampling the center of the pixel. The texel coordinate for a specific pixel at { x, y } would be :

u = x / width + 0.5 / width;
v = y / height + 0.5 / height;

Thanks Bunny83 for the reference.