Texturing problem

Hi
I have been working on a small terrain renderer which will use shaders for texturing. The texture coordinates are calculated in the vertexshader and the different textures are mixed in the pixelshader. My problem is that I repeat the textures with the texture coordinates, but the more times I repeat the texture, the more artifacts I get(well they show up closer and closer). i have 3 screenshots below, taken from the same coordinates, they show 3 repeat-rates 64x, 128x and 512x, As you see, the problem gets worse with more repeats.

64 times repeat:

http://palobas.campus.luth.se/~magnus/test64.jpg

128 times repeat:

http://palobas.campus.luth.se/~magnus/test128.jpg

512 times repeat:

http://palobas.campus.luth.se/~magnus/test512.jpg

So, any ideas whats going on here?

Thanks in advance //
Gregof

I’ve never seen anything like that before …
JOGL or LWJGL ??

As a rough guess judging by the way the artifacts seem to be distributed I’d say a MipMap level problem or corruption of some description. On the other hand Its far more likely to be something to do with your pixelshader. Post some code and a little more information as to how you’re doing what you’re doing and someone might be able to help you out.

D.

Hi, thanks for responding
Forgot to include same info on my setup… I use JOGL 1.1b10 and jre 1.4.2 running on a linuxsystem with an nvidia fx5200 and latest drivers (its the same problem in winxp too, I dual boot).
What I am trying to do here is to apply 4 different textures on my terrain, I use a “mask-image” to encode where the different textures should be, using red-channel as one texturemask, the green as another osv. This allows me to mask out where a specific texture (ex. grass) should be and at the same time repeat that textures. Hope i make some sense here…
I have my vertex and pixel-shaders below(Shaders are in CG btw):

Vertexshader looks like this:


void main(
float4 position : POSITION,
float2 textureCoords : TEXCOORD0,
float2 lightMapCoords : TEXCOORD1,

out float4 oPosition : POSITION,
out float2 oTextureCoords : TEXCOORD0,
out float2 oLightMapCoords : TEXCOORD1
)
{
 int sizeOfTerrain = 2048;
 int numberOfTextureRepeats = 256;

 oTextureCoords.x = position.x / (sizeOfTerrain / numberOfTextureRepeats);
 oTextureCoords.y = position.z / (sizeOfTerrain / numberOfTextureRepeats);

 oLightMapCoords.x = position.x / sizeOfTerrain;
 oLightMapCoords.y = position.z / sizeOfTerrain;

 float4x4 modelViewProjectionMatrix = glstate.matrix.mvp;
 oPosition = mul(modelViewProjectionMatrix, position);
}

…and my pixelshader looks like this:


void main(
float2 textureCoords : TEXCOORD0,
float2 lightMapCoords : TEXCOORD1,
float4 color : COLOR,
out float4 oColor : COLOR,
uniform sampler2D lightMap : TEXUNIT0,
uniform sampler2D grassMap : TEXUNIT1,
uniform sampler2D gravelMap : TEXUNIT2,
uniform sampler2D ironMap : TEXUNIT3,
uniform sampler2D mosaicMap : TEXUNIT4,
uniform sampler2D mask : TEXUNIT5


)
{

float4 grassMapColor = tex2D(grassMap, textureCoords).rgba;
float4 gravelMapColor = tex2D(gravelMap, textureCoords).rgba;
float4 ironMapColor = tex2D(ironMap, textureCoords).rgba;
float4 mosaicMapColor = tex2D(mosaicMap, textureCoords).rgba;

float4 maskColor = tex2D(mask, lightMapCoords).rgba;
float4 lightColor = tex2D(lightMap, lightMapCoords).rgba;

oColor = ((grassMapColor * maskColor.r) + (gravelMapColor * maskColor.g) + (ironMapColor * maskColor.b) + (mosaicMapColor * maskColor.a)) * lightColor;
oColor = grassMapColor * lightColor;
}

Thanks //
Gregof

Hi again.
I forgot to mention that the artifacts aren’t static, the move when I move the camera, the effect is somewhat hard to describe, but it reminds me of the Moiré effect. I also noted that this effect only is visible when I use mipmap textures, if I use LINEAR or NEAREST filtering it doesn’t show up. Is there somthing special I should do to use mipmaps and shaders? (I dont think so, but i’am known to be wrong :slight_smile: )

// Gregof

You do not want to use mipmaps on the “mask-image”. The image will be smeared and that might break the thing your doing in the shader.

Yes good point, I did use mipmaps for the maskimage, I tried to use linear or nearest just now, but then the terrain showed up black?
I did some further investigation and it seems to be the case that if I use linear or nearest and then try even the simplest case involving the maskColor, like maskColor.r * lightColor; which should give me a black and white terrain, it just becomes black :frowning:
Are there some restrictions/recommendations as to how the textures should be loaded when used in shaders?

// Gregof