Browse Source

Remove old clustered shading

Panagiotis Christopoulos Charitos 4 years ago
parent
commit
668c02f216
36 changed files with 53 additions and 1828 deletions
  1. 1 4
      AnKi/Core/App.cpp
  2. 2 1
      AnKi/Core/ConfigSet.cpp
  3. 0 1
      AnKi/Renderer.h
  4. 0 804
      AnKi/Renderer/ClusterBin.cpp
  5. 0 67
      AnKi/Renderer/ClusterBin.h
  6. 1 1
      AnKi/Renderer/ClusterBinning.cpp
  7. 0 26
      AnKi/Renderer/Common.h
  8. 1 4
      AnKi/Renderer/ConfigDefs.h
  9. 1 1
      AnKi/Renderer/GlobalIllumination.cpp
  10. 0 2
      AnKi/Renderer/MainRenderer.cpp
  11. 1 1
      AnKi/Renderer/MainRenderer.h
  12. 0 1
      AnKi/Renderer/ProbeReflections.h
  13. 3 3
      AnKi/Renderer/RenderQueue.h
  14. 1 88
      AnKi/Renderer/Renderer.cpp
  15. 0 30
      AnKi/Renderer/Renderer.h
  16. 9 9
      AnKi/Renderer/ShadowMapping.cpp
  17. 4 3
      AnKi/Scene/Components/DecalComponent.cpp
  18. 2 2
      AnKi/Scene/Components/FrustumComponent.h
  19. 7 7
      AnKi/Scene/Components/LightComponent.cpp
  20. 1 1
      AnKi/Scene/GlobalIlluminationProbeNode.cpp
  21. 4 3
      AnKi/Scene/LightNode.cpp
  22. 2 2
      AnKi/Scene/ReflectionProbeNode.cpp
  23. 2 2
      AnKi/Scene/Visibility.cpp
  24. 1 1
      AnKi/Shaders/ApplyIrradianceToReflection.ankiprog
  25. 0 162
      AnKi/Shaders/ClusteredShadingCommon.glsl
  26. 1 1
      AnKi/Shaders/ExponentialShadowmappingResolve.ankiprog
  27. 0 7
      AnKi/Shaders/ForwardShadingCommonVert.glsl
  28. 1 41
      AnKi/Shaders/Include/ClusteredShadingFunctions.h
  29. 0 167
      AnKi/Shaders/Include/ClusteredShadingTypes.h
  30. 5 3
      AnKi/Shaders/Include/ClusteredShadingTypes2.h
  31. 1 1
      AnKi/Shaders/IrradianceDice.ankiprog
  32. 0 378
      AnKi/Shaders/LightFunctions.glsl
  33. 1 1
      AnKi/Shaders/LightFunctions2.glsl
  34. 0 1
      AnKi/Shaders/LightShading.ankiprog
  35. 1 1
      AnKi/Shaders/TraditionalDeferredShading.ankiprog
  36. 0 1
      AnKi/Shaders/VolumetricFogAccumulation.ankiprog

+ 1 - 4
AnKi/Core/App.cpp

@@ -74,7 +74,6 @@ public:
 
 	BufferedValue<Second> m_frameTime;
 	BufferedValue<Second> m_renderTime;
-	BufferedValue<Second> m_lightBinTime;
 	BufferedValue<Second> m_sceneUpdateTime;
 	BufferedValue<Second> m_visTestsTime;
 	BufferedValue<Second> m_physicsTime;
@@ -122,8 +121,7 @@ public:
 
 			ImGui::Text("CPU Time:");
 			labelTime(m_frameTime.get(flush), "Total frame");
-			labelTime(m_renderTime.get(flush) - m_lightBinTime.get(flush), "Renderer");
-			labelTime(m_lightBinTime.get(false), "Light bin");
+			labelTime(m_renderTime.get(flush), "Renderer");
 			labelTime(m_sceneUpdateTime.get(flush), "Scene update");
 			labelTime(m_visTestsTime.get(flush), "Visibility");
 			labelTime(m_physicsTime.get(flush), "Physics");
@@ -627,7 +625,6 @@ Error App::mainLoop()
 				StatsUi& statsUi = static_cast<StatsUi&>(*m_statsUi);
 				statsUi.m_frameTime.set(frameTime);
 				statsUi.m_renderTime.set(m_renderer->getStats().m_renderingCpuTime);
-				statsUi.m_lightBinTime.set(m_renderer->getStats().m_lightBinTime);
 				statsUi.m_sceneUpdateTime.set(m_scene->getStats().m_updateTime);
 				statsUi.m_visTestsTime.set(m_scene->getStats().m_visibilityTestsTime);
 				statsUi.m_physicsTime.set(m_scene->getStats().m_physicsUpdate);

+ 2 - 1
AnKi/Core/ConfigSet.cpp

@@ -10,7 +10,8 @@
 
 // Used by the config options
 #include <AnKi/Util/System.h>
-#include <AnKi/Renderer/ClusterBin.h>
+#include <AnKi/Math.h>
+#include <AnKi/Shaders/Include/ClusteredShadingTypes2.h>
 
 namespace anki
 {

+ 0 - 1
AnKi/Renderer.h

@@ -11,7 +11,6 @@
 #include <AnKi/Renderer/VolumetricFog.h>
 #include <AnKi/Renderer/ForwardShading.h>
 #include <AnKi/Renderer/FinalComposite.h>
-#include <AnKi/Renderer/ClusterBin.h>
 #include <AnKi/Renderer/Renderer.h>
 #include <AnKi/Renderer/ShadowMapping.h>
 #include <AnKi/Renderer/MainRenderer.h>

+ 0 - 804
AnKi/Renderer/ClusterBin.cpp

@@ -1,804 +0,0 @@
-// Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
-// All rights reserved.
-// Code licensed under the BSD License.
-// http://www.anki3d.org/LICENSE
-
-#include <AnKi/Renderer/ClusterBin.h>
-#include <AnKi/Renderer/RenderQueue.h>
-#include <AnKi/Collision.h>
-#include <AnKi/Util/ThreadHive.h>
-#include <AnKi/Util/Tracer.h>
-#include <AnKi/Core/ConfigSet.h>
-
-namespace anki
-{
-
-/// Get a view space point.
-static Vec4 unproject(const F32 zVspace, const Vec2& ndc, const Vec4& unprojParams)
-{
-	Vec4 view;
-	view.x() = ndc.x() * unprojParams.x();
-	view.y() = ndc.y() * unprojParams.y();
-	view.z() = 1.0f;
-	view.w() = 0.0f;
-
-	return view * zVspace;
-}
-
-template<typename TShape>
-static Bool insideClusterFrustum(const Array<Plane, 4>& planeArr, const TShape& shape)
-{
-	for(const Plane& plane : planeArr)
-	{
-		if(testPlane(plane, shape) < 0.0f)
-		{
-			return false;
-		}
-	}
-
-	return true;
-}
-
-/// Bin context.
-class ClusterBin::BinCtx
-{
-public:
-	ClusterBin* m_bin ANKI_DEBUG_CODE(= nullptr);
-	ClusterBinIn* m_in ANKI_DEBUG_CODE(= nullptr);
-	ClusterBinOut* m_out ANKI_DEBUG_CODE(= nullptr);
-
-	WeakArray<PointLight> m_pointLights;
-	WeakArray<SpotLight> m_spotLights;
-	WeakArray<ReflectionProbe> m_probes;
-	WeakArray<Decal> m_decals;
-
-	WeakArray<U32> m_lightIds;
-	WeakArray<U32> m_clusters;
-
-	Atomic<U32> m_tileIdxToProcess = {0};
-	Atomic<U32> m_allocatedIndexCount = {TYPED_OBJECT_COUNT};
-
-	Vec4 m_unprojParams;
-
-	Bool m_clusterEdgesDirty;
-};
-
-class ClusterBin::TileCtx
-{
-public:
-	struct ClusterMetaInfo
-	{
-		Array<U16, TYPED_OBJECT_COUNT> m_counts;
-		U16 m_offset;
-	};
-
-	DynamicArrayAuto<Vec4> m_clusterEdgesWSpace;
-	DynamicArrayAuto<Aabb> m_clusterBoxes;
-	DynamicArrayAuto<Sphere> m_clusterSpheres;
-
-	DynamicArrayAuto<ClusterMetaInfo> m_clusterInfos;
-	DynamicArrayAuto<U32> m_indices;
-
-	U32 m_clusterCountZ = MAX_U32;
-
-	TileCtx(StackAllocator<U8>& alloc)
-		: m_clusterEdgesWSpace(alloc)
-		, m_clusterBoxes(alloc)
-		, m_clusterSpheres(alloc)
-		, m_clusterInfos(alloc)
-		, m_indices(alloc)
-	{
-	}
-
-	WeakArray<U32> getClusterIndices(const U32 clusterZ)
-	{
-		ANKI_ASSERT(clusterZ < m_clusterCountZ);
-		const U32 perClusterCount = m_indices.getSize() / m_clusterCountZ;
-		return WeakArray<U32>(&m_indices[perClusterCount * clusterZ], perClusterCount);
-	}
-};
-
-ClusterBin::~ClusterBin()
-{
-	m_clusterEdges.destroy(m_alloc);
-}
-
-void ClusterBin::init(HeapAllocator<U8> alloc, U32 clusterCountX, U32 clusterCountY, U32 clusterCountZ,
-					  const ConfigSet& cfg)
-{
-	m_alloc = alloc;
-
-	m_clusterCounts[0] = clusterCountX;
-	m_clusterCounts[1] = clusterCountY;
-	m_clusterCounts[2] = clusterCountZ;
-
-	m_totalClusterCount = clusterCountX * clusterCountY * clusterCountZ;
-
-	m_avgObjectsPerCluster = cfg.getNumberU32("r_avgObjectsPerCluster");
-
-	// The actual indices per cluster are
-	// - the object indices per cluster
-	// - plus TYPED_OBJECT_COUNT-1 that is the offset per object type minus the first object type
-	// - plus TYPED_OBJECT_COUNT the stopper dummy indices
-	m_indexCount = m_totalClusterCount * (m_avgObjectsPerCluster + TYPED_OBJECT_COUNT - 1 + TYPED_OBJECT_COUNT);
-
-	m_clusterEdges.create(m_alloc, m_clusterCounts[0] * m_clusterCounts[1] * (m_clusterCounts[2] + 1) * 4);
-}
-
-void ClusterBin::bin(ClusterBinIn& in, ClusterBinOut& out)
-{
-	ANKI_TRACE_SCOPED_EVENT(R_BIN_TO_CLUSTERS);
-
-	BinCtx ctx;
-	ctx.m_bin = this;
-	ctx.m_in = &in;
-	ctx.m_out = &out;
-
-	prepare(ctx);
-
-	if(ctx.m_unprojParams != m_prevUnprojParams)
-	{
-		ctx.m_clusterEdgesDirty = true;
-		m_prevUnprojParams = ctx.m_unprojParams;
-	}
-	else
-	{
-		ctx.m_clusterEdgesDirty = false;
-	}
-
-	// Allocate indices
-	U32* indices = static_cast<U32*>(ctx.m_in->m_stagingMem->allocateFrame(
-		m_indexCount * sizeof(U32), StagingGpuMemoryType::STORAGE, ctx.m_out->m_indicesToken));
-	ctx.m_lightIds = WeakArray<U32>(indices, m_indexCount);
-
-	// Reserve some indices for empty clusters
-	for(U i = 0; i < TYPED_OBJECT_COUNT; ++i)
-	{
-		indices[i] = 0;
-	}
-
-	// Allocate clusters
-	U32* clusters = static_cast<U32*>(ctx.m_in->m_stagingMem->allocateFrame(
-		sizeof(U32) * m_totalClusterCount, StagingGpuMemoryType::STORAGE, ctx.m_out->m_clustersToken));
-	ctx.m_clusters = WeakArray<U32>(clusters, m_totalClusterCount);
-
-	// Create task for writing GPU buffers
-	Array<ThreadHiveTask, ThreadHive::MAX_THREADS + 1> tasks;
-	tasks[0] = ANKI_THREAD_HIVE_TASK(
-		{
-			ANKI_TRACE_SCOPED_EVENT(R_WRITE_LIGHT_BUFFERS);
-			self->m_bin->writeTypedObjectsToGpuBuffers(*self);
-		},
-		&ctx, nullptr, nullptr);
-
-	// Create tasks for binning
-	tasks[1] = ANKI_THREAD_HIVE_TASK(
-		{
-			ANKI_TRACE_SCOPED_EVENT(R_BIN_TO_CLUSTERS);
-			BinCtx& ctx = *self;
-
-			TileCtx tileCtx(ctx.m_in->m_tempAlloc);
-			const U32 clusterCountZ = ctx.m_bin->m_clusterCounts[2];
-			tileCtx.m_clusterEdgesWSpace.create((clusterCountZ + 1) * 4);
-			tileCtx.m_clusterBoxes.create(clusterCountZ);
-			tileCtx.m_clusterSpheres.create(clusterCountZ);
-			tileCtx.m_indices.create(clusterCountZ * ctx.m_bin->m_avgObjectsPerCluster);
-			tileCtx.m_clusterInfos.create(clusterCountZ);
-			tileCtx.m_clusterCountZ = clusterCountZ;
-
-			const U32 tileCount = ctx.m_bin->m_clusterCounts[0] * ctx.m_bin->m_clusterCounts[1];
-			U32 tileIdx;
-			while((tileIdx = ctx.m_tileIdxToProcess.fetchAdd(1)) < tileCount)
-			{
-				ctx.m_bin->binTile(tileIdx, ctx, tileCtx);
-			}
-		},
-		&ctx, nullptr, nullptr);
-
-	for(U threadIdx = 1; threadIdx < in.m_threadHive->getThreadCount(); ++threadIdx)
-	{
-		tasks[threadIdx + 1] = tasks[1];
-	}
-
-	// Submit and wait
-	in.m_threadHive->submitTasks(&tasks[0], in.m_threadHive->getThreadCount() + 1);
-	in.m_threadHive->waitAllTasks();
-}
-
-void ClusterBin::prepare(BinCtx& ctx)
-{
-	const F32 near = ctx.m_in->m_renderQueue->m_cameraNear;
-	const F32 far = ctx.m_in->m_renderQueue->m_cameraFar;
-
-	const F32 calcNearOpt = (far - near) / F32(m_clusterCounts[2] * m_clusterCounts[2]);
-
-	// Compute magic val 0
-	// It's been used to calculate the 'k' of a cluster given the world position
-	{
-		// Given a distance 'd' from the camera's near plane in world space the 'k' split is calculated like:
-		// k = sqrt(d / (f - n) * Cz2)  (1)
-		// where 'n' and 'f' are the near and far vals of the projection and Cz2 is the m_counts[2]^2
-		// If the 'd' is not known and the world position instead is known then 'd' is the distance from that position
-		// to the camera's near plane.
-		// d = dot(Pn, W) - Po  (2)
-		// where 'Pn' is the plane's normal, 'Po' is the plane's offset and 'W' is the world position.
-		// Substituting d from (2) in (1) we have:
-		// k = sqrt((dot(Pn, W) - Po) / (f - n) * Cz2) =>
-		// k = sqrt((dot(Pn, W) * Cz2 - Po * Cz2) / (f - n))
-		// k = sqrt(dot(Pn, W) * Cz2 / (f - n) - Po * Cz2 / (f - n))
-		// k = sqrt(dot(Pn * Cz2 / (f - n), W) - Po * Cz2 / (f - n))
-		// If we assume that:
-		// A = Pn * Cz2 / (f - n) and B =  Po * Cz2 / (f - n)
-		// Then:
-		// k = sqrt(dot(A, W) - B)
-
-		const Mat4& vp = ctx.m_in->m_renderQueue->m_viewProjectionMatrix;
-		Plane nearPlane;
-		extractClipPlane(vp, FrustumPlaneType::NEAR, nearPlane);
-
-		Vec3 A = nearPlane.getNormal().xyz() * F32(m_clusterCounts[2] * m_clusterCounts[2]) / (far - near);
-		F32 B = nearPlane.getOffset() * F32(m_clusterCounts[2] * m_clusterCounts[2]) / (far - near);
-
-		ctx.m_out->m_shaderMagicValues.m_val0 = Vec4(A, B);
-	}
-
-	// Compute magic val 1
-	{
-		ctx.m_out->m_shaderMagicValues.m_val1.x() = calcNearOpt;
-		ctx.m_out->m_shaderMagicValues.m_val1.y() = near;
-	}
-
-	// Unproj params
-	ctx.m_unprojParams = ctx.m_in->m_renderQueue->m_projectionMatrix.extractPerspectiveUnprojectionParams();
-}
-
-void ClusterBin::binTile(U32 tileIdx, BinCtx& ctx, TileCtx& tileCtx)
-{
-	ANKI_ASSERT(tileIdx < m_clusterCounts[0] * m_clusterCounts[1]);
-	const U32 tileX = tileIdx % m_clusterCounts[0];
-	const U32 tileY = tileIdx / m_clusterCounts[0];
-
-	// Compute the tile's cluster edges in view space
-	WeakArray<Vec4> clusterEdgesVSpace(&m_clusterEdges[tileIdx * (m_clusterCounts[2] + 1) * 4],
-									   (m_clusterCounts[2] + 1) * 4);
-	if(ctx.m_clusterEdgesDirty)
-	{
-		const Vec2 tileSize = 2.0f / Vec2(F32(m_clusterCounts[0]), F32(m_clusterCounts[1]));
-		const Vec2 startNdc =
-			Vec2(F32(tileX) / F32(m_clusterCounts[0]), F32(tileY) / F32(m_clusterCounts[1])) * 2.0f - 1.0f;
-		const Vec4& unprojParams = ctx.m_unprojParams;
-
-		for(U32 clusterZ = 0; clusterZ < m_clusterCounts[2] + 1; ++clusterZ)
-		{
-			const F32 zNear = -computeClusterNear(ctx.m_out->m_shaderMagicValues, clusterZ);
-			const U32 idx = clusterZ * 4;
-
-			clusterEdgesVSpace[idx + 0] = unproject(zNear, startNdc, unprojParams).xyz1();
-			clusterEdgesVSpace[idx + 1] = unproject(zNear, startNdc + Vec2(tileSize.x(), 0.0f), unprojParams).xyz1();
-			clusterEdgesVSpace[idx + 2] = unproject(zNear, startNdc + tileSize, unprojParams).xyz1();
-			clusterEdgesVSpace[idx + 3] = unproject(zNear, startNdc + Vec2(0.0f, tileSize.y()), unprojParams).xyz1();
-		}
-	}
-
-	// Transform the tile's cluster edges to world space
-	DynamicArrayAuto<Vec4>& clusterEdgesWSpace = tileCtx.m_clusterEdgesWSpace;
-	for(U32 clusterZ = 0; clusterZ < m_clusterCounts[2] + 1; ++clusterZ)
-	{
-		const U32 idx = clusterZ * 4;
-		clusterEdgesWSpace[idx + 0] = (ctx.m_in->m_renderQueue->m_cameraTransform * clusterEdgesVSpace[idx + 0]).xyz0();
-		clusterEdgesWSpace[idx + 1] = (ctx.m_in->m_renderQueue->m_cameraTransform * clusterEdgesVSpace[idx + 1]).xyz0();
-		clusterEdgesWSpace[idx + 2] = (ctx.m_in->m_renderQueue->m_cameraTransform * clusterEdgesVSpace[idx + 2]).xyz0();
-		clusterEdgesWSpace[idx + 3] = (ctx.m_in->m_renderQueue->m_cameraTransform * clusterEdgesVSpace[idx + 3]).xyz0();
-	}
-
-	// Compute the tile frustum
-	Array<Plane, 4> frustumPlanes;
-	const U32 lastQuartet = clusterEdgesWSpace.getSize() - 1 - 4;
-	const U32 beforeLastQuartet = lastQuartet - 4;
-	frustumPlanes[0].setFrom3Points(clusterEdgesWSpace[beforeLastQuartet + 0],
-									clusterEdgesWSpace[beforeLastQuartet + 1], clusterEdgesWSpace[lastQuartet + 0]);
-	frustumPlanes[1].setFrom3Points(clusterEdgesWSpace[beforeLastQuartet + 1],
-									clusterEdgesWSpace[beforeLastQuartet + 2], clusterEdgesWSpace[lastQuartet + 2]);
-	frustumPlanes[2].setFrom3Points(clusterEdgesWSpace[beforeLastQuartet + 2],
-									clusterEdgesWSpace[beforeLastQuartet + 3], clusterEdgesWSpace[lastQuartet + 2]);
-	frustumPlanes[3].setFrom3Points(clusterEdgesWSpace[beforeLastQuartet + 3],
-									clusterEdgesWSpace[beforeLastQuartet + 0], clusterEdgesWSpace[lastQuartet + 0]);
-
-	// Compute the cluster AABBs and spheres
-	DynamicArrayAuto<Aabb>& clusterBoxes = tileCtx.m_clusterBoxes;
-	DynamicArrayAuto<Sphere>& clusterSpheres = tileCtx.m_clusterSpheres;
-	for(U32 clusterZ = 0; clusterZ < m_clusterCounts[2]; ++clusterZ)
-	{
-		// Compute an AABB and a sphere that contains the cluster
-		Vec4 aabbMin(MAX_F32, MAX_F32, MAX_F32, 0.0f);
-		Vec4 aabbMax(MIN_F32, MIN_F32, MIN_F32, 0.0f);
-		for(U32 i = 0; i < 8; ++i)
-		{
-			aabbMin = aabbMin.min(clusterEdgesWSpace[clusterZ * 4 + i]);
-			aabbMax = aabbMax.max(clusterEdgesWSpace[clusterZ * 4 + i]);
-		}
-
-		clusterBoxes[clusterZ] = Aabb(aabbMin, aabbMax);
-
-		const Vec4 sphereCenter = (aabbMin + aabbMax) / 2.0f;
-		clusterSpheres[clusterZ] = Sphere(sphereCenter, (aabbMin - sphereCenter).getLength());
-	}
-
-	// Zero the infos
-	memset(&tileCtx.m_clusterInfos[0], 0, tileCtx.m_clusterInfos.getSizeInBytes());
-
-#define ANKI_SET_IDX(typeIdx) \
-	ClusterBin::TileCtx::ClusterMetaInfo& inf = tileCtx.m_clusterInfos[clusterZ]; \
-	if(ANKI_UNLIKELY(U32(inf.m_offset) + 1 >= m_avgObjectsPerCluster)) \
-	{ \
-		ANKI_R_LOGW("Out of cluster indices. Increase r_avgObjectsPerCluster"); \
-		continue; \
-	} \
-	tileCtx.getClusterIndices(clusterZ)[inf.m_offset++] = i; \
-	++inf.m_counts[typeIdx]; \
-	ANKI_ASSERT(inf.m_counts[typeIdx] <= m_avgObjectsPerCluster)
-
-	// Point lights
-	{
-		Sphere lightSphere;
-		for(U32 i = 0; i < ctx.m_in->m_renderQueue->m_pointLights.getSize(); ++i)
-		{
-			const PointLightQueueElement& plight = ctx.m_in->m_renderQueue->m_pointLights[i];
-			lightSphere.setCenter(plight.m_worldPosition.xyz0());
-			lightSphere.setRadius(plight.m_radius);
-
-			if(!insideClusterFrustum(frustumPlanes, lightSphere))
-			{
-				continue;
-			}
-
-			for(U32 clusterZ = 0; clusterZ < m_clusterCounts[2]; ++clusterZ)
-			{
-				if(!testCollision(lightSphere, clusterBoxes[clusterZ]))
-				{
-					continue;
-				}
-
-				ANKI_SET_IDX(0);
-			}
-		}
-	}
-
-	// Spot lights
-	{
-		Array<Vec4, 5> lightEdges;
-		lightEdges[0] = Vec4(0.0f); // Eye
-		ConvexHullShape spotLightShape(&lightEdges[0], lightEdges.getSize());
-
-		for(U32 i = 0; i < ctx.m_in->m_renderQueue->m_spotLights.getSize(); ++i)
-		{
-			const SpotLightQueueElement& slight = ctx.m_in->m_renderQueue->m_spotLights[i];
-
-			computeEdgesOfFrustum(slight.m_distance, slight.m_outerAngle, slight.m_outerAngle, &lightEdges[1]);
-			spotLightShape.setTransform(Transform(slight.m_worldTransform));
-
-			if(!insideClusterFrustum(frustumPlanes, spotLightShape))
-			{
-				continue;
-			}
-
-			for(U32 clusterZ = 0; clusterZ < m_clusterCounts[2]; ++clusterZ)
-			{
-				if(!testCollision(clusterSpheres[clusterZ],
-								  Cone(slight.m_worldTransform.getTranslationPart().xyz0(),
-									   -slight.m_worldTransform.getZAxis(), slight.m_distance, slight.m_outerAngle)))
-				{
-					continue;
-				}
-
-				ANKI_SET_IDX(1);
-			}
-		}
-	}
-
-	// Probes
-	{
-		Aabb probeBox;
-		for(U32 i = 0; i < ctx.m_in->m_renderQueue->m_reflectionProbes.getSize(); ++i)
-		{
-			const ReflectionProbeQueueElement& probe = ctx.m_in->m_renderQueue->m_reflectionProbes[i];
-			probeBox.setMin(probe.m_aabbMin);
-			probeBox.setMax(probe.m_aabbMax);
-
-			if(!insideClusterFrustum(frustumPlanes, probeBox))
-			{
-				continue;
-			}
-
-			for(U32 clusterZ = 0; clusterZ < m_clusterCounts[2]; ++clusterZ)
-			{
-				if(!testCollision(probeBox, clusterBoxes[clusterZ]))
-				{
-					continue;
-				}
-
-				ANKI_SET_IDX(2);
-			}
-		}
-	}
-
-	// GI probes
-	{
-		Aabb probeBox;
-		for(U32 i = 0; i < ctx.m_in->m_renderQueue->m_giProbes.getSize(); ++i)
-		{
-			const GlobalIlluminationProbeQueueElement& probe = ctx.m_in->m_renderQueue->m_giProbes[i];
-			probeBox.setMin(probe.m_aabbMin);
-			probeBox.setMax(probe.m_aabbMax);
-
-			if(!insideClusterFrustum(frustumPlanes, probeBox))
-			{
-				continue;
-			}
-
-			for(U32 clusterZ = 0; clusterZ < m_clusterCounts[2]; ++clusterZ)
-			{
-				if(!testCollision(probeBox, clusterBoxes[clusterZ]))
-				{
-					continue;
-				}
-
-				ANKI_SET_IDX(3);
-			}
-		}
-	}
-
-	// Decals
-	{
-		Obb decalBox;
-		for(U32 i = 0; i < ctx.m_in->m_renderQueue->m_decals.getSize(); ++i)
-		{
-			const DecalQueueElement& decal = ctx.m_in->m_renderQueue->m_decals[i];
-			decalBox.setCenter(decal.m_obbCenter.xyz0());
-			decalBox.setRotation(Mat3x4(Vec3(0.0f), decal.m_obbRotation));
-			decalBox.setExtend(decal.m_obbExtend.xyz0());
-
-			if(!insideClusterFrustum(frustumPlanes, decalBox))
-			{
-				continue;
-			}
-
-			for(U32 clusterZ = 0; clusterZ < m_clusterCounts[2]; ++clusterZ)
-			{
-				if(!testCollision(decalBox, clusterBoxes[clusterZ]))
-				{
-					continue;
-				}
-
-				ANKI_SET_IDX(4);
-			}
-		}
-	}
-
-	// Fog volumes
-	{
-		for(U32 i = 0; i < ctx.m_in->m_renderQueue->m_fogDensityVolumes.getSize(); ++i)
-		{
-			const FogDensityQueueElement& fogVol = ctx.m_in->m_renderQueue->m_fogDensityVolumes[i];
-
-			if(fogVol.m_isBox)
-			{
-				Aabb box;
-				box.setMin(fogVol.m_aabbMin);
-				box.setMax(fogVol.m_aabbMax);
-
-				if(!insideClusterFrustum(frustumPlanes, box))
-				{
-					continue;
-				}
-
-				for(U32 clusterZ = 0; clusterZ < m_clusterCounts[2]; ++clusterZ)
-				{
-					if(!testCollision(box, clusterBoxes[clusterZ]))
-					{
-						continue;
-					}
-
-					ANKI_SET_IDX(5);
-				}
-			}
-			else
-			{
-				Sphere sphere;
-				sphere.setCenter(fogVol.m_sphereCenter.xyz0());
-				sphere.setRadius(fogVol.m_sphereRadius);
-
-				if(!insideClusterFrustum(frustumPlanes, sphere))
-				{
-					continue;
-				}
-
-				for(U32 clusterZ = 0; clusterZ < m_clusterCounts[2]; ++clusterZ)
-				{
-					if(!testCollision(sphere, clusterBoxes[clusterZ]))
-					{
-						continue;
-					}
-
-					ANKI_SET_IDX(5);
-				}
-			}
-		}
-	}
-
-	// Upload the indices for all clusters of the tile
-	for(U32 clusterZ = 0; clusterZ < m_clusterCounts[2]; ++clusterZ)
-	{
-		WeakArray<U32> inIndices = tileCtx.getClusterIndices(clusterZ);
-		const ClusterBin::TileCtx::ClusterMetaInfo& inf = tileCtx.m_clusterInfos[clusterZ];
-
-		const U32 other = (TYPED_OBJECT_COUNT - 1) + TYPED_OBJECT_COUNT;
-		const U32 indexCountPlusOther = inf.m_offset + other;
-		ANKI_ASSERT(indexCountPlusOther <= m_avgObjectsPerCluster + other);
-		ANKI_ASSERT(indexCountPlusOther >= other);
-
-		// Write indices
-		const U32 firstIndex = ctx.m_allocatedIndexCount.fetchAdd(indexCountPlusOther);
-		ANKI_ASSERT(firstIndex + indexCountPlusOther <= ctx.m_lightIds.getSize());
-		WeakArray<U32> outIndices(&ctx.m_lightIds[firstIndex], indexCountPlusOther);
-
-		// Write the offsets
-		U32 offset = firstIndex + TYPED_OBJECT_COUNT - 1;
-		for(U32 i = 1; i < TYPED_OBJECT_COUNT; ++i)
-		{
-			offset += inf.m_counts[i - 1] + 1; // Count plus the stop
-			outIndices[i - 1] = offset;
-		}
-
-		// Write indices
-		U32 outIndicesOffset = TYPED_OBJECT_COUNT - 1;
-		U32 inIndicesOffset = 0;
-		for(U32 i = 0; i < TYPED_OBJECT_COUNT; ++i)
-		{
-			for(U32 c = 0; c < inf.m_counts[i]; ++c)
-			{
-				outIndices[outIndicesOffset++] = inIndices[inIndicesOffset++];
-			}
-
-			// Stop
-			outIndices[outIndicesOffset++] = MAX_U32;
-		}
-		ANKI_ASSERT(inIndicesOffset == inf.m_offset);
-		ANKI_ASSERT(outIndicesOffset == indexCountPlusOther);
-
-		// Write the cluster
-		const U32 clusterIndex =
-			clusterZ * (m_clusterCounts[0] * m_clusterCounts[1]) + tileY * m_clusterCounts[0] + tileX;
-		ctx.m_clusters[clusterIndex] = firstIndex + TYPED_OBJECT_COUNT - 1; // Points to the first object
-	}
-}
-
-void ClusterBin::writeTypedObjectsToGpuBuffers(BinCtx& ctx) const
-{
-	const RenderQueue& rqueue = *ctx.m_in->m_renderQueue;
-
-	// Write the point lights
-	const U32 visiblePointLightCount = rqueue.m_pointLights.getSize();
-	if(visiblePointLightCount)
-	{
-		PointLight* data = static_cast<PointLight*>(ctx.m_in->m_stagingMem->allocateFrame(
-			sizeof(PointLight) * visiblePointLightCount, StagingGpuMemoryType::UNIFORM, ctx.m_out->m_pointLightsToken));
-
-		WeakArray<PointLight> gpuLights(data, visiblePointLightCount);
-
-		for(U32 i = 0; i < visiblePointLightCount; ++i)
-		{
-			const PointLightQueueElement& in = rqueue.m_pointLights[i];
-			PointLight& out = gpuLights[i];
-
-			out.m_position = in.m_worldPosition;
-			out.m_squareRadiusOverOne = 1.0f / (in.m_radius * in.m_radius);
-			out.m_diffuseColor = in.m_diffuseColor;
-
-			if(in.m_shadowRenderQueues[0] == nullptr || !ctx.m_in->m_shadowsEnabled)
-			{
-				out.m_shadowAtlasTileScale = INVALID_TEXTURE_INDEX;
-			}
-			else
-			{
-				out.m_shadowAtlasTileScale = in.m_shadowAtlasTileSize;
-				ANKI_ASSERT(sizeof(out.m_shadowAtlasTileOffsets) == sizeof(in.m_shadowAtlasTileOffsets));
-				memcpy(&out.m_shadowAtlasTileOffsets[0], &in.m_shadowAtlasTileOffsets[0],
-					   sizeof(in.m_shadowAtlasTileOffsets));
-			}
-
-			out.m_radius = in.m_radius;
-			out.m_shadowLayer = in.m_shadowLayer;
-		}
-	}
-	else
-	{
-		ctx.m_out->m_pointLightsToken.markUnused();
-	}
-
-	// Write the spot lights
-	const U32 visibleSpotLightCount = rqueue.m_spotLights.getSize();
-	if(visibleSpotLightCount)
-	{
-		SpotLight* data = static_cast<SpotLight*>(ctx.m_in->m_stagingMem->allocateFrame(
-			sizeof(SpotLight) * visibleSpotLightCount, StagingGpuMemoryType::UNIFORM, ctx.m_out->m_spotLightsToken));
-
-		WeakArray<SpotLight> gpuLights(data, visibleSpotLightCount);
-
-		for(U32 i = 0; i < visibleSpotLightCount; ++i)
-		{
-			const SpotLightQueueElement& in = rqueue.m_spotLights[i];
-			SpotLight& out = gpuLights[i];
-
-			F32 shadowmapIndex = INVALID_TEXTURE_INDEX;
-
-			if(in.hasShadow() && ctx.m_in->m_shadowsEnabled)
-			{
-				// bias * proj_l * view_l
-				out.m_texProjectionMat = in.m_textureMatrix;
-
-				shadowmapIndex = 1.0f; // Just set a value
-			}
-
-			// Pos & dist
-			out.m_position = in.m_worldTransform.getTranslationPart().xyz();
-			out.m_squareRadiusOverOne = 1.0f / (in.m_distance * in.m_distance);
-
-			// Diff color and shadowmap ID now
-			out.m_diffuseColor = in.m_diffuseColor;
-			out.m_shadowmapId = shadowmapIndex;
-			out.m_shadowLayer = in.m_shadowLayer;
-
-			// Light dir & radius
-			Vec3 lightDir = -in.m_worldTransform.getRotationPart().getZAxis();
-			out.m_dir = lightDir;
-			out.m_radius = in.m_distance;
-
-			// Angles
-			out.m_outerCos = cos(in.m_outerAngle / 2.0f);
-			out.m_innerCos = cos(in.m_innerAngle / 2.0f);
-		}
-	}
-	else
-	{
-		ctx.m_out->m_spotLightsToken.markUnused();
-	}
-
-	// Write the decals
-	const U32 visibleDecalCount = rqueue.m_decals.getSize();
-	if(visibleDecalCount)
-	{
-		Decal* data = static_cast<Decal*>(ctx.m_in->m_stagingMem->allocateFrame(
-			sizeof(Decal) * visibleDecalCount, StagingGpuMemoryType::UNIFORM, ctx.m_out->m_decalsToken));
-
-		WeakArray<Decal> gpuDecals(data, visibleDecalCount);
-		TextureView* diffuseAtlas = nullptr;
-		TextureView* specularRoughnessAtlas = nullptr;
-
-		for(U32 i = 0; i < visibleDecalCount; ++i)
-		{
-			const DecalQueueElement& in = rqueue.m_decals[i];
-			Decal& out = gpuDecals[i];
-
-			if((diffuseAtlas != nullptr && diffuseAtlas != in.m_diffuseAtlas)
-			   || (specularRoughnessAtlas != nullptr && specularRoughnessAtlas != in.m_specularRoughnessAtlas))
-			{
-				ANKI_R_LOGF("All decals should have the same tex atlas");
-			}
-
-			diffuseAtlas = in.m_diffuseAtlas;
-			specularRoughnessAtlas = in.m_specularRoughnessAtlas;
-
-			// Diff
-			Vec4 uv = in.m_diffuseAtlasUv;
-			out.m_diffUv = Vec4(uv.x(), uv.y(), uv.z() - uv.x(), uv.w() - uv.y());
-			out.m_blendFactors[0] = in.m_diffuseAtlasBlendFactor;
-
-			// Other
-			uv = in.m_specularRoughnessAtlasUv;
-			out.m_normRoughnessUv = Vec4(uv.x(), uv.y(), uv.z() - uv.x(), uv.w() - uv.y());
-			out.m_blendFactors[1] = in.m_specularRoughnessAtlasBlendFactor;
-
-			// bias * proj_l * view
-			out.m_texProjectionMat = in.m_textureMatrix;
-		}
-
-		ANKI_ASSERT(diffuseAtlas || specularRoughnessAtlas);
-		ctx.m_out->m_diffDecalTexView.reset(diffuseAtlas);
-		ctx.m_out->m_specularRoughnessDecalTexView.reset(specularRoughnessAtlas);
-	}
-	else
-	{
-		ctx.m_out->m_decalsToken.markUnused();
-	}
-
-	// Write the probes
-	const U32 visibleProbeCount = rqueue.m_reflectionProbes.getSize();
-	if(visibleProbeCount)
-	{
-		ReflectionProbe* data = static_cast<ReflectionProbe*>(
-			ctx.m_in->m_stagingMem->allocateFrame(sizeof(ReflectionProbe) * visibleProbeCount,
-												  StagingGpuMemoryType::UNIFORM, ctx.m_out->m_reflectionProbesToken));
-
-		WeakArray<ReflectionProbe> gpuProbes(data, visibleProbeCount);
-
-		for(U32 i = 0; i < visibleProbeCount; ++i)
-		{
-			const ReflectionProbeQueueElement& in = rqueue.m_reflectionProbes[i];
-			ReflectionProbe& out = gpuProbes[i];
-
-			out.m_position = in.m_worldPosition;
-			out.m_cubemapIndex = F32(in.m_textureArrayIndex);
-			out.m_aabbMin = in.m_aabbMin;
-			out.m_aabbMax = in.m_aabbMax;
-		}
-	}
-	else
-	{
-		ctx.m_out->m_reflectionProbesToken.markUnused();
-	}
-
-	// Fog volumes
-	const U32 visibleFogVolumeCount = rqueue.m_fogDensityVolumes.getSize();
-	if(visibleFogVolumeCount)
-	{
-		FogDensityVolume* data = static_cast<FogDensityVolume*>(
-			ctx.m_in->m_stagingMem->allocateFrame(sizeof(FogDensityVolume) * visibleFogVolumeCount,
-												  StagingGpuMemoryType::UNIFORM, ctx.m_out->m_fogDensityVolumesToken));
-
-		WeakArray<FogDensityVolume> gpuFogVolumes(data, visibleFogVolumeCount);
-
-		for(U32 i = 0; i < visibleFogVolumeCount; ++i)
-		{
-			const FogDensityQueueElement& in = rqueue.m_fogDensityVolumes[i];
-			FogDensityVolume& out = gpuFogVolumes[i];
-
-			out.m_density = in.m_density;
-			if(in.m_isBox)
-			{
-				out.m_isBox = 1;
-				out.m_aabbMinOrSphereCenter = in.m_aabbMin;
-				out.m_aabbMaxOrSphereRadiusSquared = in.m_aabbMax;
-			}
-			else
-			{
-				out.m_isBox = 0;
-				out.m_aabbMinOrSphereCenter = in.m_sphereCenter;
-				out.m_aabbMaxOrSphereRadiusSquared = Vec3(in.m_sphereRadius * in.m_sphereRadius);
-			}
-		}
-	}
-	else
-	{
-		ctx.m_out->m_fogDensityVolumesToken.markUnused();
-	}
-
-	// Write the probes
-	const U32 visibleGiProbeCount = rqueue.m_giProbes.getSize();
-	if(visibleGiProbeCount)
-	{
-		GlobalIlluminationProbe* data = static_cast<GlobalIlluminationProbe*>(ctx.m_in->m_stagingMem->allocateFrame(
-			sizeof(GlobalIlluminationProbe) * visibleGiProbeCount, StagingGpuMemoryType::UNIFORM,
-			ctx.m_out->m_globalIlluminationProbesToken));
-
-		WeakArray<GlobalIlluminationProbe> gpuProbes(data, visibleGiProbeCount);
-
-		for(U32 i = 0; i < visibleGiProbeCount; ++i)
-		{
-			const GlobalIlluminationProbeQueueElement& in = rqueue.m_giProbes[i];
-			GlobalIlluminationProbe& out = gpuProbes[i];
-
-			out.m_aabbMin = in.m_aabbMin;
-			out.m_aabbMax = in.m_aabbMax;
-			out.m_textureIndex = U32(&in - &rqueue.m_giProbes.getFront());
-			out.m_halfTexelSizeU = 1.0f / F32(F32(in.m_cellCounts.x()) * 6.0f) / 2.0f;
-			out.m_fadeDistance = in.m_fadeDistance;
-		}
-	}
-	else
-	{
-		ctx.m_out->m_globalIlluminationProbesToken.markUnused();
-	}
-}
-
-} // end namespace anki

+ 0 - 67
AnKi/Renderer/ClusterBin.h

@@ -1,67 +0,0 @@
-// Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
-// All rights reserved.
-// Code licensed under the BSD License.
-// http://www.anki3d.org/LICENSE
-
-#pragma once
-
-#include <AnKi/Renderer/Common.h>
-#include <AnKi/Shaders/Include/ClusteredShadingFunctions.h>
-
-namespace anki
-{
-
-// Forward
-class ThreadHiveSemaphore;
-class Config;
-
-/// @addtogroup renderer
-/// @{
-
-/// @memberof ClusterBin
-class ClusterBinIn
-{
-public:
-	ThreadHive* m_threadHive ANKI_DEBUG_CODE(= nullptr);
-	StackAllocator<U8> m_tempAlloc;
-
-	const RenderQueue* m_renderQueue ANKI_DEBUG_CODE(= nullptr);
-
-	StagingGpuMemoryManager* m_stagingMem ANKI_DEBUG_CODE(= nullptr);
-
-	Bool m_shadowsEnabled ANKI_DEBUG_CODE(= false);
-};
-
-/// Bins lights, probes, decals etc to clusters.
-class ClusterBin
-{
-public:
-	~ClusterBin();
-
-	void init(HeapAllocator<U8> alloc, U32 clusterCountX, U32 clusterCountY, U32 clusterCountZ, const ConfigSet& cfg);
-
-	void bin(ClusterBinIn& in, ClusterBinOut& out);
-
-private:
-	class BinCtx;
-	class TileCtx;
-
-	HeapAllocator<U8> m_alloc;
-
-	Array<U32, 3> m_clusterCounts = {};
-	U32 m_totalClusterCount = 0;
-	U32 m_indexCount = 0;
-	U32 m_avgObjectsPerCluster = 0;
-
-	DynamicArray<Vec4> m_clusterEdges; ///< Cache those for opt. [tileCount][K+1][4]
-	Vec4 m_prevUnprojParams = Vec4(0.0f); ///< To check if m_tiles is dirty.
-
-	void prepare(BinCtx& ctx);
-
-	void binTile(U32 tileIdx, BinCtx& ctx, TileCtx& tileCtx);
-
-	void writeTypedObjectsToGpuBuffers(BinCtx& ctx) const;
-};
-/// @}
-
-} // end namespace anki

+ 1 - 1
AnKi/Renderer/ClusterBinning.cpp

@@ -254,7 +254,7 @@ void ClusterBinning::writeClustererBuffersTask()
 
 			if(in.m_shadowRenderQueues[0] == nullptr)
 			{
-				out.m_shadowAtlasTileScale = INVALID_TEXTURE_INDEX;
+				out.m_shadowAtlasTileScale = -1.0f;
 				out.m_shadowLayer = MAX_U32;
 			}
 			else

+ 0 - 26
AnKi/Renderer/Common.h

@@ -9,7 +9,6 @@
 #include <AnKi/Core/StagingGpuMemoryManager.h>
 #include <AnKi/Util/Ptr.h>
 #include <AnKi/Shaders/Include/Evsm.h>
-#include <AnKi/Shaders/Include/ClusteredShadingTypes.h>
 #include <AnKi/Shaders/Include/ClusteredShadingTypes2.h>
 
 namespace anki
@@ -62,7 +61,6 @@ class ReflectionProbeQueueElement;
 class DecalQueueElement;
 
 class ShaderProgramResourceVariant;
-class ClusterBin;
 
 /// @addtogroup renderer
 /// @{
@@ -117,25 +115,6 @@ constexpr Format SHADOW_COLOR_PIXEL_FORMAT = Format::R32G32B32A32_SFLOAT;
 constexpr Format SHADOW_COLOR_PIXEL_FORMAT = Format::R32G32_SFLOAT;
 #endif
 
-/// @memberof ClusterBin
-class ClusterBinOut
-{
-public:
-	StagingGpuMemoryToken m_pointLightsToken;
-	StagingGpuMemoryToken m_spotLightsToken;
-	StagingGpuMemoryToken m_reflectionProbesToken;
-	StagingGpuMemoryToken m_decalsToken;
-	StagingGpuMemoryToken m_fogDensityVolumesToken;
-	StagingGpuMemoryToken m_globalIlluminationProbesToken;
-	StagingGpuMemoryToken m_clustersToken;
-	StagingGpuMemoryToken m_indicesToken;
-
-	TextureViewPtr m_diffDecalTexView;
-	TextureViewPtr m_specularRoughnessDecalTexView;
-
-	ClustererMagicValues m_shaderMagicValues;
-};
-
 /// GPU buffers and textures that the clusterer refers to.
 class ClusteredShadingContext
 {
@@ -178,11 +157,6 @@ public:
 	U32 m_outRenderTargetWidth = 0;
 	U32 m_outRenderTargetHeight = 0;
 
-	ClusterBinOut m_clusterBinOut;
-	ClustererMagicValues m_prevClustererMagicValues;
-
-	StagingGpuMemoryToken m_lightShadingUniformsToken;
-
 	ClusteredShadingContext m_clusteredShading;
 
 	RenderingContext(const StackAllocator<U8>& alloc)

+ 1 - 4
AnKi/Renderer/ConfigDefs.h

@@ -3,9 +3,6 @@
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 
-ANKI_CONFIG_OPTION(r_clusterSizeX, 32, 1, 256)
-ANKI_CONFIG_OPTION(r_clusterSizeY, 26, 1, 256)
-ANKI_CONFIG_OPTION(r_clusterSizeZ, 32, 1, 256)
 ANKI_CONFIG_OPTION(r_textureAnisotropy, 8, 1, 16)
 ANKI_CONFIG_OPTION(r_tileSize, 64, 8, 256, "Tile lighting tile size")
 ANKI_CONFIG_OPTION(r_zSplitCount, 64, 8, 1024, "Clusterer number of Z splits")
@@ -24,7 +21,7 @@ ANKI_CONFIG_OPTION(r_ssgiDepthLod, 2, 0, 1000)
 
 ANKI_CONFIG_OPTION(r_shadowMappingTileResolution, 128, 16, 2048)
 ANKI_CONFIG_OPTION(r_shadowMappingTileCountPerRowOrColumn, 16, 1, 256)
-ANKI_CONFIG_OPTION(r_shadowMappingScratchTileCountX, 4 * (MAX_SHADOW_CASCADES + 2), 1u, 256u,
+ANKI_CONFIG_OPTION(r_shadowMappingScratchTileCountX, 4 * (MAX_SHADOW_CASCADES2 + 2), 1u, 256u,
 				   "Number of tiles of the scratch buffer in X")
 ANKI_CONFIG_OPTION(r_shadowMappingScratchTileCountY, 4, 1, 256, "Number of tiles of the scratch buffer in Y")
 

+ 1 - 1
AnKi/Renderer/GlobalIllumination.cpp

@@ -83,7 +83,7 @@ void GlobalIllumination::setRenderGraphDependencies(RenderingContext& ctx, Rende
 void GlobalIllumination::bindVolumeTextures(const RenderingContext& ctx, RenderPassWorkContext& rgraphCtx, U32 set,
 											U32 binding) const
 {
-	for(U32 idx = 0; idx < MAX_VISIBLE_GLOBAL_ILLUMINATION_PROBES; ++idx)
+	for(U32 idx = 0; idx < MAX_VISIBLE_GLOBAL_ILLUMINATION_PROBES2; ++idx)
 	{
 		if(idx < ctx.m_renderQueue->m_giProbes.getSize())
 		{

+ 0 - 2
AnKi/Renderer/MainRenderer.cpp

@@ -79,7 +79,6 @@ Error MainRenderer::render(RenderQueue& rqueue, TexturePtr presentTex)
 {
 	ANKI_TRACE_SCOPED_EVENT(RENDER);
 
-	m_r->setStatsEnabled(m_statsEnabled);
 	m_stats.m_renderingCpuTime = (m_statsEnabled) ? HighRezTimer::getCurrentTime() : -1.0;
 
 	// First thing, reset the temp mem pool
@@ -178,7 +177,6 @@ Error MainRenderer::render(RenderQueue& rqueue, TexturePtr presentTex)
 	// Stats
 	if(m_statsEnabled)
 	{
-		static_cast<RendererStats&>(m_stats) = m_r->getStats();
 		m_stats.m_renderingCpuTime = HighRezTimer::getCurrentTime() - m_stats.m_renderingCpuTime;
 
 		RenderGraphStatistics rgraphStats;

+ 1 - 1
AnKi/Renderer/MainRenderer.h

@@ -22,7 +22,7 @@ class UiManager;
 /// @{
 
 /// MainRenderer statistics.
-class MainRendererStats : public RendererStats
+class MainRendererStats
 {
 public:
 	Second m_renderingCpuTime ANKI_DEBUG_CODE(= -1.0);

+ 0 - 1
AnKi/Renderer/ProbeReflections.h

@@ -8,7 +8,6 @@
 #include <AnKi/Renderer/Renderer.h>
 #include <AnKi/Renderer/RendererObject.h>
 #include <AnKi/Renderer/TraditionalDeferredShading.h>
-#include <AnKi/Renderer/ClusterBin.h>
 #include <AnKi/Resource/TextureResource.h>
 
 namespace anki

+ 3 - 3
AnKi/Renderer/RenderQueue.h

@@ -8,7 +8,7 @@
 #include <AnKi/Renderer/Common.h>
 #include <AnKi/Resource/RenderingKey.h>
 #include <AnKi/Ui/Canvas.h>
-#include <AnKi/Shaders/Include/ClusteredShadingTypes.h>
+#include <AnKi/Shaders/Include/ClusteredShadingTypes2.h>
 #include <AnKi/Shaders/Include/ModelTypes.h>
 
 namespace anki
@@ -164,8 +164,8 @@ static_assert(std::is_trivially_destructible<SpotLightQueueElement>::value == tr
 class DirectionalLightQueueElement final
 {
 public:
-	Array<Mat4, MAX_SHADOW_CASCADES> m_textureMatrices;
-	Array<RenderQueue*, MAX_SHADOW_CASCADES> m_shadowRenderQueues;
+	Array<Mat4, MAX_SHADOW_CASCADES2> m_textureMatrices;
+	Array<RenderQueue*, MAX_SHADOW_CASCADES2> m_shadowRenderQueues;
 	RenderQueueDrawCallback m_drawCallback;
 	const void* m_drawCallbackUserData;
 	U64 m_uuid; ///< Zero means that there is no dir light

+ 1 - 88
AnKi/Renderer/Renderer.cpp

@@ -12,7 +12,7 @@
 #include <AnKi/Collision/Aabb.h>
 #include <AnKi/Collision/Plane.h>
 #include <AnKi/Collision/Functions.h>
-#include <AnKi/Shaders/Include/ClusteredShadingTypes.h>
+#include <AnKi/Shaders/Include/ClusteredShadingTypes2.h>
 
 #include <AnKi/Renderer/ProbeReflections.h>
 #include <AnKi/Renderer/GBuffer.h>
@@ -91,13 +91,6 @@ Error Renderer::initInternal(const ConfigSet& config)
 	m_height = config.getNumberU32("height");
 	ANKI_R_LOGI("Initializing offscreen renderer. Size %ux%u", m_width, m_height);
 
-	m_clusterCount[0] = config.getNumberU32("r_clusterSizeX");
-	m_clusterCount[1] = config.getNumberU32("r_clusterSizeY");
-	m_clusterCount[2] = config.getNumberU32("r_clusterSizeZ");
-	m_clusterCount[3] = m_clusterCount[0] * m_clusterCount[1] * m_clusterCount[2];
-
-	m_clusterBin.init(m_alloc, m_clusterCount[0], m_clusterCount[1], m_clusterCount[2], config);
-
 	m_tileSize = config.getNumberU32("r_tileSize");
 	m_tileCounts.x() = (m_width + m_tileSize - 1) / m_tileSize;
 	m_tileCounts.y() = (m_height + m_tileSize - 1) / m_tileSize;
@@ -364,23 +357,6 @@ Error Renderer::populateRenderGraph(RenderingContext& ctx)
 	// Populate the uniforms
 	m_clusterBinning->writeClusterBuffersAsync();
 
-	// Bin lights and update uniforms
-	m_stats.m_lightBinTime = (m_statsEnabled) ? HighRezTimer::getCurrentTime() : -1.0;
-	ClusterBinIn cin;
-	cin.m_renderQueue = ctx.m_renderQueue;
-	cin.m_tempAlloc = ctx.m_tempAllocator;
-	cin.m_shadowsEnabled = true; // TODO
-	cin.m_stagingMem = m_stagingMem;
-	cin.m_threadHive = m_threadHive;
-	m_clusterBin.bin(cin, ctx.m_clusterBinOut);
-
-	ctx.m_prevClustererMagicValues =
-		(m_frameCount > 0) ? m_prevClustererMagicValues : ctx.m_clusterBinOut.m_shaderMagicValues;
-	m_prevClustererMagicValues = ctx.m_clusterBinOut.m_shaderMagicValues;
-
-	updateLightShadingUniforms(ctx);
-	m_stats.m_lightBinTime = (m_statsEnabled) ? (HighRezTimer::getCurrentTime() - m_stats.m_lightBinTime) : -1.0;
-
 	return Error::NONE;
 }
 
@@ -589,69 +565,6 @@ TexturePtr Renderer::createAndClearRenderTarget(const TextureInitInfo& inf, cons
 	return tex;
 }
 
-void Renderer::updateLightShadingUniforms(RenderingContext& ctx) const
-{
-	LightingUniforms* blk = static_cast<LightingUniforms*>(m_stagingMem->allocateFrame(
-		sizeof(LightingUniforms), StagingGpuMemoryType::UNIFORM, ctx.m_lightShadingUniformsToken));
-
-	// Start writing
-	blk->m_unprojectionParams = ctx.m_matrices.m_unprojectionParameters;
-
-	blk->m_rendererSize = Vec2(F32(m_width), F32(m_height));
-	blk->m_time = F32(HighRezTimer::getCurrentTime());
-	blk->m_near = ctx.m_renderQueue->m_cameraNear;
-
-	blk->m_clusterCount = UVec4(m_clusterCount[0], m_clusterCount[1], m_clusterCount[2], m_clusterCount[3]);
-
-	blk->m_cameraPos = ctx.m_renderQueue->m_cameraTransform.getTranslationPart().xyz();
-	blk->m_far = ctx.m_renderQueue->m_cameraFar;
-
-	blk->m_clustererMagicValues = ctx.m_clusterBinOut.m_shaderMagicValues;
-	blk->m_prevClustererMagicValues = ctx.m_prevClustererMagicValues;
-
-	blk->m_lightVolumeLastCluster = m_volLighting->getFinalZSplit();
-	blk->m_frameCount = m_frameCount & MAX_U32;
-
-	// Matrices
-	blk->m_viewMat = ctx.m_renderQueue->m_viewMatrix;
-	blk->m_invViewMat = ctx.m_renderQueue->m_viewMatrix.getInverse();
-
-	blk->m_projMat = ctx.m_matrices.m_projectionJitter;
-	blk->m_invProjMat = ctx.m_matrices.m_projectionJitter.getInverse();
-
-	blk->m_viewProjMat = ctx.m_matrices.m_viewProjectionJitter;
-	blk->m_invViewProjMat = ctx.m_matrices.m_viewProjectionJitter.getInverse();
-
-	blk->m_prevViewProjMat = ctx.m_prevMatrices.m_viewProjectionJitter;
-
-	blk->m_prevViewProjMatMulInvViewProjMat =
-		ctx.m_prevMatrices.m_viewProjection * ctx.m_matrices.m_viewProjectionJitter.getInverse();
-
-	// Directional light
-	if(ctx.m_renderQueue->m_directionalLight.m_uuid != 0)
-	{
-		DirectionalLight& out = blk->m_dirLight;
-		const DirectionalLightQueueElement& in = ctx.m_renderQueue->m_directionalLight;
-
-		out.m_diffuseColor = in.m_diffuseColor;
-		out.m_cascadeCount = in.m_shadowCascadeCount;
-		out.m_dir = in.m_direction;
-		out.m_active = 1;
-		out.m_effectiveShadowDistance = in.m_effectiveShadowDistance;
-		out.m_shadowCascadesDistancePower = in.m_shadowCascadesDistancePower;
-		out.m_shadowLayer = in.m_shadowLayer;
-
-		for(U cascade = 0; cascade < in.m_shadowCascadeCount; ++cascade)
-		{
-			out.m_textureMatrices[cascade] = in.m_textureMatrices[cascade];
-		}
-	}
-	else
-	{
-		blk->m_dirLight.m_active = 0;
-	}
-}
-
 void Renderer::registerDebugRenderTarget(RendererObject* obj, CString rtName)
 {
 #if ANKI_ENABLE_ASSERTS

+ 0 - 30
AnKi/Renderer/Renderer.h

@@ -7,7 +7,6 @@
 
 #include <AnKi/Renderer/Common.h>
 #include <AnKi/Renderer/Drawer.h>
-#include <AnKi/Renderer/ClusterBin.h>
 #include <AnKi/Math.h>
 #include <AnKi/Gr.h>
 #include <AnKi/Resource/Forward.h>
@@ -27,12 +26,6 @@ class UiManager;
 /// @{
 
 /// Renderer statistics.
-class RendererStats
-{
-public:
-	Second m_lightBinTime ANKI_DEBUG_CODE(= -1.0);
-};
-
 class RendererPrecreatedSamplers
 {
 public:
@@ -205,16 +198,6 @@ public:
 
 	void finalize(const RenderingContext& ctx);
 
-	void setStatsEnabled(Bool enable)
-	{
-		m_statsEnabled = enable;
-	}
-
-	const RendererStats& getStats() const
-	{
-		return m_stats;
-	}
-
 	U64 getFrameCount() const
 	{
 		return m_frameCount;
@@ -298,11 +281,6 @@ public:
 		return m_samplers;
 	}
 
-	const Array<U32, 4>& getClusterCount() const
-	{
-		return m_clusterCount;
-	}
-
 	StagingGpuMemoryManager& getStagingGpuMemoryManager()
 	{
 		ANKI_ASSERT(m_stagingMem);
@@ -396,8 +374,6 @@ private:
 	UniquePtr<ClusterBinning> m_clusterBinning;
 	/// @}
 
-	Array<U32, 4> m_clusterCount;
-	ClusterBin m_clusterBin;
 	U32 m_tileSize = 0;
 	UVec2 m_tileCounts = UVec2(0u);
 	U32 m_zSplitCount = 0;
@@ -414,7 +390,6 @@ private:
 	Bool m_resourcesDirty = true;
 
 	CommonMatrices m_prevMatrices;
-	ClustererMagicValues m_prevClustererMagicValues;
 
 	Array<Mat4, 16> m_jitteredMats16x;
 	Array<Mat4, 8> m_jitteredMats8x;
@@ -427,9 +402,6 @@ private:
 
 	ShaderProgramResourcePtr m_clearTexComputeProg;
 
-	RendererStats m_stats;
-	Bool m_statsEnabled = false;
-
 	class DebugRtInfo
 	{
 	public:
@@ -442,8 +414,6 @@ private:
 	ANKI_USE_RESULT Error initInternal(const ConfigSet& initializer);
 
 	void initJitteredMats();
-
-	void updateLightShadingUniforms(RenderingContext& ctx) const;
 };
 /// @}
 

+ 9 - 9
AnKi/Renderer/ShadowMapping.cpp

@@ -467,15 +467,15 @@ void ShadowMapping::processLights(RenderingContext& ctx, U32& threadCountForScra
 	{
 		DirectionalLightQueueElement& light = ctx.m_renderQueue->m_directionalLight;
 
-		Array<U64, MAX_SHADOW_CASCADES> timestamps;
-		Array<U32, MAX_SHADOW_CASCADES> cascadeIndices;
-		Array<U32, MAX_SHADOW_CASCADES> drawcallCounts;
-		Array<Viewport, MAX_SHADOW_CASCADES> atlasViewports;
-		Array<Viewport, MAX_SHADOW_CASCADES> scratchViewports;
-		Array<TileAllocatorResult, MAX_SHADOW_CASCADES> subResults;
-		Array<U32, MAX_SHADOW_CASCADES> lods;
-		Array<U32, MAX_SHADOW_CASCADES> renderQueueElementsLods;
-		Array<Bool, MAX_SHADOW_CASCADES> blurAtlass;
+		Array<U64, MAX_SHADOW_CASCADES2> timestamps;
+		Array<U32, MAX_SHADOW_CASCADES2> cascadeIndices;
+		Array<U32, MAX_SHADOW_CASCADES2> drawcallCounts;
+		Array<Viewport, MAX_SHADOW_CASCADES2> atlasViewports;
+		Array<Viewport, MAX_SHADOW_CASCADES2> scratchViewports;
+		Array<TileAllocatorResult, MAX_SHADOW_CASCADES2> subResults;
+		Array<U32, MAX_SHADOW_CASCADES2> lods;
+		Array<U32, MAX_SHADOW_CASCADES2> renderQueueElementsLods;
+		Array<Bool, MAX_SHADOW_CASCADES2> blurAtlass;
 
 		U32 activeCascades = 0;
 

+ 4 - 3
AnKi/Scene/Components/DecalComponent.cpp

@@ -6,7 +6,7 @@
 #include <AnKi/Scene/Components/DecalComponent.h>
 #include <AnKi/Scene/SceneGraph.h>
 #include <AnKi/Resource/ResourceManager.h>
-#include <AnKi/Shaders/Include/ClusteredShadingTypes.h>
+#include <AnKi/Shaders/Include/ClusteredShadingTypes2.h>
 
 namespace anki
 {
@@ -62,8 +62,9 @@ void DecalComponent::updateInternal()
 
 	const Mat4 viewMat = worldTransform.getInverse();
 
-	const Mat4 projMat = Mat4::calculateOrthographicProjectionMatrix(
-		halfBoxSize.x(), -halfBoxSize.x(), halfBoxSize.y(), -halfBoxSize.y(), LIGHT_FRUSTUM_NEAR_PLANE, m_boxSize.z());
+	const Mat4 projMat =
+		Mat4::calculateOrthographicProjectionMatrix(halfBoxSize.x(), -halfBoxSize.x(), halfBoxSize.y(),
+													-halfBoxSize.y(), CLUSTER_OBJECT_FRUSTUM_NEAR_PLANE, m_boxSize.z());
 
 	static const Mat4 biasMat4(0.5f, 0.0f, 0.0f, 0.5f, 0.0f, 0.5f, 0.0f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
 							   1.0f);

+ 2 - 2
AnKi/Scene/Components/FrustumComponent.h

@@ -11,8 +11,8 @@
 #include <AnKi/Collision/Obb.h>
 #include <AnKi/Collision/ConvexHullShape.h>
 #include <AnKi/Collision/Plane.h>
-#include <AnKi/Shaders/Include/ClusteredShadingFunctions.h>
 #include <AnKi/Resource/Common.h>
+#include <AnKi/Shaders/Include/ClusteredShadingFunctions.h>
 
 namespace anki
 {
@@ -442,7 +442,7 @@ private:
 	U32 getCascadeCount() const
 	{
 		return !!(m_flags & FrustumComponentVisibilityTestFlag::DIRECTIONAL_LIGHT_SHADOWS_ALL_CASCADES)
-				   ? MAX_SHADOW_CASCADES
+				   ? MAX_SHADOW_CASCADES2
 				   : 1;
 	}
 };

+ 7 - 7
AnKi/Scene/Components/LightComponent.cpp

@@ -11,7 +11,7 @@
 #include <AnKi/Collision.h>
 #include <AnKi/Resource/ResourceManager.h>
 #include <AnKi/Resource/TextureResource.h>
-#include <AnKi/Shaders/Include/ClusteredShadingTypes.h>
+#include <AnKi/Shaders/Include/ClusteredShadingTypes2.h>
 
 namespace anki
 {
@@ -45,8 +45,8 @@ Error LightComponent::update(SceneNode& node, Second prevTime, Second crntTime,
 	{
 
 		const Mat4 biasMat4(0.5, 0.0, 0.0, 0.5, 0.0, 0.5, 0.0, 0.5, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0);
-		const Mat4 proj = Mat4::calculatePerspectiveProjectionMatrix(m_spot.m_outerAngle, m_spot.m_outerAngle,
-																	 LIGHT_FRUSTUM_NEAR_PLANE, m_spot.m_distance);
+		const Mat4 proj = Mat4::calculatePerspectiveProjectionMatrix(
+			m_spot.m_outerAngle, m_spot.m_outerAngle, CLUSTER_OBJECT_FRUSTUM_NEAR_PLANE, m_spot.m_distance);
 		m_spot.m_textureMat = biasMat4 * proj * Mat4(m_worldtransform.getInverse());
 
 		Array<Vec4, 4> points;
@@ -71,7 +71,7 @@ void LightComponent::setupDirectionalLightQueueElement(const FrustumComponent& f
 													   WeakArray<FrustumComponent> cascadeFrustumComponents) const
 {
 	ANKI_ASSERT(m_type == LightComponentType::DIRECTIONAL);
-	ANKI_ASSERT(cascadeFrustumComponents.getSize() <= MAX_SHADOW_CASCADES);
+	ANKI_ASSERT(cascadeFrustumComponents.getSize() <= MAX_SHADOW_CASCADES2);
 
 	const U32 shadowCascadeCount = cascadeFrustumComponents.getSize();
 
@@ -102,7 +102,7 @@ void LightComponent::setupDirectionalLightQueueElement(const FrustumComponent& f
 		const F32 fovY = frustumComp.getFovY();
 
 		// Compute a sphere per cascade
-		Array<Sphere, MAX_SHADOW_CASCADES> boundingSpheres;
+		Array<Sphere, MAX_SHADOW_CASCADES2> boundingSpheres;
 		for(U32 i = 0; i < shadowCascadeCount; ++i)
 		{
 			// Compute the center of the sphere
@@ -168,7 +168,7 @@ void LightComponent::setupDirectionalLightQueueElement(const FrustumComponent& f
 			// Projection
 			const F32 far = (eye - sphereCenter).getLength() + sphereRadius;
 			Mat4 cascadeProjMat = Mat4::calculateOrthographicProjectionMatrix(
-				sphereRadius, -sphereRadius, sphereRadius, -sphereRadius, LIGHT_FRUSTUM_NEAR_PLANE, far);
+				sphereRadius, -sphereRadius, sphereRadius, -sphereRadius, CLUSTER_OBJECT_FRUSTUM_NEAR_PLANE, far);
 
 			// View
 			Transform cascadeTransform = m_worldtransform;
@@ -213,7 +213,7 @@ void LightComponent::setupDirectionalLightQueueElement(const FrustumComponent& f
 			const F32 bottom = plane.getOffset();
 
 			FrustumComponent& cascadeFrustumComp = cascadeFrustumComponents[i];
-			cascadeFrustumComp.setOrthographic(LIGHT_FRUSTUM_NEAR_PLANE, far, right, left, top, bottom);
+			cascadeFrustumComp.setOrthographic(CLUSTER_OBJECT_FRUSTUM_NEAR_PLANE, far, right, left, top, bottom);
 			cascadeFrustumComp.setWorldTransform(cascadeTransform);
 		}
 	}

+ 1 - 1
AnKi/Scene/GlobalIlluminationProbeNode.cpp

@@ -94,7 +94,7 @@ GlobalIlluminationProbeNode::GlobalIlluminationProbeNode(SceneGraph* scene, CStr
 
 	// The frustum components
 	constexpr F32 ang = toRad(90.0f);
-	const F32 zNear = LIGHT_FRUSTUM_NEAR_PLANE;
+	const F32 zNear = CLUSTER_OBJECT_FRUSTUM_NEAR_PLANE;
 
 	Mat3 rot;
 	rot = Mat3(Euler(0.0f, -PI / 2.0f, 0.0f)) * Mat3(Euler(0.0f, 0.0f, PI));

+ 4 - 3
AnKi/Scene/LightNode.cpp

@@ -9,7 +9,7 @@
 #include <AnKi/Scene/Components/MoveComponent.h>
 #include <AnKi/Scene/Components/SpatialComponent.h>
 #include <AnKi/Scene/Components/FrustumComponent.h>
-#include <AnKi/Shaders/Include/ClusteredShadingTypes.h>
+#include <AnKi/Shaders/Include/ClusteredShadingTypes2.h>
 
 namespace anki
 {
@@ -173,7 +173,7 @@ Error PointLightNode::frameUpdate(Second prevUpdateTime, Second crntTime)
 
 		const F32 ang = toRad(90.0f);
 		const F32 dist = lightc.getRadius();
-		const F32 zNear = LIGHT_FRUSTUM_NEAR_PLANE;
+		const F32 zNear = CLUSTER_OBJECT_FRUSTUM_NEAR_PLANE;
 
 		Mat3 rot;
 
@@ -273,7 +273,8 @@ void SpotLightNode::onMoved(const MoveComponent& move)
 void SpotLightNode::onLightShapeUpdated(LightComponent& light)
 {
 	FrustumComponent& frc = getFirstComponentOfType<FrustumComponent>();
-	frc.setPerspective(LIGHT_FRUSTUM_NEAR_PLANE, light.getDistance(), light.getOuterAngle(), light.getOuterAngle());
+	frc.setPerspective(CLUSTER_OBJECT_FRUSTUM_NEAR_PLANE, light.getDistance(), light.getOuterAngle(),
+					   light.getOuterAngle());
 }
 
 void SpotLightNode::onFrustumUpdated(FrustumComponent& frc)

+ 2 - 2
AnKi/Scene/ReflectionProbeNode.cpp

@@ -10,7 +10,7 @@
 #include <AnKi/Scene/Components/SpatialComponent.h>
 #include <AnKi/Scene/SceneGraph.h>
 #include <AnKi/Renderer/LightShading.h>
-#include <AnKi/Shaders/Include/ClusteredShadingTypes.h>
+#include <AnKi/Shaders/Include/ClusteredShadingTypes2.h>
 
 namespace anki
 {
@@ -110,7 +110,7 @@ ReflectionProbeNode::ReflectionProbeNode(SceneGraph* scene, CString name)
 
 		FrustumComponent* frc = newComponent<FrustumComponent>();
 		frc->setFrustumType(FrustumType::PERSPECTIVE);
-		frc->setPerspective(LIGHT_FRUSTUM_NEAR_PLANE, 10.0f, ang, ang);
+		frc->setPerspective(CLUSTER_OBJECT_FRUSTUM_NEAR_PLANE, 10.0f, ang, ang);
 		frc->setWorldTransform(m_frustumTransforms[i]);
 		frc->setEnabledVisibilityTests(FrustumComponentVisibilityTestFlag::NONE);
 		frc->setEffectiveShadowDistance(getSceneGraph().getConfig().m_reflectionProbeShadowEffectiveDistance);

+ 2 - 2
AnKi/Scene/Visibility.cpp

@@ -464,9 +464,9 @@ void VisibilityTestTask::test(ThreadHive& hive, U32 taskId)
 				{
 					ANKI_ASSERT(!!(enabledVisibilityTests
 								   & FrustumComponentVisibilityTestFlag::DIRECTIONAL_LIGHT_SHADOWS_ALL_CASCADES));
-					cascadeCount = MAX_SHADOW_CASCADES;
+					cascadeCount = MAX_SHADOW_CASCADES2;
 				}
-				ANKI_ASSERT(cascadeCount <= MAX_SHADOW_CASCADES);
+				ANKI_ASSERT(cascadeCount <= MAX_SHADOW_CASCADES2);
 
 				// Create some dummy frustum components and initialize them
 				WeakArray<FrustumComponent> cascadeFrustumComponents(

+ 1 - 1
AnKi/Shaders/ApplyIrradianceToReflection.ankiprog

@@ -5,7 +5,7 @@
 
 #pragma anki start comp
 #include <AnKi/Shaders/Pack.glsl>
-#include <AnKi/Shaders/LightFunctions.glsl>
+#include <AnKi/Shaders/LightFunctions2.glsl>
 
 layout(local_size_x = 8, local_size_y = 8, local_size_z = 6) in;
 

+ 0 - 162
AnKi/Shaders/ClusteredShadingCommon.glsl

@@ -1,162 +0,0 @@
-// Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
-// All rights reserved.
-// Code licensed under the BSD License.
-// http://www.anki3d.org/LICENSE
-
-#pragma once
-
-#include <AnKi/Shaders/LightFunctions.glsl>
-
-//
-// Common uniforms
-//
-#if defined(LIGHT_COMMON_UNIS_BINDING)
-
-layout(set = LIGHT_SET, binding = LIGHT_COMMON_UNIS_BINDING, std140, row_major) uniform lu0_
-{
-	LightingUniforms u_lightingUniforms;
-};
-
-#	define u_near UNIFORM(u_lightingUniforms.m_near)
-#	define u_far UNIFORM(u_lightingUniforms.m_far)
-#	define u_cameraPos UNIFORM(u_lightingUniforms.m_cameraPos)
-#	define u_clusterCountX UNIFORM(u_lightingUniforms.m_clusterCount.x)
-#	define u_clusterCountY UNIFORM(u_lightingUniforms.m_clusterCount.y)
-#	define u_clustererMagic u_lightingUniforms.m_clustererMagicValues
-#	define u_prevClustererMagic u_lightingUniforms.m_prevClustererMagicValues
-#	define u_time UNIFORM(u_lightingUniforms.m_time)
-#	define u_unprojectionParams UNIFORM(u_lightingUniforms.m_unprojectionParams)
-#	define u_rendererSize u_lightingUniforms.m_rendererSize
-#	define u_lightVolumeLastCluster UNIFORM(u_lightingUniforms.m_lightVolumeLastCluster)
-
-#	define u_viewMat u_lightingUniforms.m_viewMat
-#	define u_invViewMat u_lightingUniforms.m_invViewMat
-#	define u_projMat u_lightingUniforms.m_projMat
-#	define u_invProjMat u_lightingUniforms.m_invProjMat
-#	define u_viewProjMat u_lightingUniforms.m_viewProjMat
-#	define u_invViewProjMat u_lightingUniforms.m_invViewProjMat
-#	define u_prevViewProjMat u_lightingUniforms.m_prevViewProjMat
-#	define u_prevViewProjMatMulInvViewProjMat u_lightingUniforms.m_prevViewProjMatMulInvViewProjMat
-#	define u_dirLight u_lightingUniforms.m_dirLight
-#endif
-
-//
-// Light uniforms (3)
-//
-#if defined(LIGHT_LIGHTS_BINDING)
-layout(set = LIGHT_SET, binding = LIGHT_LIGHTS_BINDING, std140) uniform u1_
-{
-	PointLight u_pointLights[UBO_MAX_SIZE / ANKI_SIZEOF(PointLight)];
-};
-
-layout(set = LIGHT_SET, binding = LIGHT_LIGHTS_BINDING + 1, std140, row_major) uniform u2_
-{
-	SpotLight u_spotLights[UBO_MAX_SIZE / ANKI_SIZEOF(SpotLight)];
-};
-
-layout(set = LIGHT_SET, binding = LIGHT_LIGHTS_BINDING + 2) uniform highp texture2D u_shadowTex;
-#endif
-
-//
-// Indirect uniforms (3)
-//
-#if defined(LIGHT_INDIRECT_SPECULAR_BINDING)
-layout(std140, row_major, set = LIGHT_SET, binding = LIGHT_INDIRECT_SPECULAR_BINDING) uniform u3_
-{
-	ReflectionProbe u_reflectionProbes[UBO_MAX_SIZE / ANKI_SIZEOF(ReflectionProbe)];
-};
-
-layout(set = LIGHT_SET, binding = LIGHT_INDIRECT_SPECULAR_BINDING + 1) uniform textureCubeArray u_reflectionsTex;
-layout(set = LIGHT_SET, binding = LIGHT_INDIRECT_SPECULAR_BINDING + 2) uniform texture2D u_integrationLut;
-#endif
-
-//
-// Decal uniforms (3)
-//
-#if defined(LIGHT_DECALS_BINDING)
-layout(std140, row_major, set = LIGHT_SET, binding = LIGHT_DECALS_BINDING) uniform u4_
-{
-	Decal u_decals[UBO_MAX_SIZE / ANKI_SIZEOF(Decal)];
-};
-
-layout(set = LIGHT_SET, binding = LIGHT_DECALS_BINDING + 1) uniform texture2D u_diffDecalTex;
-layout(set = LIGHT_SET, binding = LIGHT_DECALS_BINDING + 2) uniform texture2D u_specularRoughnessDecalTex;
-#endif
-
-//
-// Fog density uniforms (1)
-//
-#if defined(LIGHT_FOG_DENSITY_VOLUMES_BINDING)
-layout(std140, row_major, set = LIGHT_SET, binding = LIGHT_FOG_DENSITY_VOLUMES_BINDING) uniform u5_
-{
-	FogDensityVolume u_fogDensityVolumes[UBO_MAX_SIZE / ANKI_SIZEOF(FogDensityVolume)];
-};
-#endif
-
-//
-// GI (2)
-//
-#if defined(LIGHT_GLOBAL_ILLUMINATION_BINDING)
-layout(set = LIGHT_SET, binding = LIGHT_GLOBAL_ILLUMINATION_BINDING) uniform texture3D
-	u_globalIlluminationTextures[MAX_VISIBLE_GLOBAL_ILLUMINATION_PROBES];
-
-layout(set = LIGHT_SET, binding = LIGHT_GLOBAL_ILLUMINATION_BINDING + 1) uniform ugi_
-{
-	GlobalIlluminationProbe u_giProbes[MAX_VISIBLE_GLOBAL_ILLUMINATION_PROBES];
-};
-#endif
-
-//
-// Cluster uniforms
-//
-#if defined(LIGHT_CLUSTERS_BINDING)
-layout(set = LIGHT_SET, binding = LIGHT_CLUSTERS_BINDING, std430) readonly buffer s0_
-{
-	U32 u_clusters[];
-};
-
-layout(set = LIGHT_SET, binding = LIGHT_CLUSTERS_BINDING + 1, std430) readonly buffer s1_
-{
-	U32 u_lightIndices[];
-};
-#endif
-
-// Debugging function
-Vec3 lightHeatmap(U32 firstIndex, U32 maxObjects, U32 typeMask)
-{
-	U32 count = 0;
-	U32 idx;
-
-	while((idx = u_lightIndices[firstIndex++]) != MAX_U32)
-	{
-		count += ((typeMask & (1u << 0u)) != 0u) ? 1u : 0u;
-	}
-
-	while((idx = u_lightIndices[firstIndex++]) != MAX_U32)
-	{
-		count += ((typeMask & (1u << 1u)) != 0u) ? 1u : 0u;
-	}
-
-	while((idx = u_lightIndices[firstIndex++]) != MAX_U32)
-	{
-		count += ((typeMask & (1u << 2u)) != 0u) ? 1u : 0u;
-	}
-
-	while((idx = u_lightIndices[firstIndex++]) != MAX_U32)
-	{
-		count += ((typeMask & (1u << 3u)) != 0u) ? 1u : 0u;
-	}
-
-	while((idx = u_lightIndices[firstIndex++]) != MAX_U32)
-	{
-		count += ((typeMask & (1u << 4u)) != 0u) ? 1u : 0u;
-	}
-
-	while((idx = u_lightIndices[firstIndex++]) != MAX_U32)
-	{
-		count += ((typeMask & (1u << 5u)) != 0u) ? 1u : 0u;
-	}
-
-	const F32 factor = min(1.0, F32(count) / F32(maxObjects));
-	return heatmap(factor);
-}

+ 1 - 1
AnKi/Shaders/ExponentialShadowmappingResolve.ankiprog

@@ -7,7 +7,7 @@ ANKI_SPECIALIZATION_CONSTANT_UVEC2(INPUT_TEXTURE_SIZE, 0);
 
 #pragma anki start comp
 #include <AnKi/Shaders/GaussianBlurCommon.glsl>
-#include <AnKi/Shaders/LightFunctions.glsl>
+#include <AnKi/Shaders/LightFunctions2.glsl>
 
 layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
 

+ 0 - 7
AnKi/Shaders/ForwardShadingCommonVert.glsl

@@ -8,13 +8,6 @@
 // Common code for all vertex shaders of FS
 #include <AnKi/Shaders/Common.glsl>
 
-// Global resources
-#define LIGHT_SET 0
-#define LIGHT_COMMON_UNIS_BINDING 3
-#define LIGHT_LIGHTS_BINDING 4
-#define LIGHT_CLUSTERS_BINDING 7
-#include <AnKi/Shaders/ClusteredShadingCommon.glsl>
-
 // In/out
 layout(location = POSITION_LOCATION) in Vec3 in_position;
 

+ 1 - 41
AnKi/Shaders/Include/ClusteredShadingFunctions.h

@@ -5,50 +5,10 @@
 
 #pragma once
 
-#include <AnKi/Shaders/Include/ClusteredShadingTypes.h>
+#include <AnKi/Shaders/Include/ClusteredShadingTypes2.h>
 
 ANKI_BEGIN_NAMESPACE
 
-ANKI_SHADER_FUNC_INLINE F32 computeClusterKf(ClustererMagicValues magic, Vec3 worldPos)
-{
-	const F32 fz = sqrt(dot(magic.m_val0.xyz(), worldPos) - magic.m_val0.w());
-	return fz;
-}
-
-ANKI_SHADER_FUNC_INLINE U32 computeClusterK(ClustererMagicValues magic, Vec3 worldPos)
-{
-	return U32(computeClusterKf(magic, worldPos));
-}
-
-// Compute cluster index
-ANKI_SHADER_FUNC_INLINE U32 computeClusterIndex(ClustererMagicValues magic, Vec2 uv, Vec3 worldPos, U32 clusterCountX,
-												U32 clusterCountY)
-{
-	const UVec2 xy = UVec2(uv * Vec2(F32(clusterCountX), F32(clusterCountY)));
-	const U32 k = computeClusterK(magic, worldPos);
-	return k * (clusterCountX * clusterCountY) + xy.y() * clusterCountX + xy.x();
-}
-
-// Compute the Z of the near plane given a cluster idx
-ANKI_SHADER_FUNC_INLINE F32 computeClusterNearf(ClustererMagicValues magic, F32 fk)
-{
-	return magic.m_val1.x() * fk * fk + magic.m_val1.y();
-}
-
-// Compute the Z of the near plane given a cluster idx
-ANKI_SHADER_FUNC_INLINE F32 computeClusterNear(ClustererMagicValues magic, U32 k)
-{
-	return computeClusterNearf(magic, F32(k));
-}
-
-// Compute the UV coordinates of a volume texture that encloses the clusterer
-ANKI_SHADER_FUNC_INLINE Vec3 computeClustererVolumeTextureUvs(ClustererMagicValues magic, Vec2 uv, Vec3 worldPos,
-															  U32 clusterCountZ)
-{
-	const F32 k = computeClusterKf(magic, worldPos);
-	return Vec3(uv, k / F32(clusterCountZ));
-}
-
 // Compute the far plane of a shadow cascade. "p" is the power that defines the distance curve.
 // "effectiveShadowDistance" is the far plane of the last cascade.
 ANKI_SHADER_FUNC_INLINE F32 computeShadowCascadeDistance(U32 cascadeIdx, F32 p, F32 effectiveShadowDistance,

+ 0 - 167
AnKi/Shaders/Include/ClusteredShadingTypes.h

@@ -1,167 +0,0 @@
-// Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
-// All rights reserved.
-// Code licensed under the BSD License.
-// http://www.anki3d.org/LICENSE
-
-// Mainly contains light related structures. Everything is packed to align with std140
-
-#pragma once
-
-#include <AnKi/Shaders/Include/Common.h>
-
-ANKI_BEGIN_NAMESPACE
-
-// Consts
-const U32 TYPED_OBJECT_COUNT = 6u; // Point lights, spot lights, refl probes, GI probes, decals and fog volumes
-const F32 INVALID_TEXTURE_INDEX = -1.0f;
-const F32 LIGHT_FRUSTUM_NEAR_PLANE = 0.1f / 4.0f; // The near plane on the shadow map frustums.
-const U32 MAX_SHADOW_CASCADES = 4u;
-const F32 SUBSURFACE_MIN = 0.01f;
-const U32 MAX_VISIBLE_GLOBAL_ILLUMINATION_PROBES = 8u; // Global illumination clipmap count.
-
-// See the documentation in the ClustererBin class.
-struct ClustererMagicValues
-{
-	Vec4 m_val0;
-	Vec4 m_val1;
-};
-
-// Point light
-struct PointLight
-{
-	Vec3 m_position; // Position in world space
-	F32 m_squareRadiusOverOne; // 1/(radius^2)
-	Vec3 m_diffuseColor;
-	F32 m_shadowAtlasTileScale; // UV scale for all tiles
-	Vec2 m_padding;
-	F32 m_radius; // Radius
-	U32 m_shadowLayer;
-	Vec4 m_shadowAtlasTileOffsets[3u]; // It's a Vec4 because of the std140 limitations
-};
-const U32 _ANKI_SIZEOF_PointLight = 6 * ANKI_SIZEOF(Vec4);
-ANKI_SHADER_STATIC_ASSERT(sizeof(PointLight) == _ANKI_SIZEOF_PointLight);
-
-// Spot light
-struct SpotLight
-{
-	Vec3 m_position; // Position in world space
-	F32 m_squareRadiusOverOne; // 1/(radius^2)
-	Vec3 m_diffuseColor;
-	F32 m_shadowmapId; // Shadowmap tex ID
-	Vec3 m_dir; // Light direction
-	F32 m_radius; // Max distance
-	F32 m_outerCos;
-	F32 m_innerCos;
-	U32 m_shadowLayer;
-	U32 m_padding;
-	Mat4 m_texProjectionMat;
-};
-const U32 _ANKI_SIZEOF_SpotLight = 4 * ANKI_SIZEOF(Vec4) + ANKI_SIZEOF(Mat4);
-ANKI_SHADER_STATIC_ASSERT(sizeof(SpotLight) == _ANKI_SIZEOF_SpotLight);
-
-// Directional light (sun)
-struct DirectionalLight
-{
-	Vec3 m_diffuseColor;
-	U32 m_cascadeCount; // If it's zero then it doesn't case shadow
-	Vec3 m_dir;
-	U32 m_active;
-	F32 m_effectiveShadowDistance;
-	F32 m_shadowCascadesDistancePower;
-	U32 m_shadowLayer;
-	U32 m_padding;
-	Mat4 m_textureMatrices[MAX_SHADOW_CASCADES];
-};
-const U32 _ANKI_SIZEOF_DirectionalLight = 3 * ANKI_SIZEOF(Vec4) + MAX_SHADOW_CASCADES * ANKI_SIZEOF(Mat4);
-ANKI_SHADER_STATIC_ASSERT(sizeof(DirectionalLight) == _ANKI_SIZEOF_DirectionalLight);
-
-// Representation of a reflection probe
-struct ReflectionProbe
-{
-	Vec3 m_position; // Position of the probe in world space
-	F32 m_cubemapIndex; // Slice in cubemap array texture
-	Vec3 m_aabbMin;
-	F32 m_padding0;
-	Vec3 m_aabbMax;
-	F32 m_padding1;
-};
-const U32 _ANKI_SIZEOF_ReflectionProbe = 3 * ANKI_SIZEOF(Vec4);
-ANKI_SHADER_STATIC_ASSERT(sizeof(ReflectionProbe) == _ANKI_SIZEOF_ReflectionProbe);
-
-// Decal
-struct Decal
-{
-	Vec4 m_diffUv;
-	Vec4 m_normRoughnessUv;
-	Mat4 m_texProjectionMat;
-	Vec4 m_blendFactors;
-};
-const U32 _ANKI_SIZEOF_Decal = 3 * ANKI_SIZEOF(Vec4) + ANKI_SIZEOF(Mat4);
-ANKI_SHADER_STATIC_ASSERT(sizeof(Decal) == _ANKI_SIZEOF_Decal);
-
-// Fog density volume
-struct FogDensityVolume
-{
-	Vec3 m_aabbMinOrSphereCenter;
-	U32 m_isBox;
-	Vec3 m_aabbMaxOrSphereRadiusSquared;
-	F32 m_density;
-};
-const U32 _ANKI_SIZEOF_FogDensityVolume = 2u * ANKI_SIZEOF(Vec4);
-ANKI_SHADER_STATIC_ASSERT(sizeof(FogDensityVolume) == _ANKI_SIZEOF_FogDensityVolume);
-
-// Global illumination probe
-struct GlobalIlluminationProbe
-{
-	Vec3 m_aabbMin;
-	U32 m_textureIndex;
-
-	Vec3 m_aabbMax;
-	F32 m_halfTexelSizeU; // (1.0 / textureSize(texArr[m_textureIndex]).x) / 2.0
-
-	// Used to calculate a factor that is zero when fragPos is close to AABB bounds and 1.0 at m_fadeDistance and less.
-	F32 m_fadeDistance;
-	F32 m_padding0;
-	F32 m_padding1;
-	F32 m_padding2;
-};
-const U32 _ANKI_SIZEOF_GlobalIlluminationProbe = 3u * ANKI_SIZEOF(Vec4);
-ANKI_SHADER_STATIC_ASSERT(sizeof(GlobalIlluminationProbe) == _ANKI_SIZEOF_GlobalIlluminationProbe);
-
-// Common uniforms for light shading passes
-struct LightingUniforms
-{
-	Vec4 m_unprojectionParams;
-
-	Vec2 m_rendererSize;
-	F32 m_time;
-	F32 m_near;
-
-	Vec3 m_cameraPos;
-	F32 m_far;
-
-	ClustererMagicValues m_clustererMagicValues;
-	ClustererMagicValues m_prevClustererMagicValues;
-
-	UVec4 m_clusterCount;
-
-	Vec2 m_padding;
-	U32 m_frameCount;
-	U32 m_lightVolumeLastCluster;
-
-	Mat4 m_viewMat;
-	Mat4 m_invViewMat;
-	Mat4 m_projMat;
-	Mat4 m_invProjMat;
-	Mat4 m_viewProjMat;
-	Mat4 m_invViewProjMat;
-	Mat4 m_prevViewProjMat;
-	Mat4 m_prevViewProjMatMulInvViewProjMat; // Used to re-project previous frames
-
-	DirectionalLight m_dirLight;
-};
-const U32 _ANKI_SIZEOF_LightingUniforms =
-	9u * ANKI_SIZEOF(Vec4) + 8u * ANKI_SIZEOF(Mat4) + ANKI_SIZEOF(DirectionalLight);
-ANKI_SHADER_STATIC_ASSERT(sizeof(LightingUniforms) == _ANKI_SIZEOF_LightingUniforms);
-
-ANKI_END_NAMESPACE

+ 5 - 3
AnKi/Shaders/Include/ClusteredShadingTypes2.h

@@ -18,9 +18,6 @@ const U32 CLUSTER_OBJECT_TYPE_REFLECTION_PROBE = 4u;
 const U32 CLUSTER_OBJECT_TYPE_GLOBAL_ILLUMINATION_PROBE = 5u;
 const U32 CLUSTER_OBJECT_TYPE_COUNT = 6u; ///< Point and spot lights, refl and GI probes, decals and fog volumes.
 
-const F32 CLUSTER_OBJECT_FRUSTUM_NEAR_PLANE = 0.1f / 4.0f; ///< The near plane of various clusterer object frustums.
-const U32 MAX_SHADOW_CASCADES2 = 4u;
-
 // Limits
 const U32 MAX_VISIBLE_POINT_LIGHTS = 64u;
 const U32 MAX_VISIBLE_SPOT_LIGHTS = 64u;
@@ -29,6 +26,11 @@ const U32 MAX_VISIBLE_FOG_DENSITY_VOLUMES = 16u;
 const U32 MAX_VISIBLE_REFLECTION_PROBES = 16u;
 const U32 MAX_VISIBLE_GLOBAL_ILLUMINATION_PROBES2 = 8u;
 
+// Other consts
+const F32 CLUSTER_OBJECT_FRUSTUM_NEAR_PLANE = 0.1f / 4.0f; ///< The near plane of various clusterer object frustums.
+const U32 MAX_SHADOW_CASCADES2 = 4u;
+const F32 SUBSURFACE_MIN = 0.01f;
+
 /// Point light.
 struct PointLight2
 {

+ 1 - 1
AnKi/Shaders/IrradianceDice.ankiprog

@@ -14,7 +14,7 @@
 
 #include <AnKi/Shaders/Functions.glsl>
 #include <AnKi/Shaders/Pack.glsl>
-#include <AnKi/Shaders/LightFunctions.glsl>
+#include <AnKi/Shaders/LightFunctions2.glsl>
 
 #define DEBUG_MODE 0 // 0: disable, 1: different color per dice face, 2: different color per cell
 

+ 0 - 378
AnKi/Shaders/LightFunctions.glsl

@@ -1,378 +0,0 @@
-// Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
-// All rights reserved.
-// Code licensed under the BSD License.
-// http://www.anki3d.org/LICENSE
-
-// Contains functions for light calculations
-
-#pragma once
-
-#include <AnKi/Shaders/Functions.glsl>
-#include <AnKi/Shaders/CollisionFunctions.glsl>
-#include <AnKi/Shaders/Pack.glsl>
-#include <AnKi/Shaders/Include/ClusteredShadingTypes.h>
-#include <AnKi/Shaders/Include/ClusteredShadingFunctions.h>
-#include <AnKi/Shaders/Include/Evsm.h>
-
-// Do some EVSM magic with depth
-Vec2 evsmProcessDepth(F32 depth)
-{
-	depth = 2.0 * depth - 1.0;
-	const F32 pos = exp(EVSM_POSITIVE_CONSTANT * depth);
-	const F32 neg = -exp(EVSM_NEGATIVE_CONSTANT * depth);
-	return Vec2(pos, neg);
-}
-
-F32 linstep(F32 a, F32 b, F32 v)
-{
-	return saturate((v - a) / (b - a));
-}
-
-// Reduces VSM light bleedning
-F32 reduceLightBleeding(F32 pMax, F32 amount)
-{
-	// Remove the [0, amount] tail and linearly rescale (amount, 1].
-	return linstep(amount, 1.0, pMax);
-}
-
-F32 chebyshevUpperBound(Vec2 moments, F32 mean, F32 minVariance, F32 lightBleedingReduction)
-{
-	// Compute variance
-	F32 variance = moments.y - (moments.x * moments.x);
-	variance = max(variance, minVariance);
-
-	// Compute probabilistic upper bound
-	const F32 d = mean - moments.x;
-	F32 pMax = variance / (variance + (d * d));
-
-	pMax = reduceLightBleeding(pMax, lightBleedingReduction);
-
-	// One-tailed Chebyshev
-	return (mean <= moments.x) ? 1.0 : pMax;
-}
-
-// Compute the shadow factor of EVSM given the 2 depths
-F32 evsmComputeShadowFactor(F32 occluderDepth, Vec4 shadowMapMoments)
-{
-	const Vec2 evsmOccluderDepths = evsmProcessDepth(occluderDepth);
-	const Vec2 depthScale =
-		EVSM_BIAS * 0.01 * Vec2(EVSM_POSITIVE_CONSTANT, EVSM_NEGATIVE_CONSTANT) * evsmOccluderDepths;
-	const Vec2 minVariance = depthScale * depthScale;
-
-#if !ANKI_EVSM4
-	return chebyshevUpperBound(shadowMapMoments.xy, evsmOccluderDepths.x, minVariance.x, EVSM_LIGHT_BLEEDING_REDUCTION);
-#else
-	const F32 pos =
-		chebyshevUpperBound(shadowMapMoments.xy, evsmOccluderDepths.x, minVariance.x, EVSM_LIGHT_BLEEDING_REDUCTION);
-	const F32 neg =
-		chebyshevUpperBound(shadowMapMoments.zw, evsmOccluderDepths.y, minVariance.y, EVSM_LIGHT_BLEEDING_REDUCTION);
-	return min(pos, neg);
-#endif
-}
-
-// Fresnel term unreal
-// specular: The specular color aka F0
-Vec3 F_Unreal(Vec3 specular, F32 VoH)
-{
-	return specular + (1.0 - specular) * pow(2.0, (-5.55473 * VoH - 6.98316) * VoH);
-}
-
-// Fresnel Schlick: "An Inexpensive BRDF Model for Physically-Based Rendering"
-// It has lower VGRPs than F_Unreal
-// specular: The specular color aka F0
-Vec3 F_Schlick(Vec3 specular, F32 VoH)
-{
-	const F32 a = 1.0 - VoH;
-	const F32 a2 = a * a;
-	const F32 a5 = a2 * a2 * a; // a5 = a^5
-	return /*saturate(50.0 * specular.g) */ a5 + (1.0 - a5) * specular;
-}
-
-// D(n,h) aka NDF: GGX Trowbridge-Reitz
-F32 D_GGX(F32 roughness, F32 NoH)
-{
-	const F32 a = roughness * roughness;
-	const F32 a2 = a * a;
-
-	const F32 D = (NoH * a2 - NoH) * NoH + 1.0;
-	return a2 / (PI * D * D);
-}
-
-// Visibility term: Geometric shadowing divided by BRDF denominator
-F32 V_Schlick(F32 roughness, F32 NoV, F32 NoL)
-{
-	const F32 k = (roughness * roughness) * 0.5;
-	const F32 Vis_SchlickV = NoV * (1.0 - k) + k;
-	const F32 Vis_SchlickL = NoL * (1.0 - k) + k;
-	return 0.25 / (Vis_SchlickV * Vis_SchlickL);
-}
-
-Vec3 envBRDF(Vec3 specular, F32 roughness, texture2D integrationLut, sampler integrationLutSampler, F32 NoV)
-{
-	const Vec2 envBRDF = textureLod(integrationLut, integrationLutSampler, Vec2(roughness, NoV), 0.0).xy;
-	return specular * envBRDF.x + min(1.0, 50.0 * specular.g) * envBRDF.y;
-}
-
-Vec3 diffuseLambert(Vec3 diffuse)
-{
-	return diffuse * (1.0 / PI);
-}
-
-// Performs BRDF specular lighting
-Vec3 computeSpecularColorBrdf(GbufferInfo gbuffer, Vec3 viewDir, Vec3 frag2Light)
-{
-	const Vec3 H = normalize(frag2Light + viewDir);
-
-	const F32 NoL = max(EPSILON, dot(gbuffer.m_normal, frag2Light));
-	const F32 VoH = max(EPSILON, dot(viewDir, H));
-	const F32 NoH = max(EPSILON, dot(gbuffer.m_normal, H));
-	const F32 NoV = max(EPSILON, dot(gbuffer.m_normal, viewDir));
-
-	// F
-#if 0
-	const Vec3 F = F_Unreal(gbuffer.m_specular, VoH);
-#else
-	const Vec3 F = F_Schlick(gbuffer.m_specular, VoH);
-#endif
-
-	// D
-	const F32 D = D_GGX(gbuffer.m_roughness, NoH);
-
-	// Vis
-	const F32 V = V_Schlick(gbuffer.m_roughness, NoV, NoL);
-
-	return F * (V * D);
-}
-
-F32 computeSpotFactor(Vec3 l, F32 outerCos, F32 innerCos, Vec3 spotDir)
-{
-	const F32 costheta = -dot(l, spotDir);
-	const F32 spotFactor = smoothstep(outerCos, innerCos, costheta);
-	return spotFactor;
-}
-
-U32 computeShadowSampleCount(const U32 COUNT, F32 zVSpace)
-{
-	const F32 MAX_DISTANCE = 5.0;
-
-	const F32 z = max(zVSpace, -MAX_DISTANCE);
-	F32 sampleCountf = F32(COUNT) + z * (F32(COUNT) / MAX_DISTANCE);
-	sampleCountf = max(sampleCountf, 1.0);
-	const U32 sampleCount = U32(sampleCountf);
-
-	return sampleCount;
-}
-
-F32 computeShadowFactorSpotLight(SpotLight light, Vec3 worldPos, texture2D spotMap, sampler spotMapSampler)
-{
-	const Vec4 texCoords4 = light.m_texProjectionMat * Vec4(worldPos, 1.0);
-	const Vec3 texCoords3 = texCoords4.xyz / texCoords4.w;
-
-	const Vec4 shadowMoments = textureLod(spotMap, spotMapSampler, texCoords3.xy, 0.0);
-
-	return evsmComputeShadowFactor(texCoords3.z, shadowMoments);
-}
-
-// Compute the shadow factor of point (omni) lights.
-F32 computeShadowFactorPointLight(PointLight light, Vec3 frag2Light, texture2D shadowMap, sampler shadowMapSampler)
-{
-	const Vec3 dir = -frag2Light;
-	const Vec3 dirabs = abs(dir);
-	const F32 dist = max(dirabs.x, max(dirabs.y, dirabs.z));
-
-	// 1) Project the dist to light's proj mat
-	//
-	const F32 near = LIGHT_FRUSTUM_NEAR_PLANE;
-	const F32 far = light.m_radius;
-	const F32 g = near - far;
-
-	const F32 zVSpace = -dist;
-	const F32 w = -zVSpace;
-	F32 z = (far * zVSpace + far * near) / g;
-	z /= w;
-
-	// 2) Read shadow tex
-	//
-
-	// Convert cube coords
-	U32 faceIdxu;
-	Vec2 uv = convertCubeUvsu(dir, faceIdxu);
-
-	// Get the atlas offset
-	Vec2 atlasOffset;
-	atlasOffset.x = light.m_shadowAtlasTileOffsets[faceIdxu >> 1u][(faceIdxu & 1u) << 1u];
-	atlasOffset.y = light.m_shadowAtlasTileOffsets[faceIdxu >> 1u][((faceIdxu & 1u) << 1u) + 1u];
-
-	// Compute UV
-	uv = fma(uv, Vec2(light.m_shadowAtlasTileScale), atlasOffset);
-
-	// Sample
-	const Vec4 shadowMoments = textureLod(shadowMap, shadowMapSampler, uv, 0.0);
-
-	// 3) Compare
-	//
-	const F32 shadowFactor = evsmComputeShadowFactor(z, shadowMoments);
-
-	return shadowFactor;
-}
-
-// Compute the shadow factor of a directional light
-F32 computeShadowFactorDirLight(DirectionalLight light, U32 cascadeIdx, Vec3 worldPos, texture2D shadowMap,
-								sampler shadowMapSampler)
-{
-#define ANKI_FAST_CASCADES_WORKAROUND 1 // Doesn't make sense but it's super fast
-
-#if ANKI_FAST_CASCADES_WORKAROUND
-	// Assumes MAX_SHADOW_CASCADES is 4
-	Mat4 lightProjectionMat;
-	switch(cascadeIdx)
-	{
-	case 0:
-		lightProjectionMat = light.m_textureMatrices[0];
-		break;
-	case 1:
-		lightProjectionMat = light.m_textureMatrices[1];
-		break;
-	case 2:
-		lightProjectionMat = light.m_textureMatrices[2];
-		break;
-	default:
-		lightProjectionMat = light.m_textureMatrices[3];
-	}
-#else
-	const Mat4 lightProjectionMat = light.m_textureMatrices[cascadeIdx];
-#endif
-
-	const Vec4 texCoords4 = lightProjectionMat * Vec4(worldPos, 1.0);
-	const Vec3 texCoords3 = texCoords4.xyz / texCoords4.w;
-
-	const Vec4 shadowMoments = textureLod(shadowMap, shadowMapSampler, texCoords3.xy, 0.0);
-
-	return evsmComputeShadowFactor(texCoords3.z, shadowMoments);
-}
-
-// Compute the shadow factor of a directional light
-F32 computeShadowFactorDirLight(Mat4 lightProjectionMat, Vec3 worldPos, texture2D shadowMap,
-								samplerShadow shadowMapSampler)
-{
-	const Vec4 texCoords4 = lightProjectionMat * Vec4(worldPos, 1.0);
-	const Vec3 texCoords3 = texCoords4.xyz / texCoords4.w;
-
-	const F32 shadowFactor = textureLod(shadowMap, shadowMapSampler, texCoords3, 0.0);
-	return shadowFactor;
-}
-
-// Compute the cubemap texture lookup vector given the reflection vector (r) the radius squared of the probe (R2) and
-// the frag pos in sphere space (f)
-Vec3 computeCubemapVecAccurate(Vec3 r, F32 R2, Vec3 f)
-{
-	// Compute the collision of the r to the inner part of the sphere
-	// From now on we work on the sphere's space
-
-	// Project the center of the sphere (it's zero now since we are in sphere space) in ray "f,r"
-	const Vec3 p = f - r * dot(f, r);
-
-	// The collision to the sphere is point x where x = p + T * r
-	// Because of the pythagorean theorem: R^2 = dot(p, p) + dot(T * r, T * r)
-	// solving for T, T = R / |p|
-	// then x becomes x = sqrt(R^2 - dot(p, p)) * r + p;
-	F32 pp = dot(p, p);
-	pp = min(pp, R2);
-	const F32 sq = sqrt(R2 - pp);
-	const Vec3 x = p + sq * r;
-
-	return x;
-}
-
-// Cheap version of computeCubemapVecAccurate
-Vec3 computeCubemapVecCheap(Vec3 r, F32 R2, Vec3 f)
-{
-	return r;
-}
-
-F32 computeAttenuationFactor(F32 squareRadiusOverOne, Vec3 frag2Light)
-{
-	const F32 fragLightDist = dot(frag2Light, frag2Light);
-	F32 att = 1.0 - fragLightDist * squareRadiusOverOne;
-	att = max(0.0, att);
-	return att * att;
-}
-
-// Given the probe properties trace a ray inside the probe and find the cube tex coordinates to sample
-Vec3 intersectProbe(Vec3 fragPos, // Ray origin
-					Vec3 rayDir, // Ray direction
-					Vec3 probeAabbMin, Vec3 probeAabbMax,
-					Vec3 probeOrigin // Cubemap origin
-)
-{
-	// Compute the intersection point
-	const F32 intresectionDist = testRayAabbInside(fragPos, rayDir, probeAabbMin, probeAabbMax);
-	const Vec3 intersectionPoint = fragPos + intresectionDist * rayDir;
-
-	// Compute the cubemap vector
-	return intersectionPoint - probeOrigin;
-}
-
-// Compute a weight (factor) of fragPos against some probe's bounds. The weight will be zero when fragPos is close to
-// AABB bounds and 1.0 at fadeDistance and less.
-F32 computeProbeBlendWeight(Vec3 fragPos, // Doesn't need to be inside the AABB
-							Vec3 probeAabbMin, Vec3 probeAabbMax, F32 fadeDistance)
-{
-	// Compute the min distance of fragPos from the edges of the AABB
-	const Vec3 distFromMin = fragPos - probeAabbMin;
-	const Vec3 distFromMax = probeAabbMax - fragPos;
-	const Vec3 minDistVec = min(distFromMin, distFromMax);
-	const F32 minDist = min(minDistVec.x, min(minDistVec.y, minDistVec.z));
-
-	// Use saturate because minDist might be negative.
-	return saturate(minDist / fadeDistance);
-}
-
-// Given the value of the 6 faces of the dice and a normal, sample the correct weighted value.
-// https://www.shadertoy.com/view/XtcBDB
-Vec3 sampleAmbientDice(Vec3 posx, Vec3 negx, Vec3 posy, Vec3 negy, Vec3 posz, Vec3 negz, Vec3 normal)
-{
-	const Vec3 axisWeights = abs(normal);
-	const Vec3 uv = NDC_TO_UV(normal);
-
-	Vec3 col = mix(negx, posx, uv.x) * axisWeights.x;
-	col += mix(negy, posy, uv.y) * axisWeights.y;
-	col += mix(negz, posz, uv.z) * axisWeights.z;
-
-	// Divide by weight
-	col /= axisWeights.x + axisWeights.y + axisWeights.z + EPSILON;
-
-	return col;
-}
-
-// Sample the irradiance term from the clipmap
-Vec3 sampleGlobalIllumination(const Vec3 worldPos, const Vec3 normal, const GlobalIlluminationProbe probe,
-							  texture3D textures[MAX_VISIBLE_GLOBAL_ILLUMINATION_PROBES], sampler linearAnyClampSampler)
-{
-	// Find the UVW
-	Vec3 uvw = (worldPos - probe.m_aabbMin) / (probe.m_aabbMax - probe.m_aabbMin);
-
-	// The U contains the 6 directions so divide
-	uvw.x /= 6.0;
-
-	// Calmp it to avoid direction leaking
-	uvw.x = clamp(uvw.x, probe.m_halfTexelSizeU, (1.0 / 6.0) - probe.m_halfTexelSizeU);
-
-	// Read the irradiance
-	Vec3 irradiancePerDir[6u];
-	ANKI_UNROLL for(U32 dir = 0u; dir < 6u; ++dir)
-	{
-		// Point to the correct UV
-		Vec3 shiftedUVw = uvw;
-		shiftedUVw.x += (1.0 / 6.0) * F32(dir);
-
-		irradiancePerDir[dir] =
-			textureLod(textures[nonuniformEXT(probe.m_textureIndex)], linearAnyClampSampler, shiftedUVw, 0.0).rgb;
-	}
-
-	// Sample the irradiance
-	const Vec3 irradiance = sampleAmbientDice(irradiancePerDir[0], irradiancePerDir[1], irradiancePerDir[2],
-											  irradiancePerDir[3], irradiancePerDir[4], irradiancePerDir[5], normal);
-
-	return irradiance;
-}

+ 1 - 1
AnKi/Shaders/LightFunctions2.glsl

@@ -220,7 +220,7 @@ F32 computeShadowFactorDirLight(DirectionalLight2 light, U32 cascadeIdx, Vec3 wo
 #define ANKI_FAST_CASCADES_WORKAROUND 1 // Doesn't make sense but it's super fast
 
 #if ANKI_FAST_CASCADES_WORKAROUND
-	// Assumes MAX_SHADOW_CASCADES is 4
+	// Assumes MAX_SHADOW_CASCADES2 is 4
 	Mat4 lightProjectionMat;
 	switch(cascadeIdx)
 	{

+ 0 - 1
AnKi/Shaders/LightShading.ankiprog

@@ -18,7 +18,6 @@ ANKI_SPECIALIZATION_CONSTANT_U32(IR_MIPMAP_COUNT, 4);
 #include <AnKi/Shaders/Pack.glsl>
 #include <AnKi/Shaders/Functions.glsl>
 #include <AnKi/Shaders/RtShadows.glsl>
-#include <AnKi/Shaders/Include/ClusteredShadingTypes.h>
 
 #define CLUSTERED_SHADING_SET 0
 #define CLUSTERED_SHADING_UNIFORMS_BINDING 0

+ 1 - 1
AnKi/Shaders/TraditionalDeferredShading.ankiprog

@@ -46,7 +46,7 @@ void main()
 // FRAG
 #pragma anki start frag
 #include <AnKi/Shaders/Pack.glsl>
-#include <AnKi/Shaders/LightFunctions.glsl>
+#include <AnKi/Shaders/LightFunctions2.glsl>
 #include <AnKi/Shaders/Include/TraditionalDeferredShadingTypes.h>
 
 layout(location = 0) out Vec3 out_color;

+ 0 - 1
AnKi/Shaders/VolumetricFogAccumulation.ankiprog

@@ -9,7 +9,6 @@ ANKI_SPECIALIZATION_CONSTANT_U32(Z_SPLIT_COUNT, 4);
 
 #pragma anki start comp
 
-#include <AnKi/Shaders/Include/ClusteredShadingTypes.h>
 #include <AnKi/Shaders/Include/ClusteredShadingFunctions.h>
 #include <AnKi/Shaders/Common.glsl>