Jump to content


Atmospheric Scattering


11 replies to this topic

#1 DoG

    New Member

  • Members
  • PipPip
  • 11 posts

Posted 06 November 2006 - 07:10 PM

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:
Posted Image

Posted Image

Posted Image

Posted Image

Posted Image

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

#2 roel

    Senior Member

  • Members
  • PipPipPipPip
  • 697 posts

Posted 06 November 2006 - 08: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, didn't you? :)

#3 DoG

    New Member

  • Members
  • PipPip
  • 11 posts

Posted 06 November 2006 - 10: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.

#4 roel

    Senior Member

  • Members
  • PipPipPipPip
  • 697 posts

Posted 06 November 2006 - 10:30 PM

By the way, what causes the sharp transition in your atmosphere? And I already said it, but just again: it looks cool! :)

#5 DoG

    New Member

  • Members
  • PipPip
  • 11 posts

Posted 07 November 2006 - 10:02 AM

roel said:

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.o...ces/atmosim.cpp

#6 DoG

    New Member

  • Members
  • PipPip
  • 11 posts

Posted 13 November 2006 - 02:44 PM

I managed to improve things, now its nearly perfect:
Posted Image


And just the atmosphere:
Posted Image

Posted Image

#7 Kenneth Gorking

    Senior Member

  • Members
  • PipPipPipPip
  • 911 posts

Posted 13 November 2006 - 02:53 PM

Much nicer! Good work. How does it look from inside the atmosphere, and have you tried moving the simulation to the GPU?
"Stupid bug! You go squish now!!" - Homer Simpson

#8 roel

    Senior Member

  • Members
  • PipPipPipPip
  • 697 posts

Posted 13 November 2006 - 10:07 PM

wow yeah, that is nice! really smooth!

#9 DoG

    New Member

  • Members
  • PipPip
  • 11 posts

Posted 13 November 2006 - 10: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.

#10 tleyotlocelocoatl

    New Member

  • Members
  • Pip
  • 1 posts

Posted 14 November 2006 - 06:27 PM

Im new to ogl, but in other place i found a reference to this http://www.cescg.org...-Josth-Radovan/ perhaps it can help you a little more.

#11 Kenneth Gorking

    Senior Member

  • Members
  • PipPipPipPip
  • 911 posts

Posted 14 November 2006 - 08:53 PM

DoG said:

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);

}


"Stupid bug! You go squish now!!" - Homer Simpson

#12 DoG

    New Member

  • Members
  • PipPip
  • 11 posts

Posted 15 November 2006 - 12:33 AM

Kenneth Gorking said:

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?

Posted Image





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users