Sign in to follow this  
VoidAccess

Terrain UV coordinate help

Recommended Posts

VoidAccess    109

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
turch    590

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
GeneralQuery    1263
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

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