chore: checkpoint current workspace changes

This commit is contained in:
2026-04-11 22:14:02 +08:00
parent 3e55f8c204
commit 8848cfd958
227 changed files with 34027 additions and 6711 deletions

View File

@@ -78,7 +78,7 @@ Shader "Builtin Forward Lit"
return output;
}
float ComputeShadowAttenuation(float3 positionWS)
float ComputeShadowAttenuation(float3 positionWS, float3 normalWS, float3 lightDirectionWS)
{
#ifndef XC_MAIN_LIGHT_SHADOWS
return 1.0f;
@@ -87,7 +87,10 @@ Shader "Builtin Forward Lit"
return 1.0f;
}
const float4 shadowClip = mul(gWorldToShadowMatrix, float4(positionWS, 1.0f));
const float nDotL = saturate(dot(normalize(normalWS), normalize(lightDirectionWS)));
const float normalBiasWorld = gShadowOptions.y * gShadowOptions.z * (1.0f - nDotL);
const float3 shadowPositionWS = positionWS + normalize(normalWS) * normalBiasWorld;
const float4 shadowClip = mul(gWorldToShadowMatrix, float4(shadowPositionWS, 1.0f));
if (shadowClip.w <= 0.0f) {
return 1.0f;
}
@@ -116,9 +119,28 @@ Shader "Builtin Forward Lit"
const float receiverDepth = shadowNdc.z - gShadowBiasAndTexelSize.x;
#endif
const float shadowDepth = ShadowMapTexture.Sample(ShadowMapSampler, shadowUv).r;
const float2 shadowTexelSize = gShadowBiasAndTexelSize.yz;
float visibility = 0.0f;
[unroll]
for (int offsetY = -1; offsetY <= 1; ++offsetY) {
[unroll]
for (int offsetX = -1; offsetX <= 1; ++offsetX) {
const float2 sampleUv =
shadowUv + float2((float)offsetX, (float)offsetY) * shadowTexelSize;
if (sampleUv.x < 0.0f || sampleUv.x > 1.0f ||
sampleUv.y < 0.0f || sampleUv.y > 1.0f) {
visibility += 1.0f;
continue;
}
const float shadowDepth = ShadowMapTexture.Sample(ShadowMapSampler, sampleUv).r;
visibility += receiverDepth <= shadowDepth ? 1.0f : 0.0f;
}
}
visibility *= (1.0f / 9.0f);
const float shadowStrength = saturate(gShadowBiasAndTexelSize.w);
return receiverDepth <= shadowDepth ? 1.0f : (1.0f - shadowStrength);
return lerp(1.0f - shadowStrength, 1.0f, visibility);
#endif
}
@@ -207,7 +229,7 @@ Shader "Builtin Forward Lit"
const float3 directionToLightWS = normalize(gMainLightDirectionAndIntensity.xyz);
const float diffuse = saturate(dot(normalWS, directionToLightWS));
const float shadowAttenuation =
diffuse > 0.0f ? ComputeShadowAttenuation(input.positionWS) : 1.0f;
diffuse > 0.0f ? ComputeShadowAttenuation(input.positionWS, normalWS, directionToLightWS) : 1.0f;
lighting +=
gMainLightColorAndFlags.rgb *
(diffuse * gMainLightDirectionAndIntensity.w * shadowAttenuation);

View File

@@ -62,6 +62,10 @@ Shader "Builtin Shadow Caster"
{
Name "ShadowCaster"
Tags { "LightMode" = "ShadowCaster" }
Cull Back
ZWrite On
ZTest LEqual
Offset 1.0, 2
HLSLPROGRAM
#pragma target 4.5
#pragma vertex MainVS