Improved LightingPasses interfaces

This commit is contained in:
Elderme
2015-10-09 22:19:57 +02:00
parent 84d3f19daf
commit 0ebadf7963
3 changed files with 72 additions and 83 deletions

View File

@@ -325,52 +325,6 @@ static void renderPointLights(unsigned count)
glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, count);
} // renderPointLights
// ----------------------------------------------------------------------------
void LightingPasses::renderRadianceHints(ShadowMatrices *shadow_matrices,
const FrameBuffer& radiance_hint_framebuffer,
const FrameBuffer& reflective_shadow_map_framebuffer)
{
ScopedGPUTimer timer(irr_driver->getGPUTimer(Q_RH));
glDisable(GL_BLEND);
radiance_hint_framebuffer.bind();
glBindVertexArray(SharedGPUObjects::getFullScreenQuadVAO());
if (CVS->needRHWorkaround())
{
NVWorkaroundRadianceHintsConstructionShader::getInstance()->use();
NVWorkaroundRadianceHintsConstructionShader::getInstance()
->setTextureUnits(
reflective_shadow_map_framebuffer.getRTT()[0],
reflective_shadow_map_framebuffer.getRTT()[1],
reflective_shadow_map_framebuffer.getDepthTexture());
for (unsigned i = 0; i < 32; i++)
{
NVWorkaroundRadianceHintsConstructionShader::getInstance()
->setUniforms(shadow_matrices->getRSMMatrix(),
shadow_matrices->getRHMatrix(),
shadow_matrices->getRHExtend(), i,
irr_driver->getSunColor());
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
}
else
{
RadianceHintsConstructionShader::getInstance()->use();
RadianceHintsConstructionShader::getInstance()
->setTextureUnits(
reflective_shadow_map_framebuffer.getRTT()[0],
reflective_shadow_map_framebuffer.getRTT()[1],
reflective_shadow_map_framebuffer.getDepthTexture()
);
RadianceHintsConstructionShader::getInstance()
->setUniforms(shadow_matrices->getRSMMatrix(),
shadow_matrices->getRHMatrix(),
shadow_matrices->getRHExtend(),
irr_driver->getSunColor());
glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, 32);
}
}
// ----------------------------------------------------------------------------
unsigned LightingPasses::updateLightsInfo(scene::ICameraSceneNode * const camnode,
float dt)
@@ -453,37 +407,68 @@ unsigned LightingPasses::updateLightsInfo(scene::ICameraSceneNode * const camnod
return lightnum;
} // updateLightsInfo
void LightingPasses::renderLights( unsigned point_light_count, bool has_shadow,
ShadowMatrices *shadow_matrices,
const FrameBuffer& shadow_framebuffer,
const FrameBuffer& radiance_hint_framebuffer,
const FrameBuffer& reflective_shadow_map_framebuffer,
const FrameBuffer& diffuse_framebuffer,
const FrameBuffer& diffuse_specular_framebuffer)
// ----------------------------------------------------------------------------
void LightingPasses::renderGlobalIllumination( ShadowMatrices *shadow_matrices,
const FrameBuffer& radiance_hint_framebuffer,
const FrameBuffer& reflective_shadow_map_framebuffer,
const FrameBuffer& diffuse_framebuffer)
{
//TODO: split this method in several smaller methods
if (CVS->isGlobalIlluminationEnabled() && has_shadow)
{
renderRadianceHints(shadow_matrices, radiance_hint_framebuffer, reflective_shadow_map_framebuffer);
//Radiance hints
ScopedGPUTimer timer(irr_driver->getGPUTimer(Q_RH));
glDisable(GL_BLEND);
radiance_hint_framebuffer.bind();
glBindVertexArray(SharedGPUObjects::getFullScreenQuadVAO());
if (CVS->needRHWorkaround())
{
NVWorkaroundRadianceHintsConstructionShader::getInstance()->use();
NVWorkaroundRadianceHintsConstructionShader::getInstance()
->setTextureUnits(
reflective_shadow_map_framebuffer.getRTT()[0],
reflective_shadow_map_framebuffer.getRTT()[1],
reflective_shadow_map_framebuffer.getDepthTexture());
for (unsigned i = 0; i < 32; i++)
{
NVWorkaroundRadianceHintsConstructionShader::getInstance()
->setUniforms(shadow_matrices->getRSMMatrix(),
shadow_matrices->getRHMatrix(),
shadow_matrices->getRHExtend(), i,
irr_driver->getSunColor());
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
}
else
{
RadianceHintsConstructionShader::getInstance()->use();
RadianceHintsConstructionShader::getInstance()
->setTextureUnits(
reflective_shadow_map_framebuffer.getRTT()[0],
reflective_shadow_map_framebuffer.getRTT()[1],
reflective_shadow_map_framebuffer.getDepthTexture()
);
RadianceHintsConstructionShader::getInstance()
->setUniforms(shadow_matrices->getRSMMatrix(),
shadow_matrices->getRHMatrix(),
shadow_matrices->getRHExtend(),
irr_driver->getSunColor());
glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, 32);
}
shadow_matrices->updateSunOrthoMatrices();
diffuse_framebuffer.bind();
PostProcessing *post_processing = irr_driver->getPostProcessing();
if (CVS->isGlobalIlluminationEnabled() && has_shadow)
//Global illumination
{
ScopedGPUTimer timer(irr_driver->getGPUTimer(Q_GI));
post_processing->renderGI(shadow_matrices->getRHMatrix(),
shadow_matrices->getRHExtend(),
radiance_hint_framebuffer);
diffuse_framebuffer.bind();
irr_driver->getPostProcessing()->renderGI( shadow_matrices->getRHMatrix(),
shadow_matrices->getRHExtend(),
radiance_hint_framebuffer);
}
}
void LightingPasses::renderLights( unsigned point_light_count, bool has_shadow,
const FrameBuffer& shadow_framebuffer,
const FrameBuffer& diffuse_specular_framebuffer)
{
PostProcessing *post_processing = irr_driver->getPostProcessing();
diffuse_specular_framebuffer.bind();
glClear(GL_COLOR_BUFFER_BIT);
@@ -498,8 +483,8 @@ void LightingPasses::renderLights( unsigned point_light_count, bool has_shadow,
{
post_processing->renderEnvMap(0);
}
}
}
// Render sunlight if and only if track supports shadow
if (!World::getWorld() || World::getWorld()->getTrack()->hasShadows())
{

View File

@@ -24,20 +24,19 @@
class LightingPasses
{
private:
void renderRadianceHints(ShadowMatrices *shadow_matrices,
const FrameBuffer& radiance_hint_framebuffer,
const FrameBuffer& reflective_shadow_map_framebuffer);
public:
unsigned updateLightsInfo(irr::scene::ICameraSceneNode * const camnode,
float dt);
void renderGlobalIllumination( ShadowMatrices *shadow_matrices,
const FrameBuffer& radiance_hint_framebuffer,
const FrameBuffer& reflective_shadow_map_framebuffer,
const FrameBuffer& diffuse_framebuffer);
void renderLights( unsigned point_light_count, bool has_shadow,
ShadowMatrices *shadow_matrices,
const FrameBuffer& shadow_framebuffer,
const FrameBuffer& radiance_hint_framebuffer,
const FrameBuffer& reflective_shadow_map_framebuffer,
const FrameBuffer& diffuse_framebuffer,
const FrameBuffer& diffuse_specular_framebuffer);
void renderAmbientScatter();
void renderLightsScatter(unsigned point_light_count);

View File

@@ -226,12 +226,16 @@ void ShaderBasedRenderer::renderScene(scene::ICameraSceneNode * const camnode, u
{
PROFILER_PUSH_CPU_MARKER("- Light", 0x00, 0xFF, 0x00);
if (CVS->isDefferedEnabled())
if (CVS->isGlobalIlluminationEnabled() && hasShadow)
{
m_lighting_passes->renderGlobalIllumination(irr_driver->getShadowMatrices(),
irr_driver->getRTT()->getRadianceHintFrameBuffer(),
irr_driver->getRTT()->getReflectiveShadowMapFrameBuffer(),
irr_driver->getRTT()->getFBO(FBO_DIFFUSE));
}
m_lighting_passes->renderLights(pointlightcount, hasShadow,
irr_driver->getShadowMatrices(),
irr_driver->getRTT()->getShadowFrameBuffer(),
irr_driver->getRTT()->getRadianceHintFrameBuffer(),
irr_driver->getRTT()->getReflectiveShadowMapFrameBuffer(),
irr_driver->getRTT()->getFBO(FBO_DIFFUSE),
irr_driver->getRTT()->getFBO(FBO_COMBINED_DIFFUSE_SPECULAR));
PROFILER_POP_CPU_MARKER();
}
@@ -514,6 +518,7 @@ void ShaderBasedRenderer::render(float dt)
PROFILER_POP_CPU_MARKER();
PROFILER_PUSH_CPU_MARKER("UBO upload", 0x0, 0xFF, 0x0);
irr_driver->computeMatrixesAndCameras(camnode, viewport.LowerRightCorner.X - viewport.UpperLeftCorner.X, viewport.LowerRightCorner.Y - viewport.UpperLeftCorner.Y);
irr_driver->getShadowMatrices()->updateSunOrthoMatrices();
irr_driver->uploadLightingData(); //TODO: move method; update "global" lighting (sun and spherical harmonics)
PROFILER_POP_CPU_MARKER();
renderScene(camnode, plc, glows, dt, track->hasShadows(), false);