I wish to have shadows with multiple lights.
Each light's shadow rendered to a depth cubemap.
How do I render each cubemap onto a single cubemap with transparency so have a cubemap with all the shadows?
This is how i'm setting up the cubemaps: code based on tutorial https://learnopengl.com/#!Advanced-Lighting/Shadows/Point-Shadows
const GLuint SHADOW_WIDTH = 1024, SHADOW_HEIGHT = 1024;
const int totalLights = 4;
GLuint depthMapFBO[totalLights];
GLuint depthCubemap[totalLights];
for (GLuint light = 0; light < totalLights; ++light)
{
glGenFramebuffers(1, &depthMapFBO[light]);
// Create depth cubemap texture
glGenTextures(1, &depthCubemap[light]);
glBindTexture(GL_TEXTURE_CUBE_MAP, depthCubemap[light]);
for (GLuint i = 0; i < 6; ++i)
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_DEPTH_COMPONENT, SHADOW_WIDTH, SHADOW_HEIGHT, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
// Attach cubemap as depth map FBO's color buffer
glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO[light]);
glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthCubemap[light], 0);
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
std::cout << "Framebuffer not complete!" << std::endl;
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
And this is the code to render a single cubemap:
// 1. Render scene to depth cubemap
glViewport(0, 0, SHADOW_WIDTH, SHADOW_HEIGHT);
glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO[0]);
glClear(GL_DEPTH_BUFFER_BIT);
// Set texture samples
simpleDepthShader.Use();
// 0. Create depth cubemap transformation matrices
GLfloat aspect = (GLfloat)SHADOW_WIDTH / (GLfloat)SHADOW_HEIGHT;
glm::mat4 shadowProj = glm::perspective(90.0f, aspect, fNear, fFaar);
std::vector<glm::mat4> shadowTransforms;
shadowTransforms.push_back(shadowProj * glm::lookAt(lightPositions[light], lightPositions[light] + glm::vec3(1.0, 0.0, 0.0), glm::vec3(0.0, -1.0, 0.0)));
shadowTransforms.push_back(shadowProj * glm::lookAt(lightPositions[light], lightPositions[light] + glm::vec3(-1.0, 0.0, 0.0), glm::vec3(0.0, -1.0, 0.0)));
shadowTransforms.push_back(shadowProj * glm::lookAt(lightPositions[light], lightPositions[light] + glm::vec3(0.0, 1.0, 0.0), glm::vec3(0.0, 0.0, 1.0)));
shadowTransforms.push_back(shadowProj * glm::lookAt(lightPositions[light], lightPositions[light] + glm::vec3(0.0, -1.0, 0.0), glm::vec3(0.0, 0.0, -1.0)));
shadowTransforms.push_back(shadowProj * glm::lookAt(lightPositions[light], lightPositions[light] + glm::vec3(0.0, 0.0, 1.0), glm::vec3(0.0, -1.0, 0.0)));
shadowTransforms.push_back(shadowProj * glm::lookAt(lightPositions[light], lightPositions[light] + glm::vec3(0.0, 0.0, -1.0), glm::vec3(0.0, -1.0, 0.0)));
for (GLuint i = 0; i < 6; ++i)
glUniformMatrix4fv(glGetUniformLocation(simpleDepthShader.Program, ("shadowTransforms[" + std::to_string(i) + "]").c_str()), 1, GL_FALSE, glm::value_ptr(shadowTransforms[i]));
glUniform1f(glGetUniformLocation(simpleDepthShader.Program, "far_plane"), fFaar);
glUniform3fv(glGetUniformLocation(simpleDepthShader.Program, "lightPos"), 1, &lightPositions[light][0]);
RenderScene(simpleDepthShader);
glBindFramebuffer(GL_FRAMEBUFFER, 0);