Board index FlightGear Development Effects and shaders

Atmospheric scattering, with terrain shader preview

An exciting "new" option in FlightGear, that includes reflections, lightmaps, the particle system etc.. A lot is yet to be discovered/implemented!

Re: Atmospheric scattering, patch available

Postby jack » Thu Apr 21, 2011 6:22 am

I bet a flight in Vostok-1 with the shader on would be awesome. I wish I could try this myself, but git has crapped out on me and I'm stuck with a month-old build. :(
For Military Aircraft, Scenery, and more, visit http://alphashangar.co.nr/

'Retired' from FlightGear as of July 2011. You can contact me via my website if you'd like to pick up any old projects.
jack
Retired
 
Posts: 1432
Joined: Wed Mar 03, 2010 12:26 am
Location: KLVK
Callsign: Alpha-J, Rescue1
Version: GIT
OS: Mac OS X

Re: Atmospheric scattering, patch available

Postby Zan » Tue May 03, 2011 9:41 pm

Some new progress, I got the terrain shader to work pretty well, so I guess it's time for first release :)

Back up all necessary files first, if I missed something and it doesn't work:

This goes to Effects/
http://users.tkk.fi/~lapelto2/fgfs/scatter/terrain-default.eff

And Shaders/
http://users.tkk.fi/~lapelto2/fgfs/scatter/terrain-default.frag
http://users.tkk.fi/~lapelto2/fgfs/scatter/terrain-default.vert

It replaces the default terrain shader (at the moment) so toggle of all other shaders (but leave the Material Shaders on) in rendering settings.

And some screenies:
Image
Image
Image

Zan
Zan
 
Posts: 123
Joined: Tue Oct 20, 2009 11:28 am

Re: Atmospheric scattering, with terrain shader preview

Postby kyokoyama » Wed May 04, 2011 12:28 am

Nice!

Now, if only we can get the 420000ft atmosphere to blend perfectly with space, too...
(notice the abrupt change from yellow to black on the left)
Look for "B-BIRD" "N127KY" or "AVA0004" -that's me.

Despite having over 1700 posts here, I am not even close to being the most skilled guy here... I'm just words and bad drawing, not experience. :P
kyokoyama
 
Posts: 1981
Joined: Sun May 03, 2009 3:16 am
Location: Earth
Callsign: B-BIRD, N127KY
Version: 2.12.1
OS: Windows Vista

Re: Atmospheric scattering, with terrain shader preview

Postby Zan » Wed May 04, 2011 7:34 am

In the last screenshot I had already pushed the visibility to over thousand kilometers which was at the limits of my computer (even with just ocean and not terrain). I think that is still not enough, so some terrain is still missing (when you think about how far you could see from 143km alt). That would cause an abrupt change in colors... But I'm not 100% sure this is the case, and cannot verify if the visibility cannot be pushed high enough....

Still I think it looks pretty nice from lower altitudes, at least when having >200km visibility.

(Note that this is possible because I have disabled all models, so just bare terrain is rendered)

Zan
Zan
 
Posts: 123
Joined: Tue Oct 20, 2009 11:28 am

Re: Atmospheric scattering, with terrain shader preview

Postby kyokoyama » Wed May 04, 2011 11:48 pm

Alright...
..except I actually meant for the "border" between the sky and space, not the sky and land...
Look for "B-BIRD" "N127KY" or "AVA0004" -that's me.

Despite having over 1700 posts here, I am not even close to being the most skilled guy here... I'm just words and bad drawing, not experience. :P
kyokoyama
 
Posts: 1981
Joined: Sun May 03, 2009 3:16 am
Location: Earth
Callsign: B-BIRD, N127KY
Version: 2.12.1
OS: Windows Vista

Re: Atmospheric scattering, with terrain shader preview

Postby Thorsten » Tue May 10, 2011 5:20 pm

I've pulled a new GIT today and had a look at the atmospheric scattering. I believe there's something fundamentally wrong with the density/Mie part of the shader.

Mie scattering is supposed to take care of the scattering from dust and water vapour, where I think the density in the shader controls the density of scattering centers overall whereas the Mie factor seems to control the size of the scatterers, i.e. the amount of forward scattering. In principle, Mie scattering should give you the white hue of clouds on the sun-side and the dark grey of a layer away from the sun.

