Jump to content
  • Advertisement
Sign in to follow this  
ilflyer12

UV Texture Coords go above 1.0

This topic is 4081 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 everyone, i am trying to get my texture coordinates from a mesh's vertex data so i can test before moving code to the GPU but i am getting values that are greater than the standard 0 - 1 UV coordinates. I get values that go up to 2.0. Below is the vertex declaration and the code i use to get the data from it. Does anyone know how / why this is happening and how i can fix this issue?
D3DVERTEXELEMENT9 decl[MAX_FVF_DECL_SIZE] = 
    {
        {0,  0,  D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
        {0,  12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0},
        {0,  24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},

        {0,  32, D3DDECLTYPE_FLOAT1, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDWEIGHT, 0},
        {0,  36, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDWEIGHT, 1},
        {0,  52, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDWEIGHT, 2},
        {0,  68, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDWEIGHT, 3},
        {0,  84, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDWEIGHT, 4},
        {0, 100, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDWEIGHT, 5},
        {0, 116, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDWEIGHT, 6},
        D3DDECL_END()
    };

const DWORD TEX_SHIFT = 24;

v_pTextureCoords = *((D3DXVECTOR2*)(pVert + TEX_SHIFT));
Thanks a lot for the help but i just cant seem to figure out why i get those values.

Share this post


Link to post
Share on other sites
Advertisement
UV coordinates can easily go above 1.0 and below 0.0 and that's normal. When that happens the method takes over (ie: clamp, etc).

-Devin

Share this post


Link to post
Share on other sites
Probably not, it depends on how the model was unwrapped. What the graphics card does when sampling a texture with UVs outside the 0-1 range depends on the currently set wrap mode for the sampler. On D3D9 this can be one of CLAMP, WRAP, MIRROR, MIRRORONCE or BORDER and is set independently for each of U, V and W. Check the D3D docs for D3DSAMPLERSTATETYPE. UVs outside the 0-1 range are not unusual and are usually but not always used because the artist wants the texture to tile across the model which implies using the WRAP texture addressing mode.

Share this post


Link to post
Share on other sites
Alright, so lets say it was meant to be wrapped. Since this is on my CPU and I am manually getting the pixels in the texture by locking it, i would basically just subtract 1 from all the values that are greater than 1 (since i know the largest is less than 2) since that would make a coord of 1.7 become .7 as if it was being wrapped. Would this be correct or am I still thinking in the wrong terms? Thanks again for the help

Share this post


Link to post
Share on other sites
Yep, that would be right, though a more robust solution would be :
coord = coord - floor(coord);

Which would handle negative coordinates and coordinates greater than 2 as well.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!