Browse Source

Add more code

Panagiotis Christopoulos Charitos 5 years ago
parent
commit
6f72b76ee1
3 changed files with 38 additions and 3 deletions
  1. 20 2
      shaders/Ssgi.ankiprog
  2. 1 0
      shaders/glsl_cpp_common/Ssgi.h
  3. 17 1
      src/anki/renderer/Ssgi.cpp

+ 20 - 2
shaders/Ssgi.ankiprog

@@ -14,6 +14,7 @@
 #pragma anki start comp
 #include <shaders/SsRaymarching.glsl>
 #include <shaders/Functions.glsl>
+#include <shaders/Pack.glsl>
 #include <shaders/glsl_cpp_common/Ssgi.h>
 
 const UVec2 WORKGROUP_SIZE = UVec2(16, 16);
@@ -21,11 +22,19 @@ layout(local_size_x = WORKGROUP_SIZE.x, local_size_y = WORKGROUP_SIZE.y, local_s
 
 layout(set = 0, binding = 0, rgba16f) uniform image2D out_img;
 
-layout(set = 0, binding = 1, row_major) uniform u_
+layout(set = 0, binding = 1, row_major, std140) uniform u_
 {
 	SsgiUniforms u_unis;
 };
 
+layout(set = 0, binding = 2) uniform sampler u_trilinearClampSampler;
+layout(set = 0, binding = 3) uniform texture2D u_gbufferRt2;
+layout(set = 0, binding = 4) uniform texture2D u_depthRt;
+layout(set = 0, binding = 5) uniform texture2D u_lightBufferRt;
+
+layout(set = 0, binding = 6) uniform sampler u_trilinearRepeatSampler;
+layout(set = 0, binding = 7) uniform texture2D u_noiseTex;
+
 void main()
 {
 	// Compute a global invocation ID that takes the checkerboard pattern into account
@@ -45,7 +54,16 @@ void main()
 
 	const Vec2 uv = (Vec2(fixedInvocationId.xy) + 0.5) / Vec2(u_unis.m_framebufferSize);
 
-	imageStore(out_img, fixedInvocationId, Vec4(uv, 1, 0));
+	const Vec3 worldNormal = readNormalFromGBuffer(u_gbufferRt2, u_trilinearClampSampler, uv);
+
+	// Get depth
+	const F32 depth = textureLod(u_depthRt, u_trilinearClampSampler, uv, 0.0).r;
+
+	// Get view pos
+	const Vec4 viewPos4 = u_unis.m_invProjMat * Vec4(UV_TO_NDC(uv), depth, 1.0);
+	const Vec3 viewPos = viewPos4.xyz / viewPos4.w;
+
+	imageStore(out_img, fixedInvocationId, Vec4(worldNormal, depth));
 }
 
 #pragma anki end

+ 1 - 0
shaders/glsl_cpp_common/Ssgi.h

@@ -14,6 +14,7 @@ struct SsgiUniforms
 {
 	UVec2 m_depthBufferSize;
 	UVec2 m_framebufferSize;
+	Mat4 m_invProjMat;
 };
 
 ANKI_END_NAMESPACE

+ 17 - 1
src/anki/renderer/Ssgi.cpp

@@ -6,6 +6,8 @@
 #include <anki/renderer/Ssgi.h>
 #include <anki/renderer/Renderer.h>
 #include <anki/renderer/DepthDownscale.h>
+#include <anki/renderer/GBuffer.h>
+#include <anki/renderer/DownscaleBlur.h>
 #include <anki/core/ConfigSet.h>
 #include <shaders/glsl_cpp_common/Ssgi.h>
 
@@ -84,7 +86,7 @@ void Ssgi::populateRenderGraph(RenderingContext& ctx)
 
 void Ssgi::run(RenderPassWorkContext& rgraphCtx)
 {
-	// RenderingContext& ctx = *m_runCtx.m_ctx;
+	RenderingContext& ctx = *m_runCtx.m_ctx;
 	CommandBufferPtr& cmdb = rgraphCtx.m_commandBuffer;
 	cmdb->bindShaderProgram(m_main.m_grProg[m_r->getFrameCount() & 1u]);
 
@@ -94,6 +96,20 @@ void Ssgi::run(RenderPassWorkContext& rgraphCtx)
 	SsgiUniforms* unis = allocateAndBindUniforms<SsgiUniforms*>(sizeof(SsgiUniforms), cmdb, 0, 1);
 	unis->m_depthBufferSize = UVec2(m_r->getWidth(), m_r->getHeight()) >> (m_main.m_depthLod + 1);
 	unis->m_framebufferSize = UVec2(m_r->getWidth(), m_r->getHeight());
+	unis->m_invProjMat = ctx.m_matrices.m_projectionJitter.getInverse();
+
+	cmdb->bindSampler(0, 2, m_r->getSamplers().m_trilinearClamp);
+
+	rgraphCtx.bindColorTexture(0, 3, m_r->getGBuffer().getColorRt(2));
+
+	TextureSubresourceInfo hizSubresource;
+	hizSubresource.m_firstMipmap = m_main.m_depthLod;
+	rgraphCtx.bindTexture(0, 4, m_r->getDepthDownscale().getHiZRt(), hizSubresource);
+
+	rgraphCtx.bindColorTexture(0, 5, m_r->getDownscaleBlur().getRt());
+
+	cmdb->bindSampler(0, 6, m_r->getSamplers().m_trilinearRepeat);
+	cmdb->bindTexture(0, 7, m_main.m_noiseTex->getGrTextureView(), TextureUsageBit::SAMPLED_ALL);
 
 	// Dispatch
 	dispatchPPCompute(cmdb, 16, 16, m_r->getWidth() / 2, m_r->getHeight());