Search Unity

Feedback Physically Based Sky

Discussion in 'High Definition Render Pipeline' started by SebLazyWizard, Oct 23, 2019.

  1. SebLazyWizard

    SebLazyWizard

    Joined:
    Jun 15, 2018
    Posts:
    234
    Well it is "functional enough" for static environments and high sun/moon altitudes only, but as soon as the directional light is close to or below the horizon it fails miserably. Dynamic day/night cycles are barely achievable due to the visual artifacts and it's huge performance overhead when updating the sky.

    There hasn't been any update to the PBS for like 2 years, that's why I started to work on it myself.
    I was just sick of waiting for it to improve. (well that never really happend as you can see)
     
    Last edited: Dec 20, 2021
  2. HIBIKI_entertainment

    HIBIKI_entertainment

    Joined:
    Dec 4, 2018
    Posts:
    595
    U

    I absolutely agree with you.
    Low light external scenes have often been a Dodge topic, or different approaches combined.
    Mostly because of the wish for dynamic ToDs.

    Even the PBS doc states that it was only used in the day time scene.

    I certainly appreciate your time and studies over the years that I've seen.

    With many really wishing to hone in on realtime features and larger landscapes, you certainly took action in this quickly.
     
  3. SebLazyWizard

    SebLazyWizard

    Joined:
    Jun 15, 2018
    Posts:
    234
    Last edited: Jan 13, 2022
  4. PutridEx

    PutridEx

    Joined:
    Feb 3, 2021
    Posts:
    1,136
    Maybe, if you have time, you can send a pull with some of your improvements/fixes. I believe they accept public pull sometimes, if they aren't very big changes.

    That light UV was fixed due to a bug report, it was sent ages ago though, if i remember correctly.
     
    SebLazyWizard likes this.
  5. SebLazyWizard

    SebLazyWizard

    Joined:
    Jun 15, 2018
    Posts:
    234
    I allways wondered why there's no visible multiple scattering happening in the atmosphere, although it's being processed in the renderer ("Number Of Bounces" set to 2 or more).

    It turned out that the multiple scattering contribution in the atmosphere is zero when the sampling point is in the planets shadow.
    It simply doesn't correctly account for the atmosphere depth and treats it as if it's infinity thin.
    That's why the sky turns pitch black when it's in the plantes shadow, so there is absolutely no multiple scattering happening where it matters most.

    Here's a picture to illustrate the issue.
    This time I ONLY rendered the multiple scattering contribution of the atmosphere and the planet itself (which is being correctly lit by multiple scattering btw) for better visualisation.
    ms_debug.jpg
    So it somehow illuminates the planet correctly, but not the atmosphere itself.

    This clearly has to be a bug.
    Precalculation of multiple scattering happens here;
    https://github.com/Unity-Technologi...nScatteredRadiancePrecomputation.compute#L339
    I haven't found a way to correct it yet, but I'll try my best to figure it out.
    No Idea if I should just do it myself or spend waiting (probably)months for a potential fix from Unity.

    EDIT
    Related bug report;
    Case 1394838
     
    Last edited: Jan 13, 2022
    cLick1338, ftejada and Ruchir like this.
  6. rafaelpereiratek

    rafaelpereiratek

    Joined:
    Jun 9, 2021
    Posts:
    1
    Since the HDRP change from version 12.1.0 until version 12.1.3 the PBS is messing with the light if it's the light is turned off or with 0 of intensity it gives this error:


    NullReferenceException: Object reference not set to an instance of an object
    UnityEngine.Rendering.HighDefinition.PhysicallyBasedSkyRenderer.RenderSky (UnityEngine.Rendering.HighDefinition.BuiltinSkyParameters builtinParams, System.Boolean renderForCubemap, System.Boolean renderSunDisk) (at Library/PackageCache/com.unity.render-pipelines.high-definition@12.1.3/Runtime/Sky/PhysicallyBasedSky/PhysicallyBasedSkyRenderer.cs:505)
    UnityEngine.Rendering.HighDefinition.SkyManager.RenderSkyToCubemap (UnityEngine.Rendering.HighDefinition.SkyUpdateContext skyContext) (at Library/PackageCache/com.unity.render-pipelines.high-definition@12.1.3/Runtime/Sky/SkyManager.cs:596)
    UnityEngine.Rendering.HighDefinition.SkyManager.UpdateEnvironment (UnityEngine.Rendering.HighDefinition.HDCamera hdCamera, UnityEngine.Rendering.ScriptableRenderContext renderContext, UnityEngine.Rendering.HighDefinition.SkyUpdateContext skyContext, UnityEngine.Light sunLight, System.Boolean updateRequired, System.Boolean updateAmbientProbe, System.Boolean staticSky, UnityEngine.Rendering.HighDefinition.SkyAmbientMode ambientMode, UnityEngine.Rendering.CommandBuffer cmd) (at Library/PackageCache/com.unity.render-pipelines.high-definition@12.1.3/Runtime/Sky/SkyManager.cs:885)
    UnityEngine.Rendering.HighDefinition.SkyManager.UpdateEnvironment (UnityEngine.Rendering.HighDefinition.HDCamera hdCamera, UnityEngine.Rendering.ScriptableRenderContext renderContext, UnityEngine.Light sunLight, UnityEngine.Rendering.CommandBuffer cmd) (at Library/PackageCache/com.unity.render-pipelines.high-definition@12.1.3/Runtime/Sky/SkyManager.cs:948)
    UnityEngine.Rendering.HighDefinition.HDRenderPipeline.UpdateSkyEnvironment (UnityEngine.Rendering.HighDefinition.HDCamera hdCamera, UnityEngine.Rendering.ScriptableRenderContext renderContext, UnityEngine.Rendering.CommandBuffer cmd) (at Library/PackageCache/com.unity.render-pipelines.high-definition@12.1.3/Runtime/RenderPipeline/HDRenderPipeline.cs:2564)
    UnityEngine.Rendering.HighDefinition.HDRenderPipeline.ExecuteRenderRequest (UnityEngine.Rendering.HighDefinition.HDRenderPipeline+RenderRequest renderRequest, UnityEngine.Rendering.ScriptableRenderContext renderContext, UnityEngine.Rendering.CommandBuffer cmd, UnityEngine.Rendering.HighDefinition.AOVRequestData aovRequest) (at Library/PackageCache/com.unity.render-pipelines.high-definition@12.1.3/Runtime/RenderPipeline/HDRenderPipeline.cs:2062)
    UnityEngine.Rendering.HighDefinition.HDRenderPipeline.Render (UnityEngine.Rendering.ScriptableRenderContext renderContext, System.Collections.Generic.List`1[T] cameras) (at Library/PackageCache/com.unity.render-pipelines.high-definition@12.1.3/Runtime/RenderPipeline/HDRenderPipeline.cs:1855)
    UnityEngine.Rendering.RenderPipeline.InternalRender (UnityEngine.Rendering.ScriptableRenderContext context, System.Collections.Generic.List`1[T] cameras) (at <15e405c9beda435fb78db5a973118bc4>:0)
    UnityEngine.Rendering.RenderPipelineManager.DoRenderLoop_Internal (UnityEngine.Rendering.RenderPipelineAsset pipe, System.IntPtr loopPtr, System.Collections.Generic.List`1[T] renderRequests, Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle safety) (at <15e405c9beda435fb78db5a973118bc4>:0)
    UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)

     
  7. SebLazyWizard

    SebLazyWizard

    Joined:
    Jun 15, 2018
    Posts:
    234
    I updated my version to HDRP 12.1.3 and fixed some issues with the volumetric clouds in combination with the PBR fog.
    https://gitlab.com/bad-bug-busters/...mmit/b987ba66e1c7ee03ee6455c89b792cf12d3e87d6

    The clouds really benefit from the atmospheric pbr fog.
    screen_1920x1080_2022-01-25_20-15-44.jpg screen_1920x1080_2022-01-25_20-16-36.jpg
    screen_1920x1080_2022-01-25_20-24-43.jpg screen_1920x1080_2022-01-25_20-26-14.jpg

    EDIT
    Regarding my previous post about the multiple scattering issue;
    I still haven't found out what's wrong with it, since it's calculation seems to be correct from what I can tell, but the result isn't.
    Maybe it's a precision issue with the LUT's, I don't know.

    However I posted a bug report a while ago, still waiting for a response though.
    https://fogbugz.unity3d.com/default.asp?1394838_1o4vs80t21e8rtre
     
    Last edited: Jan 25, 2022
    m0nsky, nirvanajie, ftejada and 4 others like this.
  8. SebLazyWizard

    SebLazyWizard

    Joined:
    Jun 15, 2018
    Posts:
    234
    I reworked the spherical PBR Fog to be faster and less prone to artifacts.
    The new one basically uses the same technique as the regular fog and get's it color from a blurred cubemap of the sky itself, this is not as accurate as it used to be, but it's way faster.
    It also get's rid of the ugly banding artifacts around the horizon.
    https://gitlab.com/bad-bug-busters/...mmit/03bee5f5bb26a8922b5f166fdb89b7eb3a356dd0

    No PBR Fog at all, just the regular height fog.
    screen_1920x1080_2022-02-10_04-21-19.jpg

    Old method, has a proper scattering result but doesn't blend well with the regular fog and causes banding at the horizon.
    screen_1920x1080_2022-02-10_04-14-37.jpg

    New method, approximates the scattering based on the blurred sky cubemap, properly blends with the regular fog and has no banding artifacts at all.
    screen_1920x1080_2022-02-10_04-09-49.jpg
     
  9. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    @SebLazyWizard out of curiosity did you manage to fix the performance issue when updating the sky setting at runtime?
     
  10. newguy123

    newguy123

    Joined:
    Aug 22, 2018
    Posts:
    1,248
    To implement this in my own project, do I just replace the existing HDRP file with the one you linked to on gitlab?
     
  11. SebLazyWizard

    SebLazyWizard

    Joined:
    Jun 15, 2018
    Posts:
    234
    Not really, it triggers it's precomputations almost every time you change some of it's settings.
    The only thing you can do frequently (not realtime) is to change the position and intensity of the directional lights, which doesn't require additional precomputations, but still comes with a bit of overhead, so only update the lights as rarely as possible (like once every few seconds).
    It's documentation got updated recently and provides more info about the precomputations;
    https://github.com/Unity-Technologi...ically-Based-Sky.md#warmup-performance-impact

    The PBSky is based on an ancient implementation from 2008 which has many drawbacks like the poor realtime performance and it's many visual artifacts.
    To be honest it needs a complete rewrite, or atleast an update to later versions of the original creator (Bruneton), which in the end is also a big amount of work.

    Yea, make HDRP a local custom package and replace the specific files with the ones on gitlab, that's it.
    However if you're on a different version than HDRP 12.1.4 then you have to port the changes over to your version yourself.
    I'm not going to support multiple HDRP versions out of the box, it's just my little personal project and not worth the effort.
     
    Last edited: Feb 10, 2022
    ftejada likes this.
  12. ftejada

    ftejada

    Joined:
    Jul 1, 2015
    Posts:
    695
    @SebLazyWizard Do you know if this overload also occurs if we change the Vector3 of the "Space Rotation" parameter in real time?
    It is not clear to me reading the documentation
     
  13. SebLazyWizard

    SebLazyWizard

    Joined:
    Jun 15, 2018
    Posts:
    234
    Atleast the sky cubemap gets rebaked (for lighting/reflections), but that happens every time the sky gets changed anyway.
    So again, to minimize overhead, try to change lights/sky settings as rarely as possible.
     
    ftejada likes this.
  14. CaseyHofland

    CaseyHofland

    Joined:
    Mar 18, 2016
    Posts:
    613
    I'm pretty sure you can also set the Update Mode to Realtime with an Update Period of your choosing. This will update the physically based sky based on your interval, leaving you free to rotate your sun and space every frame.

    See the docs about Update Mode and Update Period
     
  15. ftejada

    ftejada

    Joined:
    Jul 1, 2015
    Posts:
    695
    Yes yes... I already use it. I found that with a 0.5 sec update period it has practically no performance impact for me...
     
  16. Wolfos

    Wolfos

    Joined:
    Mar 17, 2011
    Posts:
    951
    Does that spread the task over multiple frames or does it spike when it updates?
     
  17. PutridEx

    PutridEx

    Joined:
    Feb 3, 2021
    Posts:
    1,136
    it does all the work in one frame, so it'll spike. I wonder if that will be noticeable if done every half a second though, when playing with high FPS.
     
  18. Wolfos

    Wolfos

    Joined:
    Mar 17, 2011
    Posts:
    951
    It'll be noticeable if it puts it below 60 and vsync locks the framerate to 30. Will definitely cause some microstutter.
     
  19. Deleted User

    Deleted User

    Guest

    Red dead Redemption 2 used the same algorithm for their sky.... I wonder how they optimized it.... Maybe it's completely prebaked??!
     
  20. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    Which version of bruneton sky they use 2008 or 2017? afaik the current version of HDRP Sky are using the old 2008 version.
     
  21. CaseyHofland

    CaseyHofland

    Joined:
    Mar 18, 2016
    Posts:
    613
    I wonder what improvements we could get with 2017: I don’t think it would have a significant performance improvement (and truth be told I haven’t experienced any performance issues with pb sky, I run a 3060 RTX).

    You ‘could’ try closing the Profiler window if it’s open, though it probably won’t help much.

    Still, I would like to know
    @SebLazyWizard why does it need a rewrite, what issues do you see?
    @pierred_unity in your opinion, what improvements would Bruneton 2017 bring to Unity?
     
    ftejada likes this.
  22. SebLazyWizard

    SebLazyWizard

    Joined:
    Jun 15, 2018
    Posts:
    234
    Banding artifacts everywhere, especially at the horizon. Bad visuals at twilight due to missing multiple scattering (well it's there but wrong). This thread is full of examples of it's many issues.

    That's the 2017 version: https://ebruneton.github.io/precomputed_atmospheric_scattering/
    Web demo: https://ebruneton.github.io/precomputed_atmospheric_scattering/demo.html

    There's even a newer and better version out there which is currently implemented into the Unreal engine.
    https://github.com/sebh/UnrealEngineSkyAtmosphere
     
  23. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    So it seems lot of people are agree that bruneton sky are heavy when updating the sky parameter. . . .
     
  24. ftejada

    ftejada

    Joined:
    Jul 1, 2015
    Posts:
    695
    Hey @pierred_unity !!!
    Do you have a road time for these improvements that you are going to make?
    What improvements are you talking about? do you have something planned?

    I do not ask for a date for the improvements, but will they be in the short term or long term? months or years?

    I don't want what I'm going to say to bother you, but we've been waiting for several years now with almost no improvement.

    Regards
     
  25. Deleted User

    Deleted User

    Guest

    I tried out UE5 and it sky and atmospheric system is silky, buttery smooth and consistent and no artifacts while the PBS sky keeps stuttering the whole game and is useless for day and night cycle... i hope that unity improves it soon.... +1 vote from my side
     
    ftejada likes this.
  26. Wolfos

    Wolfos

    Joined:
    Mar 17, 2011
    Posts:
    951
    That's odd. It works fine for me. I'm just rotating the sun and there's no artifacts to be seen.
     
    Deleted User likes this.
  27. HIBIKI_entertainment

    HIBIKI_entertainment

    Joined:
    Dec 4, 2018
    Posts:
    595

    Are you by chance changing any of the PBS component settings during runtime? if so, that is why.

    instead, you can change your directional lights ( sun/moon) and your exposure overrides on your local or global volumes instead if needbe.
     
    Deleted User likes this.
  28. Deleted User

    Deleted User

    Guest

    Artifact's occur when u move up at an altitude of somewhere 5000m to 8000m during the sunset like this
    There are some more... I will provide those screenshots later this week
    I am rotating the directional light (very fast) but it lags a lot.... maybe I am doing something wrong?!!
     
    Last edited by a moderator: Mar 1, 2022
    ftejada likes this.
  29. Wolfos

    Wolfos

    Joined:
    Mar 17, 2011
    Posts:
    951
    Seems fine here, until I move into space at which point it breaks.
     
  30. HIBIKI_entertainment

    HIBIKI_entertainment

    Joined:
    Dec 4, 2018
    Posts:
    595

    Fast would be my particular guess there. Directional light movement should be fine in editor of you're moving it fast, and updating probes/shadows at realtime too etcetc during run time you'd probably struggle.

    Have you got a video of the lagging that you're able to share?
    Certainly peaked my curiosity.
     
  31. Deleted User

    Deleted User

    Guest

    Fixed the stuttering by setting physically based sky update mode to every frame(by default its set to on changed)... here are the images of artifacts


    about the second image i don't know if this occurs in real life but seems very odd to me... its also very bright at certain angles which makes it even more odd
    (all the images are taken when the sun moves below the horizon in under a range of 10 degrees)
     

    Attached Files:

  32. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    isn't that reduce the fps a lot? like the sky are updating all the time
     
  33. SebLazyWizard

    SebLazyWizard

    Joined:
    Jun 15, 2018
    Posts:
    234
    I guess he meant "Realtime" but with an update period set to anything greater than 0... Doing it every frame is utterly slow.
     
  34. Deleted User

    Deleted User

    Guest

    Hmm does change anything for me... performance is same... The advantage of using realtime i see that we get update mode which does help in optimizing it
     
  35. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    ah right, setting it to realtime but custom update period could help improving the performance
     
  36. ftejada

    ftejada

    Joined:
    Jul 1, 2015
    Posts:
    695
    From my experience, setting the PBS update to 0.3~0.4 usually gives good performance.
    On the other hand, the fact that it looks so bright in the moments after the sun goes down from the horizon, you have to manage by lowering the lux intensity of your directionallight depending on the angle it has. With that the problem of it being so bright disappears.
     
    Deleted User likes this.
  37. SebLazyWizard

    SebLazyWizard

    Joined:
    Jun 15, 2018
    Posts:
    234
    ftejada likes this.
  38. ftejada

    ftejada

    Joined:
    Jul 1, 2015
    Posts:
    695
    SebLazyWizard likes this.
  39. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    Can someone from unity please comment or give us any update of the PBSky status? will it be fixed, improved, updated, or maybe changed to other skymodel. The current sky have a lot of issue on visual and performance
     
    Deleted User, ftejada and PutridEx like this.
  40. RevC2

    RevC2

    Joined:
    May 2, 2021
    Posts:
    49
    Has anyone found a solution to have both Sun and moon directional lights in scene without breaking volumetric clouds? No matter what setting I use, the cloud always get "lit" by the moon directional light resulting in black shadeless clouds.
     
    ftejada likes this.
  41. PutridEx

    PutridEx

    Joined:
    Feb 3, 2021
    Posts:
    1,136
    Volumetric clouds currently only supports 1 active directional light, doubt there's a workaround without changing volumetric cloud code
     
  42. RevC2

    RevC2

    Joined:
    May 2, 2021
    Posts:
    49
    That's likely the case, them would need a check like "if 2 dir lights are present, use the one with higher intensity". So for now the solution seems to add the moon to the space texture or having a textured plane and just switch the directional lights on/off the "usual way" (which feels like that renders the new system somewhat limited and not that usefull)
     
    Last edited: May 26, 2022
  43. soleron

    soleron

    Joined:
    Apr 21, 2013
    Posts:
    584

    Just for proper continuity and reference.

    The clouds came 2 years after the discussion happened.
    And about 3 years since first mentioned.

    Simply unacceptable for any project.
    The studio would have shut down if they depended on it.
    (The same happens in other, more crucial features.)

    As such my estimate was correct.
    Key features that are standard in every other real time engine without any arguments in the forums, are not considered a priority. The solution delivered is adequate, but nothing to write home about considering how many times we heard the "physically accurate" mantra.
     
    Ruchir and ftejada like this.
  44. Lymdun

    Lymdun

    Joined:
    Jan 1, 2017
    Posts:
    46
    Well... I guess it is yet another half-baked abandoned unity feature..?
     
    iamarugin likes this.
  45. Deleted User

    Deleted User

    Guest

    Currently you can reduce the number of bounces and update it in every 2-3 seconds to greatly improve the performance
     
    soleron likes this.
  46. iamarugin

    iamarugin

    Joined:
    Dec 17, 2014
    Posts:
    883
    I don't know how the atmosphere was released with such a bug



    Was it tested at all?
     
    Ruchir likes this.
  47. Deleted User

    Deleted User

    Guest


     
  48. SebLazyWizard

    SebLazyWizard

    Joined:
    Jun 15, 2018
    Posts:
    234
    ftejada likes this.
  49. iamarugin

    iamarugin

    Joined:
    Dec 17, 2014
    Posts:
    883
    Thank you. I've removed the hack and it is much better right now. I also think, they disabled atmoshperic scattering because of this hack. It destroyed atmospheric scattering lightning on low sun angles.

    I don't know why this hack is needed. Bruneton Atmospheric Scattering, for example, has a proper implementation of such sun disk irradiance without hacks.
     
    Kabinet13 likes this.
  50. iamarugin

    iamarugin

    Joined:
    Dec 17, 2014
    Posts:
    883
    I see one more bug in the atmosphere

    upload_2022-6-14_11-7-49.png

    Does somebody encounter it? Do you have any ideas where to look, to fix it?