summaryrefslogtreecommitdiffstats
path: root/Shaders/PostProcess
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2020-05-04 04:28:11 +0000
committerassiduous <assiduous@diligentgraphics.com>2020-05-04 04:28:11 +0000
commitb7d83f64782af925a71b25d36df2bccac53e6c78 (patch)
tree5253532b12d1d0054ec1144087cb26fccf103f12 /Shaders/PostProcess
parentReworked light scattering fx to make RenderSun an explicit call, and remove S... (diff)
downloadDiligentFX-b7d83f64782af925a71b25d36df2bccac53e6c78.tar.gz
DiligentFX-b7d83f64782af925a71b25d36df2bccac53e6c78.zip
Updated atm scattering fx to allow negative altitudes
Diffstat (limited to 'Shaders/PostProcess')
-rw-r--r--Shaders/PostProcess/EpipolarLightScattering/private/CoarseInsctr.fx3
-rw-r--r--Shaders/PostProcess/EpipolarLightScattering/private/LookUpTables.fxh140
-rw-r--r--Shaders/PostProcess/EpipolarLightScattering/private/RayMarch.fx35
-rw-r--r--Shaders/PostProcess/EpipolarLightScattering/private/ScatteringIntegrals.fxh74
-rw-r--r--Shaders/PostProcess/EpipolarLightScattering/private/UnshadowedScattering.fxh20
-rw-r--r--Shaders/PostProcess/EpipolarLightScattering/private/UnwarpEpipolarScattering.fx2
-rw-r--r--Shaders/PostProcess/EpipolarLightScattering/private/precompute/ComputeScatteringOrder.fx25
-rw-r--r--Shaders/PostProcess/EpipolarLightScattering/private/precompute/ComputeSctrRadiance.fx18
-rw-r--r--Shaders/PostProcess/EpipolarLightScattering/private/precompute/PrecomputeAmbientSkyLight.fx3
-rw-r--r--Shaders/PostProcess/EpipolarLightScattering/private/precompute/PrecomputeNetDensityToAtmTop.fx6
-rw-r--r--Shaders/PostProcess/EpipolarLightScattering/private/precompute/PrecomputeSingleScattering.fx20
-rw-r--r--Shaders/PostProcess/EpipolarLightScattering/public/EpipolarLightScatteringStructures.fxh14
12 files changed, 221 insertions, 139 deletions
diff --git a/Shaders/PostProcess/EpipolarLightScattering/private/CoarseInsctr.fx b/Shaders/PostProcess/EpipolarLightScattering/private/CoarseInsctr.fx
index 12a2dac..3b1001a 100644
--- a/Shaders/PostProcess/EpipolarLightScattering/private/CoarseInsctr.fx
+++ b/Shaders/PostProcess/EpipolarLightScattering/private/CoarseInsctr.fx
@@ -59,9 +59,6 @@ void ShaderFunctionInternal(in float4 f4Pos,
7u, // Use hard-coded constant here so that compiler can optimize the code
// more efficiently
g_PPAttribs.f4EarthCenter.xyz,
- g_MediaParams.fEarthRadius,
- g_MediaParams.fAtmTopHeight,
- g_MediaParams.f4ParticleScaleHeight,
f3Inscattering, f3Extinction);
f3Inscattering *= g_LightAttribs.f4Intensity.rgb;
}
diff --git a/Shaders/PostProcess/EpipolarLightScattering/private/LookUpTables.fxh b/Shaders/PostProcess/EpipolarLightScattering/private/LookUpTables.fxh
index ecd06fd..d4dc418 100644
--- a/Shaders/PostProcess/EpipolarLightScattering/private/LookUpTables.fxh
+++ b/Shaders/PostProcess/EpipolarLightScattering/private/LookUpTables.fxh
@@ -6,18 +6,49 @@
#define SunViewPower 1.5
-float GetCosHorizonAngle(float fHeight, float EarthRadius)
+// Returns the cosine of the horizon angle for the given altitude
+// (height above the sphere surface) and sphere radius
+//
+// |
+// _ _ _ _ _| Horizon angle
+// A |'.
+// fAltitude | | '.
+// _V_ _ _ _| '.
+// . ' ' ' .'.
+// .' '.
+// ' '
+float GetCosHorizonAngle(float fAltitude, float fSphereRadius)
{
- // Due to numeric precision issues, fHeight might sometimes be slightly negative
- fHeight = max(fHeight, 0.0);
- return -sqrt(fHeight * (2.0*EarthRadius + fHeight) ) / (EarthRadius + fHeight);
+ fAltitude = max(fAltitude, 0.0);
+ return -sqrt(fAltitude * (2.0 * fSphereRadius + fAltitude)) / (fSphereRadius + fAltitude);
}
-float ZenithAngle2TexCoord(float fCosZenithAngle, float fHeight, float EarthRadius, float fTexDim, float power, float fPrevTexCoord)
+
+// Returns the lookup table zenith angle coordinate
+//
+// | Zenith .'
+// | angle .'
+// | .'
+// | .'
+// | .'
+// _ _ _ _ _|.'
+// A |
+// fAltitude | |
+// _V_ _ _ _|
+// . ' ' ' .
+// .' '.
+// ' '
+float ZenithAngle2TexCoord(float fCosZenithAngle, // Cosine of the zenith angle
+ float fAltitude, // Altitude (height above the sea level)
+ float fEarthRadius, // Earth radius at sea level
+ float fAtmBottomAltitude, // Altitude of the bottom atmosphere boundary (wrt sea level)
+ float fTexDim, // Look-up texture dimension
+ float power, // Non-linear transform power
+ float fPrevTexCoord // Previous look-up texture coordinate
+ )
{
- fCosZenithAngle = fCosZenithAngle;
- float fTexCoord;
- float fCosHorzAngle = GetCosHorizonAngle(fHeight, EarthRadius);
+ float fCosHorizonAngle = GetCosHorizonAngle(fAltitude - fAtmBottomAltitude, fEarthRadius + fAtmBottomAltitude);
+
// When performing look-ups into the scattering texture, it is very important that all the look-ups are consistent
// wrt to the horizon. This means that if the first look-up is above (below) horizon, then the second look-up
// should also be above (below) horizon.
@@ -25,11 +56,13 @@ float ZenithAngle2TexCoord(float fCosZenithAngle, float fHeight, float EarthRadi
// horizon. If texture coordinate is negative, then this is the first look-up
bool bIsAboveHorizon = fPrevTexCoord >= 0.5;
bool bIsBelowHorizon = 0.0 <= fPrevTexCoord && fPrevTexCoord < 0.5;
- if( bIsAboveHorizon ||
- !bIsBelowHorizon && (fCosZenithAngle > fCosHorzAngle) )
+
+ float fTexCoord;
+ if ( bIsAboveHorizon ||
+ !bIsBelowHorizon && (fCosZenithAngle > fCosHorizonAngle))
{
// Scale to [0,1]
- fTexCoord = saturate( (fCosZenithAngle - fCosHorzAngle) / (1.0 - fCosHorzAngle) );
+ fTexCoord = saturate( (fCosZenithAngle - fCosHorizonAngle) / (1.0 - fCosHorizonAngle) );
fTexCoord = pow(fTexCoord, power);
// Now remap texture coordinate to the upper half of the texture.
// To avoid filtering across discontinuity at 0.5, we must map
@@ -44,11 +77,11 @@ float ZenithAngle2TexCoord(float fCosZenithAngle, float fHeight, float EarthRadi
}
else
{
- fTexCoord = saturate( (fCosHorzAngle - fCosZenithAngle) / (fCosHorzAngle - (-1.0)) );
+ fTexCoord = saturate( (fCosHorizonAngle - fCosZenithAngle) / (fCosHorizonAngle - (-1.0)) );
fTexCoord = pow(fTexCoord, power);
// Now remap texture coordinate to the lower half of the texture.
// To avoid filtering across discontinuity at 0.5, we must map
- // the texture coordinate to [0.5, 0.5 - 0.5/fTexDim]
+ // the texture coordinate to [0.5/fTexDim, 0.5 - 0.5/fTexDim]
//
// 0.5 1.5 D/2-0.5 texture coordinate x dimension
// | | |
@@ -61,11 +94,19 @@ float ZenithAngle2TexCoord(float fCosZenithAngle, float fHeight, float EarthRadi
return fTexCoord;
}
-float TexCoord2ZenithAngle(float fTexCoord, float fHeight, float EarthRadius, float fTexDim, float power)
+
+// Transforms zenith angle look-up coordinate into the cosine of the zenith angle
+float TexCoord2ZenithAngle(float fTexCoord, // Texture coordinate
+ float fAltitde, // Altitude (height above the sea level)
+ float fEarthRadius, // Earth radius at sea level
+ float fAtmBottomAltitude, // Altitude of the bottom atmosphere boundary (wrt sea level)
+ float fTexDim, // Look-up texture dimension
+ float power // Non-linear transform power
+ )
{
float fCosZenithAngle;
- float fCosHorzAngle = GetCosHorizonAngle(fHeight, EarthRadius);
+ float fCosHorzAngle = GetCosHorizonAngle(fAltitde - fAtmBottomAltitude, fEarthRadius + fAtmBottomAltitude);
if( fTexCoord > 0.5 )
{
// Remap to [0,1] from the upper half of the texture [0.5 + 0.5/fTexDim, 1 - 0.5/fTexDim]
@@ -76,7 +117,7 @@ float TexCoord2ZenithAngle(float fTexCoord, float fHeight, float EarthRadius, fl
}
else
{
- // Remap to [0,1] from the lower half of the texture [0.5, 0.5 - 0.5/fTexDim]
+ // Remap to [0,1] from the lower half of the texture [0.5/fTexDim, 0.5 - 0.5/fTexDim]
fTexCoord = saturate((fTexCoord - 0.5 / fTexDim) * fTexDim / (fTexDim/2.0 - 1.0));
fTexCoord = pow(fTexCoord, 1.0/power);
// Assure that the ray DOES hit Earth
@@ -85,11 +126,12 @@ float TexCoord2ZenithAngle(float fTexCoord, float fHeight, float EarthRadius, fl
return fCosZenithAngle;
}
-
+// Transforms inscattering look-up table coordinates into world parameters
void InsctrLUTCoords2WorldParams(in float4 f4UVWQ,
in float fEarthRadius,
- in float fAtmTopHeight,
- out float fHeight,
+ in float fAtmBottomAltitude,
+ in float fAtmTopAltitude,
+ out float fAltitude,
out float fCosViewZenithAngle,
out float fCosSunZenithAngle,
out float fCosSunViewAngle)
@@ -99,11 +141,11 @@ void InsctrLUTCoords2WorldParams(in float4 f4UVWQ,
f4UVWQ.xzw = saturate(( f4UVWQ * PRECOMPUTED_SCTR_LUT_DIM - float4(0.5,0.5,0.5,0.5) ) / ( PRECOMPUTED_SCTR_LUT_DIM - float4(1.0,1.0,1.0,1.0) )).xzw;
f4UVWQ.x = pow( f4UVWQ.x, 1.0/HeightPower );
- // Allowable height range is limited to [SafetyHeightMargin, AtmTopHeight - SafetyHeightMargin] to
- // avoid numeric issues at the Earth surface and the top of the atmosphere
- fHeight = f4UVWQ.x * (fAtmTopHeight - 2.0*SafetyHeightMargin) + SafetyHeightMargin;
+ // Allowable altitude range is limited to [fAtmBottomAltitude + SafetyHeightMargin, fAtmTopAltitude - SafetyHeightMargin] to
+ // avoid numeric issues at the atmosphere boundaries
+ fAltitude = f4UVWQ.x * ((fAtmTopAltitude - fAtmBottomAltitude) - 2.0 * SafetyHeightMargin) + (fAtmBottomAltitude + SafetyHeightMargin);
- fCosViewZenithAngle = TexCoord2ZenithAngle(f4UVWQ.y, fHeight, fEarthRadius, PRECOMPUTED_SCTR_LUT_DIM.y, ViewZenithPower);
+ fCosViewZenithAngle = TexCoord2ZenithAngle(f4UVWQ.y, fAltitude, fEarthRadius, fAtmBottomAltitude, PRECOMPUTED_SCTR_LUT_DIM.y, ViewZenithPower);
// Use Eric Bruneton's formula for cosine of the sun-zenith angle
fCosSunZenithAngle = tan((2.0 * f4UVWQ.z - 1.0 + 0.26) * 1.1) / tan(1.26 * 1.1);
@@ -114,9 +156,9 @@ void InsctrLUTCoords2WorldParams(in float4 f4UVWQ,
// Rescale to exactly 0,1 range
f4UVWQ = (f4UVWQ * PRECOMPUTED_SCTR_LUT_DIM - float4(0.5,0.5,0.5,0.5)) / (PRECOMPUTED_SCTR_LUT_DIM-float4(1.0,1.0,1.0,1.0));
- // Allowable height range is limited to [SafetyHeightMargin, AtmTopHeight - SafetyHeightMargin] to
- // avoid numeric issues at the Earth surface and the top of the atmosphere
- fHeight = f4UVWQ.x * (fAtmTopHeight - 2*SafetyHeightMargin) + SafetyHeightMargin;
+ // Allowable altitude range is limited to [fAtmBottomAltitude + SafetyHeightMargin, fAtmTopAltitude - SafetyHeightMargin] to
+ // avoid numeric issues at the atmosphere boundaries
+ fAltitude = f4UVWQ.x * ((fAtmTopAltitude - fAtmBottomAltitude) - 2.0 * SafetyHeightMargin) + (fAtmBottomAltitude + SafetyHeightMargin);
fCosViewZenithAngle = f4UVWQ.y * 2.0 - 1.0;
fCosSunZenithAngle = f4UVWQ.z * 2.0 - 1.0;
@@ -147,27 +189,27 @@ void InsctrLUTCoords2WorldParams(in float4 f4UVWQ,
fCosSunViewAngle = clamp(fCosSunViewAngle, f2MinMaxCosSunViewAngle.x, f2MinMaxCosSunViewAngle.y);
}
-float4 WorldParams2InsctrLUTCoords(float fHeight,
+float4 WorldParams2InsctrLUTCoords(float fAltitude,
float fCosViewZenithAngle,
float fCosSunZenithAngle,
float fCosSunViewAngle,
float fEarthRadius,
- float fAtmTopHeight,
+ float fAtmBottomAltitude,
+ float fAtmTopAltitude,
float4 f4RefUVWQ)
{
float4 f4UVWQ;
- // Limit allowable height range to [SafetyHeightMargin, AtmTopHeight - SafetyHeightMargin] to
- // avoid numeric issues at the Earth surface and the top of the atmosphere
- // (ray/Earth and ray/top of the atmosphere intersection tests are unstable when fHeight == 0 and
- // fHeight == AtmTopHeight respectively)
- fHeight = clamp(fHeight, SafetyHeightMargin, fAtmTopHeight - SafetyHeightMargin);
- f4UVWQ.x = saturate( (fHeight - SafetyHeightMargin) / (fAtmTopHeight - 2.0*SafetyHeightMargin) );
+ // Limit allowable altitude range to [fAtmBottomAltitude + SafetyHeightMargin, AtmTopAltitude - SafetyHeightMargin] to
+ // avoid numeric issues at the atmosphere boundaries.
+ // (ray/sphere intersection tests are unstable when fAltitude == fAtmBottomAltitude and fAltitude == AtmTopAltitude)
+ fAltitude = clamp(fAltitude, fAtmBottomAltitude + SafetyHeightMargin, fAtmTopAltitude - SafetyHeightMargin);
+ f4UVWQ.x = saturate( (fAltitude - (fAtmBottomAltitude + SafetyHeightMargin)) / ((fAtmTopAltitude - fAtmBottomAltitude) - 2.0*SafetyHeightMargin) );
#if NON_LINEAR_PARAMETERIZATION
f4UVWQ.x = pow(f4UVWQ.x, HeightPower);
- f4UVWQ.y = ZenithAngle2TexCoord(fCosViewZenithAngle, fHeight, fEarthRadius, PRECOMPUTED_SCTR_LUT_DIM.y, ViewZenithPower, f4RefUVWQ.y);
+ f4UVWQ.y = ZenithAngle2TexCoord(fCosViewZenithAngle, fAltitude, fEarthRadius, fAtmBottomAltitude, PRECOMPUTED_SCTR_LUT_DIM.y, ViewZenithPower, f4RefUVWQ.y);
// Use Eric Bruneton's formula for cosine of the sun-zenith angle
f4UVWQ.z = (atan(max(fCosSunZenithAngle, -0.1975) * tan(1.26 * 1.1)) / 1.1 + (1.0 - 0.26)) * 0.5;
@@ -188,18 +230,6 @@ float4 WorldParams2InsctrLUTCoords(float fHeight,
return f4UVWQ;
}
-float4 WorldParams2InsctrLUTCoords(float fHeight,
- float fCosViewZenithAngle,
- float fCosSunZenithAngle,
- float fCosSunViewAngle,
- float fEarthRadius,
- float fAtmTopHeight)
-{
- return WorldParams2InsctrLUTCoords( fHeight, fCosViewZenithAngle, fCosSunZenithAngle, fCosSunViewAngle, fEarthRadius, fAtmTopHeight,
- float4(-1.0, -1.0, -1.0, -1.0) );
-}
-
-
float3 ComputeViewDir(in float fCosViewZenithAngle)
{
return float3(sqrt(saturate(1.0 - fCosViewZenithAngle*fCosViewZenithAngle)), fCosViewZenithAngle, 0.0);
@@ -228,7 +258,8 @@ float3 LookUpPrecomputedScattering(in float3 f3StartPoint,
in float3 f3EarthCentre,
in float fEarthRadius,
in float3 f3DirOnLight,
- in float fAtmTopHeight,
+ in float fAtmBottomAltitude,
+ in float fAtmTopAltitude,
in Texture3D<float3> tex3DScatteringLUT,
in SamplerState tex3DScatteringLUT_sampler,
inout float4 f4UVWQ)
@@ -236,15 +267,20 @@ float3 LookUpPrecomputedScattering(in float3 f3StartPoint,
float3 f3EarthCentreToPointDir = f3StartPoint - f3EarthCentre;
float fDistToEarthCentre = length(f3EarthCentreToPointDir);
f3EarthCentreToPointDir /= fDistToEarthCentre;
- float fHeightAboveSurface = fDistToEarthCentre - fEarthRadius;
+ float fAltitude = fDistToEarthCentre - fEarthRadius; // Height above sea level
float fCosViewZenithAngle = dot( f3EarthCentreToPointDir, f3ViewDir );
float fCosSunZenithAngle = dot( f3EarthCentreToPointDir, f3DirOnLight );
float fCosSunViewAngle = dot( f3ViewDir, f3DirOnLight );
// Provide previous look-up coordinates
- f4UVWQ = WorldParams2InsctrLUTCoords(fHeightAboveSurface, fCosViewZenithAngle,
- fCosSunZenithAngle, fCosSunViewAngle, fEarthRadius,
- fAtmTopHeight, f4UVWQ);
+ f4UVWQ = WorldParams2InsctrLUTCoords(fAltitude,
+ fCosViewZenithAngle,
+ fCosSunZenithAngle,
+ fCosSunViewAngle,
+ fEarthRadius,
+ fAtmBottomAltitude,
+ fAtmTopAltitude,
+ f4UVWQ);
float3 f3UVW0;
f3UVW0.xy = f4UVWQ.xy;
diff --git a/Shaders/PostProcess/EpipolarLightScattering/private/RayMarch.fx b/Shaders/PostProcess/EpipolarLightScattering/private/RayMarch.fx
index 2928ab7..926642f 100644
--- a/Shaders/PostProcess/EpipolarLightScattering/private/RayMarch.fx
+++ b/Shaders/PostProcess/EpipolarLightScattering/private/RayMarch.fx
@@ -91,10 +91,10 @@ float3 ComputeShadowedInscattering( in float2 f2RayMarchingSampleLocation,
float3 f3EarthCentre = g_PPAttribs.f4EarthCenter.xyz;
- // Intersect the ray with the top of the atmosphere and the Earth:
+ // Intersect the ray with the atmosphere boundaries:
float4 f4Isecs;
GetRaySphereIntersection2(f3CameraPos, f3ViewDir, f3EarthCentre,
- float2(g_MediaParams.fAtmTopRadius, g_MediaParams.fEarthRadius), f4Isecs);
+ float2(g_MediaParams.fAtmTopRadius, g_MediaParams.fAtmBottomRadius), f4Isecs);
float2 f2RayAtmTopIsecs = f4Isecs.xy;
float2 f2RayEarthIsecs = f4Isecs.zw;
@@ -421,7 +421,7 @@ float3 ComputeShadowedInscattering( in float2 f2RayMarchingSampleLocation,
// Get net particle density from the integration point to the top of the atmosphere:
float fCosSunZenithAngle = dot( f3EarthCentreToPointDir, -g_LightAttribs.f4Direction.xyz );
- float2 f2NetParticleDensityToAtmTop = GetNetParticleDensity(fHeightAboveSurface, fCosSunZenithAngle, g_MediaParams.fAtmTopHeight);
+ float2 f2NetParticleDensityToAtmTop = GetNetParticleDensity(fHeightAboveSurface, fCosSunZenithAngle, g_MediaParams.fAtmBottomAltitude, g_MediaParams.fAtmAltitudeRangeInv);
// Compute total particle density from the top of the atmosphere through the integraion point to camera
float2 f2TotalParticleDensity = f2ParticleNetDensityFromCam + f2NetParticleDensityToAtmTop;
@@ -490,7 +490,8 @@ float3 ComputeShadowedInscattering( in float2 f2RayMarchingSampleLocation,
f3RayEnd,
f3EarthCentre,
g_MediaParams.fEarthRadius,
- g_MediaParams.fAtmTopHeight,
+ g_MediaParams.fAtmBottomAltitude,
+ g_MediaParams.fAtmAltitudeRangeInv,
g_MediaParams.f4ParticleScaleHeight,
-g_LightAttribs.f4Direction.xyz,
uiNumSteps,
@@ -549,7 +550,8 @@ float3 ComputeShadowedInscattering( in float2 f2RayMarchingSampleLocation,
f3EarthCentre,
g_MediaParams.fEarthRadius,
-g_LightAttribs.f4Direction.xyz,
- g_MediaParams.fAtmTopHeight,
+ g_MediaParams.fAtmBottomAltitude,
+ g_MediaParams.fAtmTopAltitude,
tex3DSctrLUT,
tex3DSctrLUT_sampler,
f4UVWQ);
@@ -568,7 +570,8 @@ float3 ComputeShadowedInscattering( in float2 f2RayMarchingSampleLocation,
f3EarthCentre,
g_MediaParams.fEarthRadius,
-g_LightAttribs.f4Direction.xyz,
- g_MediaParams.fAtmTopHeight,
+ g_MediaParams.fAtmBottomAltitude,
+ g_MediaParams.fAtmTopAltitude,
tex3DSctrLUT,
tex3DSctrLUT_sampler,
f4UVWQ);
@@ -589,7 +592,8 @@ float3 ComputeShadowedInscattering( in float2 f2RayMarchingSampleLocation,
f3EarthCentre,
g_MediaParams.fEarthRadius,
-g_LightAttribs.f4Direction.xyz,
- g_MediaParams.fAtmTopHeight,
+ g_MediaParams.fAtmBottomAltitude,
+ g_MediaParams.fAtmTopAltitude,
tex3DSctrLUT,
tex3DSctrLUT_sampler,
f4UVWQ);
@@ -603,7 +607,8 @@ float3 ComputeShadowedInscattering( in float2 f2RayMarchingSampleLocation,
f3EarthCentre,
g_MediaParams.fEarthRadius,
-g_LightAttribs.f4Direction.xyz,
- g_MediaParams.fAtmTopHeight,
+ g_MediaParams.fAtmBottomAltitude,
+ g_MediaParams.fAtmTopAltitude,
tex3DSctrLUT,
tex3DSctrLUT_sampler,
f4UVWQ);
@@ -629,7 +634,8 @@ float3 ComputeShadowedInscattering( in float2 f2RayMarchingSampleLocation,
f3EarthCentre,
g_MediaParams.fEarthRadius,
-g_LightAttribs.f4Direction.xyz,
- g_MediaParams.fAtmTopHeight,
+ g_MediaParams.fAtmBottomAltitude,
+ g_MediaParams.fAtmTopAltitude,
g_tex3DHighOrderSctrLUT,
g_tex3DHighOrderSctrLUT_sampler,
f4UVWQ);
@@ -645,7 +651,8 @@ float3 ComputeShadowedInscattering( in float2 f2RayMarchingSampleLocation,
f3EarthCentre,
g_MediaParams.fEarthRadius,
-g_LightAttribs.f4Direction.xyz,
- g_MediaParams.fAtmTopHeight,
+ g_MediaParams.fAtmBottomAltitude,
+ g_MediaParams.fAtmTopAltitude,
g_tex3DHighOrderSctrLUT,
g_tex3DHighOrderSctrLUT_sampler,
f4UVWQ);
@@ -686,9 +693,6 @@ void RayMarchPS(in FullScreenTriangleVSOutput VSOut,
fRayEndCamSpaceZ,
g_PPAttribs.uiInstrIntegralSteps,
g_PPAttribs.f4EarthCenter.xyz,
- g_MediaParams.fEarthRadius,
- g_MediaParams.fAtmTopHeight,
- g_MediaParams.f4ParticleScaleHeight,
f4Inscattering.rgb,
f3Extinction);
f4Inscattering.rgb *= g_LightAttribs.f4Intensity.rgb;
@@ -737,7 +741,7 @@ void FixAndApplyInscatteredRadiancePS(FullScreenTriangleVSOutput VSOut,
f3BackgroundColor *= (fCamSpaceZ > g_CameraAttribs.fFarPlaneZ) ? g_LightAttribs.f4Intensity.rgb : float3(1.0, 1.0, 1.0);
float3 f3ReconstructedPosWS = ProjSpaceXYZToWorldSpace(float3(VSOut.f2NormalizedXY.xy, fCamSpaceZ), g_CameraAttribs.mProj, g_CameraAttribs.mViewProjInv);
float3 f3Extinction = GetExtinction(g_CameraAttribs.f4Position.xyz, f3ReconstructedPosWS, g_PPAttribs.f4EarthCenter.xyz,
- g_MediaParams.fEarthRadius, g_MediaParams.fAtmTopRadius, g_MediaParams.f4ParticleScaleHeight);
+ g_MediaParams.fAtmBottomRadius, g_MediaParams.fAtmTopRadius, g_MediaParams.f4ParticleScaleHeight);
f3BackgroundColor *= f3Extinction.rgb;
}
@@ -756,9 +760,6 @@ void FixAndApplyInscatteredRadiancePS(FullScreenTriangleVSOutput VSOut,
fCamSpaceZ,
g_PPAttribs.uiInstrIntegralSteps,
g_PPAttribs.f4EarthCenter.xyz,
- g_MediaParams.fEarthRadius,
- g_MediaParams.fAtmTopHeight,
- g_MediaParams.f4ParticleScaleHeight,
f3InsctrColor,
f3Extinction);
f3InsctrColor *= g_LightAttribs.f4Intensity.rgb;
diff --git a/Shaders/PostProcess/EpipolarLightScattering/private/ScatteringIntegrals.fxh b/Shaders/PostProcess/EpipolarLightScattering/private/ScatteringIntegrals.fxh
index 61d118f..6062421 100644
--- a/Shaders/PostProcess/EpipolarLightScattering/private/ScatteringIntegrals.fxh
+++ b/Shaders/PostProcess/EpipolarLightScattering/private/ScatteringIntegrals.fxh
@@ -1,24 +1,26 @@
-float2 GetNetParticleDensity(in float fHeightAboveSurface,
- in float fCosZenithAngle,
- in float fAtmTopHeight)
+// Returns net particle density to the atmosphere top
+//
+// | Zenith .'
+// | angle .'
+// | .'
+// | .'
+// | .'
+// _ _ _ _ _|.'
+// A |
+// fAltitude | |
+// _V_ _ _ _|
+// . ' ' ' .
+// .' '.
+// ' '
+float2 GetNetParticleDensity(in float fAltitude, // Altitude (height above the sea level) of the starting point
+ in float fCosZenithAngle, // Cosine of the zenith angle
+ in float fAtmBottomAltitude, // Altitude of the bottom atmosphere boundary
+ in float fAtmAltitudeRangeInv // 1 / (fAtmTopAltitude - fAtmBottomAltitude)
+ )
{
- float fRelativeHeightAboveSurface = fHeightAboveSurface / fAtmTopHeight;
- return g_tex2DOccludedNetDensityToAtmTop.SampleLevel(g_tex2DOccludedNetDensityToAtmTop_sampler, float2(fRelativeHeightAboveSurface, fCosZenithAngle*0.5+0.5), 0);
-}
-
-float2 GetNetParticleDensity(in float3 f3Pos,
- in float3 f3EarthCentre,
- in float fEarthRadius,
- in float fAtmTopHeight,
- in float3 f3RayDir)
-{
- float3 f3EarthCentreToPointDir = f3Pos - f3EarthCentre;
- float fDistToEarthCentre = length(f3EarthCentreToPointDir);
- f3EarthCentreToPointDir /= fDistToEarthCentre;
- float fHeightAboveSurface = fDistToEarthCentre - fEarthRadius;
- float fCosZenithAngle = dot( f3EarthCentreToPointDir, f3RayDir );
- return GetNetParticleDensity(fHeightAboveSurface, fCosZenithAngle, fAtmTopHeight);
+ float fNormalizedAltitude = (fAltitude - fAtmBottomAltitude) * fAtmAltitudeRangeInv;
+ return g_tex2DOccludedNetDensityToAtmTop.SampleLevel(g_tex2DOccludedNetDensityToAtmTop_sampler, float2(fNormalizedAltitude, fCosZenithAngle*0.5+0.5), 0);
}
void ApplyPhaseFunctions(inout float3 f3RayleighInscattering,
@@ -39,7 +41,8 @@ void ApplyPhaseFunctions(inout float3 f3RayleighInscattering,
void GetAtmosphereProperties(in float3 f3Pos,
in float3 f3EarthCentre,
in float fEarthRadius,
- in float fAtmTopHeight,
+ in float fAtmBottomAltitude,
+ in float fAtmAltitudeRangeInv,
in float4 f4ParticleScaleHeight,
in float3 f3DirOnLight,
out float2 f2ParticleDensity,
@@ -55,7 +58,7 @@ void GetAtmosphereProperties(in float3 f3Pos,
// Get net particle density from the integration point to the top of the atmosphere:
float fCosSunZenithAngleForCurrPoint = dot( f3EarthCentreToPointDir, f3DirOnLight );
- f2NetParticleDensityToAtmTop = GetNetParticleDensity(fHeightAboveSurface, fCosSunZenithAngleForCurrPoint, fAtmTopHeight);
+ f2NetParticleDensityToAtmTop = GetNetParticleDensity(fHeightAboveSurface, fCosSunZenithAngleForCurrPoint, fAtmBottomAltitude, fAtmAltitudeRangeInv);
}
// This function computes differential inscattering for the given particle densities
@@ -84,7 +87,8 @@ void ComputeInsctrIntegral(in float3 f3RayStart,
in float3 f3RayEnd,
in float3 f3EarthCentre,
in float fEarthRadius,
- in float fAtmTopHeight,
+ in float fAtmBottomAltitude,
+ in float fAtmAltitudeRangeInv,
in float4 f4ParticleScaleHeight,
in float3 f3DirOnLight,
in uint uiNumSteps,
@@ -99,7 +103,15 @@ void ComputeInsctrIntegral(in float3 f3RayStart,
// For trapezoidal integration we need to compute some variables for the starting point of the ray
float2 f2PrevParticleDensity = float2(0.0, 0.0);
float2 f2NetParticleDensityToAtmTop = float2(0.0, 0.0);
- GetAtmosphereProperties(f3RayStart, f3EarthCentre, fEarthRadius, fAtmTopHeight, f4ParticleScaleHeight, f3DirOnLight, f2PrevParticleDensity, f2NetParticleDensityToAtmTop);
+ GetAtmosphereProperties(f3RayStart,
+ f3EarthCentre,
+ fEarthRadius,
+ fAtmBottomAltitude,
+ fAtmAltitudeRangeInv,
+ f4ParticleScaleHeight,
+ f3DirOnLight,
+ f2PrevParticleDensity,
+ f2NetParticleDensityToAtmTop);
float3 f3PrevDiffRInsctr = float3(0.0, 0.0, 0.0), f3PrevDiffMInsctr = float3(0.0, 0.0, 0.0);
ComputePointDiffInsctr(f2PrevParticleDensity, f2NetParticleDensityFromCam, f2NetParticleDensityToAtmTop, f3PrevDiffRInsctr, f3PrevDiffMInsctr);
@@ -119,7 +131,15 @@ void ComputeInsctrIntegral(in float3 f3RayStart,
#endif
float2 f2ParticleDensity, f2NetParticleDensityToAtmTop;
- GetAtmosphereProperties(f3CurrPos, f3EarthCentre, fEarthRadius, fAtmTopHeight, f4ParticleScaleHeight, f3DirOnLight, f2ParticleDensity, f2NetParticleDensityToAtmTop);
+ GetAtmosphereProperties(f3CurrPos,
+ f3EarthCentre,
+ fEarthRadius,
+ fAtmBottomAltitude,
+ fAtmAltitudeRangeInv,
+ f4ParticleScaleHeight,
+ f3DirOnLight,
+ f2ParticleDensity,
+ f2NetParticleDensityToAtmTop);
// Accumulate net particle density from the camera to the integration point:
#if TRAPEZOIDAL_INTEGRATION
@@ -151,7 +171,8 @@ void IntegrateUnshadowedInscattering(in float3 f3RayStart,
in float3 f3ViewDir,
in float3 f3EarthCentre,
in float fEarthRadius,
- in float fAtmTopHeight,
+ in float fAtmBottomAltitude,
+ in float fAtmAltitudeRangeInv,
in float4 f4ParticleScaleHeight,
in float3 f3DirOnLight,
in uint uiNumSteps,
@@ -165,7 +186,8 @@ void IntegrateUnshadowedInscattering(in float3 f3RayStart,
f3RayEnd,
f3EarthCentre,
fEarthRadius,
- fAtmTopHeight,
+ fAtmBottomAltitude,
+ fAtmAltitudeRangeInv,
f4ParticleScaleHeight,
f3DirOnLight,
uiNumSteps,
diff --git a/Shaders/PostProcess/EpipolarLightScattering/private/UnshadowedScattering.fxh b/Shaders/PostProcess/EpipolarLightScattering/private/UnshadowedScattering.fxh
index a4dba9d..b4612ed 100644
--- a/Shaders/PostProcess/EpipolarLightScattering/private/UnshadowedScattering.fxh
+++ b/Shaders/PostProcess/EpipolarLightScattering/private/UnshadowedScattering.fxh
@@ -4,9 +4,6 @@ void ComputeUnshadowedInscattering(float2 f2SampleLocation,
float fCamSpaceZ,
uint uiNumSteps,
float3 f3EarthCentre,
- float fEarthRadius,
- float fAtmTopHeight,
- float4 f4ParticleScaleHeight,
out float3 f3Inscattering,
out float3 f3Extinction)
{
@@ -20,7 +17,7 @@ void ComputeUnshadowedInscattering(float2 f2SampleLocation,
float4 f4Isecs;
GetRaySphereIntersection2(f3CameraPos, f3ViewDir, f3EarthCentre,
- float2(fEarthRadius + fAtmTopHeight, fEarthRadius), f4Isecs);
+ float2(g_MediaParams.fAtmTopRadius, g_MediaParams.fAtmBottomRadius), f4Isecs);
float2 f2RayAtmTopIsecs = f4Isecs.xy;
float2 f2RayEarthIsecs = f4Isecs.zw;
@@ -56,9 +53,10 @@ void ComputeUnshadowedInscattering(float2 f2SampleLocation,
f3RayEnd,
f3ViewDir,
f3EarthCentre,
- fEarthRadius,
- fAtmTopHeight,
- f4ParticleScaleHeight,
+ g_MediaParams.fEarthRadius,
+ g_MediaParams.fAtmBottomAltitude,
+ g_MediaParams.fAtmAltitudeRangeInv,
+ g_MediaParams.f4ParticleScaleHeight,
-g_LightAttribs.f4Direction.xyz,
uiNumSteps,
f3Inscattering,
@@ -80,7 +78,7 @@ void ComputeUnshadowedInscattering(float2 f2SampleLocation,
#define tex3DSctrLUT_sampler g_tex3DSingleSctrLUT_sampler
#endif
- f3Extinction = GetExtinctionUnverified(f3RayStart, f3RayEnd, f3ViewDir, f3EarthCentre, fEarthRadius, f4ParticleScaleHeight);
+ f3Extinction = GetExtinctionUnverified(f3RayStart, f3RayEnd, f3ViewDir, f3EarthCentre, g_MediaParams.fEarthRadius, g_MediaParams.f4ParticleScaleHeight);
// To avoid artifacts, we must be consistent when performing look-ups into the scattering texture, i.e.
// we must assure that if the first look-up is above (below) horizon, then the second look-up
@@ -93,7 +91,8 @@ void ComputeUnshadowedInscattering(float2 f2SampleLocation,
f3EarthCentre,
g_MediaParams.fEarthRadius,
-g_LightAttribs.f4Direction.xyz,
- g_MediaParams.fAtmTopHeight,
+ g_MediaParams.fAtmBottomAltitude,
+ g_MediaParams.fAtmTopAltitude,
tex3DSctrLUT,
tex3DSctrLUT_sampler,
f4UVWQ);
@@ -106,7 +105,8 @@ void ComputeUnshadowedInscattering(float2 f2SampleLocation,
f3EarthCentre,
g_MediaParams.fEarthRadius,
-g_LightAttribs.f4Direction.xyz,
- g_MediaParams.fAtmTopHeight,
+ g_MediaParams.fAtmBottomAltitude,
+ g_MediaParams.fAtmTopAltitude,
tex3DSctrLUT,
tex3DSctrLUT_sampler,
f4UVWQ);
diff --git a/Shaders/PostProcess/EpipolarLightScattering/private/UnwarpEpipolarScattering.fx b/Shaders/PostProcess/EpipolarLightScattering/private/UnwarpEpipolarScattering.fx
index f23ec94..73479fa 100644
--- a/Shaders/PostProcess/EpipolarLightScattering/private/UnwarpEpipolarScattering.fx
+++ b/Shaders/PostProcess/EpipolarLightScattering/private/UnwarpEpipolarScattering.fx
@@ -293,7 +293,7 @@ void ApplyInscatteredRadiancePS(FullScreenTriangleVSOutput VSOut,
#if EXTINCTION_EVAL_MODE == EXTINCTION_EVAL_MODE_PER_PIXEL
float3 f3ReconstructedPosWS = ProjSpaceXYZToWorldSpace(float3(VSOut.f2NormalizedXY.xy, fCamSpaceZ), g_CameraAttribs.mProj, g_CameraAttribs.mViewProjInv);
f3Extinction = GetExtinction(g_CameraAttribs.f4Position.xyz, f3ReconstructedPosWS, g_PPAttribs.f4EarthCenter.xyz,
- g_MediaParams.fEarthRadius, g_MediaParams.fAtmTopRadius, g_MediaParams.f4ParticleScaleHeight);
+ g_MediaParams.fAtmBottomRadius, g_MediaParams.fAtmTopRadius, g_MediaParams.f4ParticleScaleHeight);
#endif
f3BackgroundColor *= f3Extinction;
}
diff --git a/Shaders/PostProcess/EpipolarLightScattering/private/precompute/ComputeScatteringOrder.fx b/Shaders/PostProcess/EpipolarLightScattering/private/precompute/ComputeScatteringOrder.fx
index fce95cd..5ede280 100644
--- a/Shaders/PostProcess/EpipolarLightScattering/private/precompute/ComputeScatteringOrder.fx
+++ b/Shaders/PostProcess/EpipolarLightScattering/private/precompute/ComputeScatteringOrder.fx
@@ -24,17 +24,24 @@ void ComputeScatteringOrderCS(uint3 ThreadId : SV_DispatchThreadID)
{
// Get attributes for the current point
float4 f4LUTCoords = LUTCoordsFromThreadID(ThreadId);
- float fHeight, fCosViewZenithAngle, fCosSunZenithAngle, fCosSunViewAngle;
- InsctrLUTCoords2WorldParams(f4LUTCoords, g_MediaParams.fEarthRadius, g_MediaParams.fAtmTopHeight, fHeight, fCosViewZenithAngle, fCosSunZenithAngle, fCosSunViewAngle );
+ float fAltitude, fCosViewZenithAngle, fCosSunZenithAngle, fCosSunViewAngle;
+ InsctrLUTCoords2WorldParams(f4LUTCoords,
+ g_MediaParams.fEarthRadius,
+ g_MediaParams.fAtmBottomAltitude,
+ g_MediaParams.fAtmTopAltitude,
+ fAltitude,
+ fCosViewZenithAngle,
+ fCosSunZenithAngle,
+ fCosSunViewAngle);
float3 f3EarthCentre = float3(0.0, -g_MediaParams.fEarthRadius, 0.0);
- float3 f3RayStart = float3(0.0, fHeight, 0.0);
+ float3 f3RayStart = float3(0.0, fAltitude, 0.0);
float3 f3ViewDir = ComputeViewDir(fCosViewZenithAngle);
float3 f3DirOnLight = ComputeLightDir(f3ViewDir, fCosSunZenithAngle, fCosSunViewAngle);
- // Intersect the ray with the atmosphere and Earth
+ // Intersect the ray with the atmosphere boundaries
float4 f4Isecs;
GetRaySphereIntersection2( f3RayStart, f3ViewDir, f3EarthCentre,
- float2(g_MediaParams.fEarthRadius, g_MediaParams.fAtmTopRadius),
+ float2(g_MediaParams.fAtmBottomRadius, g_MediaParams.fAtmTopRadius),
f4Isecs);
float2 f2RayEarthIsecs = f4Isecs.xy;
float2 f2RayAtmTopIsecs = f4Isecs.zw;
@@ -64,11 +71,12 @@ void ComputeScatteringOrderCS(uint3 ThreadId : SV_DispatchThreadID)
f3EarthCentre,
g_MediaParams.fEarthRadius,
f3DirOnLight.xyz,
- g_MediaParams.fAtmTopHeight,
+ g_MediaParams.fAtmBottomAltitude,
+ g_MediaParams.fAtmTopAltitude,
g_tex3DPointwiseSctrRadiance,
g_tex3DPointwiseSctrRadiance_sampler,
f4UVWQ);
- float2 f2PrevParticleDensity = exp( -float2(fHeight, fHeight) * g_MediaParams.f4ParticleScaleHeight.zw );
+ float2 f2PrevParticleDensity = exp( -float2(fAltitude, fAltitude) * g_MediaParams.f4ParticleScaleHeight.zw );
float2 f2NetParticleDensityFromCam = float2(0.0, 0.0);
float3 f3Inscattering = float3(0.0, 0.0, 0.0);
@@ -99,7 +107,8 @@ void ComputeScatteringOrderCS(uint3 ThreadId : SV_DispatchThreadID)
f3EarthCentre,
g_MediaParams.fEarthRadius,
f3DirOnLight.xyz,
- g_MediaParams.fAtmTopHeight,
+ g_MediaParams.fAtmBottomAltitude,
+ g_MediaParams.fAtmTopAltitude,
g_tex3DPointwiseSctrRadiance,
g_tex3DPointwiseSctrRadiance_sampler,
f4UVWQ);
diff --git a/Shaders/PostProcess/EpipolarLightScattering/private/precompute/ComputeSctrRadiance.fx b/Shaders/PostProcess/EpipolarLightScattering/private/precompute/ComputeSctrRadiance.fx
index 604a5ea..ba16990 100644
--- a/Shaders/PostProcess/EpipolarLightScattering/private/precompute/ComputeSctrRadiance.fx
+++ b/Shaders/PostProcess/EpipolarLightScattering/private/precompute/ComputeSctrRadiance.fx
@@ -28,15 +28,22 @@ void ComputeSctrRadianceCS(uint3 ThreadId : SV_DispatchThreadID)
{
// Get attributes for the current point
float4 f4LUTCoords = LUTCoordsFromThreadID(ThreadId);
- float fHeight, fCosViewZenithAngle, fCosSunZenithAngle, fCosSunViewAngle;
- InsctrLUTCoords2WorldParams( f4LUTCoords, g_MediaParams.fEarthRadius, g_MediaParams.fAtmTopHeight, fHeight, fCosViewZenithAngle, fCosSunZenithAngle, fCosSunViewAngle );
+ float fAltitude, fCosViewZenithAngle, fCosSunZenithAngle, fCosSunViewAngle;
+ InsctrLUTCoords2WorldParams(f4LUTCoords,
+ g_MediaParams.fEarthRadius,
+ g_MediaParams.fAtmBottomAltitude,
+ g_MediaParams.fAtmTopAltitude,
+ fAltitude,
+ fCosViewZenithAngle,
+ fCosSunZenithAngle,
+ fCosSunViewAngle );
float3 f3EarthCentre = float3(0.0, -g_MediaParams.fEarthRadius, 0.0);
- float3 f3RayStart = float3(0.0, fHeight, 0.0);
+ float3 f3RayStart = float3(0.0, fAltitude, 0.0);
float3 f3ViewDir = ComputeViewDir(fCosViewZenithAngle);
float3 f3DirOnLight = ComputeLightDir(f3ViewDir, fCosSunZenithAngle, fCosSunViewAngle);
// Compute particle density scale factor
- float2 f2ParticleDensity = exp( -float2(fHeight, fHeight) * g_MediaParams.f4ParticleScaleHeight.zw );
+ float2 f2ParticleDensity = exp( -float2(fAltitude, fAltitude) * g_MediaParams.f4ParticleScaleHeight.zw );
float3 f3SctrRadiance = float3(0.0, 0.0, 0.0);
// Go through a number of samples randomly distributed over the sphere
@@ -52,7 +59,8 @@ void ComputeSctrRadianceCS(uint3 ThreadId : SV_DispatchThreadID)
f3EarthCentre,
g_MediaParams.fEarthRadius,
f3DirOnLight.xyz,
- g_MediaParams.fAtmTopHeight,
+ g_MediaParams.fAtmBottomAltitude,
+ g_MediaParams.fAtmTopAltitude,
g_tex3DPreviousSctrOrder,
g_tex3DPreviousSctrOrder_sampler,
f4UVWQ);
diff --git a/Shaders/PostProcess/EpipolarLightScattering/private/precompute/PrecomputeAmbientSkyLight.fx b/Shaders/PostProcess/EpipolarLightScattering/private/precompute/PrecomputeAmbientSkyLight.fx
index 9826257..ab3efae 100644
--- a/Shaders/PostProcess/EpipolarLightScattering/private/precompute/PrecomputeAmbientSkyLight.fx
+++ b/Shaders/PostProcess/EpipolarLightScattering/private/precompute/PrecomputeAmbientSkyLight.fx
@@ -41,7 +41,8 @@ void PrecomputeAmbientSkyLightPS(FullScreenTriangleVSOutput VSOut,
f3EarthCentre,
g_MediaParams.fEarthRadius,
f3DirOnLight.xyz,
- g_MediaParams.fAtmTopHeight,
+ g_MediaParams.fAtmBottomAltitude,
+ g_MediaParams.fAtmTopAltitude,
g_tex3DMultipleSctrLUT,
g_tex3DMultipleSctrLUT_sampler,
f4UVWQ);
diff --git a/Shaders/PostProcess/EpipolarLightScattering/private/precompute/PrecomputeNetDensityToAtmTop.fx b/Shaders/PostProcess/EpipolarLightScattering/private/precompute/PrecomputeNetDensityToAtmTop.fx
index 8fdefb3..472909e 100644
--- a/Shaders/PostProcess/EpipolarLightScattering/private/precompute/PrecomputeNetDensityToAtmTop.fx
+++ b/Shaders/PostProcess/EpipolarLightScattering/private/precompute/PrecomputeNetDensityToAtmTop.fx
@@ -37,9 +37,9 @@ float2 IntegrateParticleDensityAlongRay(float3 f3Pos,
{
if( bOccludeByEarth )
{
- // If the ray intersects the Earth, return huge optical depth
+ // If the ray hits the bottom atmosphere boundary, return huge optical depth
float2 f2RayEarthIsecs;
- GetRaySphereIntersection(f3Pos, f3RayDir, f3EarthCentre, g_MediaParams.fEarthRadius, f2RayEarthIsecs);
+ GetRaySphereIntersection(f3Pos, f3RayDir, f3EarthCentre, g_MediaParams.fAtmBottomRadius, f2RayEarthIsecs);
if( f2RayEarthIsecs.x > 0.0 )
return float2(1e+20, 1e+20);
}
@@ -68,7 +68,7 @@ void PrecomputeNetDensityToAtmTopPS( FullScreenTriangleVSOutput VSOut,
{
float2 f2UV = NormalizedDeviceXYToTexUV(VSOut.f2NormalizedXY);
// Do not allow start point be at the Earth surface and on the top of the atmosphere
- float fStartHeight = clamp( lerp(0.0, g_MediaParams.fAtmTopHeight, f2UV.x), 10.0, g_MediaParams.fAtmTopHeight-10.0 );
+ float fStartHeight = clamp( lerp(g_MediaParams.fAtmBottomAltitude, g_MediaParams.fAtmTopAltitude, f2UV.x), 10.0, g_MediaParams.fAtmTopAltitude-10.0 );
float fCosTheta = f2UV.y * 2.0 - 1.0;
float fSinTheta = sqrt( saturate(1.0 - fCosTheta*fCosTheta) );
diff --git a/Shaders/PostProcess/EpipolarLightScattering/private/precompute/PrecomputeSingleScattering.fx b/Shaders/PostProcess/EpipolarLightScattering/private/precompute/PrecomputeSingleScattering.fx
index 7de162b..c06aee5 100644
--- a/Shaders/PostProcess/EpipolarLightScattering/private/precompute/PrecomputeSingleScattering.fx
+++ b/Shaders/PostProcess/EpipolarLightScattering/private/precompute/PrecomputeSingleScattering.fx
@@ -26,17 +26,24 @@ void PrecomputeSingleScatteringCS(uint3 ThreadId : SV_DispatchThreadID)
{
// Get attributes for the current point
float4 f4LUTCoords = LUTCoordsFromThreadID(ThreadId);
- float fHeight, fCosViewZenithAngle, fCosSunZenithAngle, fCosSunViewAngle;
- InsctrLUTCoords2WorldParams( f4LUTCoords, g_MediaParams.fEarthRadius, g_MediaParams.fAtmTopHeight, fHeight, fCosViewZenithAngle, fCosSunZenithAngle, fCosSunViewAngle );
+ float fAltitude, fCosViewZenithAngle, fCosSunZenithAngle, fCosSunViewAngle;
+ InsctrLUTCoords2WorldParams(f4LUTCoords,
+ g_MediaParams.fEarthRadius,
+ g_MediaParams.fAtmBottomAltitude,
+ g_MediaParams.fAtmTopAltitude,
+ fAltitude,
+ fCosViewZenithAngle,
+ fCosSunZenithAngle,
+ fCosSunViewAngle );
float3 f3EarthCentre = float3(0.0, -g_MediaParams.fEarthRadius, 0.0);
- float3 f3RayStart = float3(0.0, fHeight, 0.0);
+ float3 f3RayStart = float3(0.0, fAltitude, 0.0);
float3 f3ViewDir = ComputeViewDir(fCosViewZenithAngle);
float3 f3DirOnLight = ComputeLightDir(f3ViewDir, fCosSunZenithAngle, fCosSunViewAngle);
- // Intersect view ray with the top of the atmosphere and the Earth
+ // Intersect view ray with the atmosphere boundaries
float4 f4Isecs;
GetRaySphereIntersection2( f3RayStart, f3ViewDir, f3EarthCentre,
- float2(g_MediaParams.fEarthRadius, g_MediaParams.fAtmTopRadius),
+ float2(g_MediaParams.fAtmBottomRadius, g_MediaParams.fAtmTopRadius),
f4Isecs);
float2 f2RayEarthIsecs = f4Isecs.xy;
float2 f2RayAtmTopIsecs = f4Isecs.zw;
@@ -65,7 +72,8 @@ void PrecomputeSingleScatteringCS(uint3 ThreadId : SV_DispatchThreadID)
f3ViewDir,
f3EarthCentre,
g_MediaParams.fEarthRadius,
- g_MediaParams.fAtmTopHeight,
+ g_MediaParams.fAtmBottomAltitude,
+ g_MediaParams.fAtmAltitudeRangeInv,
g_MediaParams.f4ParticleScaleHeight,
f3DirOnLight.xyz,
100u,
diff --git a/Shaders/PostProcess/EpipolarLightScattering/public/EpipolarLightScatteringStructures.fxh b/Shaders/PostProcess/EpipolarLightScattering/public/EpipolarLightScatteringStructures.fxh
index 970da26..7516c84 100644
--- a/Shaders/PostProcess/EpipolarLightScattering/public/EpipolarLightScatteringStructures.fxh
+++ b/Shaders/PostProcess/EpipolarLightScattering/public/EpipolarLightScatteringStructures.fxh
@@ -229,16 +229,16 @@ struct AirScatteringAttribs
// Earth parameters can't be chnaged at run time
float fEarthRadius DEFAULT_VALUE(static_cast<float>(EARTH_RADIUS));
- float fAtmTopHeight DEFAULT_VALUE(80000.f);
+ float fAtmBottomAltitude DEFAULT_VALUE(0.f); // Altitude of the bottom atmosphere boundary (sea level by default)
+ float fAtmTopAltitude DEFAULT_VALUE(80000.f); // Altitude of the top atmosphere boundary, 80 km by default
float fTurbidity DEFAULT_VALUE(1.02f);
- float fAtmTopRadius DEFAULT_VALUE(fEarthRadius + fAtmTopHeight);
- float4 f4ParticleScaleHeight DEFAULT_VALUE(float4(7994.f, 1200.f, 1.f/7994.f, 1.f/1200.f));
+ float fAtmBottomRadius DEFAULT_VALUE(fEarthRadius + fAtmBottomAltitude);
+ float fAtmTopRadius DEFAULT_VALUE(fEarthRadius + fAtmTopAltitude);
+ float fAtmAltitudeRangeInv DEFAULT_VALUE(1.f / (fAtmTopAltitude - fAtmBottomAltitude));
+ float fAerosolPhaseFuncG DEFAULT_VALUE(0.76f);
- float fAerosolPhaseFuncG DEFAULT_VALUE(0.76f);
- float fDummy0;
- float fDummy1;
- float fDummy2;
+ float4 f4ParticleScaleHeight DEFAULT_VALUE(float4(7994.f, 1200.f, 1.f/7994.f, 1.f/1200.f));
};
#ifdef CHECK_STRUCT_ALIGNMENT
CHECK_STRUCT_ALIGNMENT(AirScatteringAttribs);