Original Post
Hoping everyone had a great Chrisy. I have questions relating to the correct way to preform cube mapping, and as to how the results should appear. I am using GLSL to render, and have a few doubt's regarding my math. I load my cube map in opengl using: I have to swap the Y-axis textures because if I don't the results are buggy:
And if I swap the Y-axis, all is good:
The following are my vertex and pixel shaders respectivily: My next query relates to, well, how do I describe this... ummmm. When the eye/camera is over the cube map, shouldn't I see the lovely blue sky? And not the brick ground?:
And ideas? Thanks ahead of time.
unsigned int cube_target[6] = {
GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB,
GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB,
GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB,
GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB,
GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB,
GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
};
char* file_target[6] = {
"posx.bmp",
"negx.bmp",
"negy.bmp", // Note the Y-axis is swapped!?
"posy.bmp",
"posz.bmp",
"negz.bmp",
};
uniform vec3 light_position;
uniform vec3 eye_position;
varying vec3 light_direction;
varying vec3 view_direction;
varying vec3 normal;
void main()
{
vec4 v = gl_ModelViewMatrix * gl_Vertex;
gl_Position = ftransform();
normal = normalize(gl_NormalMatrix * gl_Normal);
light_direction = normalize(light_position - v.xyz);
view_direction = normalize(eye_position - v.xyz);
}
uniform vec3 light; // Light Colour;
uniform vec3 ambient;
uniform vec3 specular;
uniform float exponent;
uniform samplerCube envMap;
varying vec3 light_direction;
varying vec3 view_direction;
varying vec3 normal;
void main()
{
vec3 reflect_direction = normalize(reflect(view_direction, normal)); // <----
vec3 diffuse = textureCube(envMap, reflect_direction); // <----
vec3 t = normalize(view_direction + light_direction);
float d = dot(light_direction, normal);
float hn = dot(t, normal);
vec3 color = diffuse * (ambient + light * max(0.0, d)) /* Ambient lighting. */;
color += light * specular * pow((max(hn, 0.0)), exponent); /* Phong exponent. */
gl_FragColor = vec4(color, 1.0);
}