title: Parallax Mapping - GLSL- OpenGL
body: <p>In the past few days I been trying to implement parallax mapping in my engine, but it doesn't seem to work, I have seen at least 15 examples, and I'm still not being able to get it to work</p>
  
  <p>Here is an Image: <img src="https://i.stack.imgur.com/p3nyD.jpg" alt="enter image description here"></p>
  
  <p>As you can see, all you can see is the base color, the height map is not there</p>
  
  <p>Here are my shaders:</p>
  
  <pre><code>Fragment Shader
  
  #version 330 core
  uniform sampler2D DiffuseTextureSampler;
  uniform sampler2D HeightTextureSampler;
  vec2 scaleBias = vec2(0.5,0.5); 
  in vec3 EyeDirection_tangentspace;
  in vec2 UV;
  void main() 
  { 
   float height = texture2D(HeightTextureSampler, vec2 (UV.x, -UV.y)).r; 
   //Our heightmap only has one color channel.
   float v = height * scaleBias.r - scaleBias.g; 
   vec3 eye = EyeDirection_tangentspace; 
   vec2 newCoords = UV + (eye.xy * v); 
  
   vec3 rgb = texture2D(DiffuseTextureSampler,  vec2 (newCoords.x, -newCoords.y)).rgb; 
   gl_FragColor = vec4(rgb, 1.0); 
  }
  
  
  
  
  
  
  Vertex Shader
  
  #version 330 core
  
  // Input vertex data, different for all executions of this shader.
  layout(location = 0) in vec3 vertexPosition_modelspace;
  layout(location = 1) in vec2 vertexUV;
  layout(location = 2) in vec3 vertexNormal_modelspace;
  layout(location = 3) in vec3 vertexTangent_modelspace;
  layout(location = 4) in vec3 vertexBitangent_modelspace;
  
  // Output data ; will be interpolated for each fragment.
  out vec2 UV;
  out vec3 Position_worldspace;
  out vec3 EyeDirection_cameraspace;
  out vec3 LightDirection_cameraspace;
  
  out vec3 LightDirection_tangentspace;
  out vec3 EyeDirection_tangentspace;
  
  // Values that stay constant for the whole mesh.
  uniform mat4 MVP;
  uniform mat4 V;
  uniform mat4 M;
  uniform mat3 MV3x3;
  uniform vec3 LightPosition_worldspace;
  
  void main() 
  { 
   gl_Position = MVP * vec4(vertexPosition_modelspace,1);
  
  Position_worldspace = (M * vec4(vertexPosition_modelspace,1)).xyz;
  
      // Vector that goes from the vertex to the camera, in camera space.
      // In camera space, the camera is at the origin (0,0,0).
      vec3 vertexPosition_cameraspace = ( V * M * vec4(vertexPosition_modelspace,1)).xyz;
      EyeDirection_cameraspace = vec3(0,0,0) - vertexPosition_cameraspace;
  
  
   UV = vertexUV;
   vec3 vertexTangent_cameraspace = MV3x3 * vertexTangent_modelspace;
      vec3 vertexBitangent_cameraspace = MV3x3 * vertexBitangent_modelspace;
      vec3 vertexNormal_cameraspace = MV3x3 * vertexNormal_modelspace;
  
   mat3 TBNMatrix = transpose(mat3(vertexTangent_cameraspace, vertexBitangent_cameraspace, vertexNormal_cameraspace)); 
   EyeDirection_tangentspace = Position_worldspace - vertexPosition_modelspace.xyz; 
   EyeDirection_tangentspace *= TBNMatrix; 
  }
  </code></pre>