Everything youre using in the vertex shader is just provided by opengl. As long as youre calling glVertexPointer etc correctly, the vertex shader looks fine. You might want to start with a fragment shader that just says gl_FragColor=vec4(1) first, so you can be sure its not a texturing problem (if youre having problems). Also, when you reply, please quote me so I get an email, or I may not respond for a while
Thanks i've managed to get the shader i posted to work. But i made things a bit more difficult for me with an improved shader
I now need to pass a vec3 CameraPos and a mat4 ModelWorld4x4 to my shader. I think did the CameraPos part right, but i don't know how to obtain the ModelWorld part.
This is what i have so far:
GLuint front, back, campos, modelworld;
glGenTextures(1, &front);
glBindTexture(GL_TEXTURE_2D, front);
int success = glfwLoadTexture2D("C:\\models\\reflect1.tga", GLFW_BUILD_MIPMAPS_BIT);
glGenTextures(1, &back);
glBindTexture(GL_TEXTURE_2D, back);
success = glfwLoadTexture2D("C:\\models\\reflect2.tga", GLFW_BUILD_MIPMAPS_BIT);
campos = glGetUniformLocation(shader.id(), "CameraPos");
glUniform3fv(campos, 0.0f, 0.0f, 3.0f);
I got the campos variables from my gluLookAt method.
gluLookAt(
0.0f, 0.0f, 3.0f, 0.f, 0.0f, 0.0f, 0.0f, 1.0f, 0.f);
Any idea on how to get the ModelWorld4x4?
For the record, this is the vertex shader:
uniform vec3 CameraPos;
uniform mat4 ModelWorld4x4;
varying vec3 R;
mat3 GetLinearPart( mat4 m )
{
mat3 result;
result[0][0] = m[0][0];
result[0][1] = m[0][1];
result[0][2] = m[0][2];
result[1][0] = m[1][0];
result[1][1] = m[1][1];
result[1][2] = m[1][2];
result[2][0] = m[2][0];
result[2][1] = m[2][1];
result[2][2] = m[2][2];
return result;
}
void main()
{
gl_Position = ftransform();
mat3 ModelWorld3x3 = GetLinearPart( ModelWorld4x4 );
// find world space position.
vec4 WorldPos = ModelWorld4x4 * gl_Vertex;
// find world space normal.
vec3 N = normalize( ModelWorld3x3 * gl_Normal );
// find world space eye vector.
vec3 E = normalize( WorldPos.xyz - CameraPos.xyz );
// calculate the reflection vector in world space.
R = reflect( E, N );
}