Skip to main content
Commonmark migration
Source Link

I have this: ![terrain][1]terrain

(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: ![target][2]target 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. ![wireframe][3]wireframe

Update2: Based on @Babis' answer the result is: ![enter image description here][4]enter image description here

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. [1]: https://i.sstatic.net/14LPT.jpg [2]: https://i.sstatic.net/Ay07r.png [3]: https://i.sstatic.net/QfFEx.jpg [4]: https://i.sstatic.net/ce11F.jpg

I have this: ![terrain][1]

(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: ![target][2] 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. ![wireframe][3]

Update2: Based on @Babis' answer the result is: ![enter image description here][4]

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. [1]: https://i.sstatic.net/14LPT.jpg [2]: https://i.sstatic.net/Ay07r.png [3]: https://i.sstatic.net/QfFEx.jpg [4]: https://i.sstatic.net/ce11F.jpg

I have this: terrain

(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: target 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. wireframe

Update2: Based on @Babis' answer the result is: enter image description here

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.

added 263 characters in body
Source Link
Zoltantan
  • 45
  • 1
  • 1
  • 6

I have this: terrain![terrain][1]

(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: target![target][2] 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. wireframe![wireframe][3]

Update2: Based on @Babis' answer the result is: ![enter image description here][4]

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. [1]: https://i.sstatic.net/14LPT.jpg [2]: https://i.sstatic.net/Ay07r.png [3]: https://i.sstatic.net/QfFEx.jpg [4]: https://i.sstatic.net/ce11F.jpg

I have this: terrain

(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: target 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. wireframe

I have this: ![terrain][1]

(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: ![target][2] 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. ![wireframe][3]

Update2: Based on @Babis' answer the result is: ![enter image description here][4]

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. [1]: https://i.sstatic.net/14LPT.jpg [2]: https://i.sstatic.net/Ay07r.png [3]: https://i.sstatic.net/QfFEx.jpg [4]: https://i.sstatic.net/ce11F.jpg

Tweeted twitter.com/#!/StackGameDev/status/529188011888480256
added 81 characters in body
Source Link
Zoltantan
  • 45
  • 1
  • 1
  • 6

I have this: terrain

(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: target 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. wireframe

I have this: terrain

What I am trying to achieve is something like this: target 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. wireframe

I have this: terrain

(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: target 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. wireframe

Source Link
Zoltantan
  • 45
  • 1
  • 1
  • 6
Loading