TUFX icon indicating copy to clipboard operation
TUFX copied to clipboard

Add atmospheric scattering effect

Open shadowmage45 opened this issue 5 years ago • 3 comments

Will be based on Bruneton's Improved Scattering.

  • Rewritten to HLSL
  • Updated to be made compatible with Post Process Package v2
  • Tested to be functional in KSP
  • Needs work to turn off the stock effects gracefully

KSP Implementation TODO:

  • [x] Add the effect to the standard config window, load/save system
  • [ ] Disable stock atmosphere rendering (both ground and space), only when atmo rendering is enabled
  • [ ] Loading of atmosphere configurations.
  • [ ] Main Menu
  • [ ] Map Scenes
  • [ ] Model culling based on parameters. Don't do a render pass for models that are not visible in the camera.

Known Issues & TODO (Shader and Effect Implementations):

  • [ ] Update compute shaders to use the HLSL includes - samplers/etc are already in DX11 format, so might not be much needed.
  • [ ] Banding on the horizon when it is occluded by an object in front of the horizon.
    • Does not appear to be caused by an NAN/INF. Testing for those does not reveal anything out of the ordinary.
    • The banding occurs inside the GetRadianceToPoint method, and is present in the evaluated difference between the scatter and scatter_p variables.
    • Everything (a bit below) the horizon renders properly.
    • Need to test if the demo scene exhibits the same behavior in
  • [ ] Aliasing in places where depth sampling is used
  • [x] Need some directional testing, will occasionally get phantom atmospheres rendered when the real atmopshere is behind the camera (these are caused by one of the depth-test fixes)
  • [x] Need to clean up branching and all of the depth based testing, optimizations in general
  • [ ] Validation for use of multiple atmospheres, optimizations (shader)
    • Cheaper to loop from render (single vars, set many times), or inside shader (array vars, set once)?
  • [ ] Clean up effect handling so that each Model gets its own PropertySheet for binding to, run these in the effect loop.
  • [ ] Can the scale factor be adjusted safely at runtime, or does it truly interfere with the precomputed data?
  • [ ] How to render and add a normals buffer for use by the screen-space effect? (could also use this for screen-space reflections).
  • [ ] Add support for multiple light sources.
    • [ ] Use reflected 'moonlight' as a second light-source on Kerbin.
    • [ ] This would have to be done as a second pass, using different 'sun' coordinates and much lower exposure, and then added into the first. Can utilize the same Model as the sunlit pass as the atmospheric properties are the same. (maybe? there is the whole 'solar luminance' input stuff..)

Will also be investigating the inclusion of some built-in basic atmospheric scattering effects (very simple stuff). https://forum.unity.com/threads/vapor-volumetric-scattering-open-source.500634/ https://github.com/Scrawk/Brunetons-Improved-Atmospheric-Scattering https://github.com/Scrawk/Brunetons-Atmospheric-Scatter https://www.alanzucconi.com/2017/10/10/atmospheric-scattering-1/ https://davidson16807.github.io/tectonics.js//2019/03/24/fast-atmospheric-scattering.html https://www.alanzucconi.com/2019/09/13/believable-caustics-reflections/ https://github.com/GuitarBro/VolumeCloud/tree/StackV2 https://github.com/yangrc1234/VolumeCloud https://github.com/yangrc1234/AtmosphereScatter https://gamedev.stackexchange.com/questions/131978/shader-reconstructing-position-from-depth-in-vr-through-projection-matrix/140924#140924 https://forum.unity.com/threads/world-space-position-in-a-post-processing-shader.114392/ https://answers.unity.com/questions/1584649/how-do-you-port-old-shaders-to-hlsl-so-they-work-w.html https://forum.unity.com/threads/screen-space-multiple-scattering.446647/page-3#post-3316350 fix for world-space recomposition from fulscreen triangle bullshit https://grrava.blogspot.com/2018/08/more-foggy-adventures.html https://michaldrobot.com/2014/04/01/gcn-execution-patterns-in-full-screen-passes/ https://github.com/SlightlyMad/VolumetricLights -- volumetric shadows (light shadow map grab with command buffer IMPORTANT) https://catlikecoding.com/unity/tutorials/rendering/part-7/ -- shadow rendering https://www.shadertoy.com/view/ldSGzR -- screen-space bump mapping https://medium.com/@shahriyarshahrabi/custom-shadow-mapping-in-unity-c42a81e1bbf8 https://github.com/IRCSS/UnityRaymarching

shadowmage45 avatar Mar 12 '20 06:03 shadowmage45

Banding on horizon on occluding object is present in the reference/demo scene: image

Though, notably, not nearly as bad (likely due to the very small size of the sphere, compared to the enormous mountains and geometry I use for testing)...


Much of the banding appears to actually be caused by some of the 'shading' effects, and appears fairly appropriate in some setups: image


What is not known, however, is what causes the partial-transparency of the obstructing objects at some view angles and camera heights: image image


Or the issues with the fully-lit scene: image

Note the random 'pop-out' pixels on the band along the horizon. image

shadowmage45 avatar Mar 14 '20 00:03 shadowmage45

Oh yeah. I don't have words...this is amazing. @shadowmage45 Do you have any PayPal or patreon account? I'd like to buy you a coffee or two :)

jrodrigv avatar Mar 15 '20 12:03 jrodrigv

Thanks for the support and appreciation. Not sure that anything functional or usable will come out of all of this, mostly working on it for... fun? I guess; something 'new' to do, and some new horizons to explore. Likely will make it into the game at some point, but no promises, either towards the timing or if it will ever be included.

Donation button can be found at the bottom of the SSTU page, if interested ( https://forum.kerbalspaceprogram.com/index.php?/topic/117090-wip18x-sstulabs-low-part-count-solutions-orbiters-landers-lifters-dev-thread-11-18-18/ ). Back when I was doing Minecraft modding I looked into Patreon a bit, but wasn't too fond of their model (too much like a real job...).

Of course, with all that said, I love coffee :)

shadowmage45 avatar Mar 16 '20 21:03 shadowmage45