瀏覽代碼

Move SSAO reading to indirect

Panagiotis Christopoulos Charitos 7 年之前
父節點
當前提交
d5a23013f7

+ 1 - 6
programs/GBufferPost.ankiprog

@@ -44,13 +44,12 @@ void main()
 #define LIGHT_SET 0
 #define LIGHT_SET 0
 #define LIGHT_SS_BINDING 0
 #define LIGHT_SS_BINDING 0
 #define LIGHT_UBO_BINDING 0
 #define LIGHT_UBO_BINDING 0
-#define LIGHT_TEX_BINDING 2
+#define LIGHT_TEX_BINDING 1
 #define LIGHT_DECALS
 #define LIGHT_DECALS
 #define LIGHT_COMMON_UNIS
 #define LIGHT_COMMON_UNIS
 #include "shaders/ClusterLightCommon.glsl"
 #include "shaders/ClusterLightCommon.glsl"
 
 
 layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2D u_msDepthRt;
 layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2D u_msDepthRt;
-layout(ANKI_TEX_BINDING(0, 1)) uniform sampler2D u_ssaoTex;
 
 
 layout(location = 0) in vec2 in_uv;
 layout(location = 0) in vec2 in_uv;
 layout(location = 1) in vec2 in_clusterIJ;
 layout(location = 1) in vec2 in_clusterIJ;
@@ -70,10 +69,6 @@ void main()
 	vec4 outDiffuse = vec4(0.0, 0.0, 0.0, 1.0);
 	vec4 outDiffuse = vec4(0.0, 0.0, 0.0, 1.0);
 	vec4 outSpecular = vec4(0.0, 0.0, 0.0, 1.0);
 	vec4 outSpecular = vec4(0.0, 0.0, 0.0, 1.0);
 
 
-	// Sample SSAO
-	float ssao = textureLod(u_ssaoTex, in_uv, 0.0).r;
-	outDiffuse.a *= ssao;
-
 	// Get worldPos
 	// Get worldPos
 	float depth = textureLod(u_msDepthRt, in_uv, 0.0).r;
 	float depth = textureLod(u_msDepthRt, in_uv, 0.0).r;
 	vec2 ndc = UV_TO_NDC(in_uv);
 	vec2 ndc = UV_TO_NDC(in_uv);

+ 6 - 1
programs/Reflections.ankiprog

@@ -38,7 +38,7 @@ http://www.anki3d.org/LICENSE
 #define LIGHT_SET 0
 #define LIGHT_SET 0
 #define LIGHT_SS_BINDING 0
 #define LIGHT_SS_BINDING 0
 #define LIGHT_UBO_BINDING 0
 #define LIGHT_UBO_BINDING 0
-#define LIGHT_TEX_BINDING 6
+#define LIGHT_TEX_BINDING 7
 #define LIGHT_INDIRECT
 #define LIGHT_INDIRECT
 #define LIGHT_COMMON_UNIS
 #define LIGHT_COMMON_UNIS
 #include "shaders/ClusterLightCommon.glsl"
 #include "shaders/ClusterLightCommon.glsl"
@@ -53,6 +53,7 @@ layout(ANKI_TEX_BINDING(0, 2)) uniform sampler2D u_gbufferRt2;
 layout(ANKI_TEX_BINDING(0, 3)) uniform sampler2D u_depthRt;
 layout(ANKI_TEX_BINDING(0, 3)) uniform sampler2D u_depthRt;
 layout(ANKI_TEX_BINDING(0, 4)) uniform sampler2D u_hizRt;
 layout(ANKI_TEX_BINDING(0, 4)) uniform sampler2D u_hizRt;
 layout(ANKI_TEX_BINDING(0, 5)) uniform sampler2D u_lightBufferRt;
 layout(ANKI_TEX_BINDING(0, 5)) uniform sampler2D u_lightBufferRt;
+layout(ANKI_TEX_BINDING(0, 6)) uniform sampler2D u_ssaoTex;
 
 
 layout(ANKI_IMAGE_BINDING(0, 0)) writeonly uniform image2D out_reflAndIndirect;
 layout(ANKI_IMAGE_BINDING(0, 0)) writeonly uniform image2D out_reflAndIndirect;
 
 
@@ -310,6 +311,10 @@ void main()
 		outColor += finalRefl;
 		outColor += finalRefl;
 	}
 	}
 
 
