View Full Version : detail maps

11-29-2004, 05:47 AM

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 ?


11-29-2004, 05:12 PM
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

11-29-2004, 07:44 PM
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

11-30-2004, 01:21 AM
Thanks guys