Public Group

# x, y, width, height to UV

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

## 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 on other sites

Edited by Alpheus

##### 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 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 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 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 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.

1. 1
2. 2
3. 3
4. 4
Rutin
17
5. 5

• 11
• 27
• 12
• 12
• 11
• ### Forum Statistics

• Total Topics
631407
• Total Posts
2999914
×