• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Tispe

Help, understanding Atmospheric and Volumetric Light Scattering

7 posts in this topic

Hello, I have seen demos that uses Atmospheric and Volumetric Light Scattering and I wish to implement it on my own. Hopefully SM3.0 will suffice.

 

But, after reading the nvidia GPU Gems articles I am still in the dark on how this actually works. The Accurate Atmospheric Scattering article by Sean O'Neil shows two pictures of the end result, a drawing of the atmosphere with a line through it. Follwing this is some history on the subject, some formulas and other jargon that does not really add any understanding to how the reader can use it.

 

Is there a better article that describes exactly how this works? The same applies to the Volumetric Light Scattering as a Post-Process article by Kenny Mitchell. This article is better, but not enough for me to grasp the subject. I have read plenty of articles and tutorials, but these are in a class of their own. I can't recall if I have ever read such difficult articles before.

 

Any references is greatly appreciated.

1

Share this post


Link to post
Share on other sites

Are you asking about the implementation, or the underlying physics? Do you mean standard atmospheric scattering such as Rayleigh scattering and so on, or more complex effects, or about volumetric scattering in general?

0

Share this post


Link to post
Share on other sites

Atmospheric Scattering

- create a ray for every pixel of your framebuffer, with your eye being the source and the rayDirection*DepthOfPixel the orientation

- step along the ray (aka divide the ray orientation by 32 and step 32times)

- at every step

   - create a ray from that particular position towards the sun (or any other light source you want) by taking that point as origin and the sun direction as orientation

   - step along this ray

   - at every step, check if you hit something (e.g. inside the earth sphere, inside a mountain, inside of a cloud)

   - add some intensity to a temporal variable

- weight that temporal variable by the amount of steps you make (aka temp/=32;) and add it to your scattering color.

 

 

that's the basic of how it works. for the intensity value you can choose some small value to start with. to improve, you can look up in those papers for 'better approximations', those depend on the height of your sample points, on the angle between your view ray and the sun etc. you can probably go infinity detailed about it and make it take days per picture :)

 

for speed up you can pre-calculate the inner loop into a 2d look up table, based on the height and the angle between the view ray and the direction towards the sun, effectively reducing it from O(n*n) to O(n), while n being the amount of steps you wanna sample.

0

Share this post


Link to post
Share on other sites

Are you asking about the implementation, or the underlying physics? Do you mean standard atmospheric scattering such as Rayleigh scattering and so on, or more complex effects, or about volumetric scattering in general?

I understand the physics, light comes in and scatters until it scatters away or towards the viewer. But how this is implemented in shaders is what I want to know.

 

 


create a ray for every pixel of your framebuffer, with your eye being the source and the rayDirection*DepthOfPixel the orientation

Does the vertex shader supply the rayDirection or is it calculated in the pixel shader?

 


at every step, check if you hit something (e.g. inside the earth sphere, inside a mountain, inside of a cloud)
 

This sounds hard, how can the pixel shader know if a ray it creates is at any point intersecting an object?

1

Share this post


Link to post
Share on other sites

 


create a ray for every pixel of your framebuffer, with your eye being the source and the rayDirection*DepthOfPixel the orientation

Does the vertex shader supply the rayDirection or is it calculated in the pixel shader?

 

[/quote]

the vertexshader can provide the direction of every corner of the screen that gets interpolated and passed to the pixelshader.

 

 

 

 

[quote]

 


at every step, check if you hit something (e.g. inside the earth sphere, inside a mountain, inside of a cloud)
 

This sounds hard, how can the pixel shader know if a ray it creates is at any point intersecting an object?

 

that's up to your implementation, in the simplest case you don't do any checks. 

a little improvement is to check the intersection with the earth-sphere, which is especially important during dust and dawn. (that's just a ray-sphere intersection test, simple, but doing it 32x32 times is not cheap, of course).

next step might be a shadowmap that just includes clouds, that way you'll get those god-ray effects.

 

it's all approximation, simulating light participating medias gets insanely complex the more accurate you want to get it and while the improvement gets more and more subtle, it's still noticeable if you compare 1:1, but for games, it usually is a very very rough approximation. e.g. the god-ray effects in alan wake or crysis are just screenspace effects, sampling from the screenspace position of the light along the projected 2d rays, checking the depth buffer or some light mask to bleed the light source color along those rays.

0

Share this post


Link to post
Share on other sites

For intersection along sun-ray: replace the second ray that's cast towards the sun with a shadow map depth test. Essentially the same thing but you can drop the second march (faster) and simply sample the shadow map. If you've already got sun shadows then you're golden.

 

The shader code supplied should be more than enough to work with IMO. The tricky bit is some of the inputs, there's some weird scale setting that's very very touchy.

Edited by Styves
0

Share this post


Link to post
Share on other sites

I have no idea what people are talking about here. Krypt0n was almost there but I didn't manage to get the whole picture.

 

So, we have a shadow map, the using depths, ray from pixel to sun etc, we can in the pixel shader get scattering?

Please reiterate the steps, but make it believable and understandable.

0

Share this post


Link to post
Share on other sites

It would help if we knew what you were having trouble with. The NVIDIA page has source code and all, so I'm a bit baffled by what's confusing you.

 

Here's the idea though:

 

Vertex Shader:

  • In the vertex shader, compute the ray direction (VertexPos - CameraPos) and output to the pixel shader.

 

Pixel Shader:

  • Setup the ray. In the NVIDIA sample, they're using sphere intersections to determine the length of the ray to get the best result from the lower sample count. In the "from space" version, it's from the front of the atmosphere to the back. In the "from earth" version, it's from the camera to the atmosphere back.
  • March along your ray direction and compute the scattering at that point (essentially it's just an RGB attenuation function that takes depth and height as inputs). You could use anything here for different effects: reading a texture, adding color, etc.
  • At each ray step, convert your ray position to shadow space (standard shadow map "mul(matrix, pos)"). Read the shadow map depth and compare it to the ray's shadow map depth (regular shadow depth test). Multiply this result onto your attenuation result.
  • The loop adds the computed color to the final result and is rendered to the scene.

 

That's basically it. If you want to get the basics working, you can replace the atmospheric scattering with a basic depth-based color (use Depth*Color).

Edited by Styves
0

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  
Followers 0