I have this:
(Right now I have the height map in a x*x size 2D array and a 1D vector too.)
What I am trying to achieve is something like this:
Without using any textures, only plain colors. So basically smooth transitions and some shadow (using shaders).
My vertex shader looks like this:
#version 330
layout (location = 0) in vec3 Position;
layout (location = 1) in vec3 Normal;
layout (location = 2) in vec3 Color;
out vec3 fragmentNormal;
out vec4 ex_color,pos;
out vec3 N;
out vec3 v;
void main () {
pos= vec4(Position,1);
ex_color = vec4(Color,1);
fragmentNormal = Normal;
v = vec3(gl_ModelViewMatrix * pos);
N = normalize(gl_NormalMatrix * Normal);
gl_Position = gl_ModelViewProjectionMatrix * vec4(Position,1);
I have normals for all the vertices. Color is set simply in the c++ code based on height.
Here is the fragment shader
in vec3 N;
in vec3 v;
in vec4 ex_color;
void main(void)
{
vec3 L = normalize(gl_LightSource[0].position.xyz - v);
vec4 Idiff = gl_FrontLightProduct[0].diffuse * max(dot(N,L), 0.0);
Idiff = clamp(Idiff, 0.0, 1.0);
gl_FragColor = Idiff*ex_color;
}
So I guess my problem is what formula should I use to mix the colors. I think I don't need to set the colors in the c++ code but in the shaders.
Update:
Here is the wireframe of the terrain.
Update2:
Based on @Babis' answer the result is:
So the gradient is not "projected" onto the surface as I would like to do. What could cause this? Maybe my qustion wasn't clear.