Sign in to follow this  

terrain borders

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

hello, i am texturing my terrain(which is without hightmap) as tiles applying a texture to one quad but it is not fitting at the quad. a small line of texture is going to the other end of quad looking it real bad and i dont know what to do. here is the code for filling the vertex data --------------------------------------------------------------------------------- int row = 0; for(int z = startZ; z >= endZ; z -= cellSpacing) { int column = 0; for(int x = startX; x <= endX; x += cellSpacing) { index = row * numVerPerRow + column; vertices[index] = VERTEX_FORMAT((float)x,0.0f,(float)z, (float)column,//tex1 (float)row);//tex2 column++; } row++; } -------------------------------------------------------------------------------

Share this post


Link to post
Share on other sites
If it is a one-texel line, then I must assume that you're attempting to stretch a texture precisely over the entire quad. At the edges, due to small rounding errors, the texture may then wrap. Obviously, you don't want this to happen, so you should switch the texture addressing mode to "clamp" instead (from the default "wrap").

In Direct3D:

//Assuming texture stage 0
lpdev->SetTextureStageState (0, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP);
lpdev->SetTextureStageState (0, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP);
//switch back to normal by using D3DTADDRESS_WRAP for the last parameter


In OpenGL:

glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
//switch back to normal by using GL_REPEAT for the last parameter

Share this post


Link to post
Share on other sites
In that case, you should do one or more of the following:

  • make sure your textures are tileable

  • bring all coordinates in 0..1 range

  • offset texture coordinates for edge vertices by one half of a texel



The first two are self explanatory. The third would eliminate the effects of these rounding errors, but may be a bit more difficult. What you do is make sure that the edge texture coordinates are not 0.00 and 1.00, but 0.00+0.5/texture_resolution and 1.00-0.5/texture_resolution. (So, for 1024x1024 textures, they would be 0.00048828125 and 0.99951171875 instead of 0 and 1). This way, the edge no longer lies in between texels (where the wrapping/clamping occurs), but inside the texels.

Share this post


Link to post
Share on other sites

This topic is 4485 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.

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