Shadows do at least something

This commit is contained in:
Dynamitos
2025-05-09 14:59:58 +02:00
parent ed66635191
commit 174ff23164
11 changed files with 63 additions and 52 deletions
+11 -2
View File
@@ -17,15 +17,24 @@ float4 fragmentMain(in FragmentParameter params) : SV_Target
LightingParameter lightingParams = params.getLightingParameter();
MaterialParameter materialParams = params.getMaterialParameter();
var brdf = Material.prepare(materialParams);
brdf.setNormal(normalize(params.normal_WS));
uint2 tileIndex = uint2(floor(params.position_CS.xy / BLOCK_SIZE));
uint startOffset = pLightCullingData.lightGrid[tileIndex].x;
uint lightCount = pLightCullingData.lightGrid[tileIndex].y;
float3 result = float3(0, 0, 0);
for(int i = 0; i < pLightEnv.numDirectionalLights; ++i)
{
result += pLightEnv.directionalLights[i].illuminate(lightingParams, brdf);
float4 lightSpacePos = mul(pLightEnv.directionalLights[i].lightSpaceMatrix, float4(params.position_WS, 1));
float3 projCoords = lightSpacePos.xyz / lightSpacePos.w;
projCoords = projCoords * 0.5 + 0.5;
float closestDepth = pLightEnv.shadowMap.Sample(pLightEnv.shadowSampler, projCoords.xy).r;
float currentDepth = projCoords.z;
float bias = max(0.05 * (1.0 - dot(brdf.getNormal(), pLightEnv.directionalLights[i].direction.xyz)), 0.005);
float shadow = currentDepth > closestDepth - bias ? 1.0 : 0.0;
result += shadow * pLightEnv.directionalLights[i].illuminate(lightingParams, brdf);
}
for (uint i = 0; i < lightCount; ++i)
for (uint i = 0; i < pLightEnv.numPo; ++i)
{
uint lightIndex = pLightCullingData.lightIndexList[startOffset + i];
result += pLightEnv.pointLights[lightIndex].illuminate(lightingParams, brdf);