|
|
@@ -13,27 +13,29 @@
|
|
|
#include <AnKi/Shaders/Pack.glsl>
|
|
|
#include <AnKi/Shaders/RtShadows.glsl>
|
|
|
|
|
|
-#define LIGHT_SET 0
|
|
|
-#define LIGHT_COMMON_UNIS_BINDING 0
|
|
|
-#define LIGHT_LIGHTS_BINDING 1
|
|
|
-#define LIGHT_CLUSTERS_BINDING 4
|
|
|
-#include <AnKi/Shaders/ClusteredShadingCommon.glsl>
|
|
|
-
|
|
|
-layout(set = 0, binding = 6) uniform sampler u_trilinearRepeatSampler; // Used by the hit shaders
|
|
|
-layout(set = 0, binding = 7) uniform uimage2D u_shadowsImage;
|
|
|
-layout(set = 0, binding = 8) uniform utexture2D u_historyShadowsTex;
|
|
|
-layout(set = 0, binding = 9) uniform sampler u_linearAnyClampSampler;
|
|
|
-layout(set = 0, binding = 10) uniform sampler u_nearestAnyClampSampler;
|
|
|
-layout(set = 0, binding = 11) uniform texture2D u_depthRt;
|
|
|
-layout(set = 0, binding = 12) uniform texture2D u_motionVectorsRt;
|
|
|
-layout(set = 0, binding = 13) uniform texture2D u_motionVectorsRejectionRt;
|
|
|
-layout(set = 0, binding = 14) uniform texture2D u_normalRt;
|
|
|
-layout(set = 0, binding = 15) uniform accelerationStructureEXT u_tlas;
|
|
|
-layout(set = 0, binding = 16) uniform texture2D u_prevHistoryLengthTex;
|
|
|
-layout(set = 0, binding = 17) uniform image2D u_historyLengthImage;
|
|
|
-layout(set = 0, binding = 18) uniform texture2D u_prevMomentsTex;
|
|
|
-layout(set = 0, binding = 19) uniform image2D u_momentsImage;
|
|
|
-layout(set = 0, binding = 20) uniform texture2D u_blueNoiseTex;
|
|
|
+#define CLUSTERED_SHADING_SET 0
|
|
|
+#define CLUSTERED_SHADING_UNIFORMS_BINDING 0
|
|
|
+#define CLUSTERED_SHADING_LIGHTS_BINDING 1
|
|
|
+#define CLUSTERED_SHADING_CLUSTERS_BINDING 4
|
|
|
+#include <AnKi/Shaders/ClusteredShadingCommon2.glsl>
|
|
|
+
|
|
|
+// Used by the hit shaders. When changing the binding you need to update other shaders
|
|
|
+layout(set = 0, binding = 5) uniform sampler u_trilinearRepeatSampler;
|
|
|
+
|
|
|
+layout(set = 0, binding = 6) uniform uimage2D u_shadowsImage;
|
|
|
+layout(set = 0, binding = 7) uniform utexture2D u_historyShadowsTex;
|
|
|
+layout(set = 0, binding = 8) uniform sampler u_linearAnyClampSampler;
|
|
|
+layout(set = 0, binding = 9) uniform sampler u_nearestAnyClampSampler;
|
|
|
+layout(set = 0, binding = 10) uniform texture2D u_depthRt;
|
|
|
+layout(set = 0, binding = 11) uniform texture2D u_motionVectorsRt;
|
|
|
+layout(set = 0, binding = 12) uniform texture2D u_motionVectorsRejectionRt;
|
|
|
+layout(set = 0, binding = 13) uniform texture2D u_normalRt;
|
|
|
+layout(set = 0, binding = 14) uniform accelerationStructureEXT u_tlas;
|
|
|
+layout(set = 0, binding = 15) uniform texture2D u_prevHistoryLengthTex;
|
|
|
+layout(set = 0, binding = 16) uniform image2D u_historyLengthImage;
|
|
|
+layout(set = 0, binding = 17) uniform texture2D u_prevMomentsTex;
|
|
|
+layout(set = 0, binding = 18) uniform image2D u_momentsImage;
|
|
|
+layout(set = 0, binding = 19) uniform texture2D u_blueNoiseTex;
|
|
|
|
|
|
ANKI_BINDLESS_SET(1); // Used by the hit shaders
|
|
|
|
|
|
@@ -66,7 +68,7 @@ void main()
|
|
|
const Vec2 uv = (Vec2(gl_LaunchIDEXT.xy) + 0.5) / Vec2(gl_LaunchSizeEXT.xy);
|
|
|
const Vec2 ndc = UV_TO_NDC(uv);
|
|
|
const F32 depth = textureLod(u_depthRt, u_linearAnyClampSampler, uv, 0.0).r;
|
|
|
- const Vec4 worldPos4 = u_invViewProjMat * Vec4(ndc, depth, 1.0);
|
|
|
+ const Vec4 worldPos4 = u_clusterShading.m_matrices.m_invertedViewProjectionJitter * Vec4(ndc, depth, 1.0);
|
|
|
const Vec3 worldPos = worldPos4.xyz / worldPos4.w;
|
|
|
|
|
|
if(depth == 1.0)
|
|
|
@@ -85,9 +87,8 @@ void main()
|
|
|
const Vec3 normal = readNormalFromGBuffer(u_normalRt, u_linearAnyClampSampler, uv);
|
|
|
|
|
|
// Cluster
|
|
|
- const U32 clusterIdx = computeClusterIndex(u_clustererMagic, uv, worldPos, u_lightingUniforms.m_clusterCount.x,
|
|
|
- u_lightingUniforms.m_clusterCount.y);
|
|
|
- U32 idxOffset = u_clusters[clusterIdx];
|
|
|
+ Cluster cluster = getClusterUv(uv, depth, u_clusterShading.m_tileCounts, u_clusterShading.m_zSplitCount,
|
|
|
+ u_clusterShading.m_zSplitMagic.x, u_clusterShading.m_zSplitMagic.y);
|
|
|
|
|
|
F32 shadowFactors[MAX_RT_SHADOW_LAYERS];
|
|
|
zeroRtShadowLayers(shadowFactors);
|
|
|
@@ -96,7 +97,7 @@ void main()
|
|
|
Vec3 random[RAYS_PER_PIXEL];
|
|
|
for(U32 i = 0; i < RAYS_PER_PIXEL; ++i)
|
|
|
{
|
|
|
- const U32 frameIdx = u_lightingUniforms.m_frameCount * RAYS_PER_PIXEL + i;
|
|
|
+ const U32 frameIdx = u_clusterShading.m_frame * RAYS_PER_PIXEL + i;
|
|
|
#if 0
|
|
|
const UVec3 irandom = rand3DPCG16(UVec3(gl_LaunchIDEXT.xy, frameIdx));
|
|
|
random[i] = Vec3(irandom) / F32(0xFFFF) * 2.0 - 1.0; // In [-1.0, 1.0]
|
|
|
@@ -109,26 +110,28 @@ void main()
|
|
|
}
|
|
|
|
|
|
// Dir light
|
|
|
- ANKI_BRANCH if(u_dirLight.m_active != 0u && u_dirLight.m_cascadeCount > 0)
|
|
|
+ const DirectionalLight2 dirLight = u_clusterShading.m_directionalLight;
|
|
|
+ ANKI_BRANCH if(dirLight.m_active != 0u && dirLight.m_cascadeCount > 0)
|
|
|
{
|
|
|
for(U32 i = 0; i < RAYS_PER_PIXEL; ++i)
|
|
|
{
|
|
|
- const Vec3 dirLightPos = worldPos + -u_dirLight.m_dir * 10.0 + random[i];
|
|
|
+ const Vec3 dirLightPos = worldPos + -dirLight.m_direction * 10.0 + random[i];
|
|
|
const Vec3 rayDir = normalize(dirLightPos - worldPos);
|
|
|
|
|
|
const F32 lambertTerm = dot(rayDir, normal);
|
|
|
ANKI_BRANCH if(lambertTerm > 0.0)
|
|
|
{
|
|
|
- shadowFactors[u_dirLight.m_shadowLayer] += trace(worldPos, rayDir, 10000.0) / F32(RAYS_PER_PIXEL);
|
|
|
+ shadowFactors[dirLight.m_shadowLayer] += trace(worldPos, rayDir, 10000.0) / F32(RAYS_PER_PIXEL);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// Point lights
|
|
|
- U32 idx;
|
|
|
- ANKI_LOOP while((idx = u_lightIndices[idxOffset++]) != MAX_U32)
|
|
|
+ ANKI_LOOP while(cluster.m_pointLightsMask != 0u)
|
|
|
{
|
|
|
- PointLight light = u_pointLights[idx];
|
|
|
+ const I32 idx = findLSB64(cluster.m_pointLightsMask);
|
|
|
+ cluster.m_pointLightsMask &= ~(1ul << U64(idx));
|
|
|
+ const PointLight2 light = u_pointLights2[idx];
|
|
|
|
|
|
ANKI_BRANCH if(light.m_shadowAtlasTileScale >= 0.0)
|
|
|
{
|
|
|
@@ -151,11 +154,13 @@ void main()
|
|
|
}
|
|
|
|
|
|
// Spot lights
|
|
|
- ANKI_LOOP while((idx = u_lightIndices[idxOffset++]) != MAX_U32)
|
|
|
+ ANKI_LOOP while(cluster.m_spotLightsMask != 0u)
|
|
|
{
|
|
|
- SpotLight light = u_spotLights[idx];
|
|
|
+ const I32 idx = findLSB64(cluster.m_spotLightsMask);
|
|
|
+ cluster.m_spotLightsMask &= ~(1ul << U64(idx));
|
|
|
+ const SpotLight2 light = u_spotLights2[idx];
|
|
|
|
|
|
- ANKI_BRANCH if(light.m_shadowmapId >= 0.0)
|
|
|
+ ANKI_BRANCH if(light.m_shadowLayer != MAX_U32)
|
|
|
{
|
|
|
for(U32 i = 0; i < RAYS_PER_PIXEL; ++i)
|
|
|
{
|