Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: effect shadows improvements #743

Merged
merged 5 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package/Shaders/Common/ShadowSampling.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ float Get3DFilteredShadow(float3 positionWS, float3 viewDirection, float2 screen
PerGeometry sD = SharedPerShadow[0];

float fadeFactor = 1.0 - pow(saturate(dot(positionWS, positionWS) / sD.ShadowLightParam.z), 8);
uint sampleCount = ceil(16.0 * (1.0 - saturate(length(positionWS) / sqrt(sD.ShadowLightParam.z))));
uint sampleCount = ceil(8.0 * (1.0 - saturate(length(positionWS) / sqrt(sD.ShadowLightParam.z))));

if (sampleCount == 0)
return 1.0;
Expand All @@ -57,8 +57,8 @@ float Get3DFilteredShadow(float3 positionWS, float3 viewDirection, float2 screen
float r = rnd.z;
float4 sincos_phi;
sincos(phi, sincos_phi.y, sincos_phi.x);
float3 sampleOffset = viewDirection * i * 64 * rcpSampleCount;
sampleOffset += (float3(r * sin_theta * sincos_phi.x, r * sin_theta * sincos_phi.y, r * cos_theta) * 0.5 + 0.5) * 64;
float3 sampleOffset = viewDirection * (float(i) - float(sampleCount) * 0.5) * 64 * rcpSampleCount;
sampleOffset += float3(r * sin_theta * sincos_phi.x, r * sin_theta * sincos_phi.y, r * cos_theta) * 64;

uint cascadeIndex = sD.EndSplitDistances.x < GetShadowDepth(positionWS.xyz + viewDirection * (sampleOffset.x + sampleOffset.y), eyeIndex); // Stochastic cascade sampling

Expand Down
28 changes: 8 additions & 20 deletions package/Shaders/Effect.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -522,27 +522,15 @@ float3 GetLightingColor(float3 msPosition, float3 worldPosition, float4 screenPo
float4 lightDistanceSquared = (PLightPositionX[eyeIndex] - msPosition.xxxx) * (PLightPositionX[eyeIndex] - msPosition.xxxx) + (PLightPositionY[eyeIndex] - msPosition.yyyy) * (PLightPositionY[eyeIndex] - msPosition.yyyy) + (PLightPositionZ[eyeIndex] - msPosition.zzzz) * (PLightPositionZ[eyeIndex] - msPosition.zzzz);
float4 lightFadeMul = 1.0.xxxx - saturate(PLightingRadiusInverseSquared * lightDistanceSquared);

float3 color = 0.0;
float angleShadow = saturate(DirLightDirectionShared.z) * saturate(DirLightDirectionShared.z);
float dirLightBacklighting = 1.0 + saturate(dot(normalize(worldPosition), -DirLightDirectionShared.xyz));

if (ExtraShaderDescriptor & ExtraFlags::EffectShadows) {
if (InMapMenu)
color = dirLightBacklighting * DirLightColorShared * angleShadow;
else if (!InInterior && (ExtraShaderDescriptor & ExtraFlags::InWorld))
color = dirLightBacklighting * DirLightColorShared * GetEffectShadow(worldPosition, normalize(worldPosition), screenPosition, eyeIndex);
else
color = dirLightBacklighting * DirLightColorShared * 0.5;
} else {
if (InMapMenu)
color = dirLightBacklighting * DirLightColorShared * angleShadow;
else if (!InInterior && (ExtraShaderDescriptor & ExtraFlags::InWorld))
color = dirLightBacklighting * DirLightColorShared * GetWorldShadow(worldPosition, length(worldPosition), 0.0, eyeIndex) * angleShadow;
else
color = dirLightBacklighting * DirLightColorShared * 0.5;
}
float3 color = DLightColor.xyz;

color += mul(DirectionalAmbientShared, float4(0, 0, 1, 1));
if ((ExtraShaderDescriptor & ExtraFlags::EffectShadows) && !InMapMenu && !InInterior) {
float3 dirLightColor = DirLightColorShared * 0.5;
float3 ambientColor = mul(DirectionalAmbientShared, float4(0, 0, 1, 1));

color = ambientColor;
color += dirLightColor * GetEffectShadow(worldPosition, normalize(worldPosition), screenPosition, eyeIndex);
}

color.x += dot(PLightColorR * lightFadeMul, 1.0.xxxx);
color.y += dot(PLightColorG * lightFadeMul, 1.0.xxxx);
Expand Down
Loading