Browse Source

Bug fix in light particles

Panagiotis Christopoulos Charitos 9 years ago
parent
commit
65aa08dec9

+ 17 - 4
shaders/Clusterer.glsl

@@ -26,19 +26,32 @@ uint computeClusterIndexUsingTileIdx(float near,
 }
 }
 
 
 //==============================================================================
 //==============================================================================
-// Compute the cluster index using the gl_FragCoord.xy.
-uint computeClusterIndexUsingFragCoord(float near,
+// Compute the cluster index using the a custom gl_FragCoord.xy.
+uint computeClusterIndexUsingCustomFragCoord(float near,
 	float clustererMagic,
 	float clustererMagic,
 	float zVSpace,
 	float zVSpace,
 	uint tileCountX,
 	uint tileCountX,
-	uint tileCountY)
+	uint tileCountY,
+	vec2 fragCoord)
 {
 {
 	// Compute tile idx
 	// Compute tile idx
-	uvec2 f = uvec2(gl_FragCoord.xy) >> 6;
+	uvec2 f = uvec2(fragCoord) >> 6;
 	uint tileIdx = f.y * tileCountX + f.x;
 	uint tileIdx = f.y * tileCountX + f.x;
 
 
 	return computeClusterIndexUsingTileIdx(
 	return computeClusterIndexUsingTileIdx(
 		near, clustererMagic, zVSpace, tileIdx, tileCountX, tileCountY);
 		near, clustererMagic, zVSpace, tileIdx, tileCountX, tileCountY);
 }
 }
 
 
+//==============================================================================
+// Compute the cluster index using the gl_FragCoord.xy.
+uint computeClusterIndexUsingFragCoord(float near,
+	float clustererMagic,
+	float zVSpace,
+	uint tileCountX,
+	uint tileCountY)
+{
+	return computeClusterIndexUsingCustomFragCoord(
+		near, clustererMagic, zVSpace, tileCountX, tileCountY, gl_FragCoord.xy);
+}
+
 #endif
 #endif

+ 3 - 2
shaders/FsCommonFrag.glsl

