Sign in to follow this  

About atmospheric scattering

Recommended Posts


I just got my atmospheric scattering to work, after studying a lot of papers & demos, and finally finding one that explained how to set up rayleigh and mie factors and so on. There is only one thing that isn't working now: The sky isn't getting whiter towards the horizon. Here is the shader code:
float3 vertex = mul(i.vPos, WorldView).xyz;

float3 viewDirection = normalize( vertex );
float distance = length( vertex )*100.0f;

// Angle between sun direction and view direction
float3 sunDirection = normalize(mul(float4(SunDir, 1.0),WorldView).xyz );

float theta = dot( sunDirection, viewDirection );

// Phase1 and Phase2

float phase1 = 1.0 + theta * theta;
float phase2 = pow( rsqrt( HGg.y - HGg.z * theta ), 3 ) * HGg.x;

// Extinction term

float3 extinction = exp( -BetaRPlusBetaM * distance );
float3 totalExtinction = extinction * Multipliers.yzw;

// Inscattering term

float3 betaRay = BetaDashR * phase1;
float3 betaMie = BetaDashM * phase2;

float3 inscatter = (betaRay + betaMie) * OneOverBetaRPlusBetaM * (1.0 - extinction);

// Apply inscattering contribution factors

inscatter *= Multipliers.x;

// Scale with sun color & intensity

inscatter *= * SunColorIntensity.w;

o.vDiff.rgb = inscatter;
o.vDiff.a = 1.0f;
return o;[/code]

It's from a demo I found [url=""]here[/url]. It's pretty obvious for me why the sky isn't getting whiter towards horizon, as the slope of the sky is not taking into the calculations anywhere in that code. I have a nice sun and so, but terrain scattering looks ugly for far distances, as the terrain simply blends white into a blue sky.


How can I enchance the shader to make the horizon white/bright? Thanks in advance!

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