0
\$\begingroup\$

I am attempting to perform shadow mapping with deferred shading, using the following code:

for (auto light : m_ShadowDirs)
{
    //render shadow map
    shadowDirPass(m_ShadowBuffer, light);
    glEnable(GL_BLEND);
    glBlendFunc(GL_ONE, GL_ONE);
    // activate shader for non shadow casting lights
    m_ShadowDirLightShader.activate();
    m_FrameBuffer.LightingPass(m_ShadowDirLightShader);
    m_ShadowDirLightShader.setUniform(("WSCamPos"), m_ActiveCamera->getPosition());
    m_ShadowDirLightShader.setDirLight(("dirLight"), static_cast<DirLightData&>(light->getLightData()));
    m_ShadowDirLightShader.setUniform(("ShadowTransform"), m_ShadowDirMatrix);
    //bind depth map
    m_ShadowDirLightShader.bindTexture(("shadowMap"),5, m_ShadowBuffer.getDepthTexture());
    //render
    renderQuad();
    glDisable(GL_BLEND);
}

shadowDirPass(m_ShadowBuffer, light); Simply renders the geometry to the shadow map. m_FrameBuffer.LightingPass(m_ShadowDirLightShader); Just binds the Gbuffer textures.

I have two directional lights in the scene, one with red colour (1,0,0), and one with blue colour (0,0,1)

One would think that the scene would be coloured purple, but no. Every time I render (for each) light, the image in the target framebuffer is overwritten completely, instead of blended together. To illustrate this, see the following images:

red light

Above is the scene with a single red light.

blue light

Above is the same scene, with a single blue light, but from a different direction. (See shadows).

When I enable both lights, the result is as if the first light was never used, though by stepping through the code, I can confirm that it is definitely going through a render cycle.

I'm pretty sure than I've messed up the blending somehow, but I could use some guidance.

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

As it turned out, I was calling glClear(COLOR_BUFFER_BIT), between lighting passes, within the FrameBuffer class. Once I removed that call, it worked fine.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .