diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2019-02-23 20:11:38 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2019-02-23 20:11:38 +0000 |
| commit | d55f0fa8db8fada02f729f51d4a2cb5afb308c3a (patch) | |
| tree | 3ba5d5ac52c0b9c995abca1bcbd74905fa5a383d /Shaders/PostProcess | |
| parent | Minor fix to scattering effect (diff) | |
| download | DiligentFX-d55f0fa8db8fada02f729f51d4a2cb5afb308c3a.tar.gz DiligentFX-d55f0fa8db8fada02f729f51d4a2cb5afb308c3a.zip | |
Light scattering: fixed issue with unshadowed scattering: the ray was not limited by intersection with earth
Diffstat (limited to 'Shaders/PostProcess')
| -rw-r--r-- | Shaders/PostProcess/EpipolarLightScattering/private/UnshadowedScattering.fxh | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/Shaders/PostProcess/EpipolarLightScattering/private/UnshadowedScattering.fxh b/Shaders/PostProcess/EpipolarLightScattering/private/UnshadowedScattering.fxh index cd7bfc5..f5d31af 100644 --- a/Shaders/PostProcess/EpipolarLightScattering/private/UnshadowedScattering.fxh +++ b/Shaders/PostProcess/EpipolarLightScattering/private/UnshadowedScattering.fxh @@ -15,17 +15,38 @@ void ComputeUnshadowedInscattering(float2 f2SampleLocation, f3ViewDir /= fRayLength; float3 f3EarthCentre = - float3(0.0, 1.0, 0.0) * EARTH_RADIUS; - float2 f2RayAtmTopIsecs; - GetRaySphereIntersection( f3CameraPos, f3ViewDir, f3EarthCentre, - ATM_TOP_RADIUS, - f2RayAtmTopIsecs); + float4 f4Isecs; + GetRaySphereIntersection2(f3CameraPos, f3ViewDir, f3EarthCentre, + float2(ATM_TOP_RADIUS, EARTH_RADIUS), f4Isecs); + float2 f2RayAtmTopIsecs = f4Isecs.xy; + float2 f2RayEarthIsecs = f4Isecs.zw; + if( f2RayAtmTopIsecs.y <= 0.0 ) + { + // view dir + // / + // d<0 / + // *---------> * + // . . . / . + // . ' ' . . ' /\ ' . + // / f2rayatmtopisecs.y < 0 + // + // the camera is outside the atmosphere and the ray either does not intersect the + // top of it or the intersection point is behind the camera. In either + // case there is no inscattering return; + } float3 f3RayStart = f3CameraPos + f3ViewDir * max(0.0, f2RayAtmTopIsecs.x); if( fCamSpaceZ > g_CameraAttribs.fFarPlaneZ ) // fFarPlaneZ is pre-multiplied with 0.999999f fRayLength = +FLT_MAX; - float3 f3RayEnd = f3CameraPos + f3ViewDir * min(fRayLength, f2RayAtmTopIsecs.y); + fRayLength = min(fRayLength, f2RayAtmTopIsecs.y); + // If there is an intersection with the Earth surface, limit the tracing distance to the intersection + if( f2RayEarthIsecs.x > 0.0 ) + { + fRayLength = min(fRayLength, f2RayEarthIsecs.x); + } + float3 f3RayEnd = f3CameraPos + f3ViewDir * fRayLength; #if SINGLE_SCATTERING_MODE == SINGLE_SCTR_MODE_INTEGRATION IntegrateUnshadowedInscattering(f3RayStart, |
