Преглед изворни кода

Fixing Tiler. Spheres not good enough

Panagiotis Christopoulos Charitos пре 12 година
родитељ
комит
e9c3df2199

+ 1 - 1
include/anki/renderer/Renderer.h

@@ -184,7 +184,7 @@ public:
 
 	const Mat4& getViewProjectionMatrix() const
 	{
-		return viewProjectionMat;
+		return viewProjectionMat; // XXX remove that crap
 	}
 
 	const SceneGraph& getSceneGraph() const

+ 1 - 1
include/anki/renderer/Tiler.h

@@ -57,7 +57,7 @@ public:
 	Bool test(
 		const CollisionShape& cs, 
 		const Aabb& aabb, 
-		Bool skipNearPlane,
+		Bool nearPlane,
 		Bitset* mask) const;
 
 private:

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

@@ -152,7 +152,7 @@ public:
 	/// @}
 
 public:
-	Sphere sphereW = Sphere(Vec3(0.0), 2.0);
+	Sphere sphereW = Sphere(Vec3(0.0), 1.0);
 };
 
 /// Spot light

+ 6 - 1
shaders/IsLpGeneric.glsl

@@ -293,7 +293,12 @@ void main()
 #if 1
 	if(tiles[vInstanceId].lightsCount[3] > 0)
 	{
-		fColor += vec3(0.1);
+		fColor += vec3(0.0, 0.2, 0.0);
+	}
+
+	if(tiles[vInstanceId].lightsCount[0] > 0)
+	{
+		fColor += vec3(0.2, 0.0, 0.0);
 	}
 #endif
 

+ 33 - 0
src/renderer/Dbg.cpp

@@ -2,6 +2,7 @@
 #include "anki/renderer/Renderer.h"
 #include "anki/resource/ShaderProgramResource.h"
 #include "anki/scene/SceneGraph.h"
+#include "anki/scene/Camera.h"
 #include "anki/scene/Light.h"
 #include "anki/core/Logger.h"
 
@@ -199,6 +200,38 @@ void Dbg::run()
 	}
 #endif
 
+	if(1)
+	{
+		drawer->setColor(Vec3(1, 0.0, 0));
+		Sphere s(Vec3(1.0, 0.1, 0.0), 2.0);
+
+		CollisionDebugDrawer coldrawer(drawer.get());
+
+		s.accept(coldrawer);
+
+		const Camera& cam = r->getSceneGraph().getActiveCamera();
+		Mat4 vm = cam.getViewMatrix();
+
+		Vec4 p(s.getCenter(), 1.0);
+		F32 r = s.getRadius();
+		Vec4 a(p.xyz() + vm.getTransposed().getColumn(1).xyz() * r, 1.0);
+		Mat4 vp = cam.getViewProjectionMatrix();
+
+		p = vp * p;
+		p /= p.w();
+		a = vp * a;
+		a /= a.w();
+
+		drawer->setViewProjectionMatrix(Mat4::getIdentity());
+		drawer->setModelMatrix(Mat4::getIdentity());
+
+		drawer->setColor(Vec3(1, 1.0, 1));
+		drawer->begin();
+		drawer->pushBackVertex(p.xyz());
+		drawer->pushBackVertex(a.xyz());
+		drawer->end();
+	}
+
 	if(0)
 	{
 		drawer->setColor(Vec3(0.1, 0.1, 0.1));

+ 1 - 1
src/renderer/Is.cpp

@@ -201,7 +201,7 @@ struct WriteTilesUboJob: ThreadJob
 		// Point lights
 		//
 
-		stile.lightsCount[3] = 0;
+		stile.lightsCount[3] = 0; // XXX remove
 
 		U pointLightsInTileCount = 0;
 		for(U i = 0; i < visiblePointLightsCount; i++)

+ 21 - 4
src/renderer/Tiler.cpp

@@ -389,6 +389,10 @@ void Tiler::updateTilesInternal()
 		tile->max.z() = pixel[1];
 		ANKI_ASSERT(tile->max.z() >= tile->min.z());
 
+		// Convert to NDC (undo the viewport transform)
+		tile->min.z() = tile->min.z() * 2.0 - 1.0;
+		tile->max.z() = tile->max.z() * 2.0 - 1.0;
+
 		pixel += 2;
 	}
 
@@ -543,7 +547,7 @@ Bool Tiler::testAll(const CollisionShape& cs,
 Bool Tiler::test(
 	const CollisionShape& cs, 
 	const Aabb& aabb, 
-	Bool skipNearPlane,
+	Bool nearPlane,
 	Bitset* outBitset) const
 {
 	//
@@ -584,7 +588,7 @@ Bool Tiler::test(
 	for(U i = 0; i < pointsCount; i++)
 	{
 		Vec4 point = projection * points[i];
-		Vec3 v3 = point.xyz() / fabs(point.w());
+		Vec3 v3 = point.xyz() / point.w();
 		points2D[i] = v3.xy();
 
 		// Min z
@@ -635,17 +639,30 @@ Bool Tiler::test(
 	}
 
 	//
-	// XXX
+	// Check the z
 	//
 	for(U i = 0; i < TILES_COUNT; i++)
 	{
+		// If tile is visible
 		if(bitset.test(i))
 		{
 			ANKI_ASSERT(i < tiles_.size());
 
+			// Check far plane
 			if(tiles0[i].max.z() > minMax[0].z())
 			{
-				// Keep it
+				if(nearPlane)
+				{
+					// Check inear plane
+					if(tiles0[i].min.z() < minMax[1].z())
+					{
+						// Keep it
+					}
+					else
+					{
+						bitset.set(i, false);
+					}
+				}
 			}
 			else
 			{

+ 1 - 1
src/scene/Visibility.cpp

@@ -98,7 +98,7 @@ struct VisibilityTestJob: ThreadJob
 				Tiler::Bitset tilerBitset;
 				if(l
 					&& tiler->test(sp->getSpatialCollisionShape(),
-					sp->getAabb(), false, &tilerBitset))
+					sp->getAabb(), true, &tilerBitset))
 				{
 					visible->lights.push_back(node);
 

+ 2 - 1
testapp/Main.cpp

@@ -166,7 +166,8 @@ void init()
 
 	PointLight* point = new PointLight("ll", &scene,
 		Movable::MF_NONE, nullptr);
-	point->setLocalTranslation(Vec3(1.0, 0.0, 0.0));
+	point->setLocalTranslation(Vec3(1.0, 0.1, 0.0));
+	point->setRadius(2.0);
 
 #if 0
 	SpotLight* spot = new SpotLight("spot0", &scene, Movable::MF_NONE, nullptr);