glsl terrain shader
hi,
ive got my terrain rendering properly with glsl. my shader currently blends between two textures depending on height.
im a bit stuck for ideas( / know-how) to make it more interesting.
ive searched around a bit for some examples but cant find much.
so has anyone got any examples or can describe what your doing?
also can/should shadows be done in a shader somehow? or should i generate a static texture for that?
thanks
dunk
Hi,
well, if static shadows are well enough for your needs, then a precalculated lightmap texture (in your app or from 3dmax or something) is the fastest & easiest way to go.
You could also try to implement blending using a blend map. And another thing - blending depending on the slope of the terrain - flat surfaces have grass, vertical have rocks, this can look very nice. Although it can also be done by using a blending map, I think getting the dot product of the normal of the terrain and "the up vector" & adjusting it a bit, to get the blending factor would be faster than a texture read.
Just some ideas that popped into my mind :P
well, if static shadows are well enough for your needs, then a precalculated lightmap texture (in your app or from 3dmax or something) is the fastest & easiest way to go.
You could also try to implement blending using a blend map. And another thing - blending depending on the slope of the terrain - flat surfaces have grass, vertical have rocks, this can look very nice. Although it can also be done by using a blending map, I think getting the dot product of the normal of the terrain and "the up vector" & adjusting it a bit, to get the blending factor would be faster than a texture read.
Just some ideas that popped into my mind :P
Here are some ideas for fun:
Add a detail texture to represent detail. One should tile a texture over the terrain so that the texture resolution stays high.
Add another texture for terrain coloring. You can generate a nice diffuse map with static shadows precomputed. This might have greens for low grass, grey for rock, etc., and the larger mountains casting shadows on the ground.
Real Shadow Mapping can also be done in a shader. The basic idea is to render a depth buffer from the lights point-of-view, and then use is for depth comparisons during the actual pass. I am sure you can find discussions on the net.
Another trivial idea would be to modify the height values over time based on some factor (height or texture value). This will give a trippy, slowly undulating mass. Maybe represent erosion over time, or volcanic buildup.....
Happy coding!
Add a detail texture to represent detail. One should tile a texture over the terrain so that the texture resolution stays high.
Add another texture for terrain coloring. You can generate a nice diffuse map with static shadows precomputed. This might have greens for low grass, grey for rock, etc., and the larger mountains casting shadows on the ground.
Real Shadow Mapping can also be done in a shader. The basic idea is to render a depth buffer from the lights point-of-view, and then use is for depth comparisons during the actual pass. I am sure you can find discussions on the net.
Another trivial idea would be to modify the height values over time based on some factor (height or texture value). This will give a trippy, slowly undulating mass. Maybe represent erosion over time, or volcanic buildup.....
Happy coding!
thanks for the quick replys guys :)
i tried to get different materials on a slope but without much success
this is my vertex shader
and the fragment shader
i dont know what iv got in 'ang' but its not right because suddenly i cant see anything at all.
thanks for the other ideas too. i think ill just use a static shadow map for the moment.
i tried to get different materials on a slope but without much success
this is my vertex shader
uniform float zoom;uniform float height_scale;varying float height;varying float ang;void main(void){ height = gl_Vertex.y / height_scale; vec3 normal = normalize(gl_NormalMatrix * gl_Normal); vec3 up = vec3(0.0, 1.0, 0.0); ang = max(dot(normal, up), 0.0); gl_TexCoord[0].x = gl_MultiTexCoord0.x * zoom; gl_TexCoord[0].y = gl_MultiTexCoord0.y * zoom; gl_Position = ftransform();}
and the fragment shader
uniform sampler2D GrassTexture;uniform sampler2D RockTexture;uniform sampler2D SnowTexture;varying float height;varying float ang;void main(void){ vec4 cg = vec4(texture2D(GrassTexture,gl_TexCoord[0].st)); vec4 cs = vec4(texture2D(SnowTexture,gl_TexCoord[0].st)); vec4 cb = vec4(texture2D(RockTexture,gl_TexCoord[0].st)); vec4 ct = vec4(mix(cg, cb, ang)); gl_FragColor = ct; //mix(ct, cb, ang);}
i dont know what iv got in 'ang' but its not right because suddenly i cant see anything at all.
thanks for the other ideas too. i think ill just use a static shadow map for the moment.
The closer the normal gets to 1.0 its very steep(the normal) so you need to mulitply that value by your grass and the difference by your other fragments. The whole needs to add up to 1.0. So if you have 4 textures the most each can have if you want all four to be on the screen is .25 == 1.0 for that texture.
HTH
HTH
use another texture to say how much of each terraiin type each pixel recieves (create this texture in a paint program or with some algorithm)
eg in the red channel u have the grass coverage
in green channel u have the rock coverage
in blue channel u have sand
etc
eg in the red channel u have the grass coverage
in green channel u have the rock coverage
in blue channel u have sand
etc
Quote:Original post by zedzeek
use another texture to say how much of each terraiin type each pixel recieves (create this texture in a paint program or with some algorithm)
eg in the red channel u have the grass coverage
in green channel u have the rock coverage
in blue channel u have sand
etc
A.K.A. Blendmap... I am using these myself and they work great.
oh so i guess i could autogenerate the blend map based on slopes and stuff and then just do the blending in the shader
interesting..
thanks guys
interesting..
thanks guys
I'm doing texture splatting for my terrain engine, I use texture unit 0 for the alpha/blend map, unit 1 for diffuse, and im tempted by unit 2 for normal mapping, and unit 3 for specular mapping (cool shiny mountain top snow!). I've got my renderer working with splatting and specular mapping in the shader. There is a LOT you can do with shaders, as I'm learning, just experiment.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement