|
|
@@ -10,6 +10,7 @@
|
|
|
#pragma anki input const UVec3 VOLUME_SIZE
|
|
|
#pragma anki input const UVec3 CLUSTER_COUNT
|
|
|
#pragma anki input const U32 FINAL_CLUSTER_Z
|
|
|
+#pragma anki input const UVec3 FRACTION
|
|
|
#pragma anki input const UVec3 WORKGROUP_SIZE
|
|
|
#pragma anki input const UVec3 NOISE_TEX_SIZE
|
|
|
|
|
|
@@ -17,7 +18,7 @@
|
|
|
|
|
|
layout(local_size_x = WORKGROUP_SIZE.x, local_size_y = WORKGROUP_SIZE.y, local_size_z = WORKGROUP_SIZE.z) in;
|
|
|
|
|
|
-layout(ANKI_IMAGE_BINDING(0, 0)) writeonly uniform image3D out_volume;
|
|
|
+layout(ANKI_IMAGE_BINDING(0, 0), r11f_g11f_b10f) uniform image3D out_volume;
|
|
|
layout(ANKI_TEX_BINDING(0, 0)) uniform sampler3D u_noiseTex;
|
|
|
|
|
|
struct PushConsts
|
|
|
@@ -36,7 +37,6 @@ ANKI_PUSH_CONSTANTS(PushConsts, u_regs);
|
|
|
#define LIGHT_COMMON_UNIS
|
|
|
#include <shaders/ClusteredShadingCommon.glsl>
|
|
|
|
|
|
-const UVec3 FRACTION = UVec3(VOLUME_SIZE.xy / CLUSTER_COUNT.xy, VOLUME_SIZE.z / (FINAL_CLUSTER_Z + 1));
|
|
|
Vec3 g_globalInvocationID = Vec3(gl_GlobalInvocationID);
|
|
|
|
|
|
Vec3 readRand()
|
|
|
@@ -52,13 +52,12 @@ Vec3 randWPos()
|
|
|
Vec3 rand = readRand();
|
|
|
|
|
|
// Compute the cluster Z as float
|
|
|
- F32 clusterK = g_globalInvocationID.z * (F32(FINAL_CLUSTER_Z + 1u) / F32(VOLUME_SIZE.z));
|
|
|
- F32 clusterK_1 = (g_globalInvocationID.z + 1.0) * (F32(FINAL_CLUSTER_Z + 1u) / F32(VOLUME_SIZE.z));
|
|
|
+ F32 clusterKNear = g_globalInvocationID.z * (F32(FINAL_CLUSTER_Z + 1u) / F32(VOLUME_SIZE.z));
|
|
|
+ F32 clusterKFar = (g_globalInvocationID.z + 1.0) * (F32(FINAL_CLUSTER_Z + 1u) / F32(VOLUME_SIZE.z));
|
|
|
+ F32 clusterK = mix(clusterKNear, clusterKFar, rand.z);
|
|
|
|
|
|
// Get a Z value
|
|
|
- F32 zVSpaceNear = computeClusterNearf(u_clustererMagic, clusterK);
|
|
|
- F32 zVSpaceFar = computeClusterNearf(u_clustererMagic, clusterK_1);
|
|
|
- F32 zVSpace = -mix(zVSpaceNear, zVSpaceFar, rand.z);
|
|
|
+ F32 zVSpace = -computeClusterNearf(u_clustererMagic, clusterK);
|
|
|
|
|
|
// Get a XY value
|
|
|
Vec2 uvMin = g_globalInvocationID.xy / Vec2(VOLUME_SIZE.xy);
|
|
|
@@ -143,16 +142,20 @@ void main()
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ // Find the cluster
|
|
|
+ UVec3 clusterXYZ = gl_GlobalInvocationID / FRACTION;
|
|
|
+ U32 clusterIdx = clusterXYZ.z * (CLUSTER_COUNT.x * CLUSTER_COUNT.y) + clusterXYZ.y * CLUSTER_COUNT.x + clusterXYZ.x;
|
|
|
+
|
|
|
// Find a random pos inside the cluster
|
|
|
Vec3 worldPos = randWPos();
|
|
|
|
|
|
- // Find the cluster
|
|
|
- UVec3 clusterXYZ = gl_GlobalInvocationID / CLUSTER_COUNT;
|
|
|
- U32 clusterIdx = clusterXYZ.z * (CLUSTER_COUNT.x * CLUSTER_COUNT.y) * clusterXYZ.y * CLUSTER_COUNT.x + clusterXYZ.x;
|
|
|
-
|
|
|
// Get lighting
|
|
|
Vec3 color = accumulateLights(clusterIdx, worldPos);
|
|
|
|
|
|
+ // Read the prev result
|
|
|
+ Vec3 prev = imageLoad(out_volume, IVec3(gl_GlobalInvocationID)).rgb;
|
|
|
+ color = mix(prev, color, 1.0 / 16.0);
|
|
|
+
|
|
|
// Write result
|
|
|
imageStore(out_volume, IVec3(gl_GlobalInvocationID), Vec4(color, 0.0));
|
|
|
}
|