mirror of
https://github.com/maxartz15/VolumetricLighting.git
synced 2024-11-23 23:15:34 +01:00
Handle the reversed depth buffer in 5.5
This commit is contained in:
parent
947b6de3a5
commit
603a19ddf4
@ -67,6 +67,14 @@ half EdgeSmooth(half2 xy)
|
||||
return saturate(1 - smoothstep(-smooth, 0, d));
|
||||
}
|
||||
|
||||
half ReverseZ(half z)
|
||||
{
|
||||
#if UNITY_REVERSED_Z
|
||||
return 1.0 - z;
|
||||
#endif
|
||||
return z;
|
||||
}
|
||||
|
||||
half Shadow(half3 position)
|
||||
{
|
||||
half4 pClip = mul(_ShadowProjectionMatrix, half4(position, 1));
|
||||
@ -83,7 +91,7 @@ half Shadow(half3 position)
|
||||
for(int j = 0; j < 10; ++j)
|
||||
{
|
||||
half2 offset = poisson[j + 24] * _ShadowReceiverWidth;
|
||||
float depth = _Shadowmap.SampleLevel(sampler_ShadowmapDummy, p.xy + offset, 0).r;
|
||||
float depth = ReverseZ(_Shadowmap.SampleLevel(sampler_ShadowmapDummy, p.xy + offset, 0).r);
|
||||
|
||||
dist += max(0.0, p.z - depth);
|
||||
}
|
||||
@ -91,6 +99,7 @@ half Shadow(half3 position)
|
||||
dist *= _ShadowReceiverDistanceScale;
|
||||
|
||||
p.z -= _ShadowBias/pClip.w;
|
||||
p.z = ReverseZ(p.z);
|
||||
half shadow = 0;
|
||||
for(int i = 0; i < 32; ++i)
|
||||
{
|
||||
|
@ -69,6 +69,10 @@ Shader "Hidden/BlurShadowmap" {
|
||||
// The texture contains just 0. But we need to sample it somewhere for Unity to initialize the corresponding sampler.
|
||||
z.r += _ShadowmapDummy.Sample(sampler_ShadowmapDummy, 0).a;
|
||||
|
||||
#if UNITY_REVERSED_Z
|
||||
z = 1.0 - z;
|
||||
#endif
|
||||
|
||||
// Transform to linear z, 0 at near, 1 at far
|
||||
z = z * 2 - 1;
|
||||
z = _ZParams.x * (z + 1.0) / (z + _ZParams.y);
|
||||
|
Loading…
Reference in New Issue
Block a user