Browse Source

Add refl probe visualization as well

Panagiotis Christopoulos Charitos 1 year ago
parent
commit
0af88a15de

+ 40 - 2
AnKi/Renderer/GBuffer.cpp

@@ -15,6 +15,7 @@
 #include <AnKi/Core/CVarSet.h>
 #include <AnKi/Core/App.h>
 #include <AnKi/Scene/Components/GlobalIlluminationProbeComponent.h>
+#include <AnKi/Scene/Components/ReflectionProbeComponent.h>
 
 namespace anki {
 
@@ -22,6 +23,7 @@ static NumericCVar<U32> g_hzbWidthCVar(CVarSubsystem::kRenderer, "HzbWidth", 512
 static NumericCVar<U32> g_hzbHeightCVar(CVarSubsystem::kRenderer, "HzbHeight", 256, 16, 4 * 1024, "HZB map height");
 static BoolCVar g_gbufferVrsCVar(CVarSubsystem::kRenderer, "GBufferVrs", false, "Enable VRS in GBuffer");
 static BoolCVar g_visualizeGiProbes(CVarSubsystem::kRenderer, "VisualizeGiProbes", false, "Visualize GI probes");
+static BoolCVar g_visualizeReflectionProbes(CVarSubsystem::kRenderer, "VisualizeReflProbes", false, "Visualize reflection probes");
 
 GBuffer::~GBuffer()
 {
@@ -75,7 +77,10 @@ Error GBuffer::initInternal()
 	}
 
 	ANKI_CHECK(loadShaderProgram("ShaderBinaries/VisualizeGBufferNormal.ankiprogbin", m_visNormalProg, m_visNormalGrProg));
-	ANKI_CHECK(loadShaderProgram("ShaderBinaries/GBufferVisualizeGiProbe.ankiprogbin", m_visualizeGiProbeProg, m_visualizeGiProbeGrProg));
+	ANKI_CHECK(
+		loadShaderProgram("ShaderBinaries/GBufferVisualizeProbe.ankiprogbin", {{"PROBE_TYPE", 0}}, m_visualizeProbeProg, m_visualizeGiProbeGrProg));
+	ANKI_CHECK(
+		loadShaderProgram("ShaderBinaries/GBufferVisualizeProbe.ankiprogbin", {{"PROBE_TYPE", 1}}, m_visualizeProbeProg, m_visualizeReflProbeGrProg));
 
 	return Error::kNone;
 }
@@ -205,7 +210,6 @@ void GBuffer::populateRenderGraph(RenderingContext& ctx)
 			if(g_visualizeGiProbes.get())
 			{
 				cmdb.bindShaderProgram(m_visualizeGiProbeGrProg.get());
-
 				cmdb.bindSrv(0, 0, GpuSceneArrays::GlobalIlluminationProbe::getSingleton().getBufferView());
 
 				for(const auto& probe : SceneGraph::getSingleton().getComponentArrays().getGlobalIlluminationProbes())
@@ -235,6 +239,40 @@ void GBuffer::populateRenderGraph(RenderingContext& ctx)
 					cmdb.draw(PrimitiveTopology::kTriangles, 6, probe.getCellCount());
 				}
 			}
+
+			// Visualize refl probes
+			if(g_visualizeReflectionProbes.get())
+			{
+				cmdb.bindShaderProgram(m_visualizeReflProbeGrProg.get());
+				cmdb.bindSrv(0, 0, GpuSceneArrays::ReflectionProbe::getSingleton().getBufferView());
+
+				for(const auto& probe : SceneGraph::getSingleton().getComponentArrays().getReflectionProbes())
+				{
+					struct Consts
+					{
+						Mat4 m_viewProjMat;
+						Mat4 m_invViewProjMat;
+
+						Vec2 m_viewportSize;
+						U32 m_probeIdx;
+						F32 m_sphereRadius;
+
+						Vec3 m_cameraPos;
+						F32 m_padding;
+					};
+
+					Consts* consts = allocateAndBindConstants<Consts>(cmdb, 0, 0);
+
+					consts->m_viewProjMat = ctx.m_matrices.m_viewProjectionJitter;
+					consts->m_invViewProjMat = ctx.m_matrices.m_invertedViewProjectionJitter;
+					consts->m_viewportSize = Vec2(getRenderer().getInternalResolution());
+					consts->m_probeIdx = probe.getGpuSceneAllocation().getIndex();
+					consts->m_sphereRadius = 0.5f;
+					consts->m_cameraPos = ctx.m_matrices.m_cameraTransform.getTranslationPart().xyz();
+
+					cmdb.draw(PrimitiveTopology::kTriangles, 6);
+				}
+			}
 		});
 	};
 

+ 2 - 1
AnKi/Renderer/GBuffer.h

@@ -72,8 +72,9 @@ private:
 	ShaderProgramResourcePtr m_visNormalProg;
 	ShaderProgramPtr m_visNormalGrProg;
 
-	ShaderProgramResourcePtr m_visualizeGiProbeProg;
+	ShaderProgramResourcePtr m_visualizeProbeProg;
 	ShaderProgramPtr m_visualizeGiProbeGrProg;
+	ShaderProgramPtr m_visualizeReflProbeGrProg;
 
 	class
 	{

+ 5 - 0
AnKi/Scene/Components/ReflectionProbeComponent.h

@@ -72,6 +72,11 @@ public:
 		return *m_reflectionTex;
 	}
 
+	const GpuSceneArrays::ReflectionProbe::Allocation& getGpuSceneAllocation() const
+	{
+		return m_gpuSceneProbe;
+	}
+
 private:
 	Vec3 m_worldPos = Vec3(kMaxF32);
 	Vec3 m_halfSize = Vec3(1.0f);

+ 23 - 8
AnKi/Shaders/GBufferVisualizeGiProbe.ankiprog → AnKi/Shaders/GBufferVisualizeProbe.ankiprog

@@ -3,12 +3,18 @@
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 
+#pragma anki mutator PROBE_TYPE 0 1
+
 #include <AnKi/Shaders/Functions.hlsl>
 #include <AnKi/Shaders/PackFunctions.hlsl>
 #include <AnKi/Shaders/VisibilityAndCollisionFunctions.hlsl>
 #include <AnKi/Shaders/Include/GpuSceneTypes.h>
 
-StructuredBuffer<GpuSceneGlobalIlluminationProbe> g_giProbes : register(t0);
+#if PROBE_TYPE == 0
+StructuredBuffer<GpuSceneGlobalIlluminationProbe> g_probes : register(t0);
+#else
+StructuredBuffer<GpuSceneReflectionProbe> g_probes : register(t0);
+#endif
 
 struct Consts
 {
@@ -59,8 +65,13 @@ UVec3 getCellCount(GpuSceneGlobalIlluminationProbe probe)
 
 VertOut main(VertIn input)
 {
-	const GpuSceneGlobalIlluminationProbe probe = SBUFF(g_giProbes, g_consts.m_probeIdx);
+#if PROBE_TYPE == 0
+	const GpuSceneGlobalIlluminationProbe probe = SBUFF(g_probes, g_consts.m_probeIdx);
+#else
+	const GpuSceneReflectionProbe probe = SBUFF(g_probes, g_consts.m_probeIdx);
+#endif
 
+#if PROBE_TYPE == 0
 	// Compute the cell ID
 	const U32 cellIdx = input.m_svInstanceId;
 	const UVec3 cellCount = getCellCount(probe);
@@ -72,9 +83,13 @@ VertOut main(VertIn input)
 	const Vec3 cellSize = (probe.m_aabbMax - probe.m_aabbMin) / Vec3(cellCount);
 
 	const Vec3 cellCenter = cellSize * Vec3(cellId) + probe.m_aabbMin + cellSize / 2.0;
+	const Vec3 sphereCenter = cellCenter;
+#else
+	const Vec3 sphereCenter = probe.m_position;
+#endif
 
-	const Vec3 sphereMin = cellCenter - g_consts.m_sphereRadius;
-	const Vec3 sphereMax = cellCenter + g_consts.m_sphereRadius;
+	const Vec3 sphereMin = sphereCenter - g_consts.m_sphereRadius;
+	const Vec3 sphereMax = sphereCenter + g_consts.m_sphereRadius;
 
 	Vec3 sphereAabbPoints[8];
 	sphereAabbPoints[0] = Vec3(sphereMin.x, sphereMin.y, sphereMax.z);
@@ -104,7 +119,7 @@ VertOut main(VertIn input)
 	output.m_svPosition.z = 0.0;
 	output.m_svPosition.w = 1.0;
 
-	output.m_sphereCenter = cellCenter;
+	output.m_sphereCenter = sphereCenter;
 
 	return output;
 }
@@ -140,13 +155,13 @@ PixelOut main(VertOut input)
 
 	// Set the GBuffer
 	GbufferInfo g;
-	g.m_diffuse = 0.5;
+	g.m_diffuse = (PROBE_TYPE == 0) ? 0.5 : 1.0;
 	g.m_normal = normalize(collisionPoint - input.m_sphereCenter);
 	g.m_f0 = 0.04;
-	g.m_roughness = 1.0;
+	g.m_roughness = (PROBE_TYPE == 0) ? 1.0 : 0.0;
 	g.m_subsurface = 0.0;
 	g.m_emission = 0.0;
-	g.m_metallic = 0.0;
+	g.m_metallic = (PROBE_TYPE == 0) ? 0.0 : 1.0;
 	g.m_velocity = 1.0;
 
 	packGBuffer(g, output.m_color0, output.m_color1, output.m_color2, output.m_color3);