Sign in to follow this  
MattL

Atmospheric Scattering halo Problem

Recommended Posts

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: Photo Sharing and Video Hosting at Photobucket Has anybody had the same problem? Took help from: Link1 Link2 Link3 HLSL Source:
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;
}

Share this post


Link to post
Share on other sites
Hello,

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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
So it was that the Beta1PlusBeta2 wasn't negated! Thanks DashR. But I think I have problems with some of the other settings. Anyone know of any general calibrations for different scales? Should scale matter?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this