|
@@ -15,6 +15,7 @@
|
|
|
#include <shaders/SsRaymarching.glsl>
|
|
#include <shaders/SsRaymarching.glsl>
|
|
|
#include <shaders/Functions.glsl>
|
|
#include <shaders/Functions.glsl>
|
|
|
#include <shaders/Pack.glsl>
|
|
#include <shaders/Pack.glsl>
|
|
|
|
|
+#include <shaders/ImportanceSampling.glsl>
|
|
|
#include <shaders/glsl_cpp_common/Ssgi.h>
|
|
#include <shaders/glsl_cpp_common/Ssgi.h>
|
|
|
|
|
|
|
|
const UVec2 WORKGROUP_SIZE = UVec2(16, 16);
|
|
const UVec2 WORKGROUP_SIZE = UVec2(16, 16);
|
|
@@ -32,9 +33,6 @@ layout(set = 0, binding = 3) uniform texture2D u_gbufferRt2;
|
|
|
layout(set = 0, binding = 4) uniform texture2D u_depthRt;
|
|
layout(set = 0, binding = 4) uniform texture2D u_depthRt;
|
|
|
layout(set = 0, binding = 5) uniform texture2D u_lightBufferRt;
|
|
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()
|
|
void main()
|
|
|
{
|
|
{
|
|
|
// Compute a global invocation ID that takes the checkerboard pattern into account
|
|
// Compute a global invocation ID that takes the checkerboard pattern into account
|
|
@@ -54,16 +52,67 @@ void main()
|
|
|
|
|
|
|
|
const Vec2 uv = (Vec2(fixedInvocationId.xy) + 0.5) / Vec2(u_unis.m_framebufferSize);
|
|
const Vec2 uv = (Vec2(fixedInvocationId.xy) + 0.5) / Vec2(u_unis.m_framebufferSize);
|
|
|
|
|
|
|
|
|
|
+ // Get normal
|
|
|
const Vec3 worldNormal = readNormalFromGBuffer(u_gbufferRt2, u_trilinearClampSampler, uv);
|
|
const Vec3 worldNormal = readNormalFromGBuffer(u_gbufferRt2, u_trilinearClampSampler, uv);
|
|
|
|
|
|
|
|
// Get depth
|
|
// Get depth
|
|
|
const F32 depth = textureLod(u_depthRt, u_trilinearClampSampler, uv, 0.0).r;
|
|
const F32 depth = textureLod(u_depthRt, u_trilinearClampSampler, uv, 0.0).r;
|
|
|
|
|
|
|
|
- // Get view pos
|
|
|
|
|
|
|
+ // Compute view pos
|
|
|
const Vec4 viewPos4 = u_unis.m_invProjMat * Vec4(UV_TO_NDC(uv), depth, 1.0);
|
|
const Vec4 viewPos4 = u_unis.m_invProjMat * Vec4(UV_TO_NDC(uv), depth, 1.0);
|
|
|
const Vec3 viewPos = viewPos4.xyz / viewPos4.w;
|
|
const Vec3 viewPos = viewPos4.xyz / viewPos4.w;
|
|
|
|
|
|
|
|
- imageStore(out_img, fixedInvocationId, Vec4(worldNormal, depth));
|
|
|
|
|
|
|
+ // Get a random point inside the hemisphere
|
|
|
|
|
+ const UVec2 random = rand3DPCG16(UVec3(fixedInvocationId, u_unis.m_frameCount)).xy;
|
|
|
|
|
+ const Vec2 randomCircle = hammersleyRandom16(0, 0xFFFFu, random);
|
|
|
|
|
+ const Vec3 randomHemisphere = rotationFromDirection(worldNormal) * hemisphereSampleUniform(randomCircle);
|
|
|
|
|
+
|
|
|
|
|
+ // Trace
|
|
|
|
|
+ Vec3 hitPoint;
|
|
|
|
|
+ F32 hitAttenuation;
|
|
|
|
|
+ const U32 lod = 0;
|
|
|
|
|
+ const U32 step = 16u;
|
|
|
|
|
+ const F32 stepf = step;
|
|
|
|
|
+ const F32 minStepf = 4.0;
|
|
|
|
|
+ const F32 noise = F32(random.x) * (1.0 / 65536.0);
|
|
|
|
|
+ raymarchGroundTruth(viewPos,
|
|
|
|
|
+ randomHemisphere,
|
|
|
|
|
+ uv,
|
|
|
|
|
+ depth,
|
|
|
|
|
+ u_unis.m_projMat,
|
|
|
|
|
+ u_unis.m_maxSteps,
|
|
|
|
|
+ u_depthRt,
|
|
|
|
|
+ u_trilinearClampSampler,
|
|
|
|
|
+ F32(lod),
|
|
|
|
|
+ u_unis.m_depthBufferSize,
|
|
|
|
|
+ step,
|
|
|
|
|
+ U32((stepf - minStepf) * noise + minStepf),
|
|
|
|
|
+ hitPoint,
|
|
|
|
|
+ hitAttenuation);
|
|
|
|
|
+
|
|
|
|
|
+ // Read the light buffer
|
|
|
|
|
+ Vec4 outColor;
|
|
|
|
|
+ ANKI_BRANCH if(hitAttenuation > 0.0)
|
|
|
|
|
+ {
|
|
|
|
|
+ // Reproject the UV because you are reading the previous frame
|
|
|
|
|
+ const Vec4 v4 = u_unis.m_prevViewProjMatMulInvViewProjMat * Vec4(UV_TO_NDC(hitPoint.xy), hitPoint.z, 1.0);
|
|
|
|
|
+ hitPoint.xy = NDC_TO_UV(v4.xy / v4.w);
|
|
|
|
|
+
|
|
|
|
|
+ // Read the light buffer
|
|
|
|
|
+ outColor.rgb = textureLod(u_lightBufferRt, u_trilinearClampSampler, hitPoint.xy, 0.0).rgb; // TODO lower lod
|
|
|
|
|
+ outColor.rgb = clamp(outColor.rgb, 0.0, FLT_MAX); // Fix the value just in case
|
|
|
|
|
+ outColor.rgb *= hitAttenuation;
|
|
|
|
|
+ outColor.a = 1.0 - hitAttenuation;
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ outColor = Vec4(0.0, 0.0, 0.0, 1.0);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const F32 NoL = dot(randomHemisphere, worldNormal);
|
|
|
|
|
+ outColor.xyz *= NoL;
|
|
|
|
|
+
|
|
|
|
|
+ imageStore(out_img, fixedInvocationId, outColor);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#pragma anki end
|
|
#pragma anki end
|