소스 검색

Fixing a bug that triggers more shadow passes than necessary. Also a small refactoring

Panagiotis Christopoulos Charitos 12 년 전
부모
커밋
8c5fe3d938

+ 5 - 0
include/anki/scene/RenderComponent.h

@@ -183,6 +183,11 @@ public:
 	/// Access the material
 	virtual const Material& getMaterial() = 0;
 
+	Bool castsShadow()
+	{
+		return getMaterial().getShadow() && !getMaterial().isBlendingEnabled();
+	}
+
 	/// Information for movables. It's actualy an array of transformations.
 	virtual const Transform* getRenderWorldTransforms()
 	{

+ 0 - 22
include/anki/scene/Visibility.h

@@ -79,28 +79,6 @@ struct VisibilityTestResults
 		renderables.reserve(renderablesReservedSize);
 		lights.reserve(lightsReservedSize);
 	}
-
-	Container::iterator getRenderablesBegin()
-	{
-		return renderables.begin();
-	}
-	Container::iterator getRenderablesEnd()
-	{
-		return renderables.end();
-	}
-	U32 getRenderablesCount() const
-	{
-		return renderables.size();
-	}
-
-	Container::iterator getLightsBegin()
-	{
-		return lights.begin();
-	}
-	Container::iterator getLightsEnd()
-	{
-		return lights.end();
-	}
 };
 
 /// Sort spatial scene nodes on distance

+ 3 - 4
src/renderer/Bs.cpp

@@ -28,12 +28,11 @@ void Bs::run()
 		scene.getActiveCamera().getFrustumComponent()->
 		getVisibilityTestResults();
 
-	for(auto it = vi.getRenderablesBegin(); it != vi.getRenderablesEnd();
-		++it)
+	for(auto it : vi.renderables)
 	{
 		drawer.render(scene.getActiveCamera(), RenderableDrawer::RS_BLEND,
-			COLOR_PASS, *(*it).node, (*it).subSpatialIndices, 
-			(*it).subSpatialIndicesCount);
+			COLOR_PASS, *it.node, it.subSpatialIndices, 
+			it.subSpatialIndicesCount);
 	}
 
 	GlStateSingleton::get().setDepthMaskEnabled(true);

+ 3 - 4
src/renderer/Ez.cpp

@@ -25,12 +25,11 @@ void Ez::run()
 		cam.getFrustumComponent()->getVisibilityTestResults();
 
 	U count = 0;
-	for(auto it = vi.getRenderablesBegin();
-		it != vi.getRenderablesEnd() && count < maxObjectsToDraw; ++it)
+	for(auto it : vi.renderables)
 	{
 		r->getSceneDrawer().render(cam, RenderableDrawer::RS_MATERIAL,
-			DEPTH_PASS, *(*it).node, (*it).subSpatialIndices, 
-			(*it).subSpatialIndicesCount);
+			DEPTH_PASS, *it.node, it.subSpatialIndices, 
+			it.subSpatialIndicesCount);
 		++count;
 	}
 }

+ 4 - 4
src/renderer/Is.cpp

@@ -590,9 +590,9 @@ void Is::lightPass()
 	U visibleSpotTexLightsCount = 0;
 	Array<Light*, Sm::MAX_SHADOW_CASTERS> shadowCasters;
 
