SHADOWS WORK
This commit is contained in:
+19
-13
@@ -11,6 +11,12 @@ struct LightCullingData
|
||||
};
|
||||
ParameterBlock<LightCullingData> pLightCullingData;
|
||||
|
||||
static const float4x4 biasMat = float4x4(
|
||||
0.5, 0.0, 0.0, 0.5,
|
||||
0.0, 0.5, 0.0, 0.5,
|
||||
0.0, 0.0, 1.0, 0.0,
|
||||
0.0, 0.0, 0.0, 1.0);
|
||||
|
||||
[shader("pixel")]
|
||||
float4 fragmentMain(in FragmentParameter params) : SV_Target
|
||||
{
|
||||
@@ -24,22 +30,22 @@ float4 fragmentMain(in FragmentParameter params) : SV_Target
|
||||
float3 result = float3(0, 0, 0);
|
||||
for(int i = 0; i < pLightEnv.numDirectionalLights; ++i)
|
||||
{
|
||||
float4 lightSpacePos = mul(pLightEnv.directionalLights[i].lightSpaceMatrix, float4(params.position_WS, 1));
|
||||
float3 projCoords = lightSpacePos.xyz / lightSpacePos.w;
|
||||
projCoords.xy = projCoords.xy * 0.5 + 0.5;
|
||||
projCoords.z /= 2;
|
||||
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 + bias < closestDepth ? 1.0 : 0.0;
|
||||
float4 lightSpacePos = mul(biasMat, mul(pLightEnv.directionalLights[i].lightSpaceMatrix, float4(params.position_WS, 1)));
|
||||
float4 shadowCoord = lightSpacePos / lightSpacePos.w;
|
||||
float shadow = 1.0f;
|
||||
float dist = pLightEnv.shadowMap.Sample(pLightEnv.shadowSampler, shadowCoord.xy).r;
|
||||
if (shadowCoord.w > 0 && dist > shadowCoord.z)
|
||||
{
|
||||
shadow = 0;
|
||||
}
|
||||
|
||||
result += float3(currentDepth, 0, 0);//shadow * pLightEnv.directionalLights[i].illuminate(lightingParams, brdf);
|
||||
result += shadow * pLightEnv.directionalLights[i].illuminate(lightingParams, brdf);
|
||||
}
|
||||
for (uint i = 0; i < lightCount; ++i)
|
||||
for (uint i = 0; i < pLightEnv.numPointLights; ++i)
|
||||
{
|
||||
uint lightIndex = pLightCullingData.lightIndexList[startOffset + i];
|
||||
result += pLightEnv.pointLights[lightIndex].illuminate(lightingParams, brdf);
|
||||
//uint lightIndex = pLightCullingData.lightIndexList[startOffset + i];
|
||||
result += pLightEnv.pointLights[i].illuminate(lightingParams, brdf);
|
||||
}
|
||||
result += brdf.evaluateAmbient(lightingParams.viewDir_WS);
|
||||
//result += brdf.evaluateAmbient(lightingParams.viewDir_WS);
|
||||
return float4(result, brdf.getAlpha());
|
||||
}
|
||||
@@ -113,5 +113,5 @@ float4 toneMapping(float2 uv : UV) : SV_Target
|
||||
value = agxLook(value);
|
||||
value = agxEotf(value);
|
||||
|
||||
return float4(value, 1);
|
||||
return float4(hdrValue, 1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user