Browse Source

Renderer: Remove the special cluster structs and use the GPU scene directly

Panagiotis Christopoulos Charitos 1 week ago
parent
commit
e454df1a09

+ 1 - 3
AnKi/Renderer/ForwardShading.cpp

@@ -65,9 +65,7 @@ void ForwardShading::run(const RenderingContext& ctx, RenderPassWorkContext& rgr
 
 		cmdb.bindConstantBuffer(ANKI_MATERIAL_REGISTER_CLUSTER_SHADING_CONSTANTS, 0, ctx.m_globalRenderingConstantsBuffer);
 
-		cmdb.bindSrv(ANKI_MATERIAL_REGISTER_CLUSTER_SHADING_POINT_LIGHTS, 0,
-					 getClusterBinning().getPackedObjectsBuffer(GpuSceneNonRenderableObjectType::kLight));
-		cmdb.bindSrv(ANKI_MATERIAL_REGISTER_CLUSTER_SHADING_SPOT_LIGHTS, 0,
+		cmdb.bindSrv(ANKI_MATERIAL_REGISTER_CLUSTER_SHADING_LIGHTS, 0,
 					 getClusterBinning().getPackedObjectsBuffer(GpuSceneNonRenderableObjectType::kLight));
 
 		rgraphCtx.bindSrv(ANKI_MATERIAL_REGISTER_SHADOW_ATLAS, 0, getShadowMapping().getShadowmapRt());

+ 11 - 13
AnKi/Renderer/LightShading.cpp

@@ -84,28 +84,26 @@ void LightShading::run(const RenderingContext& ctx, RenderPassWorkContext& rgrap
 		// Bind all
 		cmdb.bindConstantBuffer(0, 0, ctx.m_globalRenderingConstantsBuffer);
 		cmdb.bindSrv(0, 0, getClusterBinning().getPackedObjectsBuffer(GpuSceneNonRenderableObjectType::kLight));
-		cmdb.bindSrv(1, 0, getClusterBinning().getPackedObjectsBuffer(GpuSceneNonRenderableObjectType::kLight));
 		if(getRenderer().isIndirectDiffuseClipmapsEnabled())
 		{
-			rgraphCtx.bindSrv(2, 0, getIndirectDiffuseClipmaps().getRts().m_appliedIrradiance);
+			rgraphCtx.bindSrv(1, 0, getIndirectDiffuseClipmaps().getRts().m_appliedIrradiance);
 		}
 		else
 		{
-			cmdb.bindSrv(2, 0, getClusterBinning().getPackedObjectsBuffer(GpuSceneNonRenderableObjectType::kGlobalIlluminationProbe));
+			cmdb.bindSrv(1, 0, getClusterBinning().getPackedObjectsBuffer(GpuSceneNonRenderableObjectType::kGlobalIlluminationProbe));
 		}
-		cmdb.bindSrv(3, 0, getClusterBinning().getPackedObjectsBuffer(GpuSceneNonRenderableObjectType::kReflectionProbe));
-		cmdb.bindSrv(4, 0, getClusterBinning().getClustersBuffer());
+		cmdb.bindSrv(2, 0, getClusterBinning().getClustersBuffer());
 
 		cmdb.bindSampler(0, 0, getRenderer().getSamplers().m_nearestNearestClamp.get());
 		cmdb.bindSampler(1, 0, getRenderer().getSamplers().m_trilinearClamp.get());
-		rgraphCtx.bindSrv(5, 0, getGBuffer().getColorRt(0));
-		rgraphCtx.bindSrv(6, 0, getGBuffer().getColorRt(1));
-		rgraphCtx.bindSrv(7, 0, getGBuffer().getColorRt(2));
-		rgraphCtx.bindSrv(8, 0, getGBuffer().getDepthRt());
-		rgraphCtx.bindSrv(9, 0, getShadowmapsResolve().getRt());
-		rgraphCtx.bindSrv(10, 0, getSsao().getRt());
-		rgraphCtx.bindSrv(11, 0, getReflections().getRt());
-		cmdb.bindSrv(12, 0, TextureView(&getRenderer().getProbeReflections().getIntegrationLut(), TextureSubresourceDesc::all()));
+		rgraphCtx.bindSrv(3, 0, getGBuffer().getColorRt(0));
+		rgraphCtx.bindSrv(4, 0, getGBuffer().getColorRt(1));
+		rgraphCtx.bindSrv(5, 0, getGBuffer().getColorRt(2));
+		rgraphCtx.bindSrv(6, 0, getGBuffer().getDepthRt());
+		rgraphCtx.bindSrv(7, 0, getShadowmapsResolve().getRt());
+		rgraphCtx.bindSrv(8, 0, getSsao().getRt());
+		rgraphCtx.bindSrv(9, 0, getReflections().getRt());
+		cmdb.bindSrv(10, 0, TextureView(&getRenderer().getProbeReflections().getIntegrationLut(), TextureSubresourceDesc::all()));
 
 		// Draw
 		drawQuad(cmdb);

+ 0 - 1
AnKi/Renderer/Reflections.cpp

@@ -241,7 +241,6 @@ void Reflections::populateRenderGraph(RenderingContext& ctx)
 			rgraphCtx.bindSrv(8, 0, getShadowMapping().getShadowmapRt());
 			rgraphCtx.bindSrv(9, 0, classTileMapRt);
 			cmdb.bindSrv(10, 0, getClusterBinning().getPackedObjectsBuffer(GpuSceneNonRenderableObjectType::kLight));
-			cmdb.bindSrv(11, 0, getClusterBinning().getPackedObjectsBuffer(GpuSceneNonRenderableObjectType::kLight));
 
 			rgraphCtx.bindUav(0, 0, transientRt1);
 			rgraphCtx.bindUav(1, 0, hitPosAndDepthRt);

+ 0 - 1
AnKi/Renderer/Renderer.cpp

@@ -10,7 +10,6 @@
 #include <AnKi/Collision/Aabb.h>
 #include <AnKi/Collision/Plane.h>
 #include <AnKi/Collision/Functions.h>
-#include <AnKi/Shaders/Include/ClusteredShadingTypes.h>
 #include <AnKi/GpuMemory/GpuSceneBuffer.h>
 #include <AnKi/Scene/Components/CameraComponent.h>
 #include <AnKi/Scene/Components/LightComponent.h>

+ 6 - 7
AnKi/Renderer/ShadowmapsResolve.cpp

@@ -108,9 +108,8 @@ void ShadowmapsResolve::run(RenderPassWorkContext& rgraphCtx, RenderingContext&
 
 	cmdb.bindConstantBuffer(0, 0, ctx.m_globalRenderingConstantsBuffer);
 	cmdb.bindSrv(0, 0, getClusterBinning().getPackedObjectsBuffer(GpuSceneNonRenderableObjectType::kLight));
-	cmdb.bindSrv(1, 0, getClusterBinning().getPackedObjectsBuffer(GpuSceneNonRenderableObjectType::kLight));
-	rgraphCtx.bindSrv(2, 0, getShadowMapping().getShadowmapRt());
-	cmdb.bindSrv(3, 0, getClusterBinning().getClustersBuffer());
+	rgraphCtx.bindSrv(1, 0, getShadowMapping().getShadowmapRt());
+	cmdb.bindSrv(2, 0, getClusterBinning().getClustersBuffer());
 
 	cmdb.bindSampler(0, 0, getRenderer().getSamplers().m_trilinearClamp.get());
 	cmdb.bindSampler(1, 0, getRenderer().getSamplers().m_trilinearClampShadow.get());
@@ -118,17 +117,17 @@ void ShadowmapsResolve::run(RenderPassWorkContext& rgraphCtx, RenderingContext&
 
 	if(m_quarterRez)
 	{
-		rgraphCtx.bindSrv(4, 0, getDepthDownscale().getRt(), DepthDownscale::kQuarterInternalResolution);
+		rgraphCtx.bindSrv(3, 0, getDepthDownscale().getRt(), DepthDownscale::kQuarterInternalResolution);
 	}
 	else
 	{
-		rgraphCtx.bindSrv(4, 0, getGBuffer().getDepthRt());
+		rgraphCtx.bindSrv(3, 0, getGBuffer().getDepthRt());
 	}
-	cmdb.bindSrv(5, 0, TextureView(&m_noiseImage->getTexture(), TextureSubresourceDesc::all()));
+	cmdb.bindSrv(4, 0, TextureView(&m_noiseImage->getTexture(), TextureSubresourceDesc::all()));
 
 	if(isRtShadowsEnabled())
 	{
-		rgraphCtx.bindSrv(6, 0, getRtShadows().getRt());
+		rgraphCtx.bindSrv(5, 0, getRtShadows().getRt());
 	}
 
 	if(g_cvarRenderPreferCompute || g_cvarRenderSmPcf || g_cvarRenderSmPcss)

+ 0 - 1
AnKi/Renderer/VolumetricLightingAccumulation.cpp

@@ -99,7 +99,6 @@ void VolumetricLightingAccumulation::populateRenderGraph(RenderingContext& ctx)
 		cmdb.bindSrv(srv++, 0, TextureView(&m_noiseImage->getTexture(), TextureSubresourceDesc::all()));
 		rgraphCtx.bindSrv(srv++, 0, m_runCtx.m_rts[0]);
 
-		cmdb.bindSrv(srv++, 0, getClusterBinning().getPackedObjectsBuffer(GpuSceneNonRenderableObjectType::kLight));
 		cmdb.bindSrv(srv++, 0, getClusterBinning().getPackedObjectsBuffer(GpuSceneNonRenderableObjectType::kLight));
 		rgraphCtx.bindSrv(srv++, 0, getShadowMapping().getShadowmapRt());
 		cmdb.bindSrv(srv++, 0, getClusterBinning().getPackedObjectsBuffer(GpuSceneNonRenderableObjectType::kFogDensityVolume));

+ 0 - 1
AnKi/Scene/Components/DecalComponent.cpp

@@ -6,7 +6,6 @@
 #include <AnKi/Scene/Components/DecalComponent.h>
 #include <AnKi/Scene/SceneGraph.h>
 #include <AnKi/Resource/ResourceManager.h>
-#include <AnKi/Shaders/Include/ClusteredShadingTypes.h>
 #include <AnKi/GpuMemory/GpuSceneBuffer.h>
 
 namespace anki {

+ 20 - 64
AnKi/Shaders/ClusterBinning.ankiprog

@@ -14,10 +14,26 @@
 #include <AnKi/Shaders/Include/ClusteredShadingTypes.h>
 #include <AnKi/Shaders/VisibilityAndCollisionFunctions.hlsl>
 
+#if ANKI_TECHNIQUE_Binning || ANKI_TECHNIQUE_PackVisibles
+#	if OBJECT_TYPE == ANKI_GPU_SCENE_NON_RENDERABLE_OBJECT_TYPE_LIGHT
+typedef GpuSceneLight GpuSceneType;
+#	elif OBJECT_TYPE == ANKI_GPU_SCENE_NON_RENDERABLE_OBJECT_TYPE_DECAL
+typedef GpuSceneDecal GpuSceneType;
+#	elif OBJECT_TYPE == ANKI_GPU_SCENE_NON_RENDERABLE_OBJECT_TYPE_FOG_DENSITY_VOLUME
+typedef GpuSceneFogDensityVolume GpuSceneType;
+#	elif OBJECT_TYPE == ANKI_GPU_SCENE_NON_RENDERABLE_OBJECT_TYPE_REFLECTION_PROBE
+typedef GpuSceneReflectionProbe GpuSceneType;
+#	elif OBJECT_TYPE == ANKI_GPU_SCENE_NON_RENDERABLE_OBJECT_TYPE_GLOBAL_ILLUMINATION_PROBE
+typedef GpuSceneGlobalIlluminationProbe GpuSceneType;
+#	else
+#		error See file
+#	endif
+#endif
+
 // ===========================================================================
 // Setup                                                                     =
 // ===========================================================================
-#if NOT_ZERO(ANKI_TECHNIQUE_Setup)
+#if ANKI_TECHNIQUE_Setup
 
 StructuredBuffer<U32> g_visibleIndices[(U32)GpuSceneNonRenderableObjectType::kCount] : register(t0);
 
@@ -81,21 +97,7 @@ constexpr U32 kPackVisiblesThreadgroupSize = 64;
 // ===========================================================================
 // Binning                                                                   =
 // ===========================================================================
-#if NOT_ZERO(ANKI_TECHNIQUE_Binning)
-
-#	if OBJECT_TYPE == ANKI_GPU_SCENE_NON_RENDERABLE_OBJECT_TYPE_LIGHT
-typedef GpuSceneLight GpuSceneType;
-#	elif OBJECT_TYPE == ANKI_GPU_SCENE_NON_RENDERABLE_OBJECT_TYPE_DECAL
-typedef GpuSceneDecal GpuSceneType;
-#	elif OBJECT_TYPE == ANKI_GPU_SCENE_NON_RENDERABLE_OBJECT_TYPE_FOG_DENSITY_VOLUME
-typedef GpuSceneFogDensityVolume GpuSceneType;
-#	elif OBJECT_TYPE == ANKI_GPU_SCENE_NON_RENDERABLE_OBJECT_TYPE_REFLECTION_PROBE
-typedef GpuSceneReflectionProbe GpuSceneType;
-#	elif OBJECT_TYPE == ANKI_GPU_SCENE_NON_RENDERABLE_OBJECT_TYPE_GLOBAL_ILLUMINATION_PROBE
-typedef GpuSceneGlobalIlluminationProbe GpuSceneType;
-#	else
-#		error See file
-#	endif
+#if ANKI_TECHNIQUE_Binning
 
 struct ClusterBinningConstants
 {
@@ -300,29 +302,10 @@ constexpr UVec2 kSampleLocations[kSampleCount] = {LOCATION(1, -3), LOCATION(-1,
 // ===========================================================================
 // PackVisibles                                                              =
 // ===========================================================================
-#if NOT_ZERO(ANKI_TECHNIQUE_PackVisibles)
-
-#	if OBJECT_TYPE == ANKI_GPU_SCENE_NON_RENDERABLE_OBJECT_TYPE_LIGHT
-typedef LightUnion ClusteredType;
-typedef GpuSceneLight GpuSceneType;
-#	elif OBJECT_TYPE == ANKI_GPU_SCENE_NON_RENDERABLE_OBJECT_TYPE_DECAL
-typedef Decal ClusteredType;
-typedef GpuSceneDecal GpuSceneType;
-#	elif OBJECT_TYPE == ANKI_GPU_SCENE_NON_RENDERABLE_OBJECT_TYPE_FOG_DENSITY_VOLUME
-typedef FogDensityVolume ClusteredType;
-typedef GpuSceneFogDensityVolume GpuSceneType;
-#	elif OBJECT_TYPE == ANKI_GPU_SCENE_NON_RENDERABLE_OBJECT_TYPE_REFLECTION_PROBE
-typedef ReflectionProbe ClusteredType;
-typedef GpuSceneReflectionProbe GpuSceneType;
-#	elif OBJECT_TYPE == ANKI_GPU_SCENE_NON_RENDERABLE_OBJECT_TYPE_GLOBAL_ILLUMINATION_PROBE
-typedef GlobalIlluminationProbe ClusteredType;
-typedef GpuSceneGlobalIlluminationProbe GpuSceneType;
-#	else
-#		error See file
-#	endif
+#if ANKI_TECHNIQUE_PackVisibles
 
 StructuredBuffer<GpuSceneType> g_inBuffer : register(t0);
-RWStructuredBuffer<ClusteredType> g_outBuffer : register(u0);
+RWStructuredBuffer<GpuSceneType> g_outBuffer : register(u0);
 StructuredBuffer<U32> g_visibles : register(t1);
 
 #	define THREAD_GROUP_SIZE 64
@@ -336,33 +319,6 @@ StructuredBuffer<U32> g_visibles : register(t1);
 		return;
 	}
 
-#	if OBJECT_TYPE == ANKI_GPU_SCENE_NON_RENDERABLE_OBJECT_TYPE_LIGHT
-	const GpuSceneLight input = g_inBuffer[g_visibles[idxOut + 1]];
-
-	const Bool isPoint = input.m_isPointLight;
-
-	LightUnion output = (LightUnion)0;
-	output.m_position = input.m_position;
-	output.m_radius = input.m_radius;
-
-	output.m_diffuseColor = input.m_diffuseColor;
-	output.m_lightType = (isPoint) ? 0 : 1;
-
-	output.m_shadow = input.m_shadow;
-	output.m_innerCos = input.m_innerCos;
-	output.m_outerCos = input.m_outerCos;
-
-	output.m_direction = input.m_direction;
-	output.m_shadowAtlasTileScale = input.m_spotLightMatrixOrPointLightUvViewports[0].z; // Scale should be the same for all
-
-	for(U32 i = 0; i < 6; ++i)
-	{
-		output.m_spotLightMatrixOrPointLightUvViewports[i] = input.m_spotLightMatrixOrPointLightUvViewports[i];
-	}
-
-	g_outBuffer[idxOut] = output;
-#	else
 	g_outBuffer[idxOut] = g_inBuffer[g_visibles[idxOut + 1]];
-#	endif
 }
 #endif

+ 6 - 6
AnKi/Shaders/ClusteredShadingFunctions.hlsl

@@ -168,7 +168,7 @@ U32 iterateDecals(inout Cluster cluster)
 }
 
 template<typename T>
-vector<T, 3> sampleReflectionProbes(Cluster cluster, StructuredBuffer<ReflectionProbe> probes, Vec3 reflDir, Vec3 worldPos, T reflTexLod,
+vector<T, 3> sampleReflectionProbes(Cluster cluster, StructuredBuffer<GpuSceneReflectionProbe> probes, Vec3 reflDir, Vec3 worldPos, T reflTexLod,
 									SamplerState trilinearClampSampler)
 {
 	const U32 probeCount = countbits(cluster.m_reflectionProbesMask);
@@ -182,7 +182,7 @@ vector<T, 3> sampleReflectionProbes(Cluster cluster, StructuredBuffer<Reflection
 	{
 		// Only one probe, do a fast path without blending probes
 
-		const ReflectionProbe probe = probes[firstbitlow2(cluster.m_reflectionProbesMask)];
+		const GpuSceneReflectionProbe probe = probes[firstbitlow2(cluster.m_reflectionProbesMask)];
 
 		// Sample
 		Vec3 cubeUv = intersectProbe(worldPos, reflDir, probe.m_aabbMin, probe.m_aabbMax, probe.m_position);
@@ -201,7 +201,7 @@ vector<T, 3> sampleReflectionProbes(Cluster cluster, StructuredBuffer<Reflection
 		{
 			const U32 idx = U32(firstbitlow2(cluster.m_reflectionProbesMask));
 			cluster.m_reflectionProbesMask &= ~(1u << idx);
-			const ReflectionProbe probe = probes[idx];
+			const GpuSceneReflectionProbe probe = probes[idx];
 
 			// Compute blend weight
 			const T blendWeight = computeProbeBlendWeight(worldPos, probe.m_aabbMin, probe.m_aabbMax, 0.2);
@@ -223,7 +223,7 @@ vector<T, 3> sampleReflectionProbes(Cluster cluster, StructuredBuffer<Reflection
 }
 
 template<typename T>
-vector<T, 3> sampleGiProbes(Cluster cluster, StructuredBuffer<GlobalIlluminationProbe> probes, Vec3 normal, Vec3 worldPos,
+vector<T, 3> sampleGiProbes(Cluster cluster, StructuredBuffer<GpuSceneGlobalIlluminationProbe> probes, Vec3 normal, Vec3 worldPos,
 							SamplerState trilinearClampSampler)
 {
 	vector<T, 3> probeColor;
@@ -238,7 +238,7 @@ vector<T, 3> sampleGiProbes(Cluster cluster, StructuredBuffer<GlobalIllumination
 	{
 		// All subgroups point to the same probe and there is only one probe, do a fast path without blend weight
 
-		const GlobalIlluminationProbe probe = probes[firstbitlow2(cluster.m_giProbesMask)];
+		const GpuSceneGlobalIlluminationProbe probe = probes[firstbitlow2(cluster.m_giProbesMask)];
 
 		// Sample
 		probeColor = sampleGlobalIllumination<T>(worldPos, normal, probe, getBindlessTexture3DVec4(probe.m_volumeTexture), trilinearClampSampler);
@@ -255,7 +255,7 @@ vector<T, 3> sampleGiProbes(Cluster cluster, StructuredBuffer<GlobalIllumination
 		{
 			const U32 idx = U32(firstbitlow2(cluster.m_giProbesMask));
 			cluster.m_giProbesMask &= ~(1u << idx);
-			const GlobalIlluminationProbe probe = probes[idx];
+			const GpuSceneGlobalIlluminationProbe probe = probes[idx];
 
 			// Compute blend weight
 			const F32 blendWeight = computeProbeBlendWeight(worldPos, probe.m_aabbMin, probe.m_aabbMax, probe.m_fadeDistance);

+ 14 - 13
AnKi/Shaders/Dbg.ankiprog

@@ -126,21 +126,21 @@ struct Constants
 ANKI_FAST_CONSTANTS(Constants, g_consts)
 
 #	if OBJECT_TYPE == ANKI_GPU_SCENE_NON_RENDERABLE_OBJECT_TYPE_LIGHT
-typedef LightUnion ClusteredType;
+typedef GpuSceneLight GpuSceneType;
 #	elif OBJECT_TYPE == ANKI_GPU_SCENE_NON_RENDERABLE_OBJECT_TYPE_DECAL
-typedef Decal ClusteredType;
+typedef GpuSceneDecal GpuSceneType;
 #	elif OBJECT_TYPE == ANKI_GPU_SCENE_NON_RENDERABLE_OBJECT_TYPE_FOG_DENSITY_VOLUME
-typedef FogDensityVolume ClusteredType;
+typedef GpuSceneFogDensityVolume GpuSceneType;
 #	elif OBJECT_TYPE == ANKI_GPU_SCENE_NON_RENDERABLE_OBJECT_TYPE_REFLECTION_PROBE
-typedef ReflectionProbe ClusteredType;
+typedef GpuSceneReflectionProbe GpuSceneType;
 #	elif OBJECT_TYPE == ANKI_GPU_SCENE_NON_RENDERABLE_OBJECT_TYPE_GLOBAL_ILLUMINATION_PROBE
-typedef GlobalIlluminationProbe ClusteredType;
+typedef GpuSceneGlobalIlluminationProbe GpuSceneType;
 #	else
 #		error See file
 #	endif
 
 Texture2D g_depthRt : register(t0);
-StructuredBuffer<ClusteredType> g_visibleObjects : register(t1);
+StructuredBuffer<GpuSceneType> g_visibleObjects : register(t1);
 StructuredBuffer<U32> g_visibleObjectCount : register(t2);
 Texture2D<Vec4> g_tex : register(t3);
 Texture2D<Vec4> g_tex2 : register(t4);
@@ -175,19 +175,20 @@ VertOut main(VertIn input)
 
 	if(input.m_svInstanceId < objCount)
 	{
+		const GpuSceneType obj = g_visibleObjects[input.m_svInstanceId];
+
 #		if OBJECT_TYPE == ANKI_GPU_SCENE_NON_RENDERABLE_OBJECT_TYPE_LIGHT
-		const Vec3 localPos = g_visibleObjects[input.m_svInstanceId].m_position;
-		output.m_colorScale = reinhardTonemap(g_visibleObjects[input.m_svInstanceId].m_diffuseColor);
-		output.m_textureIndex = g_visibleObjects[input.m_svInstanceId].m_lightType;
+		const Vec3 localPos = obj.m_position;
+		output.m_colorScale = reinhardTonemap(obj.m_diffuseColor);
+		output.m_textureIndex = obj.m_isSpotLight;
 #		elif OBJECT_TYPE == ANKI_GPU_SCENE_NON_RENDERABLE_OBJECT_TYPE_DECAL
-		const Vec3 localPos = g_visibleObjects[input.m_svInstanceId].m_sphereCenter;
+		const Vec3 localPos = obj.m_sphereCenter;
 #		elif OBJECT_TYPE == ANKI_GPU_SCENE_NON_RENDERABLE_OBJECT_TYPE_FOG_DENSITY_VOLUME
-		const ClusteredType obj = g_visibleObjects[input.m_svInstanceId];
 		const Vec3 localPos = (obj.m_isBox) ? (obj.m_aabbMinOrSphereCenter + obj.m_aabbMaxOrSphereRadius) / 2.0f : obj.m_aabbMinOrSphereCenter;
 #		elif OBJECT_TYPE == ANKI_GPU_SCENE_NON_RENDERABLE_OBJECT_TYPE_REFLECTION_PROBE
-		const Vec3 localPos = g_visibleObjects[input.m_svInstanceId].m_position;
+		const Vec3 localPos = obj.m_position;
 #		elif OBJECT_TYPE == ANKI_GPU_SCENE_NON_RENDERABLE_OBJECT_TYPE_GLOBAL_ILLUMINATION_PROBE
-		const Vec3 localPos = (g_visibleObjects[input.m_svInstanceId].m_aabbMin + g_visibleObjects[input.m_svInstanceId].m_aabbMax) / 2.0f;
+		const Vec3 localPos = (obj.m_aabbMin + obj.m_aabbMax) / 2.0f;
 #		else
 #			error See file
 #		endif

+ 3 - 3
AnKi/Shaders/ForwardShadingCommon.hlsl

@@ -51,7 +51,7 @@ Vec3 computeLightColorHigh(Vec3 diffCol, Vec3 worldPos, Vec4 svPosition)
 	U32 idx = 0;
 	[loop] while((idx = iteratePointLights(cluster)) != kMaxU32)
 	{
-		const PointLight light = g_pointLights[idx];
+		const GpuSceneLight light = g_lights[idx];
 
 		const Vec3 diffC = diffCol * light.m_diffuseColor;
 
@@ -59,7 +59,7 @@ Vec3 computeLightColorHigh(Vec3 diffCol, Vec3 worldPos, Vec4 svPosition)
 		const F32 att = computeAttenuationFactor<F32>(light.m_radius, frag2Light);
 
 		F32 shadow = 1.0;
-		if(light.m_shadowAtlasTileScale >= 0.0)
+		if(light.m_shadow)
 		{
 			shadow = computeShadowFactorPointLight<F32>(light, frag2Light, g_shadowAtlasTex, g_shadowSampler);
 		}
@@ -70,7 +70,7 @@ Vec3 computeLightColorHigh(Vec3 diffCol, Vec3 worldPos, Vec4 svPosition)
 	// Spot lights
 	[loop] while((idx = iterateSpotLights(cluster)) != kMaxU32)
 	{
-		const SpotLight light = g_spotLights[idx];
+		const GpuSceneLight light = g_lights[idx];
 
 		const Vec3 diffC = diffCol * light.m_diffuseColor;
 

+ 2 - 2
AnKi/Shaders/GBufferPost.ankiprog

@@ -15,7 +15,7 @@ RWTexture2D<Vec4> g_gbuffer1Tex : register(u1);
 RWTexture2D<Vec4> g_gbuffer2Tex : register(u2);
 
 Texture2D<Vec4> g_depthTex : register(t0);
-StructuredBuffer<Decal> g_decals : register(t1);
+StructuredBuffer<GpuSceneDecal> g_decals : register(t1);
 StructuredBuffer<Cluster> g_clusters : register(t2);
 
 ConstantBuffer<GlobalRendererConstants> g_globalConstants : register(b0);
@@ -62,7 +62,7 @@ SamplerState g_linearAnyClampSampler : register(s0);
 	U32 idx;
 	[loop] while((idx = iterateDecals(cluster)) != kMaxU32)
 	{
-		const Decal decal = g_decals[idx];
+		const GpuSceneDecal decal = g_decals[idx];
 
 		// Project pos to decal space
 		const Vec4 texCoords4 = mul(decal.m_textureMatrix, Vec4(worldPos, 1.0));

+ 15 - 86
AnKi/Shaders/Include/ClusteredShadingTypes.h

@@ -22,87 +22,7 @@ constexpr F32 kSubsurfaceMin = 0.01f;
 constexpr U32 kMaxZsplitCount = 128u;
 constexpr U32 kClusteredShadingTileSize = 64; ///< The size of the tile in clustered shading.
 
-/// A union of all fields of spot and point lights. Since we don't have unions in HLSL we had to get creative.
-struct LightUnion
-{
-	Vec3 m_position; ///< Position in world space.
-	F32 m_radius; ///< Radius
-
-	Vec3 m_diffuseColor;
-	U32 m_lightType; ///< 0 is point and 1 is spot
-
-	U32 m_shadow;
-	F32 m_innerCos; ///< SPOT LIGHTS
-	F32 m_outerCos; ///< SPOT LIGHTS
-	F32 m_padding;
-
-	Vec3 m_direction; ///< SPOT LIGHTS: Light direction.
-	F32 m_shadowAtlasTileScale; ///< POINT LIGHTS: UV scale for all tiles.
-
-	/// When it's a point light this is an array of 6 Vec2s (but because of padding it's actually Vec4s). When it's a spot light the first 4 Vec4s are
-	/// the rows of the texture matrix
-	Vec4 m_spotLightMatrixOrPointLightUvViewports[6u];
-};
-
-/// Point light.
-/// WARNING: Don't change the layout without looking at LightUnion.
-struct PointLight
-{
-	Vec3 m_position; ///< Position in world space.
-	F32 m_radius; ///< Radius
-
-	Vec3 m_diffuseColor;
-	U32 m_padding1;
-
-	U32 m_shadow;
-	F32 m_padding2;
-	U32 m_padding3;
-	U32 m_padding4;
-
-	Vec3 m_padding5;
-	F32 m_shadowAtlasTileScale; ///< UV scale for all tiles.
-
-	Vec4 m_shadowAtlasTileOffsets[6u]; ///< It's a array of Vec2 but because of padding round it up.
-};
-static_assert(sizeof(PointLight) == sizeof(LightUnion));
-
-/// Spot light.
-/// WARNING: Don't change the layout without looking at LightUnion.
-struct SpotLight
-{
-	Vec3 m_position; ///< Position in world space.
-	F32 m_radius; ///< Radius
-
-	Vec3 m_diffuseColor;
-	U32 m_padding1;
-
-	U32 m_shadow;
-	F32 m_innerCos;
-	F32 m_outerCos;
-	F32 m_padding2;
-
-	Vec3 m_direction;
-	F32 m_padding3;
-
-	Mat4 m_textureMatrix;
-
-	Vec4 m_padding4[2];
-};
-static_assert(sizeof(SpotLight) == sizeof(LightUnion));
-
-/// Representation of a reflection probe.
-typedef GpuSceneReflectionProbe ReflectionProbe;
-
-/// Decal.
-typedef GpuSceneDecal Decal;
-
-/// Fog density volume.
-typedef GpuSceneFogDensityVolume FogDensityVolume;
-
-/// Global illumination probe
-typedef GpuSceneGlobalIlluminationProbe GlobalIlluminationProbe;
-
-/// Information that a tile or a Z-split will contain.
+// Information that a tile or a Z-split will contain.
 struct Cluster
 {
 	U32 m_pointLightsMask[kMaxVisibleLights / 32];
@@ -113,10 +33,19 @@ struct Cluster
 	U32 m_giProbesMask;
 };
 
-constexpr ANKI_ARRAY(U32, GpuSceneNonRenderableObjectType::kCount, kClusteredObjectSizes) = {
-	sizeof(LightUnion), sizeof(Decal), sizeof(FogDensityVolume), sizeof(ReflectionProbe), sizeof(GlobalIlluminationProbe)};
-
-constexpr ANKI_ARRAY(U32, GpuSceneNonRenderableObjectType::kCount, kMaxVisibleClusteredObjects) = {
-	kMaxVisibleLights, kMaxVisibleDecals, kMaxVisibleFogDensityVolumes, kMaxVisibleReflectionProbes, kMaxVisibleGlobalIlluminationProbes};
+#if defined(__cplusplus)
+constexpr Array<U32, U32(GpuSceneNonRenderableObjectType::kCount)> kClusteredObjectSizes
+#else
+constexpr U32 kClusteredObjectSizes[(U32)GpuSceneNonRenderableObjectType::kCount]
+#endif
+	= {sizeof(GpuSceneLight), sizeof(GpuSceneDecal), sizeof(GpuSceneFogDensityVolume), sizeof(GpuSceneReflectionProbe),
+	   sizeof(GpuSceneGlobalIlluminationProbe)};
+
+#if defined(__cplusplus)
+constexpr Array<U32, U32(GpuSceneNonRenderableObjectType::kCount)> kMaxVisibleClusteredObjects
+#else
+constexpr U32 kMaxVisibleClusteredObjects[(U32)GpuSceneNonRenderableObjectType::kCount]
+#endif
+	= {kMaxVisibleLights, kMaxVisibleDecals, kMaxVisibleFogDensityVolumes, kMaxVisibleReflectionProbes, kMaxVisibleGlobalIlluminationProbes};
 
 ANKI_END_NAMESPACE

+ 4 - 4
AnKi/Shaders/Include/GpuSceneTypes.h

@@ -126,7 +126,7 @@ struct GpuSceneLightVisibleRenderablesHash
 struct GpuSceneLight
 {
 	Vec3 m_position ANKI_CPP_CODE(= Vec3(kSomeFarDistance)); // Position in world space.
-	F32 m_radius ANKI_CPP_CODE(= 0.0f); // Radius.
+	F32 m_radius ANKI_CPP_CODE(= 0.0f); // Radius
 
 	Vec3 m_diffuseColor;
 	U32 m_visibleRenderablesHashIndex; // Points to a GpuSceneLightVisibleRenderablesHash
@@ -137,16 +137,16 @@ struct GpuSceneLight
 	U32 m_cpuFeedback : 1; // If true the GPU visibility will inform the CPU about it
 	U32 m_padding : 28;
 	U32 m_componentArrayIndex; // Array index of the LightComponent in the CPU scene.
-	U32 m_uuid; // The UUID of that light. If it's zero the GPU will not inform the CPU about it.
+	U32 m_uuid; // The UUID of the LightComponent
 	F32 m_innerCos; // Only for spot light.
 
 	Vec3 m_direction; // Only for spot light. Light direction.
 	F32 m_outerCos; // Only for spot light.
 
-	Vec4 m_edgePoints[4u]; // Edge points in world space. Only for spot light.
-
 	// If it's a spot light the 4 first rows are the texture matrix. If it's point light it's the UV viewports in the shadow atlas
 	Vec4 m_spotLightMatrixOrPointLightUvViewports[6u];
+
+	Vec4 m_edgePoints[4u]; // Edge points in world space. Only for spot light.
 };
 
 // Representation of a reflection probe.

+ 5 - 6
AnKi/Shaders/Include/MaterialTypes.h

@@ -46,16 +46,15 @@ static_assert(sizeof(MaterialGlobalConstants) == 15 * sizeof(Vec4));
 
 #define ANKI_MATERIAL_REGISTER_SCENE_DEPTH 11
 #define ANKI_MATERIAL_REGISTER_LIGHT_VOLUME 12
-#define ANKI_MATERIAL_REGISTER_CLUSTER_SHADING_POINT_LIGHTS 13
-#define ANKI_MATERIAL_REGISTER_CLUSTER_SHADING_SPOT_LIGHTS 14
-#define ANKI_MATERIAL_REGISTER_SHADOW_ATLAS 15
-#define ANKI_MATERIAL_REGISTER_CLUSTERS 16
+#define ANKI_MATERIAL_REGISTER_CLUSTER_SHADING_LIGHTS 13
+#define ANKI_MATERIAL_REGISTER_SHADOW_ATLAS 14
+#define ANKI_MATERIAL_REGISTER_CLUSTERS 15
 
 // UGB last
 
-#define ANKI_MATERIAL_REGISTER_UNIFIED_GEOMETRY 17
+#define ANKI_MATERIAL_REGISTER_UNIFIED_GEOMETRY 16
 // Always last because it's variable. Texture buffer bindings pointing to unified geom buffer:
 // !!WARNING!! Remember to update the UnifiedGeometryTypes.def.h if you change that one
-#define ANKI_MATERIAL_REGISTER_UNIFIED_GEOMETRY_TYPED_BUFFER_START 18
+#define ANKI_MATERIAL_REGISTER_UNIFIED_GEOMETRY_TYPED_BUFFER_START 17
 
 ANKI_END_NAMESPACE

+ 6 - 6
AnKi/Shaders/Include/UnifiedGeometryTypes.def.h

@@ -11,17 +11,17 @@
 
 // !!!! ALL FORMATS NEED TO BE MORE THAN 4 BYTES, else we can't address large typed buffers !!!!
 
-ANKI_UNIFIED_GEOM_FORMAT(R32G32_Sfloat, Vec2, 18)
+ANKI_UNIFIED_GEOM_FORMAT(R32G32_Sfloat, Vec2, 17)
 ANKI_UNIFIED_GEOM_FORMAT_SEPERATOR
-ANKI_UNIFIED_GEOM_FORMAT(R32G32B32_Sfloat, Vec3, 19)
+ANKI_UNIFIED_GEOM_FORMAT(R32G32B32_Sfloat, Vec3, 18)
 ANKI_UNIFIED_GEOM_FORMAT_SEPERATOR
-ANKI_UNIFIED_GEOM_FORMAT(R32G32B32A32_Sfloat, Vec4, 20)
+ANKI_UNIFIED_GEOM_FORMAT(R32G32B32A32_Sfloat, Vec4, 19)
 ANKI_UNIFIED_GEOM_FORMAT_SEPERATOR
-ANKI_UNIFIED_GEOM_FORMAT(R16G16B16A16_Unorm, Vec4, 21)
+ANKI_UNIFIED_GEOM_FORMAT(R16G16B16A16_Unorm, Vec4, 20)
 ANKI_UNIFIED_GEOM_FORMAT_SEPERATOR
-ANKI_UNIFIED_GEOM_FORMAT(R8G8B8A8_Snorm, Vec4, 22)
+ANKI_UNIFIED_GEOM_FORMAT(R8G8B8A8_Snorm, Vec4, 21)
 ANKI_UNIFIED_GEOM_FORMAT_SEPERATOR
-ANKI_UNIFIED_GEOM_FORMAT(R8G8B8A8_Uint, UVec4, 23)
+ANKI_UNIFIED_GEOM_FORMAT(R8G8B8A8_Uint, UVec4, 22)
 
 #undef ANKI_UNIFIED_GEOM_FORMAT
 #undef ANKI_UNIFIED_GEOM_FORMAT_SEPERATOR

+ 21 - 14
AnKi/Shaders/LightFunctions.hlsl

@@ -188,10 +188,16 @@ struct PcssDisabled
 };
 
 template<typename T, typename TPcss>
-T computeShadowFactorSpotLightGeneric(SpotLight light, Vec3 worldPos, Texture2D<Vec4> shadowTex, SamplerComparisonState shadowMapSampler, Bool pcf,
-									  T randFactor, TPcss pcss)
+T computeShadowFactorSpotLightGeneric(GpuSceneLight light, Vec3 worldPos, Texture2D<Vec4> shadowTex, SamplerComparisonState shadowMapSampler,
+									  Bool pcf, T randFactor, TPcss pcss)
 {
-	const Vec4 texCoords4 = mul(light.m_textureMatrix, Vec4(worldPos, 1.0));
+	Mat4 textureMatrix;
+	textureMatrix.m_row0 = light.m_spotLightMatrixOrPointLightUvViewports[0];
+	textureMatrix.m_row1 = light.m_spotLightMatrixOrPointLightUvViewports[1];
+	textureMatrix.m_row2 = light.m_spotLightMatrixOrPointLightUvViewports[2];
+	textureMatrix.m_row3 = light.m_spotLightMatrixOrPointLightUvViewports[3];
+
+	const Vec4 texCoords4 = mul(textureMatrix, Vec4(worldPos, 1.0));
 	const Vec3 texCoords3 = texCoords4.xyz / texCoords4.w;
 
 	T shadow;
@@ -251,21 +257,21 @@ T computeShadowFactorSpotLightGeneric(SpotLight light, Vec3 worldPos, Texture2D<
 }
 
 template<typename T>
-T computeShadowFactorSpotLight(SpotLight light, Vec3 worldPos, Texture2D shadowTex, SamplerComparisonState shadowMapSampler)
+T computeShadowFactorSpotLight(GpuSceneLight light, Vec3 worldPos, Texture2D shadowTex, SamplerComparisonState shadowMapSampler)
 {
 	PcssDisabled<T> noPcss = (PcssDisabled<T>)0;
 	return computeShadowFactorSpotLightGeneric(light, worldPos, shadowTex, shadowMapSampler, false, 0.0, noPcss);
 }
 
 template<typename T>
-T computeShadowFactorSpotLightPcf(SpotLight light, Vec3 worldPos, Texture2D shadowTex, SamplerComparisonState shadowMapSampler, T randFactor)
+T computeShadowFactorSpotLightPcf(GpuSceneLight light, Vec3 worldPos, Texture2D shadowTex, SamplerComparisonState shadowMapSampler, T randFactor)
 {
 	PcssDisabled<T> noPcss = (PcssDisabled<T>)0;
 	return computeShadowFactorSpotLightGeneric(light, worldPos, shadowTex, shadowMapSampler, true, randFactor, noPcss);
 }
 
 template<typename T>
-T computeShadowFactorSpotLightPcss(SpotLight light, Vec3 worldPos, Texture2D shadowTex, SamplerComparisonState shadowMapSampler, T randFactor,
+T computeShadowFactorSpotLightPcss(GpuSceneLight light, Vec3 worldPos, Texture2D shadowTex, SamplerComparisonState shadowMapSampler, T randFactor,
 								   SamplerState linearClampAnySampler)
 {
 	Pcss<T> pcss;
@@ -275,8 +281,8 @@ T computeShadowFactorSpotLightPcss(SpotLight light, Vec3 worldPos, Texture2D sha
 
 // Compute the shadow factor of point (omni) lights.
 template<typename T>
-T computeShadowFactorPointLightGeneric(PointLight light, Vec3 frag2Light, Texture2D shadowMap, SamplerComparisonState shadowMapSampler, T randFactor,
-									   Bool pcf)
+T computeShadowFactorPointLightGeneric(GpuSceneLight light, Vec3 frag2Light, Texture2D shadowMap, SamplerComparisonState shadowMapSampler,
+									   T randFactor, Bool pcf)
 {
 	const Vec3 dir = -frag2Light;
 	const Vec3 dirabs = abs(dir);
@@ -301,10 +307,11 @@ T computeShadowFactorPointLightGeneric(PointLight light, Vec3 frag2Light, Textur
 	Vec2 uv = convertCubeUvs(dir * Vec3(1.0, 1.0, -1.0), faceIdxu);
 
 	// Get the atlas offset
-	const Vec2 atlasOffset = light.m_shadowAtlasTileOffsets[faceIdxu].xy;
+	const Vec2 atlasOffset = light.m_spotLightMatrixOrPointLightUvViewports[faceIdxu].xy;
 
 	// Compute UV
-	uv *= Vec2(light.m_shadowAtlasTileScale, light.m_shadowAtlasTileScale);
+	const F32 shadowAtlasTileScale = light.m_spotLightMatrixOrPointLightUvViewports[0].z; // Scale should be the same for all
+	uv *= Vec2(shadowAtlasTileScale, shadowAtlasTileScale);
 	uv += atlasOffset;
 
 	// Sample
@@ -346,13 +353,13 @@ T computeShadowFactorPointLightGeneric(PointLight light, Vec3 frag2Light, Textur
 }
 
 template<typename T>
-T computeShadowFactorPointLight(PointLight light, Vec3 frag2Light, Texture2D shadowMap, SamplerComparisonState shadowMapSampler)
+T computeShadowFactorPointLight(GpuSceneLight light, Vec3 frag2Light, Texture2D shadowMap, SamplerComparisonState shadowMapSampler)
 {
 	return computeShadowFactorPointLightGeneric(light, frag2Light, shadowMap, shadowMapSampler, -1.0, false);
 }
 
 template<typename T>
-T computeShadowFactorPointLightPcf(PointLight light, Vec3 frag2Light, Texture2D shadowMap, SamplerComparisonState shadowMapSampler, T randFactor)
+T computeShadowFactorPointLightPcf(GpuSceneLight light, Vec3 frag2Light, Texture2D shadowMap, SamplerComparisonState shadowMapSampler, T randFactor)
 {
 	return computeShadowFactorPointLightGeneric(light, frag2Light, shadowMap, shadowMapSampler, randFactor, true);
 }
@@ -574,8 +581,8 @@ vector<T, 3> sampleAmbientDice(vector<T, 3> posx, vector<T, 3> negx, vector<T, 3
 
 // Sample the irradiance term from the clipmap
 template<typename T>
-vector<T, 3> sampleGlobalIllumination(const Vec3 worldPos, const vector<T, 3> normal, const GlobalIlluminationProbe probe, Texture3D<Vec4> tex,
-									  SamplerState linearAnyClampSampler)
+vector<T, 3> sampleGlobalIllumination(const Vec3 worldPos, const vector<T, 3> normal, const GpuSceneGlobalIlluminationProbe probe,
+									  Texture3D<Vec4> tex, SamplerState linearAnyClampSampler)
 {
 	// Find the UVW
 	Vec3 uvw = (worldPos - probe.m_aabbMin) / (probe.m_aabbMax - probe.m_aabbMin);

+ 14 - 15
AnKi/Shaders/LightShading.ankiprog

@@ -16,26 +16,25 @@
 #	include <AnKi/Shaders/ClusteredShadingFunctions.hlsl>
 
 ConstantBuffer<GlobalRendererConstants> g_globalConstants : register(b0);
-StructuredBuffer<PointLight> g_pointLights : register(t0);
-StructuredBuffer<SpotLight> g_spotLights : register(t1);
+StructuredBuffer<GpuSceneLight> g_lights : register(t0);
 #	if INDIRECT_DIFFUSE_TEX
-Texture2D<Vec4> g_indirectDiffuseTex : register(t2);
+Texture2D<Vec4> g_indirectDiffuseTex : register(t1);
 #	else
-StructuredBuffer<GlobalIlluminationProbe> g_giProbes : register(t2);
+StructuredBuffer<GpuSceneGlobalIlluminationProbe> g_giProbes : register(t1);
 #	endif
-StructuredBuffer<Cluster> g_clusters : register(t4);
+StructuredBuffer<Cluster> g_clusters : register(t2);
 
 SamplerState g_nearestAnyClampSampler : register(s0);
 SamplerState g_trilinearClampSampler : register(s1);
 
-Texture2D<Vec4> g_gbuffer0Tex : register(t5);
-Texture2D<Vec4> g_gbuffer1Tex : register(t6);
-Texture2D<Vec4> g_gbuffer2Tex : register(t7);
-Texture2D g_depthTex : register(t8);
-Texture2D<Vec4> g_resolvedShadowsTex : register(t9);
-Texture2D<Vec4> g_ssaoTex : register(t10);
-Texture2D<Vec4> g_reflectionsTex : register(t11);
-Texture2D<Vec4> g_integrationLut : register(t12);
+Texture2D<Vec4> g_gbuffer0Tex : register(t3);
+Texture2D<Vec4> g_gbuffer1Tex : register(t4);
+Texture2D<Vec4> g_gbuffer2Tex : register(t5);
+Texture2D g_depthTex : register(t6);
+Texture2D<Vec4> g_resolvedShadowsTex : register(t7);
+Texture2D<Vec4> g_ssaoTex : register(t8);
+Texture2D<Vec4> g_reflectionsTex : register(t9);
+Texture2D<Vec4> g_integrationLut : register(t10);
 
 // Common code for lighting
 #	define LIGHTING_COMMON_BRDF() \
@@ -137,7 +136,7 @@ Vec4 main(VertOut input) : SV_TARGET0
 	U32 idx;
 	[loop] while((idx = iteratePointLights(cluster)) != kMaxU32)
 	{
-		const PointLight light = g_pointLights[idx];
+		const GpuSceneLight light = g_lights[idx];
 
 		LIGHTING_COMMON_BRDF();
 
@@ -153,7 +152,7 @@ Vec4 main(VertOut input) : SV_TARGET0
 	// Spot lights
 	[loop] while((idx = iterateSpotLights(cluster)) != kMaxU32)
 	{
-		const SpotLight light = g_spotLights[idx];
+		const GpuSceneLight light = g_lights[idx];
 
 		LIGHTING_COMMON_BRDF();
 

+ 1 - 2
AnKi/Shaders/MaterialShadersCommon.hlsl

@@ -61,8 +61,7 @@ SamplerComparisonState g_shadowSampler : register(ANKI_REG(s, ANKI_MATERIAL_REGI
 
 ConstantBuffer<GlobalRendererConstants> g_globalRendererConstants : register(ANKI_REG(b, ANKI_MATERIAL_REGISTER_CLUSTER_SHADING_CONSTANTS));
 StructuredBuffer<Cluster> g_clusters : register(ANKI_REG(t, ANKI_MATERIAL_REGISTER_CLUSTERS));
-StructuredBuffer<PointLight> g_pointLights : register(ANKI_REG(t, ANKI_MATERIAL_REGISTER_CLUSTER_SHADING_POINT_LIGHTS));
-StructuredBuffer<SpotLight> g_spotLights : register(ANKI_REG(t, ANKI_MATERIAL_REGISTER_CLUSTER_SHADING_SPOT_LIGHTS));
+StructuredBuffer<GpuSceneLight> g_lights : register(ANKI_REG(t, ANKI_MATERIAL_REGISTER_CLUSTER_SHADING_LIGHTS));
 Texture2D<Vec4> g_shadowAtlasTex : register(ANKI_REG(t, ANKI_MATERIAL_REGISTER_SHADOW_ATLAS));
 #endif
 

+ 5 - 6
AnKi/Shaders/Reflections.ankiprog

@@ -189,12 +189,11 @@ Texture2D<Vec4> g_gbufferRt2 : register(t2);
 Texture2D<Vec4> g_downscaledDepthTex : register(t3);
 Texture2D<Vec4> g_depthTex : register(t4);
 Texture2D<Vec4> g_lightBufferRt : register(t5);
-StructuredBuffer<GlobalIlluminationProbe> g_giProbes : register(t6);
+StructuredBuffer<GpuSceneGlobalIlluminationProbe> g_giProbes : register(t6);
 StructuredBuffer<Cluster> g_clusters : register(t7);
 Texture2D<Vec4> g_shadowAtlasTex : register(t8);
 Texture2D<UVec4> g_classTileMap : register(t9);
-StructuredBuffer<PointLight> g_pointLights : register(t10);
-StructuredBuffer<SpotLight> g_spotLights : register(t11);
+StructuredBuffer<GpuSceneLight> g_lights : register(t10);
 
 RWTexture2D<Vec4> g_colorAndPdfTex : register(u0);
 RWTexture2D<Vec4> g_hitPosAndDepthTex : register(u1);
@@ -263,7 +262,7 @@ Vec3 doLightShading(Vec3 worldPos, Vec3 viewPos, UVec2 coord, F32 depth)
 	U32 idx;
 	[loop] while((idx = iteratePointLights(cluster)) != kMaxU32)
 	{
-		const PointLight light = g_pointLights[idx];
+		const GpuSceneLight light = g_lights[idx];
 
 		const Vec3 frag2Light = light.m_position - worldPos;
 		const F32 attenuation = computeAttenuationFactor(light.m_radius, frag2Light);
@@ -275,7 +274,7 @@ Vec3 doLightShading(Vec3 worldPos, Vec3 viewPos, UVec2 coord, F32 depth)
 	// Spot lights
 	[loop] while((idx = iterateSpotLights(cluster)) != kMaxU32)
 	{
-		const SpotLight light = g_spotLights[idx];
+		const GpuSceneLight light = g_lights[idx];
 
 		const Vec3 frag2Light = light.m_position - worldPos;
 		F32 attenuation = computeAttenuationFactor(light.m_radius, frag2Light);
@@ -594,7 +593,7 @@ void bestCandidateToHallucinate(IVec2 svGroupThreadId, IVec2 offset, F32 depth,
 
 Texture2D<Vec4> g_depthTex : register(t0);
 StructuredBuffer<PixelFailedSsr> g_pixelsFailedSsr : register(t1);
-StructuredBuffer<ReflectionProbe> g_reflectionProbes : register(t2);
+StructuredBuffer<GpuSceneReflectionProbe> g_reflectionProbes : register(t2);
 StructuredBuffer<Cluster> g_clusters : register(t3);
 StructuredBuffer<U32> g_pixelsFailedSsrCount : register(t4);
 Texture2D<Vec4> g_envMap : register(t5);

+ 8 - 9
AnKi/Shaders/ShadowmapsResolve.ankiprog

@@ -16,19 +16,18 @@
 #	define DEBUG_CASCADES 0
 
 ConstantBuffer<GlobalRendererConstants> g_globalConstants : register(b0);
-StructuredBuffer<PointLight> g_pointLights : register(t0);
-StructuredBuffer<SpotLight> g_spotLights : register(t1);
-Texture2D<Vec4> g_shadowAtlasTex : register(t2);
-StructuredBuffer<Cluster> g_clusters : register(t3);
+StructuredBuffer<GpuSceneLight> g_lights : register(t0);
+Texture2D<Vec4> g_shadowAtlasTex : register(t1);
+StructuredBuffer<Cluster> g_clusters : register(t2);
 
 SamplerState g_linearAnyClampSampler : register(s0);
 SamplerComparisonState g_linearAnyClampShadowSampler : register(s1);
 SamplerState g_trilinearRepeatSampler : register(s2);
-Texture2D<Vec4> g_depthRt : register(t4);
-Texture2D<Vec4> g_noiseTex : register(t5);
+Texture2D<Vec4> g_depthRt : register(t3);
+Texture2D<Vec4> g_noiseTex : register(t4);
 
 #	if DIRECTIONAL_LIGHT_SHADOW_RESOLVED
-Texture2D<Vec4> g_dirLightResolvedShadowsTex : register(t6);
+Texture2D<Vec4> g_dirLightResolvedShadowsTex : register(t5);
 #	endif
 
 #	if ANKI_COMPUTE_SHADER
@@ -195,7 +194,7 @@ Vec4 main(VertOut input) : SV_TARGET0
 	U32 idx = 0;
 	[loop] while((idx = iteratePointLights(cluster)) != kMaxU32)
 	{
-		const PointLight light = g_pointLights[idx];
+		const GpuSceneLight light = g_lights[idx];
 
 		[branch] if(light.m_shadow)
 		{
@@ -213,7 +212,7 @@ Vec4 main(VertOut input) : SV_TARGET0
 	// Spot lights
 	[loop] while((idx = iterateSpotLights(cluster)) != kMaxU32)
 	{
-		const SpotLight light = g_spotLights[idx];
+		const GpuSceneLight light = g_lights[idx];
 
 		[branch] if(light.m_shadow)
 		{

+ 8 - 9
AnKi/Shaders/VolumetricLightingAccumulation.ankiprog

@@ -25,13 +25,12 @@ RWTexture3D<Vec4> g_volume : register(u0);
 Texture2D<Vec4> g_noiseTex : register(t0);
 Texture3D<Vec4> g_prevVolume : register(t1);
 
-StructuredBuffer<PointLight> g_pointLights : register(t2);
-StructuredBuffer<SpotLight> g_spotLights : register(t3);
-Texture2D<Vec4> g_shadowAtlasTex : register(t4);
-StructuredBuffer<FogDensityVolume> g_fogDensityVolumes : register(t5);
-StructuredBuffer<Cluster> g_clusters : register(t6);
+StructuredBuffer<GpuSceneLight> g_lights : register(t2);
+Texture2D<Vec4> g_shadowAtlasTex : register(t3);
+StructuredBuffer<GpuSceneFogDensityVolume> g_fogDensityVolumes : register(t4);
+StructuredBuffer<Cluster> g_clusters : register(t5);
 #if !CLIPMAP_DIFFUSE_INDIRECT
-StructuredBuffer<GlobalIlluminationProbe> g_giProbes : register(t7);
+StructuredBuffer<GpuSceneGlobalIlluminationProbe> g_giProbes : register(t6);
 #endif
 
 ConstantBuffer<GlobalRendererConstants> g_globalConstants : register(b0);
@@ -114,7 +113,7 @@ Vec4 accumulateLightsAndFog(Cluster cluster, Vec3 worldPos, F32 negativeZViewSpa
 	U32 idx = 0;
 	[loop] while((idx = iteratePointLights(cluster)) != kMaxU32)
 	{
-		const PointLight light = g_pointLights[idx];
+		const GpuSceneLight light = g_lights[idx];
 
 		const Vec3 frag2Light = light.m_position - worldPos;
 		F32 factor = computeAttenuationFactor<F32>(light.m_radius, frag2Light);
@@ -134,7 +133,7 @@ Vec4 accumulateLightsAndFog(Cluster cluster, Vec3 worldPos, F32 negativeZViewSpa
 	// Spot lights
 	[loop] while((idx = iterateSpotLights(cluster)) != kMaxU32)
 	{
-		const SpotLight light = g_spotLights[idx];
+		const GpuSceneLight light = g_lights[idx];
 
 		const Vec3 frag2Light = light.m_position - worldPos;
 		F32 factor = computeAttenuationFactor<F32>(light.m_radius, frag2Light);
@@ -184,7 +183,7 @@ Vec4 accumulateLightsAndFog(Cluster cluster, Vec3 worldPos, F32 negativeZViewSpa
 		{
 			const U32 idx = U32(firstbitlow2(cluster.m_fogDensityVolumesMask));
 			cluster.m_fogDensityVolumesMask &= ~(1u << idx);
-			const FogDensityVolume vol = g_fogDensityVolumes[idx];
+			const GpuSceneFogDensityVolume vol = g_fogDensityVolumes[idx];
 
 			F32 factor;
 			[branch] if(vol.m_isBox == 1u)