-	for(auto it = vi.getLightsBegin(); it != vi.getLightsEnd(); ++it)
+	for(auto it : vi.lights)
 	{
-		Light* light = (*it).node->getLight();
+		Light* light = it.node->getLight();
 		ANKI_ASSERT(light);
 		switch(light->getLightType())
 		{
@@ -705,8 +705,8 @@ void Is::lightPass()
 		job.plightsIdsBuffer = plightIdsClientBuffer;
 		job.slightsIdsBuffer = slightIdsClientBuffer;
 
-		job.lightsBegin = vi.getLightsBegin();
-		job.lightsEnd = vi.getLightsEnd();
+		job.lightsBegin = vi.lights.begin();
+		job.lightsEnd = vi.lights.end();
 
 		job.pointLightsCount = &pointLightsAtomicCount;
 		job.spotLightsCount = &spotLightsAtomicCount;

+ 2 - 2
src/renderer/Lf.cpp

@@ -152,9 +152,9 @@ void Lf::run()
 	// Iterate the visible light and get those that have lens flare
 	Array<Light*, ANKI_MAX_LIGHTS_WITH_FLARE> lights;
 	U lightsCount = 0;
-	for(auto it = vi.getLightsBegin(); it != vi.getLightsEnd(); ++it)
+	for(auto it : vi.lights)
 	{
-		SceneNode& sn = *(*it).node;
+		SceneNode& sn = *it.node;
 		ANKI_ASSERT(sn.getLight());
 		Light* light = sn.getLight();
 

+ 3 - 3
src/renderer/Ms.cpp

@@ -113,11 +113,11 @@ void Ms::run()
 	VisibilityTestResults& vi =
 		r->getSceneGraph().getActiveCamera().getVisibilityTestResults();
 
-	for(auto it = vi.getRenderablesBegin(); it != vi.getRenderablesEnd(); ++it)
+	for(auto it : vi.renderables)
 	{
 		r->getSceneDrawer().render(r->getSceneGraph().getActiveCamera(),
-			RenderableDrawer::RS_MATERIAL, COLOR_PASS, *(*it).node, 
-			(*it).subSpatialIndices, (*it).subSpatialIndicesCount);
+			RenderableDrawer::RS_MATERIAL, COLOR_PASS, *it.node, 
+			it.subSpatialIndices, it.subSpatialIndicesCount);
 	}
 
 	// If there is multisampling then resolve to singlesampled

+ 5 - 5
src/renderer/Sm.cpp

@@ -164,9 +164,9 @@ Sm::Shadowmap* Sm::doLight(Light& light)
 	U32 lastUpdate = light.MoveComponent::getTimestamp();
 	lastUpdate = std::max(lastUpdate, fr->getTimestamp());
 
-	for(auto it = vi.getRenderablesBegin(); it != vi.getRenderablesEnd(); ++it)
+	for(auto it : vi.renderables)
 	{
-		SceneNode* node = (*it).node;
+		SceneNode* node = it.node;
 		FrustumComponent* bfr = node->getFrustumComponent();
 		MoveComponent* bmov = node->getMoveComponent();
 		SpatialComponent* sp = node->getSpatialComponent();
@@ -206,11 +206,11 @@ Sm::Shadowmap* Sm::doLight(Light& light)
 
 	//std::cout << "Shadowmap for: " << &sm << std::endl;
 
-	for(auto it = vi.getRenderablesBegin(); it != vi.getRenderablesEnd(); ++it)
+	for(auto it : vi.renderables)
 	{
 		r->getSceneDrawer().render(light, RenderableDrawer::RS_MATERIAL,
-			DEPTH_PASS, *(*it).node, (*it).subSpatialIndices, 
-			(*it).subSpatialIndicesCount);
+			DEPTH_PASS, *it.node, it.subSpatialIndices, 
+			it.subSpatialIndicesCount);
 	}
 
 	ANKI_COUNTER_INC(C_RENDERER_SHADOW_PASSES, (U64)1);

+ 4 - 4
src/scene/MoveComponent.cpp

@@ -55,6 +55,10 @@ void MoveComponent::updateWorldTransform()
 		}
 
 		moveUpdate();
+
+		// Now it's a good time to cleanse parent
+		disableBits(MF_MARKED_FOR_UPDATE);
+		timestamp = getGlobTimestamp();
 	}
 
 	// Update the children
@@ -68,10 +72,6 @@ void MoveComponent::updateWorldTransform()
 
 		mov.updateWorldTransform();
 	});
-
-	// Now it's a good time to cleanse parent
-	disableBits(MF_MARKED_FOR_UPDATE);
-	timestamp = getGlobTimestamp();
 }
 
 } // end namespace anki

+ 3 - 2
src/scene/Visibility.cpp

@@ -173,6 +173,8 @@ struct VisibilityTestJob: ThreadJob
 		scene->iterateSceneNodes([&](SceneNode& node)
 		{
 			FrustumComponent* fr = node.getFrustumComponent();
+			RenderComponent* r = node.getRenderComponent();
+
 			// Wont check the same
 			if(ANKI_UNLIKELY(&ref == fr))
 			{
@@ -201,8 +203,7 @@ struct VisibilityTestJob: ThreadJob
 
 			sp->enableBits(SpatialComponent::SF_VISIBLE_LIGHT);
 
-			RenderComponent* r = node.getRenderComponent();
-			if(r)
+			if(r && r->castsShadow())
 			{
 				lvisible->renderables.push_back(VisibleNode(
 					&node, subSpatialIndices, subSpatialIndicesCount));