Jump to content
  • Advertisement
Sign in to follow this  
VoidAccess

Terrain UV coordinate help

This topic is 1938 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

I have set up this alphamap terrain that does multiple textures which works correctly except the textures seem off. The more you zoom out the more it the textures seem repeated. I believe this is because of the uv coordinates, looking for help on how to fix it as I am lost. Image of the problem: http://s13.postimg.org/dgh4awilj/image.png

 

    float incrementSize, tu2Left, tu2Right, tv2Top, tv2Bottom;
    int k = 0;
    float texUIndex = 0;
    float texVIndex = 0;
    incrementSize = 1.0f / 255.0f;
    tu2Left = 0.0f;
    tu2Right = incrementSize;
    tv2Bottom = 1.0f;
    tv2Top = 1.0f - incrementSize;

    for(DWORD i = 0; i < rows-1; i++)
    {
        for(DWORD j = 0; j < cols-1; j++)
        {
            indices[k]   = i*cols+j;
            vertices[i*cols+j].texCoord = D3DXVECTOR2(texUIndex , texVIndex + 1.0f);
            vertices[i*cols+j].texCoord2 = D3DXVECTOR2(tu2Left, tv2Bottom);

            indices[k+1] = i*cols+j+1;
            vertices[i*cols+j+1].texCoord = D3DXVECTOR2(texUIndex + 1.0f, texVIndex + 1.0f); 
            vertices[i*cols+j+1].texCoord2 = D3DXVECTOR2(tu2Right, tv2Bottom);

            indices[k+2] = (i+1)*cols+j;
            vertices[(i+1)*cols+j].texCoord = D3DXVECTOR2(texUIndex + 0.0f, texVIndex + 0.0f);
            vertices[(i+1)*cols+j].texCoord2 = D3DXVECTOR2( tu2Left, tv2Top);

            indices[k+3] = (i+1)*cols+j;
            vertices[(i+1)*cols+j].texCoord = D3DXVECTOR2(texUIndex + 0.0f, texVIndex + 0.0f);
            vertices[(i+1)*cols+j].texCoord2 = D3DXVECTOR2(tu2Left, tv2Top);

            indices[k+4] = i*cols+j+1;
            vertices[i*cols+j+1].texCoord = D3DXVECTOR2(texUIndex + 1.0f, texVIndex + 1.0f); 
            vertices[i*cols+j+1].texCoord2 = D3DXVECTOR2(tu2Right, tv2Bottom);

            indices[k+5] = (i+1)*cols+j+1;
            vertices[(i+1)*cols+j+1].texCoord = D3DXVECTOR2(texUIndex + 1.0f, texVIndex + 0.0f); 
            vertices[(i+1)*cols+j+1].texCoord2 = D3DXVECTOR2(tu2Right,tv2Top);

            k += 6; // next quad
            texUIndex++;
            tu2Left += incrementSize;
            tu2Right += incrementSize;
        }
        texUIndex = 0;
        texVIndex++;
        tu2Left = 0.0f;
        tu2Right = incrementSize;
        // Increment the tv texture coords for the alpha map.
        tv2Top -= incrementSize;
        tv2Bottom -= incrementSize;
    }

 

Share this post


Link to post
Share on other sites
Advertisement

I'm not seeing the problem here. From the code, it looks like the texture using texCoord should stretch across each quad (repeat on every quad) and the texture using texCoord2 should stretch across 256 quads (repeat every 256 quads). Is that not what's happening or not what you want?

Share this post


Link to post
Share on other sites
Your tiled texture will map to a given quad using whatever ratio you choose. The repetitive pattern above a certain minification is expected as this is an inherent drawback with conventional texture mapping. Unless I'm missing something your picture demonstrates exactly what would be expected from tiling a texture across a large surface.

Edit: you can try and rub away the obviousness of the tiling by reducing the ratio of texture space to a given quad (say, a 0.25:1 ratio instead of 1:1) but this obvious repetition will still be visible in large expanses of terrain. A cheap and simple solution is to use low frequency albedo textures (downsample your existing texture set) in combination with high frequency detail textures that are blended in proportionally to the distance from the eye. It won't eliminate the repetitions completely but it can help. Edited by GeneralQuery

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!