Przeglądaj źródła

Fix some bugs with some RT combinations

Panagiotis Christopoulos Charitos 2 miesięcy temu
rodzic
commit
6b949b9757

+ 7 - 1
AnKi/Renderer/ProbeReflections.cpp

@@ -14,6 +14,7 @@
 #include <AnKi/Renderer/Utils/MipmapGenerator.h>
 #include <AnKi/Renderer/Utils/Drawer.h>
 #include <AnKi/Renderer/Reflections.h>
+#include <AnKi/Renderer/IndirectDiffuseClipmaps.h>
 #include <AnKi/Util/CVarSet.h>
 #include <AnKi/Util/Tracer.h>
 #include <AnKi/Core/StatsSet.h>
@@ -306,10 +307,14 @@ void ProbeReflections::populateRenderGraph(RenderingContext& rctx)
 				pass.newTextureDependency(getRenderer().getGeneratedSky().getSkyLutRt(), TextureUsageBit::kSrvPixel);
 			}
 
-			if(getRenderer().getIndirectDiffuseProbes().hasCurrentlyRefreshedVolumeRt())
+			if(isIndirectDiffuseProbesEnabled() && getIndirectDiffuseProbes().hasCurrentlyRefreshedVolumeRt())
 			{
 				pass.newTextureDependency(getRenderer().getIndirectDiffuseProbes().getCurrentlyRefreshedVolumeRt(), TextureUsageBit::kSrvPixel);
 			}
+			else if(!isIndirectDiffuseProbesEnabled())
+			{
+				getIndirectDiffuseClipmaps().setDependencies(pass, TextureUsageBit::kSrvPixel);
+			}
 
 			pass.setWork([this, visResult = lightVis.m_visiblesBuffer, viewProjMat = frustum.getViewProjectionMatrix(),
 						  cascadeViewProjMat = cascadeViewProjMat, probeToRefresh, gbufferColorRts, gbufferDepthRt, shadowMapRt, faceIdx = f,
@@ -335,6 +340,7 @@ void ProbeReflections::populateRenderGraph(RenderingContext& rctx)
 				dsInfo.m_gbufferRenderTargets[2] = gbufferColorRts[2];
 				dsInfo.m_gbufferRenderTargetSubresource[2].m_face = faceIdx;
 				dsInfo.m_gbufferDepthRenderTarget = gbufferDepthRt;
+				dsInfo.m_useIndirectDiffuseClipmaps = isIndirectDiffuseClipmapsEnabled();
 				if(shadowMapRt.isValid())
 				{
 					dsInfo.m_directionalLightShadowmapRenderTarget = shadowMapRt;

+ 7 - 4
AnKi/Renderer/Utils/TraditionalDeferredShading.cpp

@@ -20,11 +20,11 @@ Error TraditionalDeferredLightShading::init()
 	// Init progs
 	for(MutatorValue specular = 0; specular <= 1; ++specular)
 	{
-		for(MutatorValue applyIndirectDiffuse = 0; applyIndirectDiffuse <= 1; ++applyIndirectDiffuse)
+		for(MutatorValue indirectDiffuseType = 0; indirectDiffuseType <= 2; ++indirectDiffuseType)
 		{
 			ANKI_CHECK(loadShaderProgram("ShaderBinaries/TraditionalDeferredShading.ankiprogbin",
-										 {{"SPECULAR", specular}, {"INDIRECT_DIFFUSE", applyIndirectDiffuse}}, m_lightProg,
-										 m_lightGrProg[specular][applyIndirectDiffuse]));
+										 {{"SPECULAR", specular}, {"INDIRECT_DIFFUSE", indirectDiffuseType}}, m_lightProg,
+										 m_lightGrProg[specular][indirectDiffuseType]));
 		}
 	}
 
@@ -139,15 +139,18 @@ void TraditionalDeferredLightShading::drawLights(TraditionalDeferredLightShading
 		}
 
 		const Bool indirectDiffuse = info.m_applyIndirectDiffuse && GpuSceneArrays::GlobalIlluminationProbe::getSingleton().getElementCount();
+		Bool useIndirectDiffuseClipmaps = false;
 		if(indirectDiffuse)
 		{
 			cmdb.bindSrv(7, 0, GpuSceneArrays::GlobalIlluminationProbe::getSingleton().getBufferView());
 			cmdb.bindSampler(2, 0, getRenderer().getSamplers().m_trilinearClamp.get());
+
+			useIndirectDiffuseClipmaps = info.m_useIndirectDiffuseClipmaps;
 		}
 
 		cmdb.bindConstantBuffer(1, 0, info.m_globalRendererConsts);
 
-		cmdb.bindShaderProgram(m_lightGrProg[info.m_computeSpecular][indirectDiffuse].get());
+		cmdb.bindShaderProgram(m_lightGrProg[info.m_computeSpecular][indirectDiffuse + useIndirectDiffuseClipmaps].get());
 
 		drawQuad(cmdb);
 	}

+ 2 - 2
AnKi/Renderer/Utils/TraditionalDeferredShading.h

@@ -1,4 +1,3 @@
-// Copyright (C) 2009-present, Panagiotis Christopoulos Charitos and contributors.
 // All rights reserved.
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
@@ -27,6 +26,7 @@ public:
 
 	Bool m_computeSpecular = false;
 	Bool m_applyIndirectDiffuse = false; ///< Apply GI using the indirect diffuse probes.
+	Bool m_useIndirectDiffuseClipmaps = false;
 
 	// Render targets
 	Array<RenderTargetHandle, kGBufferColorRenderTargetCount - 1> m_gbufferRenderTargets;
@@ -56,7 +56,7 @@ public:
 
 private:
 	ShaderProgramResourcePtr m_lightProg;
-	Array2d<ShaderProgramPtr, 2, 2> m_lightGrProg;
+	Array2d<ShaderProgramPtr, 2, 3> m_lightGrProg;
 
 	ShaderProgramResourcePtr m_skyboxProg;
 	Array<ShaderProgramPtr, 3> m_skyboxGrProgs;

+ 1 - 1
AnKi/Shaders/Include/TraditionalDeferredShadingTypes.h

@@ -33,7 +33,7 @@ struct TraditionalDeferredShadingConstants
 
 struct TraditionalDeferredSkyboxConstants
 {
-	RVec3 m_solidColor;
+	Vec3 m_solidColor;
 	F32 m_padding1;
 
 	Mat4 m_invertedViewProjectionMat;

+ 18 - 6
AnKi/Shaders/TraditionalDeferredShading.ankiprog

@@ -5,8 +5,10 @@
 
 // Classic deferred lighting shader
 
+#pragma anki 16bit
+
 #pragma anki mutator SPECULAR 0 1
-#pragma anki mutator INDIRECT_DIFFUSE 0 1
+#pragma anki mutator INDIRECT_DIFFUSE 0 1 2
 
 #pragma anki technique vert pixel
 
@@ -15,6 +17,7 @@
 #if ANKI_PIXEL_SHADER
 #	include <AnKi/Shaders/PackFunctions.hlsl>
 #	include <AnKi/Shaders/LightFunctions.hlsl>
+#	include <AnKi/Shaders/IndirectDiffuseClipmaps.hlsl>
 #	include <AnKi/Shaders/Include/TraditionalDeferredShadingTypes.h>
 #	include <AnKi/Shaders/Include/GpuSceneTypes.h>
 
@@ -43,6 +46,7 @@ ConstantBuffer<GlobalRendererConstants> g_globalRendererConsts : register(b1);
 #	if INDIRECT_DIFFUSE
 Vec3 getDiffuseIndirect(Vec3 worldPos, Vec3 worldNormal)
 {
+#		if INDIRECT_DIFFUSE == 1
 	const U32 probeCount = getStructuredBufferElementCount(g_giProbes);
 	U32 i;
 	for(i = 0; i < probeCount; ++i)
@@ -63,6 +67,14 @@ Vec3 getDiffuseIndirect(Vec3 worldPos, Vec3 worldNormal)
 	{
 		return 0.0;
 	}
+#		else
+	constexpr SampleClipmapFlag flags =
+		kSampleClipmapFlagBackfacingProbeRejection | kSampleClipmapFlagBiasSamplePointSurfaceNormal | kSampleClipmapFlagUsePreviousFrame;
+	const IndirectDiffuseClipmapConstants idConsts = g_globalRendererConsts.m_indirectDiffuseClipmaps;
+	const Vec3 irradiance =
+		sampleClipmapIrradiance(worldPos, worldNormal, g_globalRendererConsts.m_cameraPosition, idConsts, g_linearAnyClampSampler, flags);
+	return irradiance;
+#		endif
 }
 #	endif
 
@@ -99,12 +111,12 @@ Vec4 main(VertOut input) : SV_TARGET0
 	if(g_globalRendererConsts.m_directionalLight.m_active)
 	{
 		const F32 dist = length(g_consts.m_cameraPos - worldPos);
-		RF32 shadowFactor;
+		F32 shadowFactor;
 		if(dist < g_consts.m_dirLight.m_effectiveShadowDistance)
 		{
 			// Acceptable distance
 
-			shadowFactor = computeShadowFactorDirLight<RF32>(g_consts.m_dirLight.m_lightMatrix, worldPos, g_shadowMap, g_shadowMapSampler);
+			shadowFactor = computeShadowFactorDirLight<F32>(g_consts.m_dirLight.m_lightMatrix, worldPos, g_shadowMap, g_shadowMapSampler);
 		}
 		else
 		{
@@ -112,8 +124,8 @@ Vec4 main(VertOut input) : SV_TARGET0
 		}
 
 		const Vec3 l = -g_globalRendererConsts.m_directionalLight.m_direction;
-		const RF32 lambert = dot(l, gbuffer.m_normal);
-		const RF32 factor = shadowFactor * max(gbuffer.m_subsurface, lambert);
+		const F32 lambert = dot(l, gbuffer.m_normal);
+		const F32 factor = shadowFactor * max(gbuffer.m_subsurface, lambert);
 
 #	if SPECULAR == 1
 		const Vec3 specC = specularIsotropicLobe(gbuffer.m_normal, gbuffer.m_f0, gbuffer.m_roughness, viewDir, l);
@@ -136,7 +148,7 @@ Vec4 main(VertOut input) : SV_TARGET0
 		const F32 att = computeAttenuationFactor<F32>(light.m_radius, frag2Light);
 		const F32 lambert = nol;
 		const F32 spot = ((U32)light.m_flags & (U32)GpuSceneLightFlag::kSpotLight)
-							 ? computeSpotFactor<RF32>(l, light.m_outerCos, light.m_innerCos, light.m_direction)
+							 ? computeSpotFactor<F32>(l, light.m_outerCos, light.m_innerCos, light.m_direction)
 							 : 1.0f;
 		const F32 factor = att * spot * max(lambert, gbuffer.m_subsurface);