I am trying to implement shadow mapping, and currently I have 2 point lights and 1 global ambient light source and my rendering loop looks roughly like this (the details are not relevant):
void OpenGLRenderer::DrawRenderables(const uint32_t windowWidth, const uint32_t windowHeight, const RenderQueue& renderQueue, const RenderableLighting& lighting)
{
GLCALL(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
for (uint32_t lightIndex = 0; lightIndex < lighting.mUsedLights; lightIndex++)
{
if (lighting.mLights[lightIndex].mLightType == LightType::LIGHT_TYPE_POINT)
{
GLCALL(glUseProgram(mShadowMapProgram.mProgramHandle));
GLCALL(glBindFramebuffer(GL_FRAMEBUFFER, mFrameBuffer));
GLCALL(glViewport(0, 0, mShadowTextureWidth, mShadowTextureHeight));
for (uint32_t faceNum = 0; faceNum < CUBEMAP_NUM_FACES; faceNum++)
{
GLCALL(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceNum, mShadowMapTexture, 0));
GLCALL(glClear(GL_DEPTH_BUFFER_BIT));
ShadowPass();
}
GLCALL(glBindFramebuffer(GL_FRAMEBUFFER, 0));
}
// final pass
GLCALL(glUseProgram(mDefaultProgram.mProgramHandle));
GLCALL(glViewport(0, 0, (GLsizei)windowWidth, (GLsizei)windowHeight));
// enable blending, how?
ShadingPass();
}
GLCALL(glUseProgram(0));
}
The problem is the screen will only be shown with last light in the light list, for example the ambient light and therefore ignoring the effects of the point lights. I assume I somehow needs to do blending but I was wondering how and where is this done?
Thanks