mirror of
https://github.com/TombEngine/TombEngine.git
synced 2025-05-02 17:57:59 +03:00
Merge branch 'master' of https://github.com/MontyTRC89/TR5Main
This commit is contained in:
commit
c3890b0e68
6 changed files with 56 additions and 12 deletions
|
@ -35,6 +35,11 @@ cbuffer CShadowLightBuffer : register(b4)
|
|||
float3 Padding2;
|
||||
};
|
||||
|
||||
cbuffer RoomBuffer : register(b5)
|
||||
{
|
||||
float4 AmbientColor;
|
||||
};
|
||||
|
||||
struct VertexShaderInput
|
||||
{
|
||||
float3 Position: POSITION;
|
||||
|
@ -61,7 +66,6 @@ Texture2D CausticsTexture : register(t1);
|
|||
|
||||
Texture2D ShadowMap : register(t2);
|
||||
SamplerState ShadowMapSampler : register(s1);
|
||||
|
||||
PixelShaderInput VS(VertexShaderInput input)
|
||||
{
|
||||
PixelShaderInput output;
|
||||
|
@ -76,6 +80,19 @@ PixelShaderInput VS(VertexShaderInput input)
|
|||
return output;
|
||||
}
|
||||
|
||||
float getShadowFactor(Texture2D shadowMap, SamplerState shadowMapSampler, float2 coords, float realDepth) {
|
||||
const float texelSize = 1.0f / 1024;
|
||||
float shadowFactor = 0.0f;
|
||||
//doing 9 samples
|
||||
for (float x = -1; x <= 1.0f; x++) {
|
||||
for (float y = -1; y <= 1.0f; y++) {
|
||||
float shadowMapDepth = ShadowMap.SampleLevel(ShadowMapSampler, coords + (float2(x, y)*texelSize),0).r;
|
||||
shadowFactor += shadowMapDepth < realDepth ? 1.0f : 0.0f;
|
||||
}
|
||||
}
|
||||
return shadowFactor / 9.0f;
|
||||
}
|
||||
|
||||
[earlydepthstencil]
|
||||
float4 PS(PixelShaderInput input) : SV_TARGET
|
||||
{
|
||||
|
@ -104,8 +121,8 @@ float4 PS(PixelShaderInput input) : SV_TARGET
|
|||
float realDepth = input.LightPosition.z;
|
||||
|
||||
// If clip space z value greater than shadow map value then pixel is in shadow
|
||||
if (shadowMapDepth < realDepth)
|
||||
return float4(output.xyz* colorMul.xyz / 2.0f, 1.0f);
|
||||
float shadow = getShadowFactor(ShadowMap, ShadowMapSampler, coords, realDepth);
|
||||
lighting = lerp(lighting, AmbientColor * 2, saturate(shadow));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -159,4 +176,5 @@ float4 PS(PixelShaderInput input) : SV_TARGET
|
|||
output.w = 1.0f;
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue