Hello. I want to create a local cubemap and store the normal, depth and radiance values on each face. The values are stored in the cubemap, but I can’t do the correct lookup. Here is the code :
Write to cubemap rendering :
vertex shader
layout(location = 0) in vec3 vertexPosition;
void main() {
gl_Position = CubeProjection * CubeView * vec4(vertexPosition, 1.f);
WorldPosition = vertexPosition;
}
fragment shader
layout(location = 0) out vec4 value;
void main() {
float lightDist = distance(WorldPosition, CubePos) / FarPlane;
value = vec4(vec3(lightDist), 1.0);
}
Main rendering :
vertex shader
layout(location = 0) in vec3 vertexPosition;
void main() {
gl_Position = MVP * vec4(ModelPosition, 1.f);
WorldPosition = vertexPosition;
}
fragment shader
layout(location = 0) out vec4 color;
uniform samplerCube CubeMap;
// cubemap lookup
vec3 fragToCube = WorldPosition - CubePos;
vec3 lookup = texture(CubeMap, fragToCube).xyz;
color = vec4(lookup, 1.f);
Result image :
When I rendered each face of the cubemap, I confirmed that it rendered correctly. However, when rendered with the main shader, it is wrong. I think the lookup to the cubemap is wrong, but I’m not sure why.
Also, when the cubemap initialization is set to DEPTH_COMPONENT, it can be looked up correctly. However, I wanted to store four values, so when I made RGBA.
thanks.