Jump to content
  • Advertisement
Sign in to follow this  

About atmospheric scattering

This topic is 2583 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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.xyz * SunColorIntensity.w;

o.vDiff.rgb = inscatter;
o.vDiff.a = 1.0f;
return o;

It's from a demo I found here. 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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!