title: OpenGL: Terrain deformation using a heightmap in the vertex shader
body: <p>I have been trying to implement a heightmap to my terrain shader, but the terrain remains flat. The texture is properly loaded in the vertex shader, and I try to use the greyscale values of the texture based on the mesh's uvs to adjust the vertex height:</p>
  
  <pre><code>//DIFFUSE VERTEX SHADER
  #version 330 
  
  uniform mat4    projectionMatrix;
  uniform mat4    viewMatrix;
  uniform mat4    modelMatrix;
  
  in vec3 vertex;
  in vec3 normal;
  in vec2 uv;
  
  uniform sampler2D heightmap;
  
  out vec2 texCoord;
  
  void main( void ){
  
  vec3 _vertex = vertex;
  _vertex.y = texture(heightmap, uv).r * 2.f;
  gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(_vertex, 1.f);
  texCoord = uv;
  
  }
  </code></pre>
  
  <p>Fragment: (the splatmap works so ignore that)</p>
  
  <pre><code>uniform sampler2D splatmap;
  uniform sampler2D diffuse1;
  uniform sampler2D diffuse2;
  uniform sampler2D diffuse3;
  uniform sampler2D diffuse4;
  
  in vec2 texCoord;
  out vec4 fragment_color;
  
  void main( void ) {
  ///Loading the splatmap and the diffuse textures
  vec4 splatTexture = texture2D(splatmap, texCoord);
  vec4 diffuseTexture1 = texture2D(diffuse1, texCoord);
  vec4 diffuseTexture2 = texture2D(diffuse2, texCoord);
  vec4 diffuseTexture3 = texture2D(diffuse3, texCoord);
  vec4 diffuseTexture4 = texture2D(diffuse4, texCoord);
  //Interpolate between the different textures using the splatmap's rgb values (works)
  diffuseTexture1 *= splatTexture.r;
  diffuseTexture2 = mix (diffuseTexture1, diffuseTexture2, splatTexture.g);
  diffuseTexture3 = mix (diffuseTexture2,diffuseTexture3, splatTexture.b);
  vec4 outcolor = mix (diffuseTexture3, diffuseTexture4, splatTexture.a);
  
  fragment_color = outcolor;
  
  }
  </code></pre>
  
  <p>Some additional info:
  All textures are loaded like this in my terrain material and passed to the shader (works properly):</p>
  
  <pre><code>glActiveTexture(GL_TEXTURE0);
  glBindTexture(GL_TEXTURE_2D, heightMap-&gt;getId());
  glUniform1i (_shader-&gt;getUniformLocation("heightMap"),0);
  ...
  </code></pre>
  
  <p>The plane mesh uvs are mapped like this:</p>
  
  <p>(0,1) (1,1)</p>
  
  <p>(0,0) (1,0)</p>
  
  <p>I guess I am doing something horribly wrong, but I can't figure out what. Any help is appreciated!</p>