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