Shadow mapping works 99%
This commit is contained in:
@@ -46,13 +46,16 @@ float4 fragmentMain(in FragmentParameter params) : SV_Target
|
||||
{
|
||||
uint cascadeIndex = 0;
|
||||
for (uint c = 0; c < NUM_CASCADES - 1; ++c) {
|
||||
if (params.position_VS.z > pShadowMapping.cascadeSplits[c]) {
|
||||
if (-params.position_VS.z > pShadowMapping.cascadeSplits[c]) {
|
||||
cascadeIndex = c + 1;
|
||||
}
|
||||
}
|
||||
float4 lightSpacePos = mul(pShadowMapping.lightSpaceMatrices[cascadeIndex][i], float4(params.position_WS, 1));
|
||||
lightSpacePos = float4(lightSpacePos.xy * 0.5 + 0.5, lightSpacePos.zw);
|
||||
// Negate Y to compensate for orthographic projection's Y negation + viewport Y-flip double-inversion
|
||||
lightSpacePos = float4(lightSpacePos.x * 0.5 + 0.5, -lightSpacePos.y * 0.5 + 0.5, lightSpacePos.zw);
|
||||
float4 shadowCoord = lightSpacePos;
|
||||
// Convert NDC z to viewport depth space (inverse depth: near=1, far=0)
|
||||
float currentDepth = 1.0 - shadowCoord.z;
|
||||
int3 texDim;
|
||||
pShadowMapping.shadowMaps[cascadeIndex].GetDimensions(texDim.x, texDim.y, texDim.z);
|
||||
float scale = 1.5f;
|
||||
@@ -65,10 +68,10 @@ float4 fragmentMain(in FragmentParameter params) : SV_Target
|
||||
//for (int x = -range; x <= range; ++x) {
|
||||
// for (int y = -range; y <= range; ++y) {
|
||||
float shadow = 1.0f;
|
||||
if (shadowCoord.z > 0.0 && shadowCoord.z < 1.0)
|
||||
if (currentDepth > 0.0 && currentDepth < 1.0)
|
||||
{
|
||||
float dist = pShadowMapping.shadowMaps[cascadeIndex].Sample(pShadowMapping.shadowSampler, float3(shadowCoord.xy, i)).r;
|
||||
if (shadowCoord.w > 0 && dist < shadowCoord.z)
|
||||
if (shadowCoord.w > 0 && currentDepth < dist)
|
||||
{
|
||||
shadow = 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user