Skip to content

Commit

Permalink
hardware pcf
Browse files Browse the repository at this point in the history
  • Loading branch information
planetchili committed May 29, 2020
1 parent ca5004c commit 3d2de2a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
24 changes: 12 additions & 12 deletions hw3d/PShadow.hlsli
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Texture2D smap : register(t3);
SamplerState ssam : register(s1);
SamplerComparisonState ssam : register(s1);

#define PCF_RANGE 4

float Shadow(const in float4 shadowHomoPos)
{
Expand All @@ -12,17 +14,15 @@ float Shadow(const in float4 shadowHomoPos)
}
else
{
// dimensions for pixel sampling with uv
uint width, height;
smap.GetDimensions(width, height);
const float dx = 0.5f / width;
const float dy = 0.5f / height;
// sample 4 pixels around actual shadow map position
const float zBiased = spos.z - 0.0005f;
shadowLevel += smap.Sample(ssam, spos.xy + float2(dx, dy)).r >= zBiased ? 0.25f : 0.0f;
shadowLevel += smap.Sample(ssam, spos.xy + float2(-dx, dy)).r >= zBiased ? 0.25f : 0.0f;
shadowLevel += smap.Sample(ssam, spos.xy + float2(dx, -dy)).r >= zBiased ? 0.25f : 0.0f;
shadowLevel += smap.Sample(ssam, spos.xy + float2(-dx, -dy)).r >= zBiased ? 0.25f : 0.0f;
[unroll]
for (int x = -PCF_RANGE; x <= PCF_RANGE; x += 2)
{
[unroll]
for (int y = -PCF_RANGE; y <= PCF_RANGE; y += 2)
{
shadowLevel = smap.SampleCmpLevelZero(ssam, spos.xy, spos.b - 0.0005f, int2(x, y));
}
}
}
return shadowLevel;
}
3 changes: 2 additions & 1 deletion hw3d/ShadowSampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ namespace Bind
D3D11_SAMPLER_DESC samplerDesc = CD3D11_SAMPLER_DESC{ CD3D11_DEFAULT{} };

samplerDesc.BorderColor[0] = 1.0f;
samplerDesc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR;
samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_BORDER;
samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_BORDER;
samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
samplerDesc.ComparisonFunc = D3D11_COMPARISON_LESS_EQUAL;

GFX_THROW_INFO( GetDevice( gfx )->CreateSamplerState( &samplerDesc,&pSampler ) );
}
Expand Down

0 comments on commit 3d2de2a

Please sign in to comment.