Przeglądaj źródła

Compute light rejection is working. It's horribly slow

Panagiotis Christopoulos Charitos 12 lat temu
rodzic
commit
025e1bfc52
4 zmienionych plików z 21 dodań i 18 usunięć
  1. 2 2
      shaders/IsLp.glsl
  2. 16 13
      shaders/IsRejectLights.glsl
  3. 2 2
      src/renderer/Is.cpp
  4. 1 1
      testapp/Main.cpp

+ 2 - 2
shaders/IsLp.glsl

@@ -344,9 +344,9 @@ void main()
 		slights[1].light.diffuseColorShadowmapId.w, 0.0);
 #endif
 
-#if 1
+#if 0
 	fColor = fColor * 0.0001 
-		+ vec3(float(tiles[vInstanceId].lightsCount[1]));
+		+ vec3(uintBitsToFloat(tiles[vInstanceId].lightsCount[1]));
 #endif
 
 #if 0

+ 16 - 13
shaders/IsRejectLights.glsl

@@ -42,22 +42,30 @@ void main()
 	//
 	// First calculate the z of the far plane
 	//
-	float maxDepth = -10000.0; // min depth of tile
+	vec2 minMaxDepth = vec2(10000.0, -10000.0); // max depth of tile
 
-	const ivec2 COORD = ivec2(ivec2(tileX, tileY) * ivec2(TILE_W, TILE_H));
+	const vec2 COORD = vec2(tileX, tileY) 
+		* (vec2(1.0) / vec2(float(TILES_X_COUNT), float(TILES_Y_COUNT)));
 
-	for(int x = 0; x < TILE_W; x++)
+	vec2 coord = COORD;
+
+	for(int x = 0; x < TILE_W; ++x)
 	{
-		for(int y = 0; y < TILE_H; y++)
+		for(int y = 0; y < TILE_H; ++y)
 		{
-			float depth = texelFetch(depthMap, COORD + ivec2(x, y), 0).r;
+			float depth = texture(depthMap, coord).r;
+
+			minMaxDepth[0] = min(depth, minMaxDepth[0]);
+			minMaxDepth[1] = max(depth, minMaxDepth[1]);
 
-			maxDepth = max(depth, maxDepth);
+			coord.y += 1.0 / float(DEPTHMAP_HEIGHT);
 		}
+
+		coord.x += 1.0 / float(DEPTHMAP_WIDTH);
 	}
 
 	// Convert to view space
-	float z = -planes.y / (planes.x + maxDepth);
+	vec2 z = -planes.y / (planes.x + minMaxDepth);
 
 	//
 	// Reject point lights
@@ -65,8 +73,6 @@ void main()
 	uint newPointLightIndices[MAX_POINT_LIGHTS_PER_TILE];
 	uint newPointLightsCount = 0;
 
-	tiles[tileIndex].lightsCount[1] = 0;
-
 	uint pointLightsCount = tiles[tileIndex].lightsCount[0];
 	for(uint i = 0U; i < pointLightsCount; ++i)
 	{
@@ -75,12 +81,9 @@ void main()
 		vec4 posRadius = pointLights[lightId].posRadius;
 		vec3 pos = posRadius.xyz;
 		float radius = -1.0 / posRadius.w;
-
-		if(pos.z < 0.0)
-		tiles[tileIndex].lightsCount[1] += 1;
 		
 		// Should reject?
-		if((pos.z - 0.5) <= z)
+		if((pos.z + radius) >= z[1] && (pos.z - radius) <= z[0])
 		{
 			// No
 

+ 2 - 2
src/renderer/Is.cpp

@@ -543,7 +543,7 @@ void Is::initInternal(const RendererInitializer& initializer)
 		throw ANKI_EXCEPTION("Problem with the commonBlock");
 	}
 
-#if ANKI_GL == ANKI_GL_DESKTOP && 0
+#if ANKI_GL == ANKI_GL_DESKTOP
 	if(rejectProg.isLoaded())
 	{
 		ublock = &rejectProg->findUniformBlock("commonBlock");
@@ -564,7 +564,7 @@ void Is::initInternal(const RendererInitializer& initializer)
 		throw ANKI_EXCEPTION("Problem with the pointLightsBlock");
 	}
 
-#if ANKI_GL == ANKI_GL_DESKTOP && 0
+#if ANKI_GL == ANKI_GL_DESKTOP
 	if(rejectProg.isLoaded())
 	{
 		ublock = &rejectProg->findUniformBlock("pointLightsBlock");

+ 1 - 1
testapp/Main.cpp

@@ -474,7 +474,7 @@ void mainLoop()
 
 		// Sleep
 		//
-#if 1
+#if 0
 		timer.stop();
 		if(timer.getElapsedTime() < AppSingleton::get().getTimerTick())
 		{