Panagiotis Christopoulos Charitos 4 years ago
parent
commit
b9564c8b5d

+ 2 - 2
AnKi/Renderer/ConfigDefs.h

@@ -12,8 +12,8 @@ ANKI_CONFIG_OPTION(r_zSplitCount, 64, 8, 1024, "Clusterer number of Z splits")
 
 ANKI_CONFIG_OPTION(r_renderingQuality, 1.0, 0.5, 1.0, "A factor over the requested renderingresolution")
 
-ANKI_CONFIG_OPTION(r_volumetricLightingAccumulationQualityXY, 1.0, 0.5, 16.0)
-ANKI_CONFIG_OPTION(r_volumetricLightingAccumulationQualityZ, 1.0, 0.5, 16.0)
+ANKI_CONFIG_OPTION(r_volumetricLightingAccumulationQualityXY, 4.0, 1.0, 16.0)
+ANKI_CONFIG_OPTION(r_volumetricLightingAccumulationQualityZ, 4.0, 1.0, 16.0)
 ANKI_CONFIG_OPTION(r_volumetricLightingAccumulationFinalZSplit, 26, 1, 256)
 
 ANKI_CONFIG_OPTION(r_ssrMaxSteps, 64, 1, 2048)

+ 9 - 6
AnKi/Renderer/LightShading.cpp

@@ -93,7 +93,8 @@ Error LightShading::initApplyFog(const ConfigSet& config)
 	ANKI_CHECK(getResourceManager().loadResource("Shaders/LightShadingApplyFog.ankiprog", m_applyFog.m_prog));
 
 	ShaderProgramResourceVariantInitInfo variantInitInfo(m_applyFog.m_prog);
-	variantInitInfo.addConstant("FOG_LAST_CLASTER", m_r->getVolumetricFog().getFinalClusterInZ());
+	variantInitInfo.addConstant("Z_SPLIT_COUNT", m_r->getZSplitCount());
+	variantInitInfo.addConstant("FINAL_Z_SPLIT", m_r->getVolumetricFog().getFinalClusterInZ());
 
 	const ShaderProgramResourceVariant* variant;
 	m_applyFog.m_prog->getOrCreateVariant(variantInitInfo, variant);
@@ -169,13 +170,15 @@ void LightShading::run(RenderPassWorkContext& rgraphCtx)
 							  TextureSubresourceInfo(DepthStencilAspectBit::DEPTH));
 		rgraphCtx.bindColorTexture(0, 3, m_r->getVolumetricFog().getRt());
 
-		struct PushConsts
+		class PushConsts
 		{
-			ClustererMagicValues m_clustererMagic;
-			Mat4 m_invViewProjMat;
+		public:
+			Vec2 m_padding;
+			F32 m_near;
+			F32 m_far;
 		} regs;
-		regs.m_clustererMagic = ctx.m_clusterBinOut.m_shaderMagicValues;
-		regs.m_invViewProjMat = ctx.m_matrices.m_viewProjectionJitter.getInverse();
+		regs.m_near = ctx.m_renderQueue->m_cameraNear;
+		regs.m_far = ctx.m_renderQueue->m_cameraFar;
 
 		cmdb->setPushConstants(&regs, sizeof(regs));
 

+ 1 - 2
AnKi/Renderer/VolumetricLightingAccumulation.cpp

