Public Group

# x, y, width, height to UV

This topic is 1077 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
Rutin
20
3. 3
khawk
17
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 11
• ### Forum Statistics

• Total Topics
633758
• Total Posts
3013713
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!