Sign in to follow this  

Direct X mesh uv values

Recommended Posts

I'm pulling out the uv coordinates of a d3dxmesh using lockvertexbuffer() etc. I've been examining the .x file in word and have noticed something that has me confused. MeshTextureCoords { 1727; 1.666667;-2.583333;, 5.666667;-1.833333;, 0.166667;-4.666667;, 0.166667;-3.000000;, 1.019571;-2.894164;, This is an extraction of part of the mesh texture coordinates from the mesh. x file. I notice that somne of the values are greater than 1. I always thought that uv coordinates were between the values of 0 and 1. Am I looking in the wrong place. I really need the uv coords between 0 and 1 so that I can calculate the rgb values at a vertex after pulling out uv and bitmap data. Can someone clear this issue up for me?/

Share this post

Link to post
Share on other sites
Texture coordinates outside the 0-1 range are usually used to repeat/tile textures. With the WRAP texture address mode (D3DTADDRESS_WRAP), the texture repeats once every integer boundary.

So texture coordinates in the 0-1 range show the texture exactly once; texture coordinates in the 0-2 range repeat the texture twice, and so on.

The fractional part of the texture coordinate determines how far into that repeat the sample is (e.g. 2.5 is halfway through the 3rd repeat/tile of the texture).

See the C++ SDK docs for a picture and examples of other texture addressing modes:

DirectX Graphics ->
Direct3D 9 ->
Programming Guide ->
Getting Started ->
Direct3D Textures ->
Basic Texturing Concepts ->
Texture Addressing Modes ->
Wrap Texture Address Mode

If you're trying to read the texel of the texture at a specific vertex, you'll need to handle up to D3DCAPS9.MaxTextureRepeat integer repeats.

Share this post

Link to post
Share on other sites
Original post by Thomo
A uv coordinate of 2.0 (and 3.0, 4.0...) is the same as 1.0, and 1.5 (and 2.5, 3.5...) is the same as 0.5???
Yes. You should be able to convert the floating point texture coordinate to an integer pixel coordinate (multiply by height/width as appropriate) and then do a modulus on the height/width to get the actual pixel...


Real_Pixel_X = (TexCoord_x * Texture_Width) % Texture_Width;


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this