From 53fe339fb38dd6a503cbe3351e40fb16f948748b Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Fri, 12 Sep 2014 01:07:02 +0200 Subject: [PATCH] Enable simple culling for non indirect codepath --- src/graphics/stkscenemanager.cpp | 50 ++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/src/graphics/stkscenemanager.cpp b/src/graphics/stkscenemanager.cpp index ace0260b9..ba65098ee 100644 --- a/src/graphics/stkscenemanager.cpp +++ b/src/graphics/stkscenemanager.cpp @@ -151,16 +151,11 @@ bool isBoxInFrontOfPlane(const core::plane3df &plane, const core::vector3df edge } static -bool isCulled(const scene::ICameraSceneNode *cam, const scene::ISceneNode *node) +bool isCulledPrecise(const scene::ICameraSceneNode *cam, const scene::ISceneNode *node) { if (!node->getAutomaticCulling()) return false; - // Faster albeit less precise alternative -/* core::aabbox3d tbox = node->getBoundingBox(); - node->getAbsoluteTransformation().transformBoxEx(tbox); - return !(tbox.intersectsWithBox(cam->getViewFrustum()->getBoundingBox()));*/ - scene::SViewFrustum frust = *cam->getViewFrustum(); //transform the frustum to the node's current absolute transformation @@ -177,8 +172,20 @@ bool isCulled(const scene::ICameraSceneNode *cam, const scene::ISceneNode *node) return false; } +static +bool isCulledFast(const scene::ICameraSceneNode *cam, const scene::ISceneNode *node) +{ + if (!node->getAutomaticCulling()) + return false; + + core::aabbox3d tbox = node->getBoundingBox(); + node->getAbsoluteTransformation().transformBoxEx(tbox); + return !(tbox.intersectsWithBox(cam->getViewFrustum()->getBoundingBox())); +} + static void -handleSTKCommon(scene::ISceneNode *Node, std::vector *ImmediateDraw) +handleSTKCommon(scene::ISceneNode *Node, std::vector *ImmediateDraw, + const scene::ICameraSceneNode *cam, scene::ICameraSceneNode *shadowcam[4], const scene::ICameraSceneNode *rsmcam) { STKMeshCommon *node = dynamic_cast(Node); if (!node) @@ -192,7 +199,6 @@ handleSTKCommon(scene::ISceneNode *Node, std::vector *Immed return; } - // Transparent GLMesh *mesh; if (World::getWorld() && World::getWorld()->isFogEnabled()) @@ -263,6 +269,8 @@ handleSTKCommon(scene::ISceneNode *Node, std::vector *Immed } else { + if (isCulledFast(cam, Node)) + continue; core::matrix4 ModelMatrix = Node->getAbsoluteTransformation(), InvModelMatrix; ModelMatrix.getInverse(InvModelMatrix); @@ -311,6 +319,8 @@ handleSTKCommon(scene::ISceneNode *Node, std::vector *Immed } else { + if (isCulledFast(shadowcam[cascade], Node)) + continue; core::matrix4 ModelMatrix = Node->getAbsoluteTransformation(), InvModelMatrix; ModelMatrix.getInverse(InvModelMatrix); @@ -364,6 +374,8 @@ handleSTKCommon(scene::ISceneNode *Node, std::vector *Immed } else { + if (isCulledFast(rsmcam, Node)) + continue; core::matrix4 ModelMatrix = Node->getAbsoluteTransformation(), InvModelMatrix; ModelMatrix.getInverse(InvModelMatrix); @@ -403,7 +415,7 @@ handleSTKCommon(scene::ISceneNode *Node, std::vector *Immed static void parseSceneManager(core::list List, std::vector *ImmediateDraw, - scene::ICameraSceneNode* cam) + const scene::ICameraSceneNode* cam, scene::ICameraSceneNode *shadow_cam[4], const scene::ICameraSceneNode *rsmcam) { core::list::Iterator I = List.begin(), E = List.end(); for (; I != E; ++I) @@ -416,14 +428,14 @@ parseSceneManager(core::list List, std::vector(*I)) { - if (!isCulled(cam, *I) && node->update()) + if (!isCulledPrecise(cam, *I) && node->update()) ParticlesList::getInstance()->push_back(node); continue; } - handleSTKCommon(*I, ImmediateDraw); + handleSTKCommon(*I, ImmediateDraw, cam, shadow_cam, rsmcam); - parseSceneManager((*I)->getChildren(), ImmediateDraw, cam); + parseSceneManager((*I)->getChildren(), ImmediateDraw, cam, shadow_cam, rsmcam); } } @@ -484,18 +496,18 @@ void IrrDriver::PrepareDrawCalls(scene::ICameraSceneNode *camnode) DeferredUpdate.clear(); core::list List = m_scene_manager->getRootSceneNode()->getChildren(); - parseSceneManager(List, ImmediateDrawList::getInstance(), camnode); + parseSceneManager(List, ImmediateDrawList::getInstance(), camnode, m_shadow_camnodes, m_suncam); #pragma omp parallel for for (int i = 0; i < (int)DeferredUpdate.size(); i++) { scene::ISceneNode *node = dynamic_cast(DeferredUpdate[i]); - DeferredUpdate[i]->setCulledForPlayerCam(isCulled(camnode, node)); - DeferredUpdate[i]->setCulledForRSMCam(isCulled(m_suncam, node)); - DeferredUpdate[i]->setCulledForShadowCam(0, isCulled(m_shadow_camnodes[0], node)); - DeferredUpdate[i]->setCulledForShadowCam(1, isCulled(m_shadow_camnodes[1], node)); - DeferredUpdate[i]->setCulledForShadowCam(2, isCulled(m_shadow_camnodes[2], node)); - DeferredUpdate[i]->setCulledForShadowCam(3, isCulled(m_shadow_camnodes[3], node)); + DeferredUpdate[i]->setCulledForPlayerCam(isCulledPrecise(camnode, node)); + DeferredUpdate[i]->setCulledForRSMCam(isCulledPrecise(m_suncam, node)); + DeferredUpdate[i]->setCulledForShadowCam(0, isCulledPrecise(m_shadow_camnodes[0], node)); + DeferredUpdate[i]->setCulledForShadowCam(1, isCulledPrecise(m_shadow_camnodes[1], node)); + DeferredUpdate[i]->setCulledForShadowCam(2, isCulledPrecise(m_shadow_camnodes[2], node)); + DeferredUpdate[i]->setCulledForShadowCam(3, isCulledPrecise(m_shadow_camnodes[3], node)); } // Add a 1 s timeout