+	// Apply SSAO
+	float ssao = textureLod(u_ssaoTex, uv, 0.0).r;
+	outColor *= ssao;
+
 	// Store the color for the resolve
 	// Store the color for the resolve
 	s_pixels[gl_LocalInvocationID.y][gl_LocalInvocationID.x] = outColor;
 	s_pixels[gl_LocalInvocationID.y][gl_LocalInvocationID.x] = outColor;
 
 

+ 2 - 6
src/anki/renderer/GBufferPost.cpp

@@ -6,7 +6,6 @@
 #include <anki/renderer/GBufferPost.h>
 #include <anki/renderer/GBufferPost.h>
 #include <anki/renderer/Renderer.h>
 #include <anki/renderer/Renderer.h>
 #include <anki/renderer/GBuffer.h>
 #include <anki/renderer/GBuffer.h>
-#include <anki/renderer/Ssao.h>
 #include <anki/renderer/LightShading.h>
 #include <anki/renderer/LightShading.h>
 #include <anki/misc/ConfigSet.h>
 #include <anki/misc/ConfigSet.h>
 
 
@@ -69,8 +68,6 @@ void GBufferPost::populateRenderGraph(RenderingContext& ctx)
 		TextureUsageBit::SAMPLED_FRAGMENT,
 		TextureUsageBit::SAMPLED_FRAGMENT,
 		TextureSubresourceInfo(DepthStencilAspectBit::DEPTH)});
 		TextureSubresourceInfo(DepthStencilAspectBit::DEPTH)});
 
 
-	rpass.newConsumer({m_r->getSsao().getRt(), TextureUsageBit::SAMPLED_FRAGMENT});
-
 	rpass.newProducer({m_r->getGBuffer().getColorRt(0), TextureUsageBit::FRAMEBUFFER_ATTACHMENT_READ_WRITE});
 	rpass.newProducer({m_r->getGBuffer().getColorRt(0), TextureUsageBit::FRAMEBUFFER_ATTACHMENT_READ_WRITE});
 	rpass.newProducer({m_r->getGBuffer().getColorRt(1), TextureUsageBit::FRAMEBUFFER_ATTACHMENT_READ_WRITE});
 	rpass.newProducer({m_r->getGBuffer().getColorRt(1), TextureUsageBit::FRAMEBUFFER_ATTACHMENT_READ_WRITE});
 }
 }
@@ -92,14 +89,13 @@ void GBufferPost::run(RenderPassWorkContext& rgraphCtx)
 		m_r->getGBuffer().getDepthRt(),
 		m_r->getGBuffer().getDepthRt(),
 		TextureSubresourceInfo(DepthStencilAspectBit::DEPTH),
 		TextureSubresourceInfo(DepthStencilAspectBit::DEPTH),
 		m_r->getNearestSampler());
 		m_r->getNearestSampler());
-	rgraphCtx.bindColorTextureAndSampler(0, 1, m_r->getSsao().getRt(), m_r->getLinearSampler());
 	cmdb->bindTextureAndSampler(0,
 	cmdb->bindTextureAndSampler(0,
-		2,
+		1,
 		(rsrc.m_diffDecalTexView) ? rsrc.m_diffDecalTexView : m_r->getDummyTextureView(),
 		(rsrc.m_diffDecalTexView) ? rsrc.m_diffDecalTexView : m_r->getDummyTextureView(),
 		m_r->getTrilinearRepeatSampler(),
 		m_r->getTrilinearRepeatSampler(),
 		TextureUsageBit::SAMPLED_FRAGMENT);
 		TextureUsageBit::SAMPLED_FRAGMENT);
 	cmdb->bindTextureAndSampler(0,
 	cmdb->bindTextureAndSampler(0,
-		3,
+		2,
 		(rsrc.m_specularRoughnessDecalTexView) ? rsrc.m_specularRoughnessDecalTexView : m_r->getDummyTextureView(),
 		(rsrc.m_specularRoughnessDecalTexView) ? rsrc.m_specularRoughnessDecalTexView : m_r->getDummyTextureView(),
 		m_r->getTrilinearRepeatSampler(),
 		m_r->getTrilinearRepeatSampler(),
 		TextureUsageBit::SAMPLED_FRAGMENT);
 		TextureUsageBit::SAMPLED_FRAGMENT);

+ 7 - 3
src/anki/renderer/Reflections.cpp