@@ -36,8 +36,7 @@ Error VolumetricLightingAccumulation::init(const ConfigSet& config)
 				m_volumeSize[2]);
 
 	if(!isAligned(m_r->getTileCounts().x(), m_volumeSize[0]) || !isAligned(m_r->getTileCounts().y(), m_volumeSize[1])
-	   || m_volumeSize[2] > m_r->getZSplitCount() || m_volumeSize[0] == 0 || m_volumeSize[1] == 0
-	   || m_volumeSize[2] == 0)
+	   || m_volumeSize[0] == 0 || m_volumeSize[1] == 0 || m_volumeSize[2] == 0)
 	{
 		ANKI_R_LOGE("Wrong input");
 		return Error::USER_DATA;

+ 1 - 3
AnKi/Shaders/LightFunctions2.glsl

@@ -198,9 +198,7 @@ F32 computeShadowFactorPointLight(PointLight2 light, Vec3 frag2Light, texture2D
 	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];
+	const Vec2 atlasOffset = light.m_shadowAtlasTileOffsets[faceIdxu];
 
 	// Compute UV
 	uv = fma(uv, Vec2(light.m_shadowAtlasTileScale), atlasOffset);

+ 15 - 12
AnKi/Shaders/LightShadingApplyFog.ankiprog

@@ -3,7 +3,8 @@
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 
-ANKI_SPECIALIZATION_CONSTANT_U32(FOG_LAST_CLASTER, 0, 1u);
+ANKI_SPECIALIZATION_CONSTANT_U32(Z_SPLIT_COUNT, 0, 1u);
+ANKI_SPECIALIZATION_CONSTANT_U32(FINAL_Z_SPLIT, 1, 1u);
 
 #pragma anki start vert
 #include <AnKi/Shaders/QuadVert.glsl>
@@ -11,9 +12,7 @@ ANKI_SPECIALIZATION_CONSTANT_U32(FOG_LAST_CLASTER, 0, 1u);
 
 #pragma anki start frag
 
-#include <AnKi/Shaders/Include/ClusteredShadingTypes.h>
-#include <AnKi/Shaders/Include/ClusteredShadingFunctions.h>
-#include <AnKi/Shaders/Common.glsl>
+#include <AnKi/Shaders/Functions.glsl>
 
 layout(location = 0) in Vec2 in_uv;
 layout(location = 0) out Vec4 out_color;
@@ -23,23 +22,27 @@ layout(set = 0, binding = 1) uniform sampler u_linearAnyClampSampler;
 layout(set = 0, binding = 2) uniform texture2D u_depthRt;
 layout(set = 0, binding = 3) uniform texture3D u_fogVolume;
 
-layout(push_constant, std140, row_major) uniform pc_
+layout(push_constant, std140, row_major) uniform b_pc
 {
-	ClustererMagicValues u_clustererMagic;
-	Mat4 u_invViewProjMat;
+	Vec2 u_padding;
+	F32 u_near;
+	F32 u_far;
 };
 
 void main()
 {
+	Vec3 uvw;
+
+	// Compute W coordinate
 	const F32 depth = textureLod(u_depthRt, u_nearestAnyClampSampler, in_uv, 0.0).r;
+	const F32 linearDepth = linearizeDepth(depth, u_near, u_far);
+	uvw.z = linearDepth * (F32(Z_SPLIT_COUNT) / F32(FINAL_Z_SPLIT + 1u));
 
-	// Get world position
-	const Vec4 worldPos4 = u_invViewProjMat * Vec4(UV_TO_NDC(in_uv), depth, 1.0);
-	const Vec3 worldPos = worldPos4.xyz / worldPos4.w;
+	// Compute UV coordinates
+	uvw.xy = in_uv;
 
 	// Read the volume
-	const Vec3 uv3d = computeClustererVolumeTextureUvs(u_clustererMagic, in_uv, worldPos, FOG_LAST_CLASTER + 1u);
-	const Vec4 fogVals = textureLod(u_fogVolume, u_linearAnyClampSampler, uv3d, 0.0);
+	const Vec4 fogVals = textureLod(u_fogVolume, u_linearAnyClampSampler, uvw, 0.0);
 	const Vec3 inScattering = fogVals.rgb;
 	const F32 transmittance = fogVals.a;
 

+ 4 - 3
AnKi/Shaders/VolumetricLightingAccumulation.ankiprog

@@ -280,12 +280,13 @@ void main()
 		// Project
 		const Vec4 prevClipPos4 = u_clusterShading.m_previousMatrices.m_viewProjection * Vec4(midWPos, 1.0);
 		const Vec3 prevClipPos = prevClipPos4.xyz / prevClipPos4.w;
-		const F32 linearDepth = linearizeDepth(prevClipPos.z, u_clusterShading.m_near, u_clusterShading.m_far);
 
 		// Read prev
-		if(all(greaterThan(prevClipPos, Vec3(-1.0))) && all(lessThan(prevClipPos, Vec3(1.0))))
+		if(all(greaterThan(prevClipPos.xy, Vec2(-1.0))) && all(lessThan(prevClipPos.xy, Vec2(1.0))))
 		{
-			const Vec3 uvw = Vec3(NDC_TO_UV(prevClipPos.xy), linearDepth);
+			const F32 linearDepth = linearizeDepth(prevClipPos.z, u_clusterShading.m_near, u_clusterShading.m_far);
+			const Vec3 uvw =
+				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);
 			lightAndFog = mix(history, lightAndFog, 1.0 / 16.0);
 		}