|
|
@@ -6,9 +6,10 @@
|
|
|
#pragma anki mutator PCF 0 1
|
|
|
#pragma anki mutator DIRECTIONAL_LIGHT_SHADOW_RESOLVED 0 1
|
|
|
|
|
|
-#include <AnKi/Shaders/ClusteredShadingFunctions.hlsl>
|
|
|
+#if defined(ANKI_COMPUTE_SHADER) || defined(ANKI_FRAGMENT_SHADER)
|
|
|
+# include <AnKi/Shaders/ClusteredShadingFunctions.hlsl>
|
|
|
|
|
|
-#define DEBUG_CASCADES 0
|
|
|
+# define DEBUG_CASCADES 0
|
|
|
|
|
|
[[vk::binding(0)]] ConstantBuffer<ClusteredShadingConstants> g_clusteredShading;
|
|
|
[[vk::binding(1)]] StructuredBuffer<PointLight> g_pointLights;
|
|
|
@@ -22,13 +23,13 @@
|
|
|
[[vk::binding(7)]] Texture2D<Vec4> g_depthRt;
|
|
|
[[vk::binding(8)]] Texture2D<Vec4> g_noiseTex;
|
|
|
|
|
|
-#if DIRECTIONAL_LIGHT_SHADOW_RESOLVED
|
|
|
+# if DIRECTIONAL_LIGHT_SHADOW_RESOLVED
|
|
|
[[vk::binding(9)]] Texture2D<Vec4> g_dirLightResolvedShadowsTex;
|
|
|
-#endif
|
|
|
+# endif
|
|
|
|
|
|
-#if defined(ANKI_COMPUTE_SHADER)
|
|
|
+# if defined(ANKI_COMPUTE_SHADER)
|
|
|
[[vk::binding(10)]] RWTexture2D<RVec4> g_outUav;
|
|
|
-#endif
|
|
|
+# endif
|
|
|
|
|
|
struct Constants
|
|
|
{
|
|
|
@@ -59,18 +60,18 @@ Vec3 computeDebugShadowCascadeColor(U32 cascade)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-#if defined(ANKI_COMPUTE_SHADER)
|
|
|
+# if defined(ANKI_COMPUTE_SHADER)
|
|
|
[numthreads(8, 8, 1)] void main(UVec2 svDispatchThreadId : SV_DISPATCHTHREADID)
|
|
|
-#else
|
|
|
+# else
|
|
|
RVec4 main(Vec2 uv : TEXCOORD) : SV_TARGET0
|
|
|
-#endif
|
|
|
+# endif
|
|
|
{
|
|
|
-#if defined(ANKI_COMPUTE_SHADER)
|
|
|
+# if defined(ANKI_COMPUTE_SHADER)
|
|
|
svDispatchThreadId = min(svDispatchThreadId, UVec2(g_consts.m_framebufferSize - 1.0f)); // Just to be sure
|
|
|
const Vec2 uv = (Vec2(svDispatchThreadId) + 0.5) / g_consts.m_framebufferSize;
|
|
|
-#endif
|
|
|
+# endif
|
|
|
|
|
|
-#if PCF
|
|
|
+# if PCF
|
|
|
// Noise
|
|
|
Vec2 noiseTexSize;
|
|
|
g_noiseTex.GetDimensions(noiseTexSize.x, noiseTexSize.y);
|
|
|
@@ -79,7 +80,7 @@ RVec4 main(Vec2 uv : TEXCOORD) : SV_TARGET0
|
|
|
RVec3 noise = g_noiseTex.SampleLevel(g_trilinearRepeatSampler, noiseUv, 0.0).rgb;
|
|
|
noise = animateBlueNoise(noise, g_clusteredShading.m_frame % 16u);
|
|
|
const RF32 randFactor = noise.x;
|
|
|
-#endif
|
|
|
+# endif
|
|
|
|
|
|
// World position
|
|
|
const Vec2 ndc = uvToNdc(uv);
|
|
|
@@ -97,10 +98,10 @@ RVec4 main(Vec2 uv : TEXCOORD) : SV_TARGET0
|
|
|
RVec4 shadowFactors = 0.0f;
|
|
|
|
|
|
// Dir light
|
|
|
-#if DIRECTIONAL_LIGHT_SHADOW_RESOLVED
|
|
|
+# if DIRECTIONAL_LIGHT_SHADOW_RESOLVED
|
|
|
shadowFactors[0] = g_dirLightResolvedShadowsTex.SampleLevel(g_linearAnyClampSampler, uv, 0.0f).x;
|
|
|
++shadowCasterCountPerFragment;
|
|
|
-#else
|
|
|
+# else
|
|
|
const DirectionalLight dirLight = g_clusteredShading.m_directionalLight;
|
|
|
if(dirLight.m_active != 0u && dirLight.m_shadowCascadeCount > 0u)
|
|
|
{
|
|
|
@@ -115,25 +116,25 @@ RVec4 main(Vec2 uv : TEXCOORD) : SV_TARGET0
|
|
|
const UVec2 cascadeIndices =
|
|
|
computeShadowCascadeIndex2(positiveZViewSpace, dirLight.m_shadowCascadeDistances, dirLight.m_shadowCascadeCount, cascadeBlendFactor);
|
|
|
|
|
|
-# if DEBUG_CASCADES
|
|
|
+# if DEBUG_CASCADES
|
|
|
const Vec3 debugColorA = computeDebugShadowCascadeColor(cascadeIndices[0]);
|
|
|
const Vec3 debugColorB = computeDebugShadowCascadeColor(cascadeIndices[1]);
|
|
|
const Vec3 debugColor = lerp(debugColorA, debugColorB, cascadeBlendFactor);
|
|
|
-# if defined(ANKI_COMPUTE_SHADER)
|
|
|
+# if defined(ANKI_COMPUTE_SHADER)
|
|
|
g_outUav[svDispatchThreadId.xy] = shadowFactors;
|
|
|
return;
|
|
|
-# else
|
|
|
+# else
|
|
|
return shadowFactors;
|
|
|
+# endif
|
|
|
# endif
|
|
|
-# endif
|
|
|
|
|
|
-# if PCF
|
|
|
+# if PCF
|
|
|
const F32 shadowFactorCascadeA =
|
|
|
computeShadowFactorDirLightPcf(dirLight, cascadeIndices.x, worldPos, g_shadowAtlasTex, g_linearAnyClampShadowSampler, randFactor);
|
|
|
-# else
|
|
|
+# else
|
|
|
const F32 shadowFactorCascadeA =
|
|
|
computeShadowFactorDirLight(dirLight, cascadeIndices.x, worldPos, g_shadowAtlasTex, g_linearAnyClampShadowSampler);
|
|
|
-# endif
|
|
|
+# endif
|
|
|
|
|
|
if(cascadeBlendFactor < 0.01 || cascadeIndices.x == cascadeIndices.y)
|
|
|
{
|
|
|
@@ -142,15 +143,15 @@ RVec4 main(Vec2 uv : TEXCOORD) : SV_TARGET0
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
-# if PCF
|
|
|
+# if PCF
|
|
|
// Blend cascades
|
|
|
const F32 shadowFactorCascadeB =
|
|
|
computeShadowFactorDirLightPcf(dirLight, cascadeIndices.y, worldPos, g_shadowAtlasTex, g_linearAnyClampShadowSampler, randFactor);
|
|
|
-# else
|
|
|
+# else
|
|
|
// Blend cascades
|
|
|
const F32 shadowFactorCascadeB =
|
|
|
computeShadowFactorDirLight(dirLight, cascadeIndices.y, worldPos, g_shadowAtlasTex, g_linearAnyClampShadowSampler);
|
|
|
-# endif
|
|
|
+# endif
|
|
|
shadowFactor = lerp(shadowFactorCascadeA, shadowFactorCascadeB, cascadeBlendFactor);
|
|
|
}
|
|
|
|
|
|
@@ -166,7 +167,7 @@ RVec4 main(Vec2 uv : TEXCOORD) : SV_TARGET0
|
|
|
shadowFactors[0] = shadowFactor;
|
|
|
++shadowCasterCountPerFragment;
|
|
|
}
|
|
|
-#endif // DIRECTIONAL_LIGHT_SHADOW_RESOLVED
|
|
|
+# endif // DIRECTIONAL_LIGHT_SHADOW_RESOLVED
|
|
|
|
|
|
// Point lights
|
|
|
U32 idx = 0;
|
|
|
@@ -178,12 +179,12 @@ RVec4 main(Vec2 uv : TEXCOORD) : SV_TARGET0
|
|
|
{
|
|
|
const Vec3 frag2Light = light.m_position - worldPos;
|
|
|
|
|
|
-#if PCF
|
|
|
+# if PCF
|
|
|
const RF32 shadowFactor =
|
|
|
computeShadowFactorPointLightPcf(light, frag2Light, g_shadowAtlasTex, g_linearAnyClampShadowSampler, randFactor);
|
|
|
-#else
|
|
|
+# else
|
|
|
const RF32 shadowFactor = computeShadowFactorPointLight(light, frag2Light, g_shadowAtlasTex, g_linearAnyClampShadowSampler);
|
|
|
-#endif
|
|
|
+# endif
|
|
|
shadowFactors[min(kMaxShadowCastersPerFragment - 1u, shadowCasterCountPerFragment++)] = shadowFactor;
|
|
|
}
|
|
|
}
|
|
|
@@ -195,19 +196,30 @@ RVec4 main(Vec2 uv : TEXCOORD) : SV_TARGET0
|
|
|
|
|
|
[branch] if(light.m_shadow)
|
|
|
{
|
|
|
-#if PCF
|
|
|
+# if PCF
|
|
|
const RF32 shadowFactor = computeShadowFactorSpotLightPcf(light, worldPos, g_shadowAtlasTex, g_linearAnyClampShadowSampler, randFactor);
|
|
|
-#else
|
|
|
+# else
|
|
|
const RF32 shadowFactor = computeShadowFactorSpotLight(light, worldPos, g_shadowAtlasTex, g_linearAnyClampShadowSampler);
|
|
|
-#endif
|
|
|
+# endif
|
|
|
shadowFactors[min(kMaxShadowCastersPerFragment - 1u, shadowCasterCountPerFragment++)] = shadowFactor;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// Store
|
|
|
-#if defined(ANKI_COMPUTE_SHADER)
|
|
|
+# if defined(ANKI_COMPUTE_SHADER)
|
|
|
g_outUav[svDispatchThreadId] = shadowFactors;
|
|
|
-#else
|
|
|
+# else
|
|
|
return shadowFactors;
|
|
|
-#endif
|
|
|
+# endif
|
|
|
}
|
|
|
+#endif // defined(ANKI_COMPUTE_SHADER) || defined(ANKI_FRAGMENT_SHADER)
|
|
|
+
|
|
|
+#pragma anki technique_start vert
|
|
|
+#include <AnKi/Shaders/QuadVert.hlsl>
|
|
|
+#pragma anki technique_end vert
|
|
|
+
|
|
|
+#pragma anki technique_start frag
|
|
|
+#pragma anki technique_end frag
|
|
|
+
|
|
|
+#pragma anki technique_start comp
|
|
|
+#pragma anki technique_end comp
|