@@ -7,6 +7,7 @@
 #include <anki/renderer/Renderer.h>
 #include <anki/renderer/Renderer.h>
 #include <anki/renderer/GBuffer.h>
 #include <anki/renderer/GBuffer.h>
 #include <anki/renderer/Indirect.h>
 #include <anki/renderer/Indirect.h>
+#include <anki/renderer/Ssao.h>
 #include <anki/renderer/DepthDownscale.h>
 #include <anki/renderer/DepthDownscale.h>
 #include <anki/renderer/DownscaleBlur.h>
 #include <anki/renderer/DownscaleBlur.h>
 #include <anki/renderer/RenderQueue.h>
 #include <anki/renderer/RenderQueue.h>
@@ -91,6 +92,7 @@ void Reflections::populateRenderGraph(RenderingContext& ctx)
 	rpass.newConsumer({m_r->getGBuffer().getDepthRt(), TextureUsageBit::SAMPLED_COMPUTE});
 	rpass.newConsumer({m_r->getGBuffer().getDepthRt(), TextureUsageBit::SAMPLED_COMPUTE});
 	rpass.newConsumer({m_r->getDepthDownscale().getHiZRt(), TextureUsageBit::SAMPLED_COMPUTE});
 	rpass.newConsumer({m_r->getDepthDownscale().getHiZRt(), TextureUsageBit::SAMPLED_COMPUTE});
 	rpass.newConsumer({m_r->getDownscaleBlur().getRt(), TextureUsageBit::SAMPLED_COMPUTE});
 	rpass.newConsumer({m_r->getDownscaleBlur().getRt(), TextureUsageBit::SAMPLED_COMPUTE});
+	rpass.newConsumer({m_r->getSsao().getRt(), TextureUsageBit::SAMPLED_FRAGMENT});
 
 
 	rpass.newConsumer({m_r->getIndirect().getReflectionRt(), TextureUsageBit::SAMPLED_COMPUTE});
 	rpass.newConsumer({m_r->getIndirect().getReflectionRt(), TextureUsageBit::SAMPLED_COMPUTE});
 	rpass.newConsumer({m_r->getIndirect().getIrradianceRt(), TextureUsageBit::SAMPLED_COMPUTE});
 	rpass.newConsumer({m_r->getIndirect().getIrradianceRt(), TextureUsageBit::SAMPLED_COMPUTE});
@@ -115,10 +117,12 @@ void Reflections::run(RenderPassWorkContext& rgraphCtx)
 	rgraphCtx.bindColorTextureAndSampler(0, 4, m_r->getDepthDownscale().getHiZRt(), m_r->getNearestNearestSampler());
 	rgraphCtx.bindColorTextureAndSampler(0, 4, m_r->getDepthDownscale().getHiZRt(), m_r->getNearestNearestSampler());
 	rgraphCtx.bindColorTextureAndSampler(0, 5, m_r->getDownscaleBlur().getRt(), m_r->getTrilinearRepeatSampler());
 	rgraphCtx.bindColorTextureAndSampler(0, 5, m_r->getDownscaleBlur().getRt(), m_r->getTrilinearRepeatSampler());
 
 
-	rgraphCtx.bindColorTextureAndSampler(0, 6, m_r->getIndirect().getReflectionRt(), m_r->getTrilinearRepeatSampler());
-	rgraphCtx.bindColorTextureAndSampler(0, 7, m_r->getIndirect().getIrradianceRt(), m_r->getTrilinearRepeatSampler());
+	rgraphCtx.bindColorTextureAndSampler(0, 6, m_r->getSsao().getRt(), m_r->getLinearSampler());
+
+	rgraphCtx.bindColorTextureAndSampler(0, 7, m_r->getIndirect().getReflectionRt(), m_r->getTrilinearRepeatSampler());
+	rgraphCtx.bindColorTextureAndSampler(0, 8, m_r->getIndirect().getIrradianceRt(), m_r->getTrilinearRepeatSampler());
 	cmdb->bindTextureAndSampler(0,
 	cmdb->bindTextureAndSampler(0,
-		8,
+		9,
 		m_r->getIndirect().getIntegrationLut(),
 		m_r->getIndirect().getIntegrationLut(),
 		m_r->getIndirect().getIntegrationLutSampler(),
 		m_r->getIndirect().getIntegrationLutSampler(),
 		TextureUsageBit::SAMPLED_COMPUTE);
 		TextureUsageBit::SAMPLED_COMPUTE);