PDA

View Full Version : Atmospheric Scattering


DoG
11-06-2006, 11:10 AM
Hiya, I have been working on a planet generator, and just implemented atmospheric scattering. It is fairly naive, and has some hiccups.

I've been trying to convert it to use lookup tables for the exp() and various other things, but that's trickier than I thought. According to profiling, the biggest sinner is the ray/sphere intersection code anyway, I just want to clean up the code to eventually make it into shaders.

Anyway, here's some pics:
http://dog4.dyndns.org:8080/wwwalt/atmos1.png

http://dog4.dyndns.org:8080/wwwalt/atmos2.png

http://dog4.dyndns.org:8080/wwwalt/atmos3.png

http://dog4.dyndns.org:8080/wwwalt/atmos4.png

http://dog4.dyndns.org:8080/wwwalt/atmos5.png

If anybody has any comments, or suggestions, I'm all ear :)

roel
11-06-2006, 12:22 PM
That is pretty cool! Did you already read "Accurate Atmospheric Scattering" in GPU Gems II? And you've probably already browsed this blog (http://www.gamedev.net/community/forums/mod/journal/journal.asp?user=ysaneya), didn't you? :)

DoG
11-06-2006, 02:25 PM
Heh, I havent found that blog yet, thanks. Some pretty amazing imagery there. I havent yet gotten hold of the Gems article, the only copy in a library nearby is out. Soon :)

There's some interesting numerics issues with this, I wonder how it will look in a shader.

roel
11-06-2006, 02:30 PM
By the way, what causes the sharp transition in your atmosphere? And I already said it, but just again: it looks cool! :)

DoG
11-07-2006, 02:02 AM
By the way, what causes the sharp transition in your atmosphere? And I already said it, but just again: it looks cool! :)

Which sharp transition? There's still some bugs running around, i reckon. In the first image, I have mistakenly taken cos(cos(theta)) instead of cos(theta) in the scattering function, hence the more orb-like appearance. In the others, I switched to a pre-computed rho for every shell, but apparently it's not doing as it should. I must be doing something wrong with table look-ups, but I just dont know what.

Code can be seen here, any insights welcome:
http://dog4.dyndns.org:8080/trac/browser/trunk/lib/sources/atmosim.cpp

DoG
11-13-2006, 06:44 AM
I managed to improve things, now its nearly perfect:
http://dog4.dyndns.org:8080/wwwalt/planet5.png


And just the atmosphere:
http://dog4.dyndns.org:8080/wwwalt/atmos8.png

http://dog4.dyndns.org:8080/wwwalt/atmos9.png

Kenneth Gorking
11-13-2006, 06:53 AM
Much nicer! Good work. How does it look from inside the atmosphere, and have you tried moving the simulation to the GPU?

roel
11-13-2006, 02:07 PM
wow yeah, that is nice! really smooth!

DoG
11-13-2006, 02:32 PM
I am working on a shader for all this. It would be nice to do it in a fragment shader, but I think it's too complex, so I probably need a vertex shader also. Also, as it is now, colors come out stupid due to OpenGL's color clamping, so using shaders with HDR colors (at least until after texturing) all the way should make it look a step better.

tleyotlocelocoatl
11-14-2006, 10:27 AM
Im new to ogl, but in other place i found a reference to this http://www.cescg.org/CESCG-2005/papers/Brno-Josth-Radovan/ perhaps it can help you a little more.

Kenneth Gorking
11-14-2006, 12:53 PM
I am working on a shader for all this. It would be nice to do it in a fragment shader, but I think it's too complex, so I probably need a vertex shader also.

I doubt there is any need to do it in a fragment shader, since there are no abrubt detail changes across the hemisphere, with the exception of the sun of course. If youre sphere is tesselated enough, people will never know the difference. The only thing I do in my fragment shader is the Rayleigh and Heneye-Greenstein phase functions to get the sun-details, and it looks just fine :)


float4 SkyPixel(const SkyOutput IN) : COLOR
{
float fCos = dot(SunDirection, normalize(IN.viewDir));
return float4(RayleighPhaseFunction(fCos) * IN.Rayleigh + MiePhaseFunction(fCos) * IN.Mie, 1);
}

DoG
11-14-2006, 04:33 PM
I doubt there is any need to do it in a fragment shader, since there are no abrubt detail changes across the hemisphere, with the exception of the sun of course. If youre sphere is tesselated enough, people will never know the difference. The only thing I do in my fragment shader is the Rayleigh and Heneye-Greenstein phase functions to get the sun-details, and it looks just fine :)


I guess you are right, fine enough tessellation should work well enough. Done on the CPU, per vertex coloring is not very fast, and not very pretty either. Artifacts, in my experience, are either seen at the edges of the planet, or at the shadow, unless tessellation is really high.

By the way: so far, I only apply Rayleigh scattering, Does applying Mie scattering additively work well, or is it more complex?

http://dog4.dyndns.org:8080/wwwalt/atmos10.png