Pre bindless

This commit is contained in:
Dynamitos
2025-05-07 16:08:12 +02:00
parent 3e36340b02
commit ed66635191
14 changed files with 120 additions and 58 deletions
+16 -1
View File
@@ -10,11 +10,26 @@ struct DirectionalLight : ILightEnv
{
float4 color;
float4 direction;
float4x4 lightSpaceMatrix;
Texture2D shadowMap;
SamplerState shadowSampler;
float3 illuminate<B:IBRDF>(LightingParameter params, B brdf)
{
float3 dir_WS = -normalize(direction.xyz);
return brdf.evaluate(params.viewDir_WS, dir_WS, color.xyz * color.w);
float3 color = brdf.evaluate(params.viewDir_WS, dir_WS, color.xyz * color.w);
float4 lightSpacePos = mul(lightSpaceMatrix, float4(params.position_WS, 1));
float3 projCoords = lightSpacePos.xyz / lightSpacePos.w;
projCoords = projCoords * 0.5 + 0.5;
float closestDepth = shadowMap.Sample(shadowSampler, projCoords.xy).r;
float currentDepth = projCoords.z;
float bias = max(0.05 * (1.0 - dot(brdf.getNormal(), direction.xyz)), 0.005);
float shadow = currentDepth - bias > closestDepth ? 1.0 : 0.0;
if (projCoords.z > 1.0)
shadow = 0;
return shadow * color;
}
};