Browse Source

Start using the RT GI

Panagiotis Christopoulos Charitos 7 months ago
parent
commit
d567a05bd1

+ 10 - 9
AnKi/Renderer/IndirectDiffuseClipmaps.cpp

@@ -31,9 +31,10 @@ static void computeClipmapBounds(Vec3 cameraPos, Vec3 lookDir, Clipmap& clipmap)
 
 Error IndirectDiffuseClipmaps::init()
 {
-	m_tmpRtDesc = getRenderer().create2DRenderTargetDescription(getRenderer().getInternalResolution().x(), getRenderer().getInternalResolution().y(),
-																Format::kR8G8B8A8_Unorm, "Test");
-	m_tmpRtDesc.bake();
+	m_appliedGiRtDesc =
+		getRenderer().create2DRenderTargetDescription(getRenderer().getInternalResolution().x(), getRenderer().getInternalResolution().y(),
+													  getRenderer().getHdrFormat(), "IndirectDiffuseClipmap: Final");
+	m_appliedGiRtDesc.bake();
 
 	m_clipmapInfo[0].m_probeCounts =
 		UVec3(g_indirectDiffuseClipmapProbesXZCVar, g_indirectDiffuseClipmapProbesYCVar, g_indirectDiffuseClipmapProbesXZCVar);
@@ -115,7 +116,7 @@ Error IndirectDiffuseClipmaps::init()
 											 {"RADIANCE_OCTAHEDRON_MAP_SIZE", MutatorValue(g_indirectDiffuseClipmapRadianceOctMapSize)},
 											 {"IRRADIANCE_OCTAHEDRON_MAP_SIZE", MutatorValue(g_indirectDiffuseClipmapIrradianceOctMapSize)}}};
 
-	ANKI_CHECK(loadShaderProgram("ShaderBinaries/IndirectDiffuseClipmaps.ankiprogbin", mutation, m_prog, m_tmpVisGrProg, "Test"));
+	ANKI_CHECK(loadShaderProgram("ShaderBinaries/IndirectDiffuseClipmaps.ankiprogbin", mutation, m_prog, m_applyGiGrProg, "Apply"));
 	ANKI_CHECK(loadShaderProgram("ShaderBinaries/IndirectDiffuseClipmaps.ankiprogbin", mutation, m_prog, m_visProbesGrProg, "VisualizeProbes"));
 	ANKI_CHECK(loadShaderProgram("ShaderBinaries/IndirectDiffuseClipmaps.ankiprogbin", mutation, m_prog, m_populateCachesGrProg, "PopulateCaches"));
 	ANKI_CHECK(
@@ -172,7 +173,7 @@ void IndirectDiffuseClipmaps::populateRenderGraph(RenderingContext& ctx)
 	RenderGraphBuilder& rgraph = ctx.m_renderGraphDescr;
 
 	const RenderTargetHandle rtResultHandle = rgraph.newRenderTarget(m_rtResultRtDesc);
-	m_runCtx.m_tmpRt = rgraph.newRenderTarget(m_tmpRtDesc);
+	m_runCtx.m_appliedGiRt = rgraph.newRenderTarget(m_appliedGiRtDesc);
 
 	Array<RenderTargetHandle, kIndirectDiffuseClipmapCount> radianceVolumes;
 	Array<RenderTargetHandle, kIndirectDiffuseClipmapCount> irradianceVolumes;
@@ -412,7 +413,7 @@ void IndirectDiffuseClipmaps::populateRenderGraph(RenderingContext& ctx)
 		});
 	}
 
-	// Test
+	// Apply GI
 	{
 		NonGraphicsRenderPass& pass = rgraph.newNonGraphicsRenderPass("IndirectDiffuseClipmaps composite");
 
@@ -424,12 +425,12 @@ void IndirectDiffuseClipmaps::populateRenderGraph(RenderingContext& ctx)
 			pass.newTextureDependency(probeValidityVolumes[i], TextureUsageBit::kSrvCompute);
 			pass.newTextureDependency(distanceMomentsVolumes[i], TextureUsageBit::kSrvCompute);
 		}
