Sunday, February 4, 2007

Realtime rendering of atmosphere scattering

I am going to talk about what i tryed to code in the past few days, SkyColors for a SkyDome. There is some papers about it, seems that there is not as much research on it as terrain rendering.

I started with A. J. Preetham's publications : "A Practical Analytic Model for Daylight" and "Rendering Outdoor Light Scattering in Real Time". I tryed to code the equations given at the end of the second paper but didn't get what i expected. Those equations give a luminance and chromaticity color sample in Yxy Space and need to be converted into RGB space, this is something that is not described in the paper and that the reader must find out.

After a few searches, you can understand this by reading "A Practical Analytic Model for Daylight" and finding "Day light sky color" that explain how to get RGB colors from Yxy Space. So, in the PS you must convert "Lin" and "Fex" values before using them. With that i finally got a blue sky and i played a bit with parameters but didn't got good results.

I gave up Preetham papers and looked for something else... and i found "Real Time Rendering of Atmospheric Scattering Effects for Flight Simulators". At the end of the paper, the autor give the code so i tryed it and got better results for skycolors. The code also has some features like and automatic Henyey Greensein's G value computed with the camera 's Y and the theta angle between sun and it's zenith. I also got some problems : during night the skydome is white and the sun is too big during day, even for a little ESun value. There is also some blanks in the code that i didn't fill : some variables a set in the C++ code that don't exist in the FX effect file, etc ... i didn't found how to contact the author and my post about his paper on gamedev didn't got feedback ( i guess nobody tryed to get it working ). Since i couldn't make it work properly i searched for others technique.

And came up with ONeil optimisations article about "Display of The Earth Taking into Account Atmospheric Scattering" on gamedev. I discovered that ONeil had written a article on Atmospheric Scattering for Gpu Gems II book, so i download the source of the chapter 16 on NVIDIA website. I convert his CG SkyFromAtmosphere shader and tryed it, but like many others people only the top of the dome had skycolors. After a few looks in his code i found that he used a special ModelMatrix that set the camera at origin, with the Y value equal to the InnerRadius and subtract camera's position from translation values of others objects ModelMatrix. At last, i finally got something realist and nice to watch.

Even if his method give pretty good results i didn't stop searching and also found "Real-Time Atmospheric Effects in Games" that decribe how they have done the atmopshere scattering and haze effect in the CryEngine2 that seems quite easy to implement and costless but that need SM 3.0 graphic card because it uses FP32 textures.



No comments: