浏览代码

The deferred shading with tiles is almost ready

Panagiotis Christopoulos Charitos 13 年之前
父节点
当前提交
e1a04a2114
共有 5 个文件被更改,包括 104 次插入24 次删除
  1. 17 2
      shaders/IsLpGeneric.glsl
  2. 11 7
      shaders/IsMinMax.glsl
  3. 58 0
      src/renderer/Dbg.cpp
  4. 6 13
      src/renderer/Is.cpp
  5. 12 2
      testapp/Main.cpp

+ 17 - 2
shaders/IsLpGeneric.glsl

@@ -69,6 +69,7 @@ uniform usampler2D msFai0;
 uniform sampler2D msDepthFai;
 uniform sampler2D lightTex;
 uniform sampler2DShadow shadowMap;
+uniform sampler2D minmax;
 /// @}
 
 /// @name Varyings
@@ -180,8 +181,22 @@ void main()
 #endif
 	}
 
-	if(lightsCount > 0)
+#if 0
+	float depth = texture(msDepthFai, vTexCoords).r;
+	vec2 mm = texture(minmax, vTexCoords).rg;
+
+	if(depth < mm.x)
 	{
-		fColor += vec3(0.0, float(lightsCount) / 7.0, 0.0);
+		fColor *= vec3(10.0, 0.0, 0.0);
+	}
+	if(depth > mm.y)
+	{
+		fColor *= vec3(0.0, 0.0, 10.0);
 	}
+#endif
+
+	/*if(lightsCount > 0)
+	{
+		fColor += vec3(0.0, float(lightsCount) / 7.0, 0.0);
+	}*/
 }

+ 11 - 7
shaders/IsMinMax.glsl

@@ -20,20 +20,24 @@ in vec2 vTexCoords;
 
 out vec2 fColor;
 
