After doing some research on the net I've merely come to understand that if I use a heightmap for doing a bumpmap then I would basically calculate the surface normal on the fly in the fragment shader and use it in my lighting computation instead of my real normal. What I need to do is find two tangent vectors in the current sampled position of my heightmap. These can be found by taking the partial derivatives and those derivatives can be approximated by a finite difference method so I decided to go on with the central difference scheme. Once this is done I go on to take the normalized cross product of these two vectors to get my normal, and then use this normal in my lighting computation
I also created a grayscale image (well a heightmap of course) through photoshop as well.
Unfortunately I seem to be doing something wrong when calculating the normal to be used. I tried feeding in the real normal and it works fine, I just get a regular diffuse lighting then. I also made sure that there's nothing wrong with my texture by mapping it to my sphere and it worked fine as well. So...I'm not entirely sure what I'm doing wrong really.
I'm slightly limited to what I can do at the moment on the CPU side of things as I am being dependant on a custom toolkit for OpenGL to do quite a bit of operations but I don't really think it would prevent me from doing a bump map anyway so there shouldn't be a problem because of that as far as I know.
Update: Fixed some small errors in the fragment shader which I just noticed, have posted the new code. I do get a visual result now but nothing close to resembling bump mapping. From the result it seems like I'm only adding the ambient color to my sphere as the whole surface consist of the same color. It's as if the diffuse part is never even considered. I'm slightly confused about what component I exactly need from my vec4 variables (x_forw etc.) when calculating the tangent vectors later in the code.
Here's the vertex and fragment shaders:
Vertex shader
#version 330
in vec4 vVertex;
in vec3 vNormal;
in vec2 vTexture0;
uniform mat4 mvMatrix;
uniform mat4 mvpMatrix;
uniform mat3 normalMatrix;
uniform vec3 lightPos;
out vec3 eyeNormal;
out vec3 lightDir;
out vec3 viewer;
out vec2 varTexture0;
void main()
{
eyeNormal = normalMatrix*vNormal;
vec4 eyeVert4 = mvMatrix*vVertex;
vec3 eyeVert3 = eyeVert4.xyz/eyeVert4.w;
lightDir = normalize(lightPos-eyeVert3);
viewer = normalize(-eyeVert3);
varTexture0 = vTexture0;
gl_Position = mvpMatrix*vVertex;
}
Fragment Shader
#version 330
//Uniforms
uniform vec4 diffuseColor;
uniform vec4 ambientColor;
uniform vec4 specularColor;
uniform sampler2D heightMap;
in vec3 eyeNormal;
in vec3 lightDir;
in vec3 viewer;
in vec2 varTexture0;
out vec4 fragColor; //Output for fragment shader
void main()
{
//Central Difference Scheme
vec4 x_forw = texture2D(heightMap, varTexture0.xy+vec2(1.0, 0.0));
vec4 x_back = texture2D(heightMap, varTexture0.xy-vec2(1.0, 0.0));
vec4 y_forw = texture2D(heightMap, varTexture0.xy+vec2(0.0, 1.0));
vec4 y_back = texture2D(heightMap, varTexture0.xy-vec2(0.0, 1.0));
vec3 tangX = vec3(1.0, 0.0, x_forw.z-x_back.z);
vec3 tangY = vec3(0.0, 1.0, y_forw.z-y_back.z);
//Calculate surface normal
vec3 heightNormal = normalize(cross(tangX, tangY));
fragColor = ambientColor +diffuseColor*max(0.0, dot(lightDir, heightNormal));
fragColor.a = 1.0;
}