VS_OUT_SKY VS_SKY(half3 pos : POSITION)
{
VS_OUT_SKY OUT;
OUT.pos = mul(half4(pos, 1.0f), matWorldViewProj );
// Scattering
// Calculate View Direction
half4 worldPos = mul( half4(pos, 1.0f), matWorld);
half3 ViewDir = normalize( vEyePos.xyz-worldPos.xyz);
// Calculate Angle btw sun direction and view direction
half CosTheta = dot(ViewDir, vecLightDir);
// RayLeigh Phase Function
// fAir(theta) = (3/16PI)(1 + cos^2(theta)) ?(3/16PI)?
half Phase1 = (CosTheta*CosTheta) + 1.0f;
// Calculate Distance
half Distance = (mul( half4(pos, 1.0f), matWorldView).z);
// Extinction
half4 Extinction = exp(Beta1PlusBeta2 * Distance * 1.4426950f);
half4 TotalExtinction = Extinction * TerrainReflectance;
// Henyey-Greenstein Phase Function
// fHG(theta) = (1 - g^2) / (4PI(1 + g^2 - 2g*cos(theta))^(3/2)
// fHG(theta) = (1 - g^2) / ((1 + g - 2g*cos(theta))^(3/2))
// theta is 180 - actual theta (this corrects for sign)
// Passed constants gConstants(1-g^2, 1+g, 2g)
half Phase2 = gConstants.x / pow((gConstants.y + gConstants.z * CosTheta), 1.5f);
// Inscattering
// (I) = (Beta'_1 * Phase1(theta) * Beta'_2 * Phase2(theta)) * [1-exp(-Beta_1*s).exp(Beta_2*s)] / (Beta_1 + Beta_2)
half4 Inscattering = ((Beta1 * Phase1) + (Beta2 * Phase2)) * ((1.0f - Extinction) * (1 /Beta1PlusBeta2));
// Apply Inscattering contribution factors
Inscattering *= InscatteringContribution;
// Scale with Sun color and intensity
Inscattering.rgb *= SunColorIntensity.rgb;
Inscattering *= SunColorIntensity.a;
TotalExtinction.rgb *= SunColorIntensity.rgb;
TotalExtinction *= SunColorIntensity.a;
//OUT.Ext = Extinction;
OUT.Ext = TotalExtinction;
OUT.Insctr = Inscattering;
return OUT;
}
Atmospheric Scattering halo Problem
I have been working on implementing Atmospheric Scattering based on the ATI paper "Rendering Outdoor Light Scattering in Real Time". I've been having problems with this crazy halo effect:
Has anybody had the same problem?
Took help from:
Link1
Link2
Link3
HLSL Source:
Hello,
Try calculating the inscattering using the formulas directly from the paper.
where bRay is your beta1 and bMie is your beta2.
Good Luck
Try calculating the inscattering using the formulas directly from the paper.
float betaRay = (3.0 / (16.0 * pi)) * bRay * (1.0 + cost*cost); float betaMie = (1.0 / (4.0 * pi)) * bMie * ((pow(1.0 - g, 2.0)) / pow(1.0 + g*g - 2.0*g*cost, 3.0 / 2.0)); float3 inscattering = ((betaRay + betaMie) / (bRay + bMie)) * Esun * (1.0 - extinction);
where bRay is your beta1 and bMie is your beta2.
Good Luck
DashR:
I think the only difference between those equations and the equations i'm using is the partial sphere coefficients (or whatever you call em': (3.0 / (16.0 * pi)) & (1.0 / (4.0 * pi)) ) Right?
I'm using a Mie Scattering Multiplier and a Rayleigh Scattering Multiplier. This should take care of that I think.
When I adjust g (the eccentricity parameter of the Henyey-Greenstein phase function) the halo ring gets bigger and smaller. Does this mean my phase function is messed-up?
I think the only difference between those equations and the equations i'm using is the partial sphere coefficients (or whatever you call em': (3.0 / (16.0 * pi)) & (1.0 / (4.0 * pi)) ) Right?
I'm using a Mie Scattering Multiplier and a Rayleigh Scattering Multiplier. This should take care of that I think.
When I adjust g (the eccentricity parameter of the Henyey-Greenstein phase function) the halo ring gets bigger and smaller. Does this mean my phase function is messed-up?
Quote:Original post by MattL
I think the only difference between those equations and the equations i'm using is the partial sphere coefficients (or whatever you call em': (3.0 / (16.0 * pi)) & (1.0 / (4.0 * pi)) ) Right?
Possibly, I'm not sure how they were derived with out doing the math. But it looks like your phase2 constants may be incorrect?
half Phase2 = 1-g^2 / pow((1+g + 2g * CosTheta), 1.5f);
try your original one
half Phase2 = (1-g)^2 / 4*pi*pow((1+g^2 - 2g * CosTheta), 1.5f);
also check if your distance is correct, and make sure you have negated Beta1PlusBeta2 (edit: for the negative in the extinction calc)
[Edited by - DashR on May 3, 2007 1:45:11 AM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement