Strange terrain texture mapping problem

Started by
4 comments, last by riff 16 years, 2 months ago
I've been having my first foray into graphics programming by attempting to create a simple terrain engine. It was all going fine until I started having a problem with the blended textures which I can't solve. Basically, for each division of the terrain, the associated texture apparently has it's edges swapped around for some reason: Example of a generated texture: bad texture The effect this has on the terrain: bad terrain I was hoping that someone with more experience might instinctively know what's going on. I've looked through my code for days and can't figure it out. Thanks for any help you can give. :)
Advertisement
thats almost certainly problem with texture address mode. search directX SDK for AddressV and AddressU and you`ll see what i`m talking about. however it might not be so easy to fix, it depends on your algorithm.
A rather quick and easy way to fix this is to make sure each texture has the exact same pixel values along its border as neighboring textures. This will get rid of the visible borders.
Author Freeworld3Dhttp://www.freeworld3d.org
Changing the texture address mode on the code that blends the textures doesn't seem to make any difference at all.
maybe if you could post your shader code? and yeah, you could use texture coordinates as a color in pixel shader to see if everything is ok.
Here's the shader code:


terrainblend.frag
----------------------

2D opacityMap;
uniform sampler2D source0;
uniform sampler2D source1;
uniform sampler2D source2;
uniform sampler2D source3;

void main()
{
vec4 opacity = texture2D(opacityMap, gl_TexCoord[0].st);
vec4 texel0 = texture2D(source0, gl_TexCoord[0].st);
vec4 texel1 = texture2D(source1, gl_TexCoord[0].st);
vec4 texel2 = texture2D(source2, gl_TexCoord[0].st);
vec4 texel3 = texture2D(source3, gl_TexCoord[0].st);

//Combine texel colours
gl_FragColor = vec4(opacity.r * texel0.rgba +
opacity.g * texel1.rgba +
opacity.b * texel2.rgba +
opacity.a * texel3.rgba);
}


terrainblend.vert
-------------------

void main()
{
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform();
}



And here is my texture blending code:

http://www.pastebin.ca/907373

This topic is closed to new replies.

Advertisement