void IrrDriver::renderScene(scene::ICameraSceneNode * const camnode, unsigned pointlightcount, std::vector<GlowData>& glows, float dt, bool hasShadow, bool forceRTT) { glBindBufferBase(GL_UNIFORM_BUFFER, 0, SharedObject::ViewProjectionMatrixesUBO); glBindBufferBase(GL_UNIFORM_BUFFER, 1, SharedObject::LightingDataUBO); m_scene_manager->setActiveCamera(camnode); PROFILER_PUSH_CPU_MARKER("- Draw Call Generation", 0xFF, 0xFF, 0xFF); PrepareDrawCalls(camnode); PROFILER_POP_CPU_MARKER(); // Shadows { // To avoid wrong culling, use the largest view possible m_scene_manager->setActiveCamera(m_suncam); if (CVS->isDefferedEnabled() && CVS->isShadowEnabled() && hasShadow) { PROFILER_PUSH_CPU_MARKER("- Shadow", 0x30, 0x6F, 0x90); renderShadows(); PROFILER_POP_CPU_MARKER(); if (CVS->isGlobalIlluminationEnabled()) { PROFILER_PUSH_CPU_MARKER("- RSM", 0xFF, 0x0, 0xFF); renderRSM(); PROFILER_POP_CPU_MARKER(); } } m_scene_manager->setActiveCamera(camnode); } PROFILER_PUSH_CPU_MARKER("- Solid Pass 1", 0xFF, 0x00, 0x00); glDepthMask(GL_TRUE); glDepthFunc(GL_LEQUAL); glEnable(GL_DEPTH_TEST); glDisable(GL_BLEND); glEnable(GL_CULL_FACE); if (CVS->isDefferedEnabled() || forceRTT) { m_rtts->getFBO(FBO_NORMAL_AND_DEPTHS).Bind(); glClearColor(0., 0., 0., 0.); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); renderSolidFirstPass(); } else { // We need a cleared depth buffer for some effect (eg particles depth blending) if (GraphicsRestrictions::isDisabled(GraphicsRestrictions::GR_FRAMEBUFFER_SRGB_WORKING)) glDisable(GL_FRAMEBUFFER_SRGB); m_rtts->getFBO(FBO_NORMAL_AND_DEPTHS).Bind(); // Bind() modifies the viewport. In order not to affect anything else, // the viewport is just reset here and not removed in Bind(). const core::recti &vp = Camera::getActiveCamera()->getViewport(); glViewport(vp.UpperLeftCorner.X, irr_driver->getActualScreenSize().Height - vp.LowerRightCorner.Y, vp.LowerRightCorner.X - vp.UpperLeftCorner.X, vp.LowerRightCorner.Y - vp.UpperLeftCorner.Y); glClear(GL_DEPTH_BUFFER_BIT); if (GraphicsRestrictions::isDisabled(GraphicsRestrictions::GR_FRAMEBUFFER_SRGB_WORKING)) glEnable(GL_FRAMEBUFFER_SRGB); glBindFramebuffer(GL_FRAMEBUFFER, 0); } PROFILER_POP_CPU_MARKER(); // Lights { PROFILER_PUSH_CPU_MARKER("- Light", 0x00, 0xFF, 0x00); if (CVS->isDefferedEnabled()) renderLights(pointlightcount, hasShadow); PROFILER_POP_CPU_MARKER(); } // Handle SSAO { PROFILER_PUSH_CPU_MARKER("- SSAO", 0xFF, 0xFF, 0x00); ScopedGPUTimer Timer(getGPUTimer(Q_SSAO)); if (UserConfigParams::m_ssao) renderSSAO(); PROFILER_POP_CPU_MARKER(); } PROFILER_PUSH_CPU_MARKER("- Solid Pass 2", 0x00, 0x00, 0xFF); if (CVS->isDefferedEnabled() || forceRTT) { m_rtts->getFBO(FBO_COLORS).Bind(); SColor clearColor(0, 150, 150, 150); if (World::getWorld() != NULL) clearColor = World::getWorld()->getClearColor(); glClearColor(clearColor.getRed() / 255.f, clearColor.getGreen() / 255.f, clearColor.getBlue() / 255.f, clearColor.getAlpha() / 255.f); glClear(GL_COLOR_BUFFER_BIT); glDepthMask(GL_FALSE); } renderSolidSecondPass(); PROFILER_POP_CPU_MARKER(); if (getNormals()) { m_rtts->getFBO(FBO_NORMAL_AND_DEPTHS).Bind(); renderNormalsVisualisation(); m_rtts->getFBO(FBO_COLORS).Bind(); } // Render ambient scattering if (CVS->isDefferedEnabled() && World::getWorld() != NULL && World::getWorld()->isFogEnabled()) { PROFILER_PUSH_CPU_MARKER("- Ambient scatter", 0xFF, 0x00, 0x00); ScopedGPUTimer Timer(getGPUTimer(Q_FOG)); renderAmbientScatter(); PROFILER_POP_CPU_MARKER(); } { PROFILER_PUSH_CPU_MARKER("- Skybox", 0xFF, 0x00, 0xFF); ScopedGPUTimer Timer(getGPUTimer(Q_SKYBOX)); renderSkybox(camnode); PROFILER_POP_CPU_MARKER(); } // Render discrete lights scattering if (CVS->isDefferedEnabled() && World::getWorld() != NULL && World::getWorld()->isFogEnabled()) { PROFILER_PUSH_CPU_MARKER("- PointLight Scatter", 0xFF, 0x00, 0x00); ScopedGPUTimer Timer(getGPUTimer(Q_FOG)); renderLightsScatter(pointlightcount); PROFILER_POP_CPU_MARKER(); } if (getRH()) { glDisable(GL_BLEND); m_rtts->getFBO(FBO_COLORS).Bind(); m_post_processing->renderRHDebug(m_rtts->getRH().getRTT()[0], m_rtts->getRH().getRTT()[1], m_rtts->getRH().getRTT()[2], rh_matrix, rh_extend); } if (getGI()) { glDisable(GL_BLEND); m_rtts->getFBO(FBO_COLORS).Bind(); m_post_processing->renderGI(rh_matrix, rh_extend, m_rtts->getRH().getRTT()[0], m_rtts->getRH().getRTT()[1], m_rtts->getRH().getRTT()[2]); } PROFILER_PUSH_CPU_MARKER("- Glow", 0xFF, 0xFF, 0x00); // Render anything glowing. if (!m_mipviz && !m_wireframe && UserConfigParams::m_glow) { ScopedGPUTimer Timer(getGPUTimer(Q_GLOW)); irr_driver->setPhase(GLOW_PASS); renderGlow(glows); } // end glow PROFILER_POP_CPU_MARKER(); PROFILER_PUSH_CPU_MARKER("- Lensflare/godray", 0x00, 0xFF, 0xFF); computeSunVisibility(); PROFILER_POP_CPU_MARKER(); // Render transparent { PROFILER_PUSH_CPU_MARKER("- Transparent Pass", 0xFF, 0x00, 0x00); ScopedGPUTimer Timer(getGPUTimer(Q_TRANSPARENT)); renderTransparent(); PROFILER_POP_CPU_MARKER(); } m_sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); // Render particles { PROFILER_PUSH_CPU_MARKER("- Particles", 0xFF, 0xFF, 0x00); ScopedGPUTimer Timer(getGPUTimer(Q_PARTICLES)); renderParticles(); PROFILER_POP_CPU_MARKER(); } if (!CVS->isDefferedEnabled() && !forceRTT) { glDisable(GL_FRAMEBUFFER_SRGB); glDisable(GL_DEPTH_TEST); glDepthMask(GL_FALSE); return; } // Ensure that no object will be drawn after that by using invalid pass irr_driver->setPhase(PASS_COUNT); }
void IrrDriver::renderScene(scene::ICameraSceneNode * const camnode, unsigned pointlightcount, std::vector<GlowData>& glows, float dt, bool hasShadow, bool forceRTT) { glBindBufferBase(GL_UNIFORM_BUFFER, 0, SharedObject::ViewProjectionMatrixesUBO); m_scene_manager->setActiveCamera(camnode); PROFILER_PUSH_CPU_MARKER("- Draw Call Generation", 0xFF, 0xFF, 0xFF); PrepareDrawCalls(camnode); PROFILER_POP_CPU_MARKER(); // Shadows { // To avoid wrong culling, use the largest view possible m_scene_manager->setActiveCamera(m_suncam); if (UserConfigParams::m_dynamic_lights && UserConfigParams::m_shadows && !irr_driver->needUBOWorkaround() && hasShadow) { PROFILER_PUSH_CPU_MARKER("- Shadow", 0x30, 0x6F, 0x90); renderShadows(); PROFILER_POP_CPU_MARKER(); if (UserConfigParams::m_gi) { PROFILER_PUSH_CPU_MARKER("- RSM", 0xFF, 0x0, 0xFF); renderRSM(); PROFILER_POP_CPU_MARKER(); } } m_scene_manager->setActiveCamera(camnode); } PROFILER_PUSH_CPU_MARKER("- Solid Pass 1", 0xFF, 0x00, 0x00); glDepthMask(GL_TRUE); glDepthFunc(GL_LEQUAL); glEnable(GL_DEPTH_TEST); glDisable(GL_BLEND); glEnable(GL_CULL_FACE); if (UserConfigParams::m_dynamic_lights || forceRTT) { m_rtts->getFBO(FBO_NORMAL_AND_DEPTHS).Bind(); glClearColor(0., 0., 0., 0.); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); renderSolidFirstPass(); } PROFILER_POP_CPU_MARKER(); // Lights { PROFILER_PUSH_CPU_MARKER("- Light", 0x00, 0xFF, 0x00); if (UserConfigParams::m_dynamic_lights) renderLights(pointlightcount, hasShadow); PROFILER_POP_CPU_MARKER(); } // Handle SSAO { PROFILER_PUSH_CPU_MARKER("- SSAO", 0xFF, 0xFF, 0x00); ScopedGPUTimer Timer(getGPUTimer(Q_SSAO)); if (UserConfigParams::m_ssao) renderSSAO(); PROFILER_POP_CPU_MARKER(); } PROFILER_PUSH_CPU_MARKER("- Solid Pass 2", 0x00, 0x00, 0xFF); if (UserConfigParams::m_dynamic_lights || forceRTT) { m_rtts->getFBO(FBO_COLORS).Bind(); SColor clearColor(0, 150, 150, 150); if (World::getWorld() != NULL) clearColor = World::getWorld()->getClearColor(); glClearColor(clearColor.getRed() / 255.f, clearColor.getGreen() / 255.f, clearColor.getBlue() / 255.f, clearColor.getAlpha() / 255.f); glClear(GL_COLOR_BUFFER_BIT); glDepthMask(GL_FALSE); } renderSolidSecondPass(); PROFILER_POP_CPU_MARKER(); if (getNormals()) { m_rtts->getFBO(FBO_NORMAL_AND_DEPTHS).Bind(); renderNormalsVisualisation(); m_rtts->getFBO(FBO_COLORS).Bind(); } if (UserConfigParams::m_dynamic_lights && World::getWorld() != NULL && World::getWorld()->isFogEnabled()) { PROFILER_PUSH_CPU_MARKER("- Fog", 0xFF, 0x00, 0x00); ScopedGPUTimer Timer(getGPUTimer(Q_FOG)); renderLightsScatter(pointlightcount); PROFILER_POP_CPU_MARKER(); } { PROFILER_PUSH_CPU_MARKER("- Skybox", 0xFF, 0x00, 0xFF); ScopedGPUTimer Timer(getGPUTimer(Q_SKYBOX)); renderSkybox(camnode); PROFILER_POP_CPU_MARKER(); } if (getRH()) { m_rtts->getFBO(FBO_COLORS).Bind(); m_post_processing->renderRHDebug(m_rtts->getRH().getRTT()[0], m_rtts->getRH().getRTT()[1], m_rtts->getRH().getRTT()[2], rh_matrix, rh_extend); } if (getGI()) { m_rtts->getFBO(FBO_COLORS).Bind(); m_post_processing->renderGI(rh_matrix, rh_extend, m_rtts->getRH().getRTT()[0], m_rtts->getRH().getRTT()[1], m_rtts->getRH().getRTT()[2]); } PROFILER_PUSH_CPU_MARKER("- Glow", 0xFF, 0xFF, 0x00); // Render anything glowing. if (!m_mipviz && !m_wireframe && UserConfigParams::m_glow) { ScopedGPUTimer Timer(getGPUTimer(Q_GLOW)); irr_driver->setPhase(GLOW_PASS); renderGlow(glows); } // end glow PROFILER_POP_CPU_MARKER(); PROFILER_PUSH_CPU_MARKER("- Lensflare/godray", 0x00, 0xFF, 0xFF); computeSunVisibility(); PROFILER_POP_CPU_MARKER(); // Render transparent { PROFILER_PUSH_CPU_MARKER("- Transparent Pass", 0xFF, 0x00, 0x00); ScopedGPUTimer Timer(getGPUTimer(Q_TRANSPARENT)); renderTransparent(); PROFILER_POP_CPU_MARKER(); } m_sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); // Render particles { PROFILER_PUSH_CPU_MARKER("- Particles", 0xFF, 0xFF, 0x00); ScopedGPUTimer Timer(getGPUTimer(Q_PARTICLES)); renderParticles(); PROFILER_POP_CPU_MARKER(); } if (!UserConfigParams::m_dynamic_lights && !forceRTT) { glDisable(GL_FRAMEBUFFER_SRGB); glDisable(GL_DEPTH_TEST); glDepthMask(GL_FALSE); return; } // Ensure that no object will be drawn after that by using invalid pass irr_driver->setPhase(PASS_COUNT); }