Sign in to follow this  
Aqua Costa

Screen space atmospheric scattering

Recommended Posts

Aqua Costa    3691
Is there any way to render atmospheric scattering on screen space? Because I have a deferred lighting renderer and wanted to know what should I do atmospheric scattering...

I was thinking about only rendering the sky dome using the atmospheric scattering shader and everything else using a blinn-phong lighting shader and simply calculate the ambient light color to approximate the sky color, but I'm not sure if the result will be good enough.

Thanks in advance

Share this post


Link to post
Share on other sites
Vilem Otte    2938
Of course computing atmospheric scattering everywhere will look better, but I don't see why you couldn't get close to actual result with good old fog? Lots of games still use it and it doesn't look that bad, of course computing atmospheric scattering using equations described [url="http://www-ljk.imag.fr/Publications/Basilic/com.lmc.publi.PUBLI_Article@11e7cdda2f7_f64b69/article.pdf"]HERE[/url] is actually a lot better.

Anyway atmospheric scattering is computed just once, so as long as you don't have some crazy physically based model, it should be okay computing it in real time.

I could post some my code if you'd be interested in it (Digging it... Maybe I applied it in screen space once, can't remember...).




EDIT: Found some of my code and I'm computing standardly on geometry, although as it uses mainly just distances to vertices and viewdirection to pixels, I don't see why it couldn't be easily moved to screen-space.

Share this post


Link to post
Share on other sites
Hodgman    51234
IIRC screen-space atmospherics is mentioned by Crytek in either the "finding next-gen" or "realtime atmospheric effects" presentation.

If all you need to compute scattering is the pixel position and camera position, then whether you do it during 'forward shading' or whether you reconstruct the pixel position from depth during a deferred pass should produce the same results.

Share this post


Link to post
Share on other sites
Vilem Otte    2938
[quote]IIRC screen-space atmospherics is mentioned by Crytek in either the "finding next-gen" or "realtime atmospheric effects" presentation.

If all you need to compute scattering is the pixel position and camera position, then whether you do it during 'forward shading' or whether you reconstruct the pixel position from depth during a deferred pass should produce the same results.[/quote]

Actually most of the algorithms can be moved to screen space (as long as they don't need some additional info from invisible areas ... and these are also quite complicated to achieve with standard rasterization, or you can try to hack them - like SSAO), although sometimes they're just so slow in screen space (F.e. transparency - you can do it using depth-peeling, but well... it is just THAT much slower than doing forward rendering of transparent objects after doing deferred pass).

Share this post


Link to post
Share on other sites
Aqua Costa    3691
[quote name='Vilem Otte' timestamp='1306325851' post='4815549']
Of course computing atmospheric scattering everywhere will look better, but I don't see why you couldn't get close to actual result with good old fog?
[/quote]

So I simply render objects like I did before and add fog? So how do I calculate fog density and color?

P.S. I just played GTA IV and looks like they also used fog to fake atmospheric scattering :rolleyes:

Share this post


Link to post
Share on other sites
bluntman    255
Fog will fake Mie scattering to an extent but if you want Rayleigh scattering then you really need to use much more complex scattering calculations that take into account camera direction, light direction and atmosphere parameters. Rayleigh scattering is what produces the change in incoming light colour associated with making the sky blue, and sunsets red, so if you want those things done "correctly" you need Rayleigh scattering. I have been thinking a lot recently about how to implement atmospheric scattering in a deferred shader and come up with the following:
Atmospheric scattering is actually a two part process for a particular fragment: first you need to calculate the light that is hitting the fragment itself, which requires scattering the light incoming towards the fragment. This is usually referred to as the inner integral because you are integrating the scattering equation along the ray from the light source to a point along the ray from the fragment to the viewer (in this case right at the start of that ray, on the fragment itself). The inner integral result is only dependant on the height of the end of the ray, and the angle between the ray and the atmosphere surface normal (i.e. straight up from the planets surface). As it only varies in two dimensions it can be encoded as a texture for quick look up in the fragment shader. This inner integral needs to be solved once for lighting the fragment during the lighting pass (as mentioned above) and it needs to be integrated again when calculating the scattering from the fragment to the eye during the atmospheric post processing.
So basically to perform atmospheric scattering in a deferred shader you split it into two parts: lighting the surfaces using a special "solar light" shader that uses the inner integral texture, then performing a post process to calculate scattering of the light from each fragment to the eye.

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