Browse Source

Move decals to the new clusters

Panagiotis Christopoulos Charitos 4 years ago
parent
commit
e213533c5f

+ 5 - 5
AnKi/Renderer/ClusterBinning.cpp

@@ -74,7 +74,7 @@ void ClusterBinning::run(RenderPassWorkContext& rgraphCtx)
 {
 {
 	CommandBufferPtr& cmdb = rgraphCtx.m_commandBuffer;
 	CommandBufferPtr& cmdb = rgraphCtx.m_commandBuffer;
 
 
-	const ClusteredShadingContext& tokens = m_runCtx.m_ctx->m_clusterShading;
+	const ClusteredShadingContext& tokens = m_runCtx.m_ctx->m_clusteredShading;
 
 
 	cmdb->bindShaderProgram(m_grProg);
 	cmdb->bindShaderProgram(m_grProg);
 	bindUniforms(cmdb, 0, 0, tokens.m_clusteredShadingUniformsToken);
 	bindUniforms(cmdb, 0, 0, tokens.m_clusteredShadingUniformsToken);
@@ -146,7 +146,7 @@ void ClusterBinning::writeClustererBuffers(RenderingContext& ctx)
 	}
 	}
 
 
 	// Allocate buffers
 	// Allocate buffers
-	ClusteredShadingContext& cs = ctx.m_clusterShading;
+	ClusteredShadingContext& cs = ctx.m_clusteredShading;
 	StagingGpuMemoryManager& stagingMem = m_r->getStagingGpuMemoryManager();
 	StagingGpuMemoryManager& stagingMem = m_r->getStagingGpuMemoryManager();
 
 
 	cs.m_clusteredShadingUniformsAddress = stagingMem.allocateFrame(
 	cs.m_clusteredShadingUniformsAddress = stagingMem.allocateFrame(
@@ -233,7 +233,7 @@ void ClusterBinning::writeClustererBuffersTask()
 	ANKI_TRACE_SCOPED_EVENT(R_WRITE_CLUSTER_SHADING_OBJECTS);
 	ANKI_TRACE_SCOPED_EVENT(R_WRITE_CLUSTER_SHADING_OBJECTS);
 
 
 	RenderingContext& ctx = *m_runCtx.m_ctx;
 	RenderingContext& ctx = *m_runCtx.m_ctx;
-	ClusteredShadingContext& cs = ctx.m_clusterShading;
+	ClusteredShadingContext& cs = ctx.m_clusteredShading;
 	const RenderQueue& rqueue = *ctx.m_renderQueue;
 	const RenderQueue& rqueue = *ctx.m_renderQueue;
 
 
 	// Point lights
 	// Point lights
@@ -352,8 +352,8 @@ void ClusterBinning::writeClustererBuffersTask()
 		}
 		}
 
 
 		ANKI_ASSERT(diffuseAtlas || specularRoughnessAtlas);
 		ANKI_ASSERT(diffuseAtlas || specularRoughnessAtlas);
-		ctx.m_clusterShading.m_diffuseDecalTextureView.reset(diffuseAtlas);
-		ctx.m_clusterShading.m_specularRoughnessDecalTextureView.reset(specularRoughnessAtlas);
+		ctx.m_clusteredShading.m_diffuseDecalTextureView.reset(diffuseAtlas);
+		ctx.m_clusteredShading.m_specularRoughnessDecalTextureView.reset(specularRoughnessAtlas);
 	}
 	}
 
 
 	// Fog volumes
 	// Fog volumes

+ 1 - 1
AnKi/Renderer/Common.h

@@ -183,7 +183,7 @@ public:
 
 
 	StagingGpuMemoryToken m_lightShadingUniformsToken;
 	StagingGpuMemoryToken m_lightShadingUniformsToken;
 
 
-	ClusteredShadingContext m_clusterShading;
+	ClusteredShadingContext m_clusteredShading;
 
 
 	RenderingContext(const StackAllocator<U8>& alloc)
 	RenderingContext(const StackAllocator<U8>& alloc)
 		: m_tempAllocator(alloc)
 		: m_tempAllocator(alloc)

+ 1 - 1
AnKi/Renderer/ForwardShading.cpp

@@ -40,7 +40,7 @@ void ForwardShading::run(const RenderingContext& ctx, RenderPassWorkContext& rgr
 		cmdb->setDepthWrite(false);
 		cmdb->setDepthWrite(false);
 		cmdb->setBlendFactors(0, BlendFactor::SRC_ALPHA, BlendFactor::ONE_MINUS_SRC_ALPHA);
 		cmdb->setBlendFactors(0, BlendFactor::SRC_ALPHA, BlendFactor::ONE_MINUS_SRC_ALPHA);
 
 
-		const ClusteredShadingContext& rsrc = ctx.m_clusterShading;
+		const ClusteredShadingContext& rsrc = ctx.m_clusteredShading;
 		cmdb->bindSampler(0, 0, m_r->getSamplers().m_trilinearClamp);
 		cmdb->bindSampler(0, 0, m_r->getSamplers().m_trilinearClamp);
 
 
 		rgraphCtx.bindTexture(0, 1, m_r->getDepthDownscale().getHiZRt(), HIZ_HALF_DEPTH);
 		rgraphCtx.bindTexture(0, 1, m_r->getDepthDownscale().getHiZRt(), HIZ_HALF_DEPTH);

+ 8 - 8
AnKi/Renderer/GBufferPost.cpp

@@ -34,8 +34,8 @@ Error GBufferPost::initInternal(const ConfigSet& cfg)
 	ANKI_CHECK(getResourceManager().loadResource("Shaders/GBufferPost.ankiprog", m_prog));
 	ANKI_CHECK(getResourceManager().loadResource("Shaders/GBufferPost.ankiprog", m_prog));
 
 
 	ShaderProgramResourceVariantInitInfo variantInitInfo(m_prog);
 	ShaderProgramResourceVariantInitInfo variantInitInfo(m_prog);
-	variantInitInfo.addConstant("CLUSTER_COUNT_X", cfg.getNumberU32("r_clusterSizeX"));
-	variantInitInfo.addConstant("CLUSTER_COUNT_Y", cfg.getNumberU32("r_clusterSizeY"));
+	variantInitInfo.addConstant("TILE_COUNTS", m_r->getTileCounts());
+	variantInitInfo.addConstant("Z_SPLIT_COUNT", m_r->getZSplitCount());
 
 
 	const ShaderProgramResourceVariant* variant;
 	const ShaderProgramResourceVariant* variant;
 	m_prog->getOrCreateVariant(variantInitInfo, variant);
 	m_prog->getOrCreateVariant(variantInitInfo, variant);
@@ -73,7 +73,7 @@ void GBufferPost::populateRenderGraph(RenderingContext& ctx)
 void GBufferPost::run(RenderPassWorkContext& rgraphCtx)
 void GBufferPost::run(RenderPassWorkContext& rgraphCtx)
 {
 {
 	const RenderingContext& ctx = *m_runCtx.m_ctx;
 	const RenderingContext& ctx = *m_runCtx.m_ctx;
-	const ClusterBinOut& rsrc = ctx.m_clusterBinOut;
+	const ClusteredShadingContext& rsrc = ctx.m_clusteredShading;
 	CommandBufferPtr& cmdb = rgraphCtx.m_commandBuffer;
 	CommandBufferPtr& cmdb = rgraphCtx.m_commandBuffer;
 
 
 	cmdb->setViewport(0, 0, m_r->getWidth(), m_r->getHeight());
 	cmdb->setViewport(0, 0, m_r->getWidth(), m_r->getHeight());
@@ -89,18 +89,18 @@ void GBufferPost::run(RenderPassWorkContext& rgraphCtx)
 
 
 	cmdb->bindSampler(0, 2, m_r->getSamplers().m_trilinearRepeat);
 	cmdb->bindSampler(0, 2, m_r->getSamplers().m_trilinearRepeat);
 
 
-	bindUniforms(cmdb, 0, 3, ctx.m_lightShadingUniformsToken);
+	bindUniforms(cmdb, 0, 3, rsrc.m_clusteredShadingUniformsToken);
 	bindUniforms(cmdb, 0, 4, rsrc.m_decalsToken);
 	bindUniforms(cmdb, 0, 4, rsrc.m_decalsToken);
 
 
-	cmdb->bindTexture(0, 5, (rsrc.m_diffDecalTexView) ? rsrc.m_diffDecalTexView : m_r->getDummyTextureView2d(),
+	cmdb->bindTexture(0, 5,
+					  (rsrc.m_diffuseDecalTextureView) ? rsrc.m_diffuseDecalTextureView : m_r->getDummyTextureView2d(),
 					  TextureUsageBit::SAMPLED_FRAGMENT);
 					  TextureUsageBit::SAMPLED_FRAGMENT);
 	cmdb->bindTexture(0, 6,
 	cmdb->bindTexture(0, 6,
-					  (rsrc.m_specularRoughnessDecalTexView) ? rsrc.m_specularRoughnessDecalTexView
-															 : m_r->getDummyTextureView2d(),
+					  (rsrc.m_specularRoughnessDecalTextureView) ? rsrc.m_specularRoughnessDecalTextureView
+																 : m_r->getDummyTextureView2d(),
 					  TextureUsageBit::SAMPLED_FRAGMENT);
 					  TextureUsageBit::SAMPLED_FRAGMENT);
 
 
 	bindStorage(cmdb, 0, 7, rsrc.m_clustersToken);
 	bindStorage(cmdb, 0, 7, rsrc.m_clustersToken);
-	bindStorage(cmdb, 0, 8, rsrc.m_indicesToken);
 
 
 	// Draw
 	// Draw
 	cmdb->drawArrays(PrimitiveTopology::TRIANGLES, 3);
 	cmdb->drawArrays(PrimitiveTopology::TRIANGLES, 3);

+ 1 - 1
AnKi/Renderer/LightShading.cpp

@@ -117,7 +117,7 @@ void LightShading::run(RenderPassWorkContext& rgraphCtx)
 		cmdb->setDepthWrite(false);
 		cmdb->setDepthWrite(false);
 
 
 		// Bind all
 		// Bind all
-		const ClusteredShadingContext& binning = ctx.m_clusterShading;
+		const ClusteredShadingContext& binning = ctx.m_clusteredShading;
 		bindUniforms(cmdb, 0, 0, binning.m_clusteredShadingUniformsToken);
 		bindUniforms(cmdb, 0, 0, binning.m_clusteredShadingUniformsToken);
 
 
 		bindUniforms(cmdb, 0, 1, binning.m_pointLightsToken);
 		bindUniforms(cmdb, 0, 1, binning.m_pointLightsToken);

+ 1 - 1
AnKi/Renderer/RtShadows.cpp

@@ -477,7 +477,7 @@ void RtShadows::run(RenderPassWorkContext& rgraphCtx)
 {
 {
 	const RenderingContext& ctx = *m_runCtx.m_ctx;
 	const RenderingContext& ctx = *m_runCtx.m_ctx;
 	CommandBufferPtr& cmdb = rgraphCtx.m_commandBuffer;
 	CommandBufferPtr& cmdb = rgraphCtx.m_commandBuffer;
-	const ClusteredShadingContext& rsrc = ctx.m_clusterShading;
+	const ClusteredShadingContext& rsrc = ctx.m_clusteredShading;
 
 
 	cmdb->bindShaderProgram(m_rtLibraryGrProg);
 	cmdb->bindShaderProgram(m_rtLibraryGrProg);
 
 

+ 1 - 1
AnKi/Renderer/ShadowmapsResolve.cpp

@@ -70,7 +70,7 @@ void ShadowmapsResolve::run(RenderPassWorkContext& rgraphCtx)
 {
 {
 	const RenderingContext& ctx = *m_runCtx.m_ctx;
 	const RenderingContext& ctx = *m_runCtx.m_ctx;
 	CommandBufferPtr& cmdb = rgraphCtx.m_commandBuffer;
 	CommandBufferPtr& cmdb = rgraphCtx.m_commandBuffer;
-	const ClusteredShadingContext& rsrc = ctx.m_clusterShading;
+	const ClusteredShadingContext& rsrc = ctx.m_clusteredShading;
 
 
 	cmdb->bindShaderProgram(m_grProg);
 	cmdb->bindShaderProgram(m_grProg);
 
 

+ 1 - 1
AnKi/Renderer/VolumetricLightingAccumulation.cpp

@@ -102,7 +102,7 @@ void VolumetricLightingAccumulation::run(RenderPassWorkContext& rgraphCtx)
 {
 {
 	CommandBufferPtr& cmdb = rgraphCtx.m_commandBuffer;
 	CommandBufferPtr& cmdb = rgraphCtx.m_commandBuffer;
 	RenderingContext& ctx = *m_runCtx.m_ctx;
 	RenderingContext& ctx = *m_runCtx.m_ctx;
-	const ClusteredShadingContext& rsrc = ctx.m_clusterShading;
+	const ClusteredShadingContext& rsrc = ctx.m_clusteredShading;
 
 
 	cmdb->bindShaderProgram(m_grProg);
 	cmdb->bindShaderProgram(m_grProg);
 
 

+ 4 - 4
AnKi/Shaders/ClusteredShadingCommon2.glsl

@@ -13,7 +13,7 @@
 #if defined(CLUSTERED_SHADING_UNIFORMS_BINDING)
 #if defined(CLUSTERED_SHADING_UNIFORMS_BINDING)
 layout(set = CLUSTERED_SHADING_SET, binding = CLUSTERED_SHADING_UNIFORMS_BINDING, scalar) uniform ANKI_RANDOM_BLOCK_NAME
 layout(set = CLUSTERED_SHADING_SET, binding = CLUSTERED_SHADING_UNIFORMS_BINDING, scalar) uniform ANKI_RANDOM_BLOCK_NAME
 {
 {
-	ClusteredShadingUniforms u_clusterShading;
+	ClusteredShadingUniforms u_clusteredShading;
 };
 };
 #endif
 #endif
 
 
@@ -195,9 +195,9 @@ Cluster getClusterFragCoord(Vec3 fragCoord, U32 tileSize, UVec2 tileCounts, U32
 
 
 Cluster getClusterFragCoord(Vec3 fragCoord)
 Cluster getClusterFragCoord(Vec3 fragCoord)
 {
 {
-	return getClusterFragCoord(fragCoord, u_clusterShading.m_tileSize, u_clusterShading.m_tileCounts,
-							   u_clusterShading.m_zSplitCount, u_clusterShading.m_zSplitMagic.x,
-							   u_clusterShading.m_zSplitMagic.y);
+	return getClusterFragCoord(fragCoord, u_clusteredShading.m_tileSize, u_clusteredShading.m_tileCounts,
+							   u_clusteredShading.m_zSplitCount, u_clusteredShading.m_zSplitMagic.x,
+							   u_clusteredShading.m_zSplitMagic.y);
 }
 }
 
 
 Cluster getClusterUv(Vec2 uv, F32 depth, UVec2 tileCounts, U32 zSplitCount, F32 a, F32 b)
 Cluster getClusterUv(Vec2 uv, F32 depth, UVec2 tileCounts, U32 zSplitCount, F32 a, F32 b)

+ 3 - 3
AnKi/Shaders/ForwardShadingCommonFrag.glsl

@@ -104,7 +104,7 @@ Vec3 computeLightColorLow(Vec3 diffCol, Vec3 worldPos)
 {
 {
 	// TODO
 	// TODO
 #if 0
 #if 0
-	const Vec2 uv = gl_FragCoord.xy / u_clusterShading.m_renderingSize;
+	const Vec2 uv = gl_FragCoord.xy / u_clusteredShading.m_renderingSize;
 	const Vec3 uv3d = computeClustererVolumeTextureUvs(u_clustererMagic, uv, worldPos, u_lightVolumeLastCluster + 1u);
 	const Vec3 uv3d = computeClustererVolumeTextureUvs(u_clustererMagic, uv, worldPos, u_lightVolumeLastCluster + 1u);
 
 
 	const Vec3 light = textureLod(u_lightVol, u_linearAnyClampSampler, uv3d, 0.0).rgb;
 	const Vec3 light = textureLod(u_lightVol, u_linearAnyClampSampler, uv3d, 0.0).rgb;
@@ -121,14 +121,14 @@ void particleAlpha(Vec4 color, Vec4 scaleColor, Vec4 biasColor)
 
 
 void fog(Vec3 color, F32 fogAlphaScale, F32 fogDistanceOfMaxThikness, F32 zVSpace)
 void fog(Vec3 color, F32 fogAlphaScale, F32 fogDistanceOfMaxThikness, F32 zVSpace)
 {
 {
-	const Vec2 screenSize = 1.0 / u_clusterShading.m_renderingSize;
+	const Vec2 screenSize = 1.0 / u_clusteredShading.m_renderingSize;
 
 
 	const Vec2 texCoords = gl_FragCoord.xy * screenSize;
 	const Vec2 texCoords = gl_FragCoord.xy * screenSize;
 	const F32 depth = textureLod(u_gbufferDepthRt, u_linearAnyClampSampler, texCoords, 0.0).r;
 	const F32 depth = textureLod(u_gbufferDepthRt, u_linearAnyClampSampler, texCoords, 0.0).r;
 	F32 zFeatherFactor;
 	F32 zFeatherFactor;
 
 
 	const Vec4 fragPosVspace4 =
 	const Vec4 fragPosVspace4 =
-		u_clusterShading.m_matrices.m_invertedProjectionJitter * Vec4(Vec3(UV_TO_NDC(texCoords), depth), 1.0);
+		u_clusteredShading.m_matrices.m_invertedProjectionJitter * Vec4(Vec3(UV_TO_NDC(texCoords), depth), 1.0);
 	const F32 sceneZVspace = fragPosVspace4.z / fragPosVspace4.w;
 	const F32 sceneZVspace = fragPosVspace4.z / fragPosVspace4.w;
 
 
 	const F32 diff = max(0.0, zVSpace - sceneZVspace);
 	const F32 diff = max(0.0, zVSpace - sceneZVspace);

+ 1 - 1
AnKi/Shaders/ForwardShadingParticles.ankiprog

@@ -62,7 +62,7 @@ void main()
 {
 {
 #if ANIMATED_TEXTURE == 1
 #if ANIMATED_TEXTURE == 1
 	Vec4 texCol = readAnimatedTextureRgba(u_diffuseMapArr, u_ankiGlobalSampler, u_ankiPerDraw.m_animationPeriod, in_uv,
 	Vec4 texCol = readAnimatedTextureRgba(u_diffuseMapArr, u_ankiGlobalSampler, u_ankiPerDraw.m_animationPeriod, in_uv,
-										  u_clusterShading.m_time);
+										  u_clusteredShading.m_time);
 #else
 #else
 	Vec4 texCol = texture(u_diffuseMap, u_ankiGlobalSampler, in_uv);
 	Vec4 texCol = texture(u_diffuseMap, u_ankiGlobalSampler, in_uv);
 #endif
 #endif

+ 21 - 45
AnKi/Shaders/GBufferPost.ankiprog

@@ -3,28 +3,11 @@
 // Code licensed under the BSD License.
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 // http://www.anki3d.org/LICENSE
 
 
-ANKI_SPECIALIZATION_CONSTANT_U32(CLUSTER_COUNT_X, 0);
-ANKI_SPECIALIZATION_CONSTANT_U32(CLUSTER_COUNT_Y, 1);
+ANKI_SPECIALIZATION_CONSTANT_UVEC2(TILE_COUNTS, 0);
+ANKI_SPECIALIZATION_CONSTANT_U32(Z_SPLIT_COUNT, 2);
 
 
 #pragma anki start vert
 #pragma anki start vert
-#include <AnKi/Shaders/Common.glsl>
-
-layout(location = 0) out Vec2 out_uv;
-layout(location = 1) out Vec2 out_clusterIJ;
-
-out gl_PerVertex
-{
-	Vec4 gl_Position;
-};
-
-void main()
-{
-	out_uv = Vec2(gl_VertexID & 1, gl_VertexID >> 1) * 2.0;
-	const Vec2 pos = out_uv * 2.0 - 1.0;
-	gl_Position = Vec4(pos, 0.0, 1.0);
-
-	out_clusterIJ = Vec2(CLUSTER_COUNT_X, CLUSTER_COUNT_Y) * out_uv;
-}
+#include <AnKi/Shaders/QuadVert.glsl>
 #pragma anki end
 #pragma anki end
 
 
 #pragma anki start frag
 #pragma anki start frag
@@ -33,16 +16,15 @@ void main()
 
 
 layout(set = 0, binding = 0) uniform sampler u_nearestAnyClampSampler;
 layout(set = 0, binding = 0) uniform sampler u_nearestAnyClampSampler;
 layout(set = 0, binding = 1) uniform texture2D u_msDepthRt;
 layout(set = 0, binding = 1) uniform texture2D u_msDepthRt;
-
 layout(set = 0, binding = 2) uniform sampler u_trilinearRepeatSampler;
 layout(set = 0, binding = 2) uniform sampler u_trilinearRepeatSampler;
-#define LIGHT_SET 0
-#define LIGHT_COMMON_UNIS_BINDING 3
-#define LIGHT_DECALS_BINDING 4
-#define LIGHT_CLUSTERS_BINDING 7
-#include <AnKi/Shaders/ClusteredShadingCommon.glsl>
+
+#define CLUSTERED_SHADING_SET 0
+#define CLUSTERED_SHADING_UNIFORMS_BINDING 3
+#define CLUSTERED_SHADING_DECALS_BINDING 4
+#define CLUSTERED_SHADING_CLUSTERS_BINDING 7
+#include <AnKi/Shaders/ClusteredShadingCommon2.glsl>
 
 
 layout(location = 0) in Vec2 in_uv;
 layout(location = 0) in Vec2 in_uv;
-layout(location = 1) in Vec2 in_clusterIJ;
 
 
 layout(location = 0) out Vec4 out_color0;
 layout(location = 0) out Vec4 out_color0;
 layout(location = 1) out Vec4 out_color1;
 layout(location = 1) out Vec4 out_color1;
@@ -62,33 +44,27 @@ void main()
 	// Get worldPos
 	// Get worldPos
 	const F32 depth = textureLod(u_msDepthRt, u_nearestAnyClampSampler, in_uv, 0.0).r;
 	const F32 depth = textureLod(u_msDepthRt, u_nearestAnyClampSampler, in_uv, 0.0).r;
 	const Vec2 ndc = UV_TO_NDC(in_uv);
 	const Vec2 ndc = UV_TO_NDC(in_uv);
-	const Vec4 worldPos4 = u_invViewProjMat * Vec4(ndc, depth, 1.0);
+	const Vec4 worldPos4 = u_clusteredShading.m_matrices.m_invertedViewProjectionJitter * Vec4(ndc, depth, 1.0);
 	const Vec3 worldPos = worldPos4.xyz / worldPos4.w;
 	const Vec3 worldPos = worldPos4.xyz / worldPos4.w;
 
 
-	// Get first decal index
-	U32 idxOffset;
-	{
-		const U32 k = computeClusterK(u_clustererMagic, worldPos);
-		const U32 clusterIdx =
-			k * (CLUSTER_COUNT_X * CLUSTER_COUNT_Y) + U32(in_clusterIJ.y) * CLUSTER_COUNT_X + U32(in_clusterIJ.x);
-
-		idxOffset = u_clusters[clusterIdx];
-		idxOffset = u_lightIndices[idxOffset - 2u]; // Use the offset metadata
-	}
+	// Get the cluster
+	Cluster cluster = getClusterUv(in_uv, depth, TILE_COUNTS, Z_SPLIT_COUNT, u_clusteredShading.m_zSplitMagic.x,
+								   u_clusteredShading.m_zSplitMagic.y);
 
 
 	// Process decals
 	// Process decals
-	U32 idx = u_lightIndices[idxOffset];
-	if(idx == MAX_U32)
+	if(cluster.m_decalsMask == 0ul)
 	{
 	{
 		discard;
 		discard;
 	}
 	}
 
 
-	ANKI_LOOP while((idx = u_lightIndices[idxOffset++]) != MAX_U32)
+	ANKI_LOOP while(cluster.m_decalsMask != 0ul)
 	{
 	{
-		const Decal decal = u_decals[idx];
+		const I32 idx = findLSB64(cluster.m_decalsMask);
+		cluster.m_decalsMask &= ~(1ul << U64(idx));
+		const Decal2 decal = u_decals2[idx];
 
 
 		// Project pos to decal space
 		// Project pos to decal space
-		const Vec4 texCoords4 = decal.m_texProjectionMat * Vec4(worldPos, 1.0);
+		const Vec4 texCoords4 = decal.m_textureMatrix * Vec4(worldPos, 1.0);
 		if(texCoords4.w <= 0.7)
 		if(texCoords4.w <= 0.7)
 		{
 		{
 			// Behind the decal, skip
 			// Behind the decal, skip
@@ -101,8 +77,8 @@ void main()
 		texCoords2 = saturate(texCoords2);
 		texCoords2 = saturate(texCoords2);
 
 
 		// Read diffuse
 		// Read diffuse
-		const Vec2 diffUv = mad(texCoords2, decal.m_diffUv.zw, decal.m_diffUv.xy);
-		const Vec4 decalDiff = texture(u_diffDecalTex, u_trilinearRepeatSampler, diffUv);
+		const Vec2 diffUv = mad(texCoords2, decal.m_diffuseUv.zw, decal.m_diffuseUv.xy);
+		const Vec4 decalDiff = texture(u_diffuseDecalTex, u_trilinearRepeatSampler, diffUv);
 
 
 		// Read roughness
 		// Read roughness
 		const Vec2 specUv = mad(texCoords2, decal.m_normRoughnessUv.zw, decal.m_normRoughnessUv.xy);
 		const Vec2 specUv = mad(texCoords2, decal.m_normRoughnessUv.zw, decal.m_normRoughnessUv.xy);

+ 4 - 4
AnKi/Shaders/LightShading.ankiprog

@@ -69,12 +69,12 @@ void main()
 	}
 	}
 
 
 	// Get world position
 	// Get world position
-	const Vec4 worldPos4 = u_clusterShading.m_matrices.m_invertedViewProjectionJitter * Vec4(ndc, depth, 1.0);
+	const Vec4 worldPos4 = u_clusteredShading.m_matrices.m_invertedViewProjectionJitter * Vec4(ndc, depth, 1.0);
 	const Vec3 worldPos = worldPos4.xyz / worldPos4.w;
 	const Vec3 worldPos = worldPos4.xyz / worldPos4.w;
 
 
 	// Get the cluster
 	// Get the cluster
 	Cluster cluster = getClusterFragCoord(Vec3(gl_FragCoord.xy, depth), TILE_SIZE, TILE_COUNTS, Z_SPLIT_COUNT,
 	Cluster cluster = getClusterFragCoord(Vec3(gl_FragCoord.xy, depth), TILE_SIZE, TILE_COUNTS, Z_SPLIT_COUNT,
-										  u_clusterShading.m_zSplitMagic.x, u_clusterShading.m_zSplitMagic.y);
+										  u_clusteredShading.m_zSplitMagic.x, u_clusteredShading.m_zSplitMagic.y);
 
 
 	// out_color = clusterHeatmap(cluster, 1u << CLUSTER_OBJECT_TYPE_POINT_LIGHT); return;
 	// out_color = clusterHeatmap(cluster, 1u << CLUSTER_OBJECT_TYPE_POINT_LIGHT); return;
 
 
@@ -100,8 +100,8 @@ void main()
 	out_color = gbuffer.m_diffuse * gbuffer.m_emission;
 	out_color = gbuffer.m_diffuse * gbuffer.m_emission;
 
 
 	// Dir light
 	// Dir light
-	const Vec3 viewDir = normalize(u_clusterShading.m_cameraPosition - worldPos);
-	const DirectionalLight2 dirLight = u_clusterShading.m_directionalLight;
+	const Vec3 viewDir = normalize(u_clusteredShading.m_cameraPosition - worldPos);
+	const DirectionalLight2 dirLight = u_clusteredShading.m_directionalLight;
 	if(dirLight.m_active != 0u)
 	if(dirLight.m_active != 0u)
 	{
 	{
 		F32 shadowFactor;
 		F32 shadowFactor;

+ 5 - 5
AnKi/Shaders/RtShadowsRayGen.ankiprog

@@ -68,7 +68,7 @@ void main()
 	const Vec2 uv = (Vec2(gl_LaunchIDEXT.xy) + 0.5) / Vec2(gl_LaunchSizeEXT.xy);
 	const Vec2 uv = (Vec2(gl_LaunchIDEXT.xy) + 0.5) / Vec2(gl_LaunchSizeEXT.xy);
 	const Vec2 ndc = UV_TO_NDC(uv);
 	const Vec2 ndc = UV_TO_NDC(uv);
 	const F32 depth = textureLod(u_depthRt, u_linearAnyClampSampler, uv, 0.0).r;
 	const F32 depth = textureLod(u_depthRt, u_linearAnyClampSampler, uv, 0.0).r;
-	const Vec4 worldPos4 = u_clusterShading.m_matrices.m_invertedViewProjectionJitter * Vec4(ndc, depth, 1.0);
+	const Vec4 worldPos4 = u_clusteredShading.m_matrices.m_invertedViewProjectionJitter * Vec4(ndc, depth, 1.0);
 	const Vec3 worldPos = worldPos4.xyz / worldPos4.w;
 	const Vec3 worldPos = worldPos4.xyz / worldPos4.w;
 
 
 	if(depth == 1.0)
 	if(depth == 1.0)
@@ -87,8 +87,8 @@ void main()
 	const Vec3 normal = readNormalFromGBuffer(u_normalRt, u_linearAnyClampSampler, uv);
 	const Vec3 normal = readNormalFromGBuffer(u_normalRt, u_linearAnyClampSampler, uv);
 
 
 	// Cluster
 	// Cluster
-	Cluster cluster = getClusterUv(uv, depth, u_clusterShading.m_tileCounts, u_clusterShading.m_zSplitCount,
-								   u_clusterShading.m_zSplitMagic.x, u_clusterShading.m_zSplitMagic.y);
+	Cluster cluster = getClusterUv(uv, depth, u_clusteredShading.m_tileCounts, u_clusteredShading.m_zSplitCount,
+								   u_clusteredShading.m_zSplitMagic.x, u_clusteredShading.m_zSplitMagic.y);
 
 
 	F32 shadowFactors[MAX_RT_SHADOW_LAYERS];
 	F32 shadowFactors[MAX_RT_SHADOW_LAYERS];
 	zeroRtShadowLayers(shadowFactors);
 	zeroRtShadowLayers(shadowFactors);
@@ -97,7 +97,7 @@ void main()
 	Vec3 random[RAYS_PER_PIXEL];
 	Vec3 random[RAYS_PER_PIXEL];
 	for(U32 i = 0; i < RAYS_PER_PIXEL; ++i)
 	for(U32 i = 0; i < RAYS_PER_PIXEL; ++i)
 	{
 	{
-		const U32 frameIdx = u_clusterShading.m_frame * RAYS_PER_PIXEL + i;
+		const U32 frameIdx = u_clusteredShading.m_frame * RAYS_PER_PIXEL + i;
 #if 0
 #if 0
 		const UVec3 irandom = rand3DPCG16(UVec3(gl_LaunchIDEXT.xy, frameIdx));
 		const UVec3 irandom = rand3DPCG16(UVec3(gl_LaunchIDEXT.xy, frameIdx));
 		random[i] = Vec3(irandom) / F32(0xFFFF) * 2.0 - 1.0; // In [-1.0, 1.0]
 		random[i] = Vec3(irandom) / F32(0xFFFF) * 2.0 - 1.0; // In [-1.0, 1.0]
@@ -110,7 +110,7 @@ void main()
 	}
 	}
 
 
 	// Dir light
 	// Dir light
-	const DirectionalLight2 dirLight = u_clusterShading.m_directionalLight;
+	const DirectionalLight2 dirLight = u_clusteredShading.m_directionalLight;
 	ANKI_BRANCH if(dirLight.m_active != 0u && dirLight.m_cascadeCount > 0)
 	ANKI_BRANCH if(dirLight.m_active != 0u && dirLight.m_cascadeCount > 0)
 	{
 	{
 		for(U32 i = 0; i < RAYS_PER_PIXEL; ++i)
 		for(U32 i = 0; i < RAYS_PER_PIXEL; ++i)

+ 6 - 6
AnKi/Shaders/ShadowmapsResolve.ankiprog

@@ -33,12 +33,12 @@ void main()
 	const Vec2 uv = (Vec2(gl_GlobalInvocationID.xy) + 0.5) / Vec2(FB_SIZE);
 	const Vec2 uv = (Vec2(gl_GlobalInvocationID.xy) + 0.5) / Vec2(FB_SIZE);
 	const Vec2 ndc = UV_TO_NDC(uv);
 	const Vec2 ndc = UV_TO_NDC(uv);
 	const F32 depth = textureLod(u_depthRt, u_linearAnyClampSampler, uv, 0.0).r;
 	const F32 depth = textureLod(u_depthRt, u_linearAnyClampSampler, uv, 0.0).r;
-	const Vec4 worldPos4 = u_clusterShading.m_matrices.m_invertedViewProjectionJitter * Vec4(ndc, depth, 1.0);
+	const Vec4 worldPos4 = u_clusteredShading.m_matrices.m_invertedViewProjectionJitter * Vec4(ndc, depth, 1.0);
 	const Vec3 worldPos = worldPos4.xyz / worldPos4.w;
 	const Vec3 worldPos = worldPos4.xyz / worldPos4.w;
 
 
 	// Cluster
 	// Cluster
-	Cluster cluster = getClusterUv(uv, depth, TILE_COUNTS, Z_SPLIT_COUNT, u_clusterShading.m_zSplitMagic.x,
-								   u_clusterShading.m_zSplitMagic.y);
+	Cluster cluster = getClusterUv(uv, depth, TILE_COUNTS, Z_SPLIT_COUNT, u_clusteredShading.m_zSplitMagic.x,
+								   u_clusteredShading.m_zSplitMagic.y);
 
 
 	// Layers
 	// Layers
 	U32 shadowCasterCountPerFragment = 0;
 	U32 shadowCasterCountPerFragment = 0;
@@ -46,12 +46,12 @@ void main()
 	F32 shadowFactors[maxShadowCastersPerFragment] = F32[](0.0, 0.0, 0.0, 0.0);
 	F32 shadowFactors[maxShadowCastersPerFragment] = F32[](0.0, 0.0, 0.0, 0.0);
 
 
 	// Dir light
 	// Dir light
-	const DirectionalLight2 dirLight = u_clusterShading.m_directionalLight;
+	const DirectionalLight2 dirLight = u_clusteredShading.m_directionalLight;
 	if(dirLight.m_active != 0u && dirLight.m_cascadeCount > 0)
 	if(dirLight.m_active != 0u && dirLight.m_cascadeCount > 0)
 	{
 	{
 		const F32 positiveZViewSpace =
 		const F32 positiveZViewSpace =
-			testPlanePoint(u_clusterShading.m_nearPlaneWSpace.xyz, u_clusterShading.m_nearPlaneWSpace.w, worldPos)
-			+ u_clusterShading.m_near;
+			testPlanePoint(u_clusteredShading.m_nearPlaneWSpace.xyz, u_clusteredShading.m_nearPlaneWSpace.w, worldPos)
+			+ u_clusteredShading.m_near;
 
 
 		F32 shadowFactor;
 		F32 shadowFactor;
 		if(positiveZViewSpace < dirLight.m_effectiveShadowDistance)
 		if(positiveZViewSpace < dirLight.m_effectiveShadowDistance)

+ 9 - 8
AnKi/Shaders/VolumetricLightingAccumulation.ankiprog

@@ -39,7 +39,7 @@ Vec3 g_globalInvocationID = Vec3(gl_GlobalInvocationID);
 Vec3 readRand()
 Vec3 readRand()
 {
 {
 	Vec3 random = textureLod(u_noiseTex, u_linearAnyRepeatSampler, (g_globalInvocationID.xy + 0.5) / 64.0, 0.0).rgb;
 	Vec3 random = textureLod(u_noiseTex, u_linearAnyRepeatSampler, (g_globalInvocationID.xy + 0.5) / 64.0, 0.0).rgb;
-	random = animateBlueNoise(random, u_clusterShading.m_frame);
+	random = animateBlueNoise(random, u_clusteredShading.m_frame);
 
 
 	return random;
 	return random;
 }
 }
@@ -55,7 +55,8 @@ Vec3 worldPosInsideClusterAndZViewSpace(Vec3 relativePos, out F32 negativeZViewS
 	uvw.z = linearDepth;
 	uvw.z = linearDepth;
 
 
 	// Z view space
 	// Z view space
-	negativeZViewSpace = linearDepth * (u_clusterShading.m_far - u_clusterShading.m_near) + u_clusterShading.m_near;
+	negativeZViewSpace =
+		linearDepth * (u_clusteredShading.m_far - u_clusteredShading.m_near) + u_clusteredShading.m_near;
 	const F32 zViewSpace = -negativeZViewSpace;
 	const F32 zViewSpace = -negativeZViewSpace;
 
 
 	// Get the position in view space
 	// Get the position in view space
@@ -63,10 +64,10 @@ Vec3 worldPosInsideClusterAndZViewSpace(Vec3 relativePos, out F32 negativeZViewS
 	const Vec2 uvMax = uvMin + 1.0 / Vec2(VOLUME_SIZE.xy);
 	const Vec2 uvMax = uvMin + 1.0 / Vec2(VOLUME_SIZE.xy);
 	const Vec2 uv = mix(uvMin, uvMax, relativePos.xy);
 	const Vec2 uv = mix(uvMin, uvMax, relativePos.xy);
 	uvw.xy = uv;
 	uvw.xy = uv;
-	const Vec2 xyViewSpace = UV_TO_NDC(uv) * u_clusterShading.m_matrices.m_unprojectionParameters.xy * zViewSpace;
+	const Vec2 xyViewSpace = UV_TO_NDC(uv) * u_clusteredShading.m_matrices.m_unprojectionParameters.xy * zViewSpace;
 
 
 	// Get the final world pos
 	// Get the final world pos
-	const Vec4 worldPos4 = u_clusterShading.m_matrices.m_invertedView * Vec4(xyViewSpace, zViewSpace, 1.0);
+	const Vec4 worldPos4 = u_clusteredShading.m_matrices.m_invertedView * Vec4(xyViewSpace, zViewSpace, 1.0);
 	const Vec3 worldPos = worldPos4.xyz;
 	const Vec3 worldPos = worldPos4.xyz;
 
 
 	return worldPos;
 	return worldPos;
@@ -95,10 +96,10 @@ F32 phaseFunction(Vec3 viewDir, Vec3 lightDir, F32 g)
 Vec4 accumulateLightsAndFog(Cluster cluster, Vec3 worldPos, F32 negativeZViewSpace)
 Vec4 accumulateLightsAndFog(Cluster cluster, Vec3 worldPos, F32 negativeZViewSpace)
 {
 {
 	Vec3 color = Vec3(0.0);
 	Vec3 color = Vec3(0.0);
-	const Vec3 viewDir = normalize(u_clusterShading.m_cameraPosition - worldPos);
+	const Vec3 viewDir = normalize(u_clusteredShading.m_cameraPosition - worldPos);
 
 
 	// Dir light
 	// Dir light
-	const DirectionalLight2 dirLight = u_clusterShading.m_directionalLight;
+	const DirectionalLight2 dirLight = u_clusteredShading.m_directionalLight;
 	if(dirLight.m_active != 0u)
 	if(dirLight.m_active != 0u)
 	{
 	{
 		F32 factor = phaseFunction(viewDir, dirLight.m_direction, PHASE_FUNCTION_ANISOTROPY);
 		F32 factor = phaseFunction(viewDir, dirLight.m_direction, PHASE_FUNCTION_ANISOTROPY);
@@ -278,13 +279,13 @@ void main()
 		const Vec3 midWPos = worldPosInsideCluster(Vec3(0.5));
 		const Vec3 midWPos = worldPosInsideCluster(Vec3(0.5));
 
 
 		// Project
 		// Project
-		const Vec4 prevClipPos4 = u_clusterShading.m_previousMatrices.m_viewProjection * Vec4(midWPos, 1.0);
+		const Vec4 prevClipPos4 = u_clusteredShading.m_previousMatrices.m_viewProjection * Vec4(midWPos, 1.0);
 		const Vec3 prevClipPos = prevClipPos4.xyz / prevClipPos4.w;
 		const Vec3 prevClipPos = prevClipPos4.xyz / prevClipPos4.w;
 
 
 		// Read prev
 		// Read prev
 		if(all(greaterThan(prevClipPos.xy, Vec2(-1.0))) && all(lessThan(prevClipPos.xy, Vec2(1.0))))
 		if(all(greaterThan(prevClipPos.xy, Vec2(-1.0))) && all(lessThan(prevClipPos.xy, Vec2(1.0))))
 		{
 		{
-			const F32 linearDepth = linearizeDepth(prevClipPos.z, u_clusterShading.m_near, u_clusterShading.m_far);
+			const F32 linearDepth = linearizeDepth(prevClipPos.z, u_clusteredShading.m_near, u_clusteredShading.m_far);
 			const Vec3 uvw =
 			const Vec3 uvw =
 				Vec3(NDC_TO_UV(prevClipPos.xy), linearDepth * (F32(Z_SPLIT_COUNT) / F32(FINAL_Z_SPLIT + 1u)));
 				Vec3(NDC_TO_UV(prevClipPos.xy), linearDepth * (F32(Z_SPLIT_COUNT) / F32(FINAL_Z_SPLIT + 1u)));
 			const Vec4 history = textureLod(u_prevVolume, u_linearAnyClampSampler, uvw, 0.0);
 			const Vec4 history = textureLod(u_prevVolume, u_linearAnyClampSampler, uvw, 0.0);