-		pass.newTextureDependency(m_runCtx.m_tmpRt, TextureUsageBit::kUavCompute);
+		pass.newTextureDependency(m_runCtx.m_appliedGiRt, TextureUsageBit::kUavCompute);
 
 		pass.setWork([this, &ctx, irradianceVolumes, probeValidityVolumes, distanceMomentsVolumes](RenderPassWorkContext& rgraphCtx) {
 			CommandBuffer& cmdb = *rgraphCtx.m_commandBuffer;
 
-			cmdb.bindShaderProgram(m_tmpVisGrProg.get());
+			cmdb.bindShaderProgram(m_applyGiGrProg.get());
 
 			rgraphCtx.bindSrv(0, 0, getRenderer().getGBuffer().getDepthRt());
 			rgraphCtx.bindSrv(1, 0, getRenderer().getGBuffer().getColorRt(2));
@@ -451,7 +452,7 @@ void IndirectDiffuseClipmaps::populateRenderGraph(RenderingContext& ctx)
 				rgraphCtx.bindSrv(srvReg++, 0, distanceMomentsVolumes[i]);
 			}
 
-			rgraphCtx.bindUav(0, 0, m_runCtx.m_tmpRt);
+			rgraphCtx.bindUav(0, 0, m_runCtx.m_appliedGiRt);
 
 			cmdb.bindConstantBuffer(0, 0, ctx.m_globalRenderingConstantsBuffer);
 

+ 37 - 14
AnKi/Renderer/IndirectDiffuseClipmaps.h

@@ -16,19 +16,37 @@ namespace anki {
 
 inline BoolCVar g_rtIndirectDiffuseClipmapsCVar("R", "RtIndirectDiffuseClipmaps", false);
 
-inline NumericCVar<U32> g_indirectDiffuseClipmapProbesXZCVar("R", "IndirectDiffuseClipmapProbesXZ", 32, 10, 100,
+constexpr U32 kDefaultClipmapProbeCountXZ = 32;
+constexpr U32 kDefaultClipmapProbeCountY = 12;
+constexpr F32 kDefaultClipmap0ProbeSize = 1.5f;
+constexpr F32 kDefaultClipmap1ProbeSize = 3.0f;
+constexpr F32 kDefaultClipmap2ProbeSize = 6.0f;
+
+inline NumericCVar<U32> g_indirectDiffuseClipmapProbesXZCVar("R", "IndirectDiffuseClipmapProbesXZ", kDefaultClipmapProbeCountXZ, 10, 100,
 															 "The cell count of each dimension of 1st clipmap");
-inline NumericCVar<U32> g_indirectDiffuseClipmapProbesYCVar("R", "IndirectDiffuseClipmapProbesY", 8, 4, 100,
+inline NumericCVar<U32> g_indirectDiffuseClipmapProbesYCVar("R", "IndirectDiffuseClipmapProbesY", kDefaultClipmapProbeCountY, 4, 100,
 															"The cell count of each dimension of 1st clipmap");
 
-inline NumericCVar<F32> g_indirectDiffuseClipmap0XZSizeCVar("R", "IndirectDiffuseClipmap0XZSize", 48.0, 10.0, 1000.0, "The clipmap size in meters");
-inline NumericCVar<F32> g_indirectDiffuseClipmap0YSizeCVar("R", "IndirectDiffuseClipmap0YSize", 12.0, 10.0, 1000.0, "The clipmap size in meters");
-
-inline NumericCVar<F32> g_indirectDiffuseClipmap1XZSizeCVar("R", "IndirectDiffuseClipmap1XZSize", 96.0, 10.0, 1000.0, "The clipmap size in meters");
-inline NumericCVar<F32> g_indirectDiffuseClipmap1YSizeCVar("R", "IndirectDiffuseClipmap1YSize", 24.0, 10.0, 1000.0, "The clipmap size in meters");
-
-inline NumericCVar<F32> g_indirectDiffuseClipmap2XZSizeCVar("R", "IndirectDiffuseClipmap2XZSize", 192.0, 10.0, 1000.0, "The clipmap size in meters");
-inline NumericCVar<F32> g_indirectDiffuseClipmap2YSizeCVar("R", "IndirectDiffuseClipmap2YSize", 48.0, 10.0, 1000.0, "The clipmap size in meters");
+inline NumericCVar<F32> g_indirectDiffuseClipmap0XZSizeCVar("R", "IndirectDiffuseClipmap0XZSize",
+															F32(kDefaultClipmapProbeCountXZ) * kDefaultClipmap0ProbeSize, 10.0, 1000.0,
+															"The clipmap size in meters");
+inline NumericCVar<F32> g_indirectDiffuseClipmap0YSizeCVar("R", "IndirectDiffuseClipmap0YSize",
+														   F32(kDefaultClipmapProbeCountY) * kDefaultClipmap0ProbeSize, 10.0, 1000.0,
+														   "The clipmap size in meters");
+
+inline NumericCVar<F32> g_indirectDiffuseClipmap1XZSizeCVar("R", "IndirectDiffuseClipmap1XZSize",
+															F32(kDefaultClipmapProbeCountXZ) * kDefaultClipmap1ProbeSize, 10.0, 1000.0,
+															"The clipmap size in meters");
+inline NumericCVar<F32> g_indirectDiffuseClipmap1YSizeCVar("R", "IndirectDiffuseClipmap1YSize",
+														   F32(kDefaultClipmapProbeCountY) * kDefaultClipmap1ProbeSize, 10.0, 1000.0,
+														   "The clipmap size in meters");
+
+inline NumericCVar<F32> g_indirectDiffuseClipmap2XZSizeCVar("R", "IndirectDiffuseClipmap2XZSize",
+															F32(kDefaultClipmapProbeCountXZ) * kDefaultClipmap2ProbeSize, 10.0, 1000.0,
+															"The clipmap size in meters");
+inline NumericCVar<F32> g_indirectDiffuseClipmap2YSizeCVar("R", "IndirectDiffuseClipmap2YSize",
+														   F32(kDefaultClipmapProbeCountY) * kDefaultClipmap2ProbeSize, 10.0, 1000.0,
+														   "The clipmap size in meters");
 
 inline NumericCVar<U32> g_indirectDiffuseClipmapRadianceOctMapSize(
 	"R", "IndirectDiffuseClipmapRadianceOctMapSize", 10,
@@ -55,7 +73,7 @@ public:
 	void getDebugRenderTarget([[maybe_unused]] CString rtName, Array<RenderTargetHandle, kMaxDebugRenderTargets>& handles,
 							  [[maybe_unused]] ShaderProgramPtr& optionalShaderProgram) const override
 	{
-		handles[0] = m_runCtx.m_tmpRt;
+		handles[0] = m_runCtx.m_appliedGiRt;
 	}
 
 	const Array<Clipmap, kIndirectDiffuseClipmapCount>& getClipmapsInfo() const
@@ -65,6 +83,11 @@ public:
 
 	void drawDebugProbes(const RenderingContext& ctx, RenderPassWorkContext& rgraphCtx) const;
 
+	RenderTargetHandle getRt() const
+	{
+		return m_runCtx.m_appliedGiRt;
+	}
+
 private:
 	Array<TexturePtr, kIndirectDiffuseClipmapCount> m_radianceVolumes;
 	Array<TexturePtr, kIndirectDiffuseClipmapCount> m_irradianceVolumes;
@@ -72,7 +95,7 @@ private:
 
 	RenderTargetDesc m_rtResultRtDesc;
 	Array<RenderTargetDesc, kIndirectDiffuseClipmapCount> m_probeValidityRtDescs;
-	RenderTargetDesc m_tmpRtDesc; // TODO rm
+	RenderTargetDesc m_appliedGiRtDesc;
 
 	Array<Clipmap, kIndirectDiffuseClipmapCount> m_clipmapInfo;
 
@@ -82,7 +105,7 @@ private:
 	ShaderProgramPtr m_libraryGrProg;
 	ShaderProgramPtr m_populateCachesGrProg;
 	ShaderProgramPtr m_computeIrradianceGrProg;
-	ShaderProgramPtr m_tmpVisGrProg;
+	ShaderProgramPtr m_applyGiGrProg;
 	ShaderProgramPtr m_sbtBuildGrProg;
 	ShaderProgramPtr m_visProbesGrProg;
 
@@ -97,7 +120,7 @@ private:
 	class
 	{
 	public:
-		RenderTargetHandle m_tmpRt;
+		RenderTargetHandle m_appliedGiRt;
 		Array<RenderTargetHandle, kIndirectDiffuseClipmapCount> m_probeValidityRts;
 	} m_runCtx;
 };

+ 7 - 8
AnKi/Renderer/LightShading.cpp

@@ -31,10 +31,9 @@ Error LightShading::init()
 {
 	{
 		// Load shaders and programs
-		ANKI_CHECK(loadShaderProgram(
-			"ShaderBinaries/LightShading.ankiprogbin",
-			{{"INDIRECT_DIFFUSE_TEX", GrManager::getSingleton().getDeviceCapabilities().m_rayTracingEnabled && g_rtIndirectDiffuseCVar}},
-			m_lightShading.m_prog, m_lightShading.m_grProg));
+		ANKI_CHECK(loadShaderProgram("ShaderBinaries/LightShading.ankiprogbin",
+									 {{"INDIRECT_DIFFUSE_TEX", getRenderer().isIndirectDiffuseClipmapsEnabled()}}, m_lightShading.m_prog,
+									 m_lightShading.m_grProg));
 
 		// Create RT descr
 		const UVec2 internalResolution = getRenderer().getInternalResolution();
@@ -87,9 +86,9 @@ void LightShading::run(const RenderingContext& ctx, RenderPassWorkContext& rgrap
 		cmdb.bindConstantBuffer(0, 0, ctx.m_globalRenderingConstantsBuffer);
 		cmdb.bindSrv(0, 0, getRenderer().getClusterBinning().getPackedObjectsBuffer(GpuSceneNonRenderableObjectType::kLight));
 		cmdb.bindSrv(1, 0, getRenderer().getClusterBinning().getPackedObjectsBuffer(GpuSceneNonRenderableObjectType::kLight));
-		if(GrManager::getSingleton().getDeviceCapabilities().m_rayTracingEnabled && g_rtIndirectDiffuseCVar)
+		if(getRenderer().isIndirectDiffuseClipmapsEnabled())
 		{
-			rgraphCtx.bindSrv(2, 0, getRenderer().getIndirectDiffuse().getRt());
+			rgraphCtx.bindSrv(2, 0, getRenderer().getIndirectDiffuseClipmaps().getRt());
 		}
 		else
 		{
@@ -282,9 +281,9 @@ void LightShading::populateRenderGraph(RenderingContext& ctx)
 	pass.newTextureDependency(getRenderer().getSsao().getRt(), readUsage);
 	pass.newTextureDependency(getRenderer().getReflections().getRt(), readUsage);
 
-	if(GrManager::getSingleton().getDeviceCapabilities().m_rayTracingEnabled && g_rtIndirectDiffuseCVar)
+	if(getRenderer().isIndirectDiffuseClipmapsEnabled())
 	{
-		pass.newTextureDependency(getRenderer().getIndirectDiffuse().getRt(), TextureUsageBit::kSrvPixel);
+		pass.newTextureDependency(getRenderer().getIndirectDiffuseClipmaps().getRt(), TextureUsageBit::kSrvPixel);
 	}
 
 	// Fog

+ 1 - 1
AnKi/Renderer/RendererObject.def.h

@@ -8,7 +8,6 @@
 ANKI_RENDERER_OBJECT_DEF(GBuffer, gbuffer, 1)
 ANKI_RENDERER_OBJECT_DEF(GBufferPost, gbufferPost, 1)
 ANKI_RENDERER_OBJECT_DEF(ShadowMapping, shadowMapping, 1)
-ANKI_RENDERER_OBJECT_DEF(LightShading, lightShading, 1)
 ANKI_RENDERER_OBJECT_DEF(ForwardShading, forwardShading, 1)
 ANKI_RENDERER_OBJECT_DEF(LensFlare, lensFlare, 1)
 ANKI_RENDERER_OBJECT_DEF(Bloom, bloom2, 1)
@@ -30,6 +29,7 @@ ANKI_RENDERER_OBJECT_DEF(AccelerationStructureBuilder, accelerationStructureBuil
 						 GrManager::getSingleton().getDeviceCapabilities().m_rayTracingEnabled
 							 && (g_rayTracedShadowsCVar || g_rtMaterialFetchDbgCVar || g_rtReflectionsCVar || g_rtIndirectDiffuseCVar
 								 || g_rtIndirectDiffuseClipmapsCVar))
+ANKI_RENDERER_OBJECT_DEF(LightShading, lightShading, 1)
 ANKI_RENDERER_OBJECT_DEF(MotionVectors, motionVectors, 1)
 ANKI_RENDERER_OBJECT_DEF(TemporalUpscaler, temporalUpscaler, 1)
 ANKI_RENDERER_OBJECT_DEF(VrsSriGeneration, vrsSriGeneration, 1)

+ 7 - 5
AnKi/Shaders/IndirectDiffuseClipmaps.ankiprog

@@ -12,7 +12,7 @@
 #pragma anki technique RtMaterialFetch rgen mutators
 #pragma anki technique PopulateCaches comp mutators RADIANCE_OCTAHEDRON_MAP_SIZE
 #pragma anki technique ComputeIrradiance comp mutators GPU_WAVE_SIZE RADIANCE_OCTAHEDRON_MAP_SIZE IRRADIANCE_OCTAHEDRON_MAP_SIZE
-#pragma anki technique Test comp mutators
+#pragma anki technique Apply comp mutators
 #pragma anki technique VisualizeProbes vert pixel mutators
 
 // #define ANKI_ASSERTIONS_ENABLED 1
@@ -138,7 +138,8 @@ Vec3 sampleClipmapIrradianceCommon(Vec3 samplePoint, Vec3 normal, Vec3 cameraPos
 	const Vec3 probeSize = clipmap.m_size / clipmap.m_probeCounts;
 	const Vec3 fakeVolumeSize = clipmap.m_probeCounts; // Volume size without the octahedron
 
-	const Vec3 biasedWorldPos = samplePoint + normal * min3(probeSize) * 0.1;
+	const Vec3 biasDir = normalize(cameraPos - samplePoint);
+	const Vec3 biasedWorldPos = samplePoint + biasDir * probeSize * 0.2;
 
 	F32 octahedronSize = 0.0;
 	Vec3 realVolumeSize;
@@ -218,7 +219,8 @@ Vec3 sampleClipmapIrradianceCommon(Vec3 samplePoint, Vec3 normal, Vec3 cameraPos
 				chebyshevWeight = variance / (variance + (v * v));
 
 				// Increase the contrast in the weight
-				chebyshevWeight = max((chebyshevWeight * chebyshevWeight * chebyshevWeight), 0.05);
+				chebyshevWeight = chebyshevWeight * chebyshevWeight * chebyshevWeight;
+				chebyshevWeight = max(chebyshevWeight, 0.05);
 			}
 
 			w *= chebyshevWeight;
@@ -652,9 +654,9 @@ groupshared Vec3 g_irradianceResults[kThreadCount];
 #endif
 
 // ===========================================================================
-// Test                                                                      =
+// Apply                                                                     =
 // ===========================================================================
-#if NOT_ZERO(ANKI_TECHNIQUE_Test)
+#if NOT_ZERO(ANKI_TECHNIQUE_Apply)
 Texture2D<Vec4> g_depthTex : register(t0);
 Texture2D<Vec4> g_gbufferRt2 : register(t1);