detail maps

Hi,

In my terrain engine, i’m tryng to apply a diferent detail map, depending on the height of the terrain.
In this case, if the heigth is below 65, i want to use a sand texture, if it is above i want to use a grass texture.
This is my shader :

uniform sampler2D myPaintMap;
uniform sampler2D Detail1;
uniform sampler2D Detail2;
uniform sampler2D hMap;

vec4 theMap;

void main (void)
{
    vec4 paintmap = texture2D(myPaintMap, vec2(gl_TexCoord[0]));
    vec4 sand = texture2D(Detail1, vec2(gl_TexCoord[1]));
    vec4 grass = texture2D(Detail2, vec2(gl_TexCoord[2]));
    vec4 heightmap = texture2D(hMap, vec2(gl_TexCoord[3]));

    float paint_color = (heightmap.x + heightmap.y + heightmap.z) / 3.0;

    theMap = grass;
    if(paint_color < 65.0) theMap = sand;
    

    gl_FragColor = 0.5*(paintmap + theMap);
}

paintmap is the color map, detail1 is the sand texture, detail2 is the grass texture, and hMap is the heightmap.

Using this shader i get both detail maps spread in the landscape but all in wrong positions.
It seems that i’m getting the color wrong from the heightmap.
I tried using a 8bit greyscale image for the heightmap, and using a 24bit rgb image, but they both don’t work.

What am i doing wrong ?
Am i getting the color(height) of the heightmap correctly ?

thanks,
Bruno

Why do you average the heightmap colors in a shader? Do it offline.

  
if(paint_color < 65.0)

If you are using integer formats like 8 bit (luminance) or RGB8, then reading them in shader will give normalized float values, that is to say values from 0.0 to 1.0

just use the vertices worldspace .y component (from the vertex shader) shade depending on where this is in relation to 64.0 ie no need to lookup in a texture

Thanks guys

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.