@@ -146,12 +146,13 @@ vec3 computeLightColor(vec3 diffCol)
 	uint pointLightsCount;
 	uint pointLightsCount;
 	uint spotLightsCount;
 	uint spotLightsCount;
 	{
 	{
-		uint clusterIdx = computeClusterIndexUsingFragCoord(
+		uint clusterIdx = computeClusterIndexUsingCustomFragCoord(
 			u_lightingUniforms.nearFarClustererMagicPad1.x,
 			u_lightingUniforms.nearFarClustererMagicPad1.x,
 			u_lightingUniforms.nearFarClustererMagicPad1.z,
 			u_lightingUniforms.nearFarClustererMagicPad1.z,
 			fragPos.z,
 			fragPos.z,
 			u_lightingUniforms.tileCountPad1.x,
 			u_lightingUniforms.tileCountPad1.x,
-			u_lightingUniforms.tileCountPad1.y);
+			u_lightingUniforms.tileCountPad1.y,
+			gl_FragCoord.xy * 2.0);
 
 
 		uint cluster = u_clusters[clusterIdx];
 		uint cluster = u_clusters[clusterIdx];
 
 

+ 5 - 7
src/renderer/Is.cpp

@@ -401,15 +401,15 @@ Error Is::lightPass(RenderingContext& ctx)
 	if(visiblePointLightsCount)
 	if(visiblePointLightsCount)
 	{
 	{
 		taskData.m_vPointLights = std::move(
 		taskData.m_vPointLights = std::move(
-			SArray<VisibleNode>(vi.getBegin(VisibilityGroupType::LIGHTS_POINT), 
-			visiblePointLightsCount));
+			SArray<VisibleNode>(vi.getBegin(VisibilityGroupType::LIGHTS_POINT),
+				visiblePointLightsCount));
 	}
 	}
 
 
 	if(visibleSpotLightsCount)
 	if(visibleSpotLightsCount)
 	{
 	{
 		taskData.m_vSpotLights = std::move(
 		taskData.m_vSpotLights = std::move(
-			SArray<VisibleNode>(vi.getBegin(VisibilityGroupType::LIGHTS_SPOT), 
-			visibleSpotLightsCount));
+			SArray<VisibleNode>(vi.getBegin(VisibilityGroupType::LIGHTS_SPOT),
+				visibleSpotLightsCount));
 	}
 	}
 
 
 	taskData.m_is = this;
 	taskData.m_is = this;
@@ -483,7 +483,6 @@ void Is::binLights(U32 threadId, PtrSize threadsCount, TaskCommonData& task)
 		{
 		{
 			binLight(sp, pos, 0, task, testResult);
 			binLight(sp, pos, 0, task, testResult);
 		}
 		}
-
 	}
 	}
 
 
 	ThreadPool::Task::choseStartEnd(
 	ThreadPool::Task::choseStartEnd(
@@ -494,8 +493,7 @@ void Is::binLights(U32 threadId, PtrSize threadsCount, TaskCommonData& task)
 		MoveComponent& move = snode.getComponent<MoveComponent>();
 		MoveComponent& move = snode.getComponent<MoveComponent>();
 		LightComponent& light = snode.getComponent<LightComponent>();
 		LightComponent& light = snode.getComponent<LightComponent>();
 		SpatialComponent& sp = snode.getComponent<SpatialComponent>();
 		SpatialComponent& sp = snode.getComponent<SpatialComponent>();
-		const FrustumComponent* frc =
-			snode.tryGetComponent<FrustumComponent>();
+		const FrustumComponent* frc = snode.tryGetComponent<FrustumComponent>();
 
 
 		I pos = writeSpotLight(light, move, frc, cammove, camfrc, task);
 		I pos = writeSpotLight(light, move, frc, cammove, camfrc, task);
 		if(pos != -1)
 		if(pos != -1)

+ 1 - 1
src/renderer/Sm.cpp

@@ -323,7 +323,7 @@ void Sm::prepareBuildCommandBuffers(RenderingContext& ctx)
 		SceneNode* node = (*it).m_node;
 		SceneNode* node = (*it).m_node;
 		LightComponent& light = node->getComponent<LightComponent>();
 		LightComponent& light = node->getComponent<LightComponent>();
 		ANKI_ASSERT(light.getLightType() == LightComponent::LightType::POINT);
 		ANKI_ASSERT(light.getLightType() == LightComponent::LightType::POINT);
-		
+
 		if(light.getShadowEnabled())
 		if(light.getShadowEnabled())
 		{
 		{
 			ShadowmapOmni* sm;
 			ShadowmapOmni* sm;

+ 1 - 1
src/scene/FrustumComponent.cpp

@@ -32,7 +32,7 @@ void FrustumComponent::setVisibilityTestResults(VisibilityTestResults* visible)
 
 
 	m_stats.m_renderablesCount =
 	m_stats.m_renderablesCount =
 		visible->getCount(VisibilityGroupType::RENDERABLES_MS);
 		visible->getCount(VisibilityGroupType::RENDERABLES_MS);
-	m_stats.m_lightsCount = 
+	m_stats.m_lightsCount =
 		visible->getCount(VisibilityGroupType::LIGHTS_POINT);
 		visible->getCount(VisibilityGroupType::LIGHTS_POINT);
 }
 }
 
 

+ 4 - 2
testapp/Main.cpp

@@ -270,8 +270,10 @@ Error init()
 		if(err)
 		if(err)
 			return err;
 			return err;
 
 
-		app->getMainRenderer().getOffscreenRenderer().getPps().loadColorGradingTexture(
-			"textures/adis/dungeon.ankitex");
+		app->getMainRenderer()
+			.getOffscreenRenderer()
+			.getPps()
+			.loadColorGradingTexture("textures/adis/dungeon.ankitex");
 	}
 	}
 
 
 /*{
 /*{