Sign in to follow this  

x, y, width, height to UV

This topic is 742 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, i really need to know how to convert picture's x, y, width, height(They're in pixels) to UV, thanks!

Edited by Paulpetk123

Share this post


Link to post
Share on other sites
	|     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)

Share this post


Link to post
Share on other sites
	|     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!

Share this post


Link to post
Share on other sites

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.001953125
For 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

Share this post


Link to post
Share on other sites

 

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.001953125
For 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!

Share this post


Link to post
Share on other sites

 

 

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.001953125
For 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.

Share this post


Link to post
Share on other sites
Sign in to follow this