Hey, i really need to know how to convert picture's x, y, width, height(They're in pixels) to UV, thanks!
x, y, width, height to UV
| W
| /
V | /
| /
|/_______________
U
TextureA = 256X128;
U(TextureA(64) = (1 / 256) * 64 = 0.25
V(TextureA(32) = (1 / 128) * 32 = 0.25
TexturaA(64, 32) = UV(0.25, 0.25)
| W | / V | / | / |/_______________ U TextureA = 256X128; U(TextureA(64) = (1 / 256) * 64 = 0.25 V(TextureA(32) = (1 / 128) * 32 = 0.25 TexturaA(64, 32) = UV(0.25, 0.25)
Thanks! That worked!
in UV space, 0 is the left-hand edge of the leftmost pixel, and 1.0 is the rightmost edge of the right hand pixel.
The above math will always give you the UV coordinates for the top/left corner of the pixel.
If you want the UV coordinates for the centers of the pixels, add 0.5 to the pixel coordinates before performing the conversion.
e.g.
. 22 Racing Series .
in UV space, 0 is the left-hand edge of the leftmost pixel, and 1.0 is the rightmost edge of the right hand pixel.
The above math will always give you the UV coordinates for the top/left corner of the pixel.
If you want the UV coordinates for the centers of the pixels, add 0.5 to the pixel coordinates before performing the conversion.
e.g.
For pixel #0, the left edge is 0/256=0, the right edge is 1/256=0.00390625, and the center is 0.5/256=0.001953125For pixel #64, the left edge is 64/256=0.25, the right edge is 65/256=0.25390625, and the center is 64.5/256=0.251953125
I did not know that you could have outer coordinates of a pixel. I always thought that coordinates were for the entire pixel. Thank you correcting me on that!
in UV space, 0 is the left-hand edge of the leftmost pixel, and 1.0 is the rightmost edge of the right hand pixel.
The above math will always give you the UV coordinates for the top/left corner of the pixel.
If you want the UV coordinates for the centers of the pixels, add 0.5 to the pixel coordinates before performing the conversion.
e.g.
For pixel #0, the left edge is 0/256=0, the right edge is 1/256=0.00390625, and the center is 0.5/256=0.001953125For pixel #64, the left edge is 64/256=0.25, the right edge is 65/256=0.25390625, and the center is 64.5/256=0.251953125
I did not know that you could have outer coordinates of a pixel. I always thought that coordinates were for the entire pixel. Thank you correcting me on that!
Mostly comes up when dealing with sprite graphics. The UV space is fully continuous while texel coords are discrete. Texture smoothing can sometimes create artifacts at the edges of polygons if you don't offset a little bit because the sampler will blend in the row/column outside the edges of the texture.
There are ten kinds of people in this world: those who understand binary and those who don't.