ソースを参照

Sorting renderables enabled

Panagiotis Christopoulos Charitos 13 年 前
コミット
944fa99f64

+ 1 - 1
include/anki/scene/Camera.h

@@ -32,7 +32,7 @@ public:
 		uint movableFlags, Movable* movParent, // Movable
 		Frustum* frustum) // Spatial & Frustumable
 		: SceneNode(name, scene), Movable(movableFlags, movParent, *this),
-			Spatial(this, frustum), Frustumable(frustum), type(type_)
+			Spatial(this, frustum), Frustumable(frustum, this), type(type_)
 	{}
 
 	virtual ~Camera();

+ 12 - 2
include/anki/scene/Frustumable.h

@@ -18,8 +18,8 @@ public:
 	/// @{
 
 	/// Pass the frustum here so we can avoid the virtuals
-	Frustumable(Frustum* fr)
-		: frustum(fr)
+	Frustumable(Frustum* fr, SceneNode* sn)
+		: frustum(fr), node(sn)
 	{}
 	/// @}
 
@@ -58,6 +58,15 @@ public:
 	{
 		return viewProjectionMat;
 	}
+
+	const SceneNode& getSceneNode() const
+	{
+		return *node;
+	}
+	SceneNode& getSceneNode()
+	{
+		return *node;
+	}
 	/// @}
 
 	void frustumableMarkUpdated()
@@ -83,6 +92,7 @@ protected:
 	Mat4 projectionMat = Mat4::getIdentity();
 	Mat4 viewMat = Mat4::getIdentity();
 	Mat4 viewProjectionMat = Mat4::getIdentity();
+	SceneNode* node;
 
 private:
 	U32 timestamp = Timestamp::getTimestamp();

+ 7 - 0
include/anki/scene/Spatial.h

@@ -52,6 +52,11 @@ public:
 	{
 		return timestamp;
 	}
+
+	const Vec3& getSpatialOrigin() const
+	{
+		return origin;
+	}
 	/// @}
 
 	/// The derived class has to manually set when the collision shape got
@@ -60,6 +65,7 @@ public:
 	{
 		timestamp = Timestamp::getTimestamp();
 		spatialCs->toAabb(aabb);
+		origin = (aabb.getMin() + aabb.getMax()) * 0.5;
 	}
 
 protected:
@@ -70,6 +76,7 @@ private:
 	OctreeNode* octreeNode = nullptr; ///< What octree node includes this
 	Aabb aabb; ///< A faster shape
 	SceneNode* sceneNode; ///< Know your father
+	Vec3 origin;
 };
 /// @}
 

+ 3 - 3
src/renderer/Hdr.cpp

@@ -92,10 +92,10 @@ void Hdr::init(const RendererInitializer& initializer)
 void Hdr::run()
 {
 	ANKI_ASSERT(enabled);
-	/*if(r->getFramesCount() % 2 == 0)
+	if(r->getFramesCount() % 2 == 0)
 	{
 		return;
-	}*/
+	}
 
 	GlStateSingleton::get().setViewport(0, 0, width, height);
 
@@ -119,7 +119,7 @@ void Hdr::run()
 	toneSProg->findUniformVariable("fai").set(r->getIs().getFai());
 	r->drawQuad();
 
-#if 1
+#if 0
 	// blurring passes
 	for(U32 i = 0; i < blurringIterationsCount; i++)
 	{

+ 1 - 1
src/renderer/Renderer.cpp

@@ -113,7 +113,7 @@ void Renderer::drawQuadMultiple(U times)
 {
 	quadVao.bind();
 #if ANKI_GL == ANKI_GL_DESKTOP
-	const U max_times = 8;
+	const U max_times = 16;
 	Array<GLsizei, max_times> count;
 	Array<const GLvoid*, max_times> indices;
 

+ 1 - 1
src/scene/Light.cpp

@@ -48,7 +48,7 @@ PointLight::PointLight(const char* name, Scene* scene,
 SpotLight::SpotLight(const char* name, Scene* scene,
 	U32 movableFlags, Movable* movParent)
 	: Light(LT_SPOT, name, scene, movableFlags, movParent, &frustum),
-		Frustumable(&frustum)
+		Frustumable(&frustum, this)
 {
 	const F32 ang = toRad(45.0);
 	setOuterAngle(ang / 2.0);

+ 35 - 7
src/scene/VisibilityTester.cpp

@@ -7,6 +7,25 @@
 
 namespace anki {
 
+//==============================================================================
+
+struct DistanceSortFunctor
+{
+	Vec3 origin;
+
+	bool operator()(SceneNode* a, SceneNode* b)
+	{
+		ANKI_ASSERT(a->getSpatial() != nullptr && b->getSpatial() != nullptr);
+
+		F32 dist0 = origin.getDistanceSquared(
+			a->getSpatial()->getSpatialOrigin());
+		F32 dist1 = origin.getDistanceSquared(
+			b->getSpatial()->getSpatialOrigin());
+
+		return dist0 < dist1;
+	}
+};
+
 //==============================================================================
 VisibilityTester::~VisibilityTester()
 {}
@@ -54,18 +73,27 @@ void VisibilityTester::test(Frustumable& ref, Scene& scene, Renderer& r)
 		{
 			vinfo.renderables.push_back(node);
 		}
-
-		Light* l = node->getLight();
-		if(l)
+		else
 		{
-			vinfo.lights.push_back(node);
-
-			if(l->getShadowEnabled() && fr)
+			Light* l = node->getLight();
+			if(l)
 			{
-				testLight(*l, scene);
+				vinfo.lights.push_back(node);
+
+				if(l->getShadowEnabled() && fr)
+				{
+					testLight(*l, scene);
+				}
 			}
 		}
 	}
+
+	DistanceSortFunctor comp;
+	comp.origin =
+		ref.getSceneNode().getMovable()->getWorldTransform().getOrigin();
+	std::sort(vinfo.lights.begin(), vinfo.lights.end(), comp);
+
+	std::sort(vinfo.renderables.begin(), vinfo.renderables.end(), comp);
 }
 
 //==============================================================================

+ 1 - 1
testapp/Main.cpp

@@ -383,7 +383,7 @@ void initSubsystems(int argc, char* argv[])
 	initializer.is.sm.resolution = 512;
 	initializer.pps.hdr.enabled = true;
 	initializer.pps.hdr.renderingQuality = 0.25;
-	initializer.pps.hdr.blurringDist = 2.0;
+	initializer.pps.hdr.blurringDist = 0.5;
 	initializer.pps.hdr.blurringIterationsCount = 2;
 	initializer.pps.hdr.exposure = 8.0;
 	initializer.pps.ssao.blurringIterationsNum = 4;