Jump to content

  • Log In with Google      Sign In   
  • Create Account

Terrain UV coordinate help


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 VoidAccess   Members   -  Reputation: 109

Like
0Likes
Like

Posted 23 March 2013 - 02:46 PM

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;
    }

 



Sponsor:

#2 turch   Members   -  Reputation: 590

Like
1Likes
Like

Posted 26 March 2013 - 08:11 AM

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?



#3 GeneralQuery   Crossbones+   -  Reputation: 1263

Like
0Likes
Like

Posted 26 March 2013 - 08:30 AM

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, 26 March 2013 - 08:45 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS