Volumetric Lighting : SunShafts

One of the very popular volumetric lighting effect is SunShafts or volumetric sun shadows or god rays.

An example from real world (image taken from Wikimedia) –


Here’s a screenshot from a video game – Crysis. It was the first game (for me) in which I saw SunShafts –


One way to achieve this effect in real time is by using a radial blur. We can use the radial blur to spread the color (god rays) or the spread the shadow (volumetric shadows). Here is a high-level overview of algorithm –

  • Create a mask texture to mark foreground objects which can occlude the rays.
  • Render the sun disk on a full-screen quad.
  • Now we run the radial blur pass either on sun texture(god rays) or on the mask texture (volumetric shadows).
  • Do a final composite pass to combine previous passes and render sun rays on scene buffer.

Depending on the actual algorithm used we can do a lot of variations and optimizations. For example, I have support for 3 colors – sun disk inner, sun disk outer and sun rays. Similarly, we can do a lot of fancy stuff in composite pass like creating some sort of fall off instead of flat sun rays color – linear falloff, exponential, etc. Instead of just simply adding color to scene buffer we can do some blending operations depending on the effect we are trying to achieve.

For optimization we have might have to reduce the number of loops in radial blur pass which will create some artifacts in rays which can be fixed by using either low res buffer for radial blur pass or noise or both.

In my case, I have tried both god rays and volumetric shadows version but I liked volumetric shadows version more (although I have tested them using some simple geometry so far). And in the case of volumetric shadows, I render sun disk in composite pass only, skipping an additional pass to render sun mentioned above.

Here’ are some screenshots (the first image is without tone mapping) –


Some New Screenshots –



References –

About chetanjags

Game Developer

Posted on February 2, 2016, in Graphics, JustAnotherGameEngine and tagged , , , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: