Hello! I'm trying to understand why my reflection code does not work and I can't think why is this happening. What I want from you is to give me hints of what might go wrong in order to check it and give you more feedback and maybe we find the problem. This is the first time I'm doing reflection.
These are the steps and order of rendering my scene:
1) First I'm creating a Frame buffer with an RGB texture as it's color buffer and a Renderer Buffer as it's depth and stencil buffer with 24_8 precision accordingly (Even though I don't use the stencil).
2) I'm rendering the skybox cube map into the custom Frame Buffer with the depth test disabled. After that I'm enabling depth test again.
3) I'm rendering the cube into the custom Frame Buffer and sampling from the cube map using the reflection from the viewer and the cube's fragment.
4) I'm rendering a quad into the default frame buffer by sampling the color buffer texture from the custom frame buffer.
Ps: I have blend enable too, but I tried to disabled it and got the same results.
Below you can see the results:
So what should I check?
Below you can see the vertex and fragment shaders for the cube (I'm doing calculations in World space):
Vertex Shader:
#version 330 core
layout(location = 0) in vec3 aPos;
layout(location = 1) in vec3 aNormal;
uniform mat4 model;
uniform mat4 view;
uniform mat4 proj;
out vec3 normal;
out vec3 fragPos;
void main()
{
gl_Position = proj * view * model * vec4(aPos, 1.0f);
normal = mat3(transpose(inverse(model))) * aNormal;
fragPos = vec3(model * vec4(aPos, 1.0f));
}
Fragment Shader:
#version 330 core
out vec4 aPixelColor;
in vec3 normal;
out vec3 fragPos;
uniform samplerCube cube_map;
uniform vec3 camPos;
void main()
{
vec3 view = normalize(fragPos - camPos);
vec3 refl = reflect(view, normalize(normal));
aPixelColor = vec4(texture(cube_map, refl).rgb, 1.0f);
}
Cube Vertices:
float l_vertices[] = {
//Positions Normals.
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
-0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f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