+layout(pixel_center_integer) in vec4 gl_FragCoord;
+
 //==============================================================================
 void main()
 {
-	const int FROM_W = RENDERER_WIDTH / TILES_X_COUNT / 2;
-	const int FROM_H = RENDERER_HEIGHT / TILES_Y_COUNT / 2;
+	const int W = RENDERER_WIDTH / TILES_X_COUNT;
+	const int H = RENDERER_HEIGHT / TILES_Y_COUNT;
+
+	float maxDepth = -10000.0;
+	float minDepth = 100000.0;
 
-	float maxDepth = -10.0;
-	float minDepth = 10.0;
+	ivec2 coord = ivec2(gl_FragCoord.xy * vec2(W, H));
 
-	for(int i = -FROM_W; i < FROM_W; i++)
+	for(int i = 0; i < W; i++)
 	{
-		for(int j = -FROM_H; j < FROM_H; j++)
+		for(int j = 0; j < H; j++)
 		{
-			float depth = textureOffset(depthMap, vTexCoords, ivec2(i, j)).r;
+			float depth = texelFetch(depthMap, coord + ivec2(i, j), 0).r;
 
 			if(depth < minDepth)
 			{

+ 58 - 0
src/renderer/Dbg.cpp

@@ -37,6 +37,8 @@ void Dbg::init(const Renderer::Initializer& initializer)
 	sceneDrawer.reset(new SceneDebugDrawer(drawer.get()));
 }
 
+U deletemeto = 0;
+
 //==============================================================================
 void Dbg::run()
 {
@@ -85,10 +87,65 @@ void Dbg::run()
 		sceneDrawer->draw(sector->getOctree());
 	}
 
+#if 0
 	// XXX
 	drawer->setViewProjectionMatrix(r->getViewProjectionMatrix());
 	drawer->setModelMatrix(Mat4::getIdentity());
 
+	Camera* camera1 = static_cast<Camera*>(scene.findSceneNode("camera1"));
+	CollisionDebugDrawer cdd(drawer.get());
+	static U ii, jj;
+	static Plane p, pp;
+
+	if(deletemeto == 0)
+	{
+		for(U i = 0; i < Is::TILES_X_COUNT; i++)
+		{
+			for(U j = 0; j < Is::TILES_Y_COUNT; j++)
+			{
+				if(r->getIs().tiles[j][i].lightsCount > 0)
+				{
+					std::cout << "--" << i << " " << j << std::endl;
+
+					p = r->getIs().tiles[j][i].planes[Frustum::FP_FAR];
+					pp = r->getIs().tiles[j][i].planes[Frustum::FP_NEAR];
+
+					ii = i;
+					jj = j;
+
+					camera1->setLocalTransform(scene.getActiveCamera().getWorldTransform());
+					camera1->update();
+
+					p.transform(camera1->getWorldTransform());
+					pp.transform(camera1->getWorldTransform());
+
+					//std::cout << scene.getActiveCamera().getWorldTransform() << std::endl;
+
+					//p.accept(cdd);
+				}
+			}
+		}
+	}
+
+	if(deletemeto == 1)
+	{
+		std::cout << "Brokolo" << std::endl;
+
+		p.accept(cdd);
+		pp.accept(cdd);
+
+	}
+
+	Plane p1 = r->getIs().tiles[jj][ii].planes[Frustum::FP_NEAR];
+	p1.transform(scene.getActiveCamera().getWorldTransform());
+	Plane p2 = r->getIs().tiles[jj][ii].planes[Frustum::FP_FAR];
+	p2.transform(scene.getActiveCamera().getWorldTransform());
+
+	//p1.accept(cdd);
+	//p2.accept(cdd);
+#endif
+
+#if 0
 	Camera* camera1 = static_cast<Camera*>(scene.findSceneNode("camera1"));
 
 	F32 fx = static_cast<PerspectiveCamera*>(camera1)->getFovX();
@@ -111,6 +168,7 @@ void Dbg::run()
 	b.transform(camera1->getWorldTransform());
 
 	drawer->drawLine(a, b, Vec4(1));
+#endif
 
 #if 0
 	{

+ 6 - 13
src/renderer/Is.cpp

@@ -91,7 +91,7 @@ void Is::initInternal(const RendererInitializer& initializer)
 		"#define TILES_X_COUNT " + std::to_string(TILES_X_COUNT) + "\n"
 		"#define TILES_Y_COUNT " + std::to_string(TILES_Y_COUNT) + "\n"
 		"#define RENDERER_WIDTH " + std::to_string(r->getWidth()) + "\n"
-		"#define RENDERER_HEIGHT " + std::to_string(r->getWidth()) + "\n"
+		"#define RENDERER_HEIGHT " + std::to_string(r->getHeight()) + "\n"
 		"#define MAX_LIGHTS_PER_TILE " + std::to_string(MAX_LIGHTS_PER_TILE)
 		+ "\n"
 		"#define TILES_COUNT " + std::to_string(TILES_X_COUNT * TILES_Y_COUNT)
@@ -335,21 +335,10 @@ void Is::updateTiles()
 #if 1
 			/// Calculate as you do in the vertex position inside the shaders
 			F32 minZ =
-				-r->getPlanes().y() / (r->getPlanes().x() + pixels[j][i][0]) ;
+				-r->getPlanes().y() / (r->getPlanes().x() + pixels[j][i][0]);
 			F32 maxZ =
 				-r->getPlanes().y() / (r->getPlanes().x() + pixels[j][i][1]);
 
-			/*minZ = -cam.getNear();
-			maxZ = -cam.getFar();*/
-
-			/*if(i == 0 && j == 0)
-				std::cout << minZ << " " << maxZ << std::endl;*/
-
-			/*F32 minZ = -pixels[j][i][0];
-			F32 maxZ = -pixels[j][i][1];*/
-
-			/*if(i == 0 && j == 0)
-				std::cout << minZ << " " << maxZ << std::endl;*/
 #else
 			F32 minZ = -cam.getNear();
 			F32 maxZ = -cam.getFar();
@@ -491,6 +480,10 @@ void Is::pointLightsPass()
 		r->getMs().getDepthFai());
 #endif
 
+#if 0
+	shader.findUniformVariable("minmax").set(minMaxFai);
+#endif
+
 	r->drawQuadInstanced(TILES_Y_COUNT * TILES_X_COUNT);
 }
 

+ 12 - 2
testapp/Main.cpp

@@ -80,9 +80,9 @@ void init()
 
 	// lights
 	Vec3 lpos(-100.0, 0.0, 0.0);
-	for(int i = 0; i < 10; i++)
+	for(int i = 0; i < 3; i++)
 	{
-		for(int j = 0; j < 1; j++)
+		for(int j = 0; j < 10; j++)
 		{
 			std::string name = "plight" + std::to_string(i) + std::to_string(j);
 
@@ -166,6 +166,9 @@ void execStdinScpripts()
 	}
 }
 
+namespace anki {
+		extern U deletemeto; }
+
 //==============================================================================
 void mainLoopExtra()
 {
@@ -213,6 +216,13 @@ void mainLoopExtra()
 		static_cast<PointLight*>(l)->setRadius(10.0);
 	}
 
+	if(in.getKey(SDL_SCANCODE_P) == 1)
+	{
+		std::cout << "sdfffffffffffffffff" << std::endl;
+
+		deletemeto = !deletemeto;
+	}
+
 	if(in.getKey(SDL_SCANCODE_UP)) mover->rotateLocalX(ang);
 	if(in.getKey(SDL_SCANCODE_DOWN)) mover->rotateLocalX(-ang);
 	if(in.getKey(SDL_SCANCODE_LEFT)) mover->rotateLocalY(ang);