|
|
@@ -6,21 +6,21 @@
|
|
|
#pragma anki start comp
|
|
|
|
|
|
ANKI_SPECIALIZATION_CONSTANT_UVEC2(FB_SIZE, 0);
|
|
|
-ANKI_SPECIALIZATION_CONSTANT_U32(CLUSTER_COUNT_X, 2);
|
|
|
-ANKI_SPECIALIZATION_CONSTANT_U32(CLUSTER_COUNT_Y, 3);
|
|
|
+ANKI_SPECIALIZATION_CONSTANT_UVEC2(TILE_COUNTS, 2);
|
|
|
+ANKI_SPECIALIZATION_CONSTANT_U32(Z_SPLIT_COUNT, 4);
|
|
|
|
|
|
-#define LIGHT_SET 0
|
|
|
-#define LIGHT_COMMON_UNIS_BINDING 3
|
|
|
-#define LIGHT_LIGHTS_BINDING 4
|
|
|
-#define LIGHT_CLUSTERS_BINDING 7
|
|
|
-#include <AnKi/Shaders/ClusteredShadingCommon.glsl>
|
|
|
+#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>
|
|
|
|
|
|
const UVec2 WORKGROUP_SIZE = UVec2(8, 8);
|
|
|
layout(local_size_x = WORKGROUP_SIZE.x, local_size_y = WORKGROUP_SIZE.y, local_size_z = 1) in;
|
|
|
|
|
|
-layout(set = 0, binding = 0, rgba8) uniform image2D out_img;
|
|
|
-layout(set = 0, binding = 1) uniform sampler u_linearAnyClampSampler;
|
|
|
-layout(set = 0, binding = 2) uniform texture2D u_depthRt;
|
|
|
+layout(set = 0, binding = 5, rgba8) writeonly uniform image2D u_outImg;
|
|
|
+layout(set = 0, binding = 6) uniform sampler u_linearAnyClampSampler;
|
|
|
+layout(set = 0, binding = 7) uniform texture2D u_depthRt;
|
|
|
|
|
|
void main()
|
|
|
{
|
|
|
@@ -33,34 +33,37 @@ void main()
|
|
|
const Vec2 uv = (Vec2(gl_GlobalInvocationID.xy) + 0.5) / Vec2(FB_SIZE);
|
|
|
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;
|
|
|
|
|
|
// Cluster
|
|
|
- const U32 clusterIdx = computeClusterIndex(u_clustererMagic, uv, worldPos, CLUSTER_COUNT_X, CLUSTER_COUNT_Y);
|
|
|
- U32 idxOffset = u_clusters[clusterIdx];
|
|
|
+ Cluster cluster = getClusterUv(uv, depth, TILE_COUNTS, Z_SPLIT_COUNT, u_clusterShading.m_zSplitMagic.x,
|
|
|
+ u_clusterShading.m_zSplitMagic.y);
|
|
|
|
|
|
+ // Layers
|
|
|
U32 shadowCasterCountPerFragment = 0;
|
|
|
const U32 maxShadowCastersPerFragment = 4;
|
|
|
F32 shadowFactors[maxShadowCastersPerFragment] = F32[](0.0, 0.0, 0.0, 0.0);
|
|
|
|
|
|
// Dir light
|
|
|
- if(u_dirLight.m_active != 0u && u_dirLight.m_cascadeCount > 0)
|
|
|
+ const DirectionalLight2 dirLight = u_clusterShading.m_directionalLight;
|
|
|
+ if(dirLight.m_active != 0u && dirLight.m_cascadeCount > 0)
|
|
|
{
|
|
|
- const Vec4 viewPos4 = u_invProjMat * Vec4(ndc, depth, 1.0);
|
|
|
- const F32 positiveZViewSpace = -(viewPos4.z / viewPos4.w);
|
|
|
+ const F32 positiveZViewSpace =
|
|
|
+ testPlanePoint(u_clusterShading.m_nearPlaneWSpace.xyz, u_clusterShading.m_nearPlaneWSpace.w, worldPos)
|
|
|
+ + u_clusterShading.m_near;
|
|
|
|
|
|
F32 shadowFactor;
|
|
|
- if(positiveZViewSpace < u_dirLight.m_effectiveShadowDistance)
|
|
|
+ if(positiveZViewSpace < dirLight.m_effectiveShadowDistance)
|
|
|
{
|
|
|
const U32 cascadeIdx =
|
|
|
- computeShadowCascadeIndex(positiveZViewSpace, u_dirLight.m_shadowCascadesDistancePower,
|
|
|
- u_dirLight.m_effectiveShadowDistance, u_dirLight.m_cascadeCount);
|
|
|
+ computeShadowCascadeIndex(positiveZViewSpace, dirLight.m_shadowCascadesDistancePower,
|
|
|
+ dirLight.m_effectiveShadowDistance, dirLight.m_cascadeCount);
|
|
|
|
|
|
shadowFactor =
|
|
|
- computeShadowFactorDirLight(u_dirLight, cascadeIdx, worldPos, u_shadowTex, u_linearAnyClampSampler);
|
|
|
+ computeShadowFactorDirLight(dirLight, cascadeIdx, worldPos, u_shadowAtlasTex, u_linearAnyClampSampler);
|
|
|
|
|
|
- F32 distanceFadeFactor = saturate(positiveZViewSpace / u_dirLight.m_effectiveShadowDistance);
|
|
|
+ F32 distanceFadeFactor = saturate(positiveZViewSpace / dirLight.m_effectiveShadowDistance);
|
|
|
distanceFadeFactor = pow(distanceFadeFactor, 8.0);
|
|
|
shadowFactor += distanceFadeFactor;
|
|
|
}
|
|
|
@@ -74,36 +77,39 @@ void main()
|
|
|
}
|
|
|
|
|
|
// 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)
|
|
|
{
|
|
|
const Vec3 frag2Light = light.m_position - worldPos;
|
|
|
|
|
|
const F32 shadowFactor =
|
|
|
- computeShadowFactorPointLight(light, frag2Light, u_shadowTex, u_linearAnyClampSampler);
|
|
|
+ computeShadowFactorPointLight(light, frag2Light, u_shadowAtlasTex, u_linearAnyClampSampler);
|
|
|
shadowFactors[min(maxShadowCastersPerFragment - 1, shadowCasterCountPerFragment++)] = shadowFactor;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 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)
|
|
|
{
|
|
|
const F32 shadowFactor =
|
|
|
- computeShadowFactorSpotLight(light, worldPos, u_shadowTex, u_linearAnyClampSampler);
|
|
|
+ computeShadowFactorSpotLight(light, worldPos, u_shadowAtlasTex, u_linearAnyClampSampler);
|
|
|
shadowFactors[min(maxShadowCastersPerFragment - 1, shadowCasterCountPerFragment++)] = shadowFactor;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// Store
|
|
|
- imageStore(out_img, IVec2(gl_GlobalInvocationID.xy),
|
|
|
+ imageStore(u_outImg, IVec2(gl_GlobalInvocationID.xy),
|
|
|
Vec4(shadowFactors[0], shadowFactors[1], shadowFactors[2], shadowFactors[3]));
|
|
|
}
|
|
|
|