From dfb8f4f5e52f63519156c55e49a43fa2d82d5023 Mon Sep 17 00:00:00 2001 From: Areloch Date: Fri, 17 Jun 2016 00:47:46 -0500 Subject: [PATCH] Makes point and spot lights be correctly culled with zoning like other objects. --- Engine/source/T3D/lightBase.cpp | 2 +- Engine/source/T3D/objectTypes.h | 3 ++- Engine/source/lighting/lightManager.cpp | 9 +++++++++ Engine/source/scene/sceneManager.cpp | 7 +++++++ Engine/source/scene/sceneManager.h | 4 ++++ 5 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Engine/source/T3D/lightBase.cpp b/Engine/source/T3D/lightBase.cpp index 028171f2ac..5c0ca1f876 100644 --- a/Engine/source/T3D/lightBase.cpp +++ b/Engine/source/T3D/lightBase.cpp @@ -68,7 +68,7 @@ LightBase::LightBase() mFlareScale( 1.0f ) { mNetFlags.set( Ghostable | ScopeAlways ); - mTypeMask = EnvironmentObjectType | LightObjectType; + mTypeMask = LightObjectType; mLight = LightManager::createLightInfo(); diff --git a/Engine/source/T3D/objectTypes.h b/Engine/source/T3D/objectTypes.h index 5f32667080..a67ea46287 100644 --- a/Engine/source/T3D/objectTypes.h +++ b/Engine/source/T3D/objectTypes.h @@ -177,7 +177,8 @@ enum SceneObjectTypeMasks StaticShapeObjectType | DynamicShapeObjectType | EntityObjectType | - ZoneObjectType ), // This improves the result of zone traversals. + ZoneObjectType | + LightObjectType ), // This improves the result of zone traversals. /// Mask for objects that should be specifically excluded from zone culling. CULLING_EXCLUDE_TYPEMASK = ( TerrainObjectType | diff --git a/Engine/source/lighting/lightManager.cpp b/Engine/source/lighting/lightManager.cpp index 2e2c4ff2ef..f53f5284d6 100644 --- a/Engine/source/lighting/lightManager.cpp +++ b/Engine/source/lighting/lightManager.cpp @@ -227,6 +227,15 @@ void LightManager::registerGlobalLights( const Frustum *frustum, bool staticLigh // Cull the lights using the frustum. getSceneManager()->getContainer()->findObjectList( *frustum, lightMask, &activeLights ); + for (U32 i = 0; i < activeLights.size(); ++i) + { + if (!getSceneManager()->mRenderedObjectsList.contains(activeLights[i])) + { + activeLights.erase(i); + --i; + } + } + // Store the culling position for sun placement // later... see setSpecialLight. mCullPos = frustum->getPosition(); diff --git a/Engine/source/scene/sceneManager.cpp b/Engine/source/scene/sceneManager.cpp index 0bb85784b9..b68de9defe 100644 --- a/Engine/source/scene/sceneManager.cpp +++ b/Engine/source/scene/sceneManager.cpp @@ -451,6 +451,13 @@ void SceneManager::_renderScene( SceneRenderState* state, U32 objectMask, SceneZ PROFILE_END(); + //store our rendered objects into a list we can easily look up against later if required + mRenderedObjectsList.clear(); + for (U32 i = 0; i < numRenderObjects; ++i) + { + mRenderedObjectsList.push_back(mBatchQueryList[i]); + } + // Render the remaining objects. PROFILE_START( Scene_renderObjects ); diff --git a/Engine/source/scene/sceneManager.h b/Engine/source/scene/sceneManager.h index 6347459130..3e7e65b61b 100644 --- a/Engine/source/scene/sceneManager.h +++ b/Engine/source/scene/sceneManager.h @@ -117,6 +117,10 @@ class SceneManager /// If true, render the AABBs of objects for debugging. static bool smRenderBoundingBoxes; + //A cache list of objects that made it through culling, so we don't have to attempt to re-test + //visibility of objects later. + Vector< SceneObject* > mRenderedObjectsList; + protected: /// Whether this is the client-side scene.