-
-
Notifications
You must be signed in to change notification settings - Fork 384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
realistic Rayleigh/Mie atmospheric scattering #5617
Conversation
Could you post some screenshots, I'm curious. |
Just checking: our eclipse at Epsilon Eridani still works? |
What's the performance like? Most Rayleigh/Mie implementations I've seen are performance intensive... |
How cool is that! Never thought it is missing until I saw what's missing. |
Actually, I don't like its performance. It should be heavily optimized/approximated in order to show truly greatest pictures of atmosphere. |
Did a quick check: it works. I was afraid if it broke eclipses. |
Origin of this code: UPD |
Thanks for taking a crack at this! There are a few "problems" which are why I've not already tried to implement this before:
If you're interested in addressing the first problem while still implementing the Nishita model, you'll be interested in this GpuGems2 chapter which manages to cram the necessary math down into something a little more performant. I cannot promise this PR will be merged however, as even if performance improves on desktop our min-spec target is semi-recent laptop/integrated GPUs, and this PR would both need to address the second point above and provide this as an "experimental" toggleable option. The other reason I can't promise to merge the PR is that we instead intend to implement If you are interested in getting some extremely useful code merged, starting with a way to procedurally generate at least semi-accurate Rayleigh/Mie coefficients for our various atmospheric exoplanets would be very worthwhile regardless of which rendering model gets implemented. |
ADDENDUM: the above reads as more dour and glum than I originally intended. I'm very glad to see someone else tackle planet and sky rendering in Pioneer, and by no means do I think you should abandon this PR just because we have plans to do it differently in a few years time. Feel free to keep working on this, just keep in mind that it'd be merged as a "v1" implementation with the intent to replace it with a more complex "v2" implementation later. |
There are several reasons why this PR is marked WIP.
That's one of them.
Atmosphere's color can be used for adjusting these coefficients (does it change between planets with similar composition?)
That's another one but it might stuck without help of whoever wrote this shader or know what some vars mean and do. |
Read this: https://developer.nvidia.com/gpugems/gpugems2/part-ii-shading-lighting-and-shadows/chapter-16-accurate-atmospheric-scattering - it's another implementation of the same atmospheric scattering model using an LUT instead of brute-forcing the integral. It also "correctly" handles aerial perspective. You'll have to transcribe the code from Cg if you want to crib off of it, but I recommend implementing it from the article's description instead. |
Read the whole article. Not understood where's the difference between this and mine (except for the LUP mentioned above) |
157a314
to
b6557f2
Compare
I agree with @Web-eWorks, most Rayleigh implementations are for Earth-like atmospheres only. @Web-eWorks does the Hillare model handle non-Earth-like atmospheres? From a quick look at the pdf, it assumes Earth (with possible density changes but still oxygenated) |
The LUT or parameterization of such is the major difference - it replaces the loop calculating Slightly unrelated, but the current version of the PR only provides Rayleigh+Mie scattering for the atmosphere - rendering proper atmospheric contribution (i.e. hue shifts) onto terrain + bodies will require computing scattering for the camera->surface ray in They're currently using the same approximation that atmosphere rendering was using, which is responsible for the blue-looking terrain in your original comparison screenshot.
It's a general-purpose model operating on Rayleigh-Mie phase functions which determine the behavior of light in the medium. If the coefficients can be derived, it can handle any kind of atmosphere. The only problem (and one that any atmospheric model will have) is finding the scientific data to describe how light behaves in a non-oxygen atmosphere. |
I am very suspicious of "density function along the vector" being similar to normal distribution. |
If we include this, it might even be "too much" to put the on/off in the settings menu, might belong in debug menu instead, for developers / people who want to render a scene for screen shot. just a thought. |
Instead, I built my own model for atmospheric density. Found out this:
|
This is a very exciting development! |
dfada9c
to
bb3519a
Compare
Pushed some optimization but it looks like I messed up some math and scattering looks unexpectedly different. Could use some fresh look at this |
@Mc-Pain Usually, devs don't even have time for their own code, so best to "self review" / leave it to future self. |
well, I'll try it myself then. Got to my high-end PC, look what happens at very high sample count |
I intend to review this PR at some point in the near future, but I've not yet had a chance to get to it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First of all, thank you for taking the time and effort to implement this as far as you have!
Regarding prior discussion on IRC about this PR's state, I'm generally willing to merge this for the upcoming release in its current condition as an experimental option. While it still requires significant further improvements to match terrain rendering with atmosphere rendering before I consider it a feature-complete replacement for our current atmosphere rendering, those improvements can be added in after its inclusion in the upcoming release.
To that end, I've pushed several commits to add "hot swapping" the used atmosphere shader from the settings menu and to clearly indicate that the Rayleigh/Mie shader is experimental.
I'd like to see the attached comments be addressed before merging, but if you consider this in a good enough state to merge for the upcoming release then I'll sign off on it.
Just checking: Could this PR cause crashes? My main thinking is: if someone opens a bug report, and attach output.txt, will we see they've enabled the "Experimental" option? |
a6fa895
to
c836b04
Compare
Very unlikely. This PR mainly makes changes to shaders and the experimental option simply influences which shader is chosen. |
4bd9e80
to
4e2c417
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Mc-Pain please go ahead and start squashing related / iterative-work commits down into feature-level commits. Ideally all "rename" and "fix" commits related to the new rayleigh scattering code should be condensed into a small number of commits adding a major feature. Generally unrelated or standalone commits (e.g. "Add experimental label to Rayleigh/Mie scattering option") can be left as-is.
I generally consider this PR as approved, but the commit history will need to be cleaned up before merge. The sooner the better - once the history has been cleaned up I consider this PR good to merge for whoever is able to hit the button first.
- Perform all calculations in planet space - Factor out common code into separate functions - Planets use Blinn-Phong to render specular highlight on water - Support arbitrary scaling of rendered planets - Cull front-face of atmosphere mesh to avoid doubling atmosphere intensity when outside atmosphere
- Convert incoming color constants from sRGB into linear space - Tonemap before converting back to sRGB for writeback to the buffer
- Match the API usage patterns of the other Drawables classes
- Add additional checks for the validity of the atmosphere material before attempting to draw atmospheres
4e2c417
to
8d4b1ec
Compare
Experimental shaders for atmospheres on terrestrial planets.
TO-DO list: