Jump to content
  • Advertisement
Sign in to follow this  

Rendering Outdoor Light Scattering in Real Time Paper

This topic is 2786 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

Is there anywhere with an implementation of this that I could look at? I've seen the source code in the RenderMonkey examples, but it seems to use an optimized technique using pre baked textures rather than the functions discussed in the paper, and is also in ASM. This code also doesnt seem to be able to produce blue skys.

Share this post

Link to post
Share on other sites
This is the paper I was talking about. I tried implementing it, (just with the Rayleigh term so far), but seem to be getting incorrect results.

The sun always appears overly bright and I cant seem to remove the hard circular shape. Also, I seem to get black patches where the angle between the sun and th epoint on the skydome is more than 90 degrees.

Here is my pixel shader code

float4 PShader( PS iPS ) : SV_TARGET
float3 Br = float3( 0.07, 0.009, 0.0001 );

//position sun somewhere on hemisphere
float3 SunPos = 100*normalize(float3( 0, 0.6, -1));
//float T = gFrame.Time;
//float3 SunPos = 100*normalize(float3( 0, sin(T), cos(T)));
float3 SunDir = normalize( -SunPos );

// Sun Intensity
float3 ESun = float3( 1.0f, 1.0f, 1.0f );

float3 EyeToPoint = iPS.PosW - gFrame.EyePosW.xyz;
float s = length(EyeToPoint);
EyeToPoint /= s;

// Is hemisphere point the sun
float DistancePointToSun = abs(length( SunPos - iPS.PosW ));
float3 L0 = DistancePointToSun < 5.0f ? ESun : 0.0f;

// Absorbtion/extinction
float3 Fex = exp( -(Br)*s );

// angle between [eye to point vector] and sun direction
float theta = dot(SunDir, EyeToPoint);

// Rayleigh phase
float3 RayPhase = (3.0 / (16.0*3.14159)) * ( 1 + (theta * theta)) * Br;

// In scattering
float3 Lin = ( RayPhase / Br ) * ESun * ( float3(1.0f,1.0f,1.0f) - Fex );

float3 Out = L0*Fex + Lin;

return float4( Out, 1);

[Edited by - hick18 on December 10, 2010 10:08:32 AM]

Share this post

Link to post
Share on other sites
check out the link above to


That is one of the best examples that I have seen on the topic. . .

Share this post

Link to post
Share on other sites
In my code I test to see if the current rendered point of the skydome is within the suns projection on the hemisphere, and if so have its L0 as 1.0f, else its just space and set it to 0.0f. Is this correct?

Secondly, looking at your source code, you seem to adjust the Br and Bm RGB vectors depending on where the sun is. Is this how you're getting the horizon to change to orange/red at sunset? They dont seem to mention this in the paper. I got the impression that Br and Bm were constants

There is a lot of computation in your calculateScatteringConstants() and ComputeAttenuation() functions. Where does all this come from? I did not see it mentioned in the paper.

Also, I couldnt find that ATI demo, but I found the book. Is the example on the CD in ASM?

Share this post

Link to post
Share on other sites
Most of the code as I remember is taken from the source of the ati light scattering demo. There are a lot of magic numbers/fudge factors/etc in the code that aren't mentioned in the paper or the slides. It's been a couple of years since I've looked at it, but I'll have a look tonight and the slides and update this post.

I can't comment on the code from Graphics Programming Methods, but Natty said that the article in that book is the most up to date and should have hlsl code. The ati source did as well (I'll try to find this too, as it looks like ati doesn't have it readily accessible anymore.).

Pm sent.

[Edited by - glaeken on December 8, 2010 12:13:26 AM]

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!