Now, if I look straight up on a sunny day with the sun high in the sky, what I should be seeing is the bare Rayleigh scattering dark blue. If I add a little haze as is always there (i.e. density and Mie), that should change into a light to very light blue. But there's just no combination of parameters which does that without transforming the Horizon into a blindingly white band. That shouldn't happen either, because there's just not enough scattered light around to achieve that kind of brightness - the horizon tends to get greyish-blue rather than brilliant white.

The fault really seems to be with the moisture/dirt physics: From high altitude, things look okay to me (that also seems to be what the shader was originally designed for - descent from orbit), but below 10 km altitude where we'd usually fly, the atmospheric physics which governs what we usually see is just not there - the shader seems completely incapable of reproducing light attenuation as on a very foggy day (it only does 1/2 of true Mie scattering) - it never tries to paint anything grey because you scattered light *away* from it. Which is consistent with the observation that it works from orbit - there is no attenuation yet.

I've scribbled down a few equations of how the missing physics might look like... if you're interested, I can have a good look at the shader code, and maybe we can come up with some model to improve things - it'd be a pity to have a skydome which isn't really doing well for 99% of our flights but only for the Blackbird, the Concorde and the Vostok...
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: Atmospheric scattering, with terrain shader preview

Postby Zan » Wed May 11, 2011 8:26 am

Hi Thorsten.

Thanks for the mail, but I must say that I soon noticed that the density calculation was horribly wrong, I was multiplying wrong values with it which gives wrong results.

I have a newer version on my comp, which works for skydome and terrain. At the moment it separates rayleigh and mie calculations and uses (at least to some degree) physical scattering parameters. This version allows changing rayleigh density i.e. atmospheric pressure I think, and mie density i.e. turbidity or amount of smoke and dust. It gives a much broader amount of variations, and I think the density functions now work correctly: 0 gives black sky (no scattering), as a huge enough value (all light is scattered away).

It still has some issues though, it is too sensitive to turbidity, and pushing visibility to something like 1 km makes the sky very white too, upto 10km or so. I'm going to check the atmosphere density distribution and the scattering coefficients and see if that fixes the few huge issues.

If you have some equations you can point me to, please feel free to post them. I've used some google sources and Bruneton's paper etc to fix the shader, but all help is welcome. There probably is no point in looking at the shader code very deeply now, as I'm going to change it to the new version soon.

Cheers, Zan
Zan
 
Posts: 123
Joined: Tue Oct 20, 2009 11:28 am

Re: Atmospheric scattering, with terrain shader preview

Postby Thorsten » Wed May 11, 2011 10:03 am

If you have some equations you can point me to, please feel free to post them.


No, I found myself starting to make them up myself for a correction due to light absorption by dust on the way home yesterday (Let's see, the atmosphere density goes like rho(h) = rho_0 * exp(-h/H), for distance scales of less than 100 km we can safely Taylor-expand the curvature of Earth and see that it's not an issue, so the amount of light scattered at position x goes like the line integral of the optical thickness \int dzeta (x,y) rho(y) where x = dist cos(phi), y=dist sin (phi) ...). I do that sort of thing for a living...

So it's not something I can give you to read, it's something I'd develop and refine on the fly if needed. But no need to fix something you have already fixed.
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: Atmospheric scattering, with terrain shader preview

Postby Thorsten » Wed May 11, 2011 1:35 pm

Okay after reading through

http://http.developer.nvidia.com/GPUGem ... ter16.html

and filling three pages of paper, I think I understand what's going on. The Mie scattering will tend to give you 'white' whenever the Mie optical thickness along the ray is >1 - thus the horizon whiteout. But the problem is that you can't assume that a single scattering approximation works when the optical thickness is larger 1, since you know that you have multiple scattering. With a visibility of 1000 m, what you get is diffuse light with multiple scattering from everywhere, and a lot backscattered into space, thus the grey fog - something which the whole formalism can't deliver even in principle, because it's valid for optically thin media only. I suspect you'll need to supplement it with some additional physics for low visibility.

As it happens, I also understand why he found that everything scales with an exponential which allowed him to eliminate one dimension of the lookup table: If you Taylor-expand the curvature of Earth, which for 8000 km radius and ~100 km atmosphere gives you an error of less than 1% for almost all paths, you can do the inner t(P_A,P_B) integral analytically which just gives you an exponential of the scaling height back (in an optically thin medium, you can also Taylor-expand the exponential in the outher integral and do the outer integral analytically as well, but let's not overdo it here...).



So, I guess I'll wait for your revised code then...

Come to think of it, is there any reason to do the computations in the vertex shaders every frame? It seems like the kind of problem where the result doesn't really change significantly from frame to frame for normal aircraft velocities, so a scheme in which you just compute 1% of your problem per frame, store it in a table and use the table for 99% would seem to be vastly superior in terms of resource consumption (?). Just thinking loud... and I was wondering the same thing about the gradient shader...
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: Atmospheric scattering, with terrain shader preview

Postby fredb » Wed May 11, 2011 3:19 pm

If you want to experiment with multiple scattering, you can read this document :
http://www-ljk.imag.fr/Publications/Bas ... rticle.pdf
User avatar
fredb
 
Posts: 753
Joined: Fri Dec 01, 2006 11:41 am
Location: Paris, France

Re: Atmospheric scattering, with terrain shader preview

Postby Thorsten » Wed May 11, 2011 5:17 pm

My quick shot would be to solve a diffusion equation for light in the optically thick limit and don't compute the messy case inbetween explicitly but just find a suitable interpolation function - but let's see.
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: Atmospheric scattering, with terrain shader preview

Postby redneck » Sat May 21, 2011 2:19 am

Hey guys. I don't mean to rush you or anything, but is there any chance I can get a time estimate for this feature? I got a great idea for showing it off in a fantastic new video. Of course, I'd like all the kinks ironed out. Guess I should probably tell you guys what the plan is. I'm gonna take the F-16 on a long, high-altitude flight. We (the viewers and I) are going to watch a sunrise like never before during the flight. Well, that sounds kinda simple. I won't be launching the F-16 into space this time though. By high-altitude, I mean just 75,000 ft. Anyway, I hope coming up with a time estimate won't be too much trouble. Or, better yet, since it seems like you guys might be almost done (at least that's how it seems to me), maybe you guys can just release the next version of it.
Call Signs: redneck, ATCredn (unspecified freq atc)
FGFSCopilot
FGFSCopilotATCEdition
System Specs
Model: Alienware M15x, OS: Windows 7 Professional 64-bit, RAM: 3 GB, CPU: Intel i3 quad core at 2.4 GHz, GPU: Nvidea GeForce GTX 460M 1.5 GB GDDR5
redneck
 
Posts: 3617
Joined: Mon Feb 02, 2009 3:17 am
Location: Pennsylvania, USA
Version: 240

Re: Atmospheric scattering, with terrain shader preview

Postby kyokoyama » Sat May 21, 2011 2:41 am

It's already included in the Developers' Snapshot, and is probably also sent up on GIT.
Look for "B-BIRD" "N127KY" or "AVA0004" -that's me.

Despite having over 1700 posts here, I am not even close to being the most skilled guy here... I'm just words and bad drawing, not experience. :P
kyokoyama
 
Posts: 1981
Joined: Sun May 03, 2009 3:16 am
Location: Earth
Callsign: B-BIRD, N127KY
Version: 2.12.1
OS: Windows Vista

Re: Atmospheric scattering, with terrain shader preview

Postby redneck » Sat May 21, 2011 4:26 am

Really?! Hey, thanks! I thought there were issues mentioned above to be worked out yet. Or maybe you misunderstood me. Well, whatever. I'm gonna try out the latest Developer Snapshot release now. Woohoo!
Call Signs: redneck, ATCredn (unspecified freq atc)
FGFSCopilot
FGFSCopilotATCEdition
System Specs
Model: Alienware M15x, OS: Windows 7 Professional 64-bit, RAM: 3 GB, CPU: Intel i3 quad core at 2.4 GHz, GPU: Nvidea GeForce GTX 460M 1.5 GB GDDR5
redneck
 
Posts: 3617
Joined: Mon Feb 02, 2009 3:17 am
Location: Pennsylvania, USA
Version: 240

Re: Atmospheric scattering, with terrain shader preview

Postby kyokoyama » Sat May 21, 2011 4:44 am

The problems are issues of inaccuracy and all; the feature itself functions.

You're welcome; enjoy!
Look for "B-BIRD" "N127KY" or "AVA0004" -that's me.

Despite having over 1700 posts here, I am not even close to being the most skilled guy here... I'm just words and bad drawing, not experience. :P
kyokoyama
 
Posts: 1981
Joined: Sun May 03, 2009 3:16 am
Location: Earth
Callsign: B-BIRD, N127KY
Version: 2.12.1
OS: Windows Vista

PreviousNext

Return to Effects and shaders

Who is online

Users browsing this forum: No registered users and 3 guests