Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Feedback Physically Based Sky

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

  1. sqallpl

    sqallpl

    Joined:
    Oct 22, 2013
    Posts:
    384
    @pierred_unity

    Thanks for the answer.

    I'm also curious about the proper sky intensity setup (Intensity Mode and its value) in this configuration (fixed 130,000 lux sunlinght).

    I'm still on HDRP 7.4.3 (will be upgrading to HDRP 12 after it's out of beta) so things may look different in HDRP 12 at the moment.

    When I don't override the Intensity Mode the sky looks very dark in comparison to sunlight intensity and objects lit by it. Wen it's set to exposure and 0 value, it's still too dark. It starts to look better when the exposure value is higher but I'm not sure if it's a correct way to achieve the proper look.

    I can calculate proper sky intensity manually but I'm not sure if there is a way to input the value with exposure/multiplier fields. I also assume that the system calculates it's automatically so it's not what we should do.
     
    Last edited: Sep 7, 2021
  2. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    upload_2021-9-13_19-59-42.png
    i'm wondering why is this artifact keep happening actually, is there a way to avoid it?
     
  3. HIBIKI_entertainment

    HIBIKI_entertainment

    Joined:
    Dec 4, 2018
    Posts:
    596
    My assumption is that it's related to the Altitude : Angular Diameter.
    It looks like you're pretty high in the sky and the sunset angular diameter will likely be higher than ~0.5 degrees at that elevation.

    Failing that the suns sunset plane is self-shadowing.

    After a bit of testing,
    I can't seem to replicate it in every project even in the same editor build, but I did, however, have control of it using the angular diameter and only at certain angles and elevations.
    2020.3.16 in some tests.
     
  4. iamarugin

    iamarugin

    Joined:
    Dec 17, 2014
    Posts:
    889
    I think is just a bug that needs to be reported.
     
  5. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    hmm, i remember that this artifact issue are already discussed before (i forgot where) hence why i was wondering why it's still happening.
     
  6. SebLazyWizard

    SebLazyWizard

    Joined:
    Jun 15, 2018
    Posts:
    234
    So since there's no update for like 2 years on the PBS (regardless of it's many issues), I tried to improve it myself.

    I changed the air scattering parameters to account for an ozone layer, which greatly improves the lighting at dusk/dawn and removes the unnatural yellowish tint in these conditions.
    (first image uses default settings and the second my tweaked ones)
    screen_1920x1080_2021-11-03_04-48-40.png
    screen_1920x1080_2021-11-03_04-49-22.png
    ...and another shot with enabled fog.
    screen_1920x1080_2021-11-03_14-48-54.png
    screen_1920x1080_2021-11-03_14-49-16.png

    You can achieve this look by simply setting the "Air Density" in the PBS override to;
    R = 0.06091079
    G = 0.1374226
    B = 0.2339507

    The absorption coefficient of ozone can be found in this paper...
    https://media.contentapi.ea.com/con...stbite_sky_clouds.pdf#page=20&zoom=100,84,126
    ...so (3.426, 8.298, 0.356) × 0.06 × 10 −5

    this has to be added to the rayleigh coefficient which is;
    (5.8e −6 , 1.35e −5 , 3.31e −5 )
    Code (CSharp):
    1.   (0.0000058,    0.0000135,    0.0000331)
    2. + (0.0000020556, 0.0000049788, 0.0000002136)
    3. --------------------------------------------
    4. = (0.0000078556, 0.0000184788, 0.0000333136)
    To get the values I posted for the PBS override, the result has to be manipulated by this function which is located in PhysicallyBasedSky.cs
    Code (CSharp):
    1.         static internal float ZenithOpacityFromExtinctionAndScaleHeight(float ext, float H)
    2.         {
    3.             float optDepth = ext * H;
    4.  
    5.             return 1 - Mathf.Exp(-optDepth);
    6.         }
    Seems like there's already some "hackery" involved to kinda adapt for ozone using the "k_DefaultAirAlbedo" parameters, but now that "k_DefaultAirScattering" is set up correctly, do I really need to set up DefaultAirAlbedo any longer (and how), or is it obsolete?

    Maybe @pierred_unity has a clue... sorry for pinging;)
    Code (CSharp):
    1.     public partial class PhysicallyBasedSky : SkySettings
    2.     {
    3.         /* We use the measurements from Earth as the defaults. */
    4.         const float k_DefaultEarthRadius    = 6.3781f * 1000000;
    5.         const float k_DefaultAirScatteringR =  5.8f / 1000000; // at 680 nm, without ozone
    6.         const float k_DefaultAirScatteringG = 13.5f / 1000000; // at 550 nm, without ozone
    7.         const float k_DefaultAirScatteringB = 33.1f / 1000000; // at 440 nm, without ozone
    8.         const float k_DefaultAirScaleHeight = 8000;
    9.         const float k_DefaultAirAlbedoR     = 0.9f; // BS values to account for absorption
    10.         const float k_DefaultAirAlbedoG     = 0.9f; // due to the ozone layer. We assume that ozone
    11.         const float k_DefaultAirAlbedoB     = 1.0f; // has the same height distribution as air (most certainly WRONG).
    12.         const float k_DefaultAerosolScaleHeight = 1200;
    13.         static readonly float k_DefaultAerosolMaximumAltitude = LayerDepthFromScaleHeight(k_DefaultAerosolScaleHeight);
     
    Last edited: Nov 3, 2021
    wetcircuit, ftejada, Lex4art and 5 others like this.
  7. Ruchir

    Ruchir

    Joined:
    May 26, 2015
    Posts:
    934
    Is that moon in background made using another Directional Light with Flare texture or are you using a spacce emmision texture?
     
  8. SebLazyWizard

    SebLazyWizard

    Joined:
    Jun 15, 2018
    Posts:
    234
    Yea I'm using a texture on the directional light.
    I pre-render the moon using correct sun intensity (even light from the earth is taken into account) into HDR (essential for the huge light intensity differences) images for like 24 moon-phases and switch the textures on the fly, depending on the moons angle to the sun.

    fov: 60
    screen_1920x1080_2021-11-03_16-52-40.png

    fov: 4
    screen_1920x1080_2021-11-03_16-53-52.png

    I even use a texture for the sun to simulate limb darkening, which is also described here;
    https://media.contentapi.ea.com/con...ostbite_sky_clouds.pdf#page=28&zoom=100,84,89
    fov: 4
    screen_1920x1080_2021-11-03_16-57-48.png
     
  9. sqallpl

    sqallpl

    Joined:
    Oct 22, 2013
    Posts:
    384
    @SebLazyWizard

    Nice!

    Would be great if PBS gets some updates and more love from devs. Especially now when the great looking volumetric clouds are implemented.
     
  10. Gokcan

    Gokcan

    Joined:
    Aug 15, 2013
    Posts:
    289
    I think pbs system needs @auzaiffe and @pierred_unity 's creative approaches and AAA knowledge. When these two guys are working on a system, amazing results are comming...
     
    sqallpl, Ruchir and SebLazyWizard like this.
  11. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    PBS sky really need some love from the devs....
     
  12. Ruchir

    Ruchir

    Joined:
    May 26, 2015
    Posts:
    934
    The paper you referenced is quite interesting, never knew that clouds in those games were volumetric clouds until now. :eek:
     
  13. cLick1338

    cLick1338

    Joined:
    Feb 23, 2017
    Posts:
    74
    Is it possible to change space emission parameters at runtime? (2021.2.0f1, HDRP 12.1.0)

    I change spaceRotation and spaceEmissionMultiplier by script, they do change in the inspector but there is no visible difference. Not in play mode, not in a build.

    EDIT: Nevermind, it seems that you have to use spaceRotation.value instead of directly assigning the spaceRotation Vector3Parameter as I was doing.
     
    Last edited: Nov 5, 2021
    ftejada likes this.
  14. HIBIKI_entertainment

    HIBIKI_entertainment

    Joined:
    Dec 4, 2018
    Posts:
    596

    Yeah this is correct, the optical depth is based on the optical depth IRL the default is okay, but again real or artistic flare, it should be adjusted for the purpose, ie polluted, smogged or just bad depth areas, like some placed in India Asia and of course deserts.

    0.29029029029 could be a good baseline for smoggy/ polluted sky areas for example. ( PBS detaults is top fyi)

    Great observance though seb, as always. :)b
     

    Attached Files:

    ftejada likes this.
  15. Ruchir

    Ruchir

    Joined:
    May 26, 2015
    Posts:
    934
    Which value should be changed to 0.29029029029?(sorry for the dumb question :p)
     
    Last edited: Nov 5, 2021
    HIBIKI_entertainment likes this.
  16. SebLazyWizard

    SebLazyWizard

    Joined:
    Jun 15, 2018
    Posts:
    234
    I do change the space rotation at runtime without any problem, make sure that you're referencing the currently active volume profile in your script.
    Show off your code if you can't fix it yourself.

    I assume he means the Aerosol Density Value (Mie scattering), but my post was just about the Air Density Values (Rayleigh scattering).
    So I was wondering too...
     
  17. cLick1338

    cLick1338

    Joined:
    Feb 23, 2017
    Posts:
    74
    Code (CSharp):
    1. //In Start():
    2. _globalVolume.profile.TryGet<PhysicallyBasedSky>(out _skyProfile);
    3.  
    4. //In a coroutine that periodically runs this test code:
    5. a += Vector3.up;
    6. _skyProfile.spaceRotation = new Vector3Parameter(a, true);
    7. _skyProfile.spaceEmissionMultiplier = new MinFloatParameter(a.y, a.y, true);
    It's the intended volume, the values are changing in debug and in inspector but nothing changes in Play mode (Game or Scene) nor in a build.

    EDIT: Ahh nevermind, using _skyProfile.spaceRotation.value instead works as intended.
     
    Last edited: Nov 5, 2021
    ftejada and SebLazyWizard like this.
  18. sqallpl

    sqallpl

    Joined:
    Oct 22, 2013
    Posts:
    384
    @SebLazyWizard

    Hey,

    Can you post a screenshot of your PBS volume settings please? I mean other values like Areosol Density, Anisotropy, Maximum Altitude etc.

    Thanks!
     
  19. SebLazyWizard

    SebLazyWizard

    Joined:
    Jun 15, 2018
    Posts:
    234
    ftejada, cLick1338 and sqallpl like this.
  20. SebLazyWizard

    SebLazyWizard

    Joined:
    Jun 15, 2018
    Posts:
    234
    If anyone is wondering what maximum altitude parameters for air and aerosol mean, it's the height at which each density drops below 0.1%.

    This info can again only be found in the source code, but it's that kind of info that should be displayed in the inspector aswell.
    Code (CSharp):
    1. /// <summary> Depth of the atmospheric layer (from the sea level) composed of air particles. Controls the rate of height-based density falloff. Units: meters. </summary>
    2. [Tooltip("Sets the depth, in meters, of the atmospheric layer, from sea level, composed of air particles. Controls the rate of height-based density falloff.")]
    3. // We assume the exponential falloff of density w.r.t. the height.
    4. // We can interpret the depth as the height at which the density drops to 0.1% of the initial (sea level) value.
    5. public MinFloatParameter airMaximumAltitude = new MinFloatParameter(LayerDepthFromScaleHeight(k_DefaultAirScaleHeight), 0);
    6. ...
    7. ...
    8. /// <summary> Depth of the atmospheric layer (from the sea level) composed of aerosol particles. Controls the rate of height-based density falloff. Units: meters. </summary>
    9. [Tooltip("Sets the depth, in meters, of the atmospheric layer, from sea level, composed of aerosol particles. Controls the rate of height-based density falloff.")]
    10. // We assume the exponential falloff of density w.r.t. the height.
    11. // We can interpret the depth as the height at which the density drops to 0.1% of the initial (sea level) value.
    12. public MinFloatParameter aerosolMaximumAltitude = new MinFloatParameter(k_DefaultAerosolMaximumAltitude, 0);
     
    Wilhye, ftejada and Ruchir like this.
  21. Onigiri

    Onigiri

    Joined:
    Aug 10, 2014
    Posts:
    502
    Yeah PB sky needs improvements
     
  22. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    Especially the performance
     
  23. sqallpl

    sqallpl

    Joined:
    Oct 22, 2013
    Posts:
    384
    I may be wrong but I'm almost sure that the default exposure/brightness of PBS is too low if Sunlight is set to 130,000lux.

    When I compare objects that are lit by the sun and the sky that is visible behind them, sky is definitely too dark. In almost all scenarios I have to set it to manual mode with exposure near 2. Anyway I'm not sure if the ambient light power is accurate in this situation.

    Here are some of my screenshots from an older version of PBS but in HDRP 12 it's pretty much the same. The left image uses sky on default settings and the right one uses manual exposure around 2.

    I think that 'visible' sky brightness is much closer to the real one on the right image (PBS exposure around 2) but ambient light is too strong. On the left image (default values) sky looks too dark but the amount of ambient lighting looks more accurate. I've added some general reference from Wikipedia below the screenshots.

    We aren't using any color adjustments. We use auto exposure and a custom tone-mapping curve that is not as aggressive as ACES but more 'vibrant' than neutral.





    Source: https://commons.wikimedia.org/wiki/File:Prague_Milicovsky_Forest_Meadow.jpg
     
    Last edited: Nov 5, 2021
  24. pierred_unity

    pierred_unity

    Unity Technologies

    Joined:
    May 25, 2018
    Posts:
    433
    Hey, you should share your volume settings. The PBSky has a ton of settings for air density and aerosol that massively affects the value and saturation of the sky. By default you'll get a more "polarised" look probably because it'll look like a very crisp sky without much aerosol in the air.

    I wouldn't really compare a photo (with a different sun angle than your scene apparently) with the default PBR sky properties. Also the fog will have a big influence on the look of the horizon (anisotropy, max height, volumetric fog, etc. ).

    And if you just need to burn the horizon slightly, use instead the "Artistic Overrides" of the PBSky, they've been designed to do exactly what you're after, without having to mess with the exposure of the entire sky.

    (I'm not saying our PBSky is perfect, far from it, but matching EXACTLY a specific real world scenario will require a lot of careful tuning for the advanced parameters of the sky and fog, understandably.)
     
    Last edited: Nov 6, 2021
    sqallpl likes this.
  25. sqallpl

    sqallpl

    Joined:
    Oct 22, 2013
    Posts:
    384
    I'm testing various settings but most of them change saturation and/or color but brightness is still on a similar level as on defaults. I would try to test more of them.

    Here is PBS with an earth (simple) preset. Number of bounces is set to 10. Exposure is manually set on the second image. All other settings are not overridden. Fog is disabled in this example.

    After testing it for a while again I think that 2.25 is probably too much. Anyway I still have a feeling that the default value gives weirdly dark results when compared to sunlight.

    Ignore the scene ;)














    And here is two more with 0 vs 1 (instead of 2.25):

     
    Last edited: Nov 6, 2021
    ftejada and newguy123 like this.
  26. pierred_unity

    pierred_unity

    Unity Technologies

    Joined:
    May 25, 2018
    Posts:
    433
    This looks very odd (even without fog), it looks as if you were in space (or extremely far from the planet center).

    Do you mind sharing a slim version of the project via PM?' I'll try to take a look at it next week.
     
  27. sqallpl

    sqallpl

    Joined:
    Oct 22, 2013
    Posts:
    384
    Sure but first I will double check if something isn't messed with my volumes and overrides carefully. If I won't find anything I will send you a small version with an example scene.

    Thanks!
     
    Last edited: Nov 6, 2021
    pierred_unity likes this.
  28. Ruchir

    Ruchir

    Joined:
    May 26, 2015
    Posts:
    934
    upload_2021-11-6_12-20-16.png
    This is what I got after changing the exposure to 1 and changing the absorbance/scattering amounts mentioned above.
    with 0 it was a bit too dark (this is dark as well, but I like it :p)
     
    Last edited: Nov 6, 2021
  29. LumaPxxx

    LumaPxxx

    Joined:
    Oct 3, 2010
    Posts:
    350
    The sky exposure issue is there from day one, i thought it's my fault that i have to use a value between 1.5-2.0.

    but,the main issue to me is that Unity team should give us an official way or example to do "REALLY SMOOTH" day night cycle in PBS.

    this is the main goal of PBS and we don't have a perfect solution to do that because

    1.HDRP dose not support two directional light cast shadows.
    2.Volumetric clouds dose not support two directional light.
     
    ftejada, cLick1338 and Lex4art like this.
  30. Ruchir

    Ruchir

    Joined:
    May 26, 2015
    Posts:
    934
    Yes, it does support it the last time I checked, it's just a matter of adjusting the values to get the look you want.

    EDIT: it doesn't seem to be working properly at least for now, Sometimes it registers the second sun, sometimes it doesn't for some reason. Also, It is really hard to get it to look right. (I tried disabling Affect diffuse and specular to just get Highlights on the clouds but it isn't working in the latest version)
     
    Last edited: Nov 6, 2021
    ftejada likes this.
  31. LumaPxxx

    LumaPxxx

    Joined:
    Oct 3, 2010
    Posts:
    350
    Which version are you in?
    i'm using 2021.2.0f1 and i have just checked it and it dose not support two directional lights.

    all i can do is use the Sun Light Dimmer to fade to another directional light.

    but as the first problem that hdrp dose not support two directional lights to cast shadows, i have to fade to a very dark sky and switch the lights.
    i don't think this is a perfect way to do that.
     
  32. Ruchir

    Ruchir

    Joined:
    May 26, 2015
    Posts:
    934
    They don't support shadowing, but I remembered that volumetric clouds do support them. (They don't, I remembered wrong :p)
    Let me link the post where they showed it:
    https://forum.unity.com/threads/volumetric-clouds.1078811/page-8#post-7484036
     
    ftejada and LumaPxxx like this.
  33. newguy123

    newguy123

    Joined:
    Aug 22, 2018
    Posts:
    1,278
    I have to agree with the findings of @sqallpl
    I'm in HDRP 12.1 with raytracing, and I too have to add exposure to the sky because it is way too dark for typical real world values. I do my tests at the sun roughly set between 10:00am and 14:00 and test various cam angles with the cam exposure set to a typical sunny day. Compared to real life and various real life photos, and also compared to VRay renders, then the Unity PBS sky is too dark on defaults. In my case I set the sky's exposure to between 0,5 and 1 for better results.

    I'll also note that I switch of the fog in the scene completely.

    On a side note, @sqallpl your grass and trees are looking awesome!!! from which asset packs are they?
     
    ftejada likes this.
  34. pierred_unity

    pierred_unity

    Unity Technologies

    Joined:
    May 25, 2018
    Posts:
    433
    That's not very surprising if you don't use fog (and don't adjust the Aerosol either in the case of @sqallpl).

    You should consider the PBSky as the "background", i.e. the simulation of high altitude sky scattering. You still need to fill the space between the camera and the sky with fog, volumetric preferably, so that it is lit properly. This requires setting up the fog realistically (several thousand m high and several km deep).

    Here are some examples of skies with fog (left) and without fog (right), hopefully, this makes my point below clear:
    upload_2021-11-6_12-13-20.png

    If you do not want to simulate any medium (air) between the camera and the sky, you will end up with darker skies, and therefore you'll have to adjust the exposure of the sky like you did, and the Aerosol too. Having no fog will also mess up the perception of depth and the slight brightening/fading of objects as they get further away from the camera.

    Imagine that our sky was brighter (as you seem to expect), what would happen when someone uses fog to realistically simulate the air between the camera and the sky? Well, their sky would look too bright and washed out, because they'd superpose a bright fog with a bright sky. So they'd have to reduce the sky exposure to compensate for that feedback loop. And we're back to adjusting the sky exposure again, so the problem isn't solved.

    It's the exact same type of discussion when using an HDRI sky that will indeed have fog baked into it: what happens if you want to add fog inside the scene in front of your HDRI sky that already contains fog? again, you'll have to adjust your HDRI so that the sky doesn't become washed out (usually by tuning the exposure or contrast of the HDRI).
    [some older or non/less physically based render pipelines avoid this by preventing sky pixels from being affected by the fog, but this always results in issues at the horizon and makes volumetric fog tricky to implement and look right]

    It's two sides of the same problem: sky and fog need to be decoupled no matter the type of sky you want to use, gradient, HDRI, or Physically Based, in order to avoid this unwanted feedback loop. And it's especially important with the PBSky that the fog is correctly set up based on the conditions you want to recreate. This will probably make a lot more sense as soon as you start working in very large-scale environments where distant objects need to be fogged out correctly. If you work on smaller scenes and are used to an HDRI workflow without too much fog, I can understand why you'd think it's a burden. ;)

    One of the ultimate solutions would be to simulate spatially spherical fog all around the globe, with different types of gas compositions per altitude, but obviously, the cost of such a system would be incredibly high. So for now we have to make do with the approximation of a sky and a camera-based-only volumetric fog.

    (Again, I'm not saying the system is perfect. We'll look into improving the PBSky, especially day/night transitions, and its relationship with the fog. Step by step.)
     
  35. valarnur

    valarnur

    Joined:
    Apr 7, 2019
    Posts:
    441
    Could you improve atmospheric scattering without having sky? For example when light shines through the windows, light rays scatter along window border.
     
  36. Ruchir

    Ruchir

    Joined:
    May 26, 2015
    Posts:
    934
    Can you share some settings you used for the scene? :)

    The default fog height is very low and really doesn't look good in most of the scenarios and given I'm not an artist I have a really hard time figuring out what should be correct fog height and attenuation distance. Some examples would be really appreciated (for example, foggy situations, clear sky, etc.)

    Also, some way of determining appropriate Volumetric fog distance for our scene and its settings would be good. (The cheat sheet you made for light units is really helpful till now)
     
    ftejada likes this.
  37. pierred_unity

    pierred_unity

    Unity Technologies

    Joined:
    May 25, 2018
    Posts:
    433
    The default settings are not tuned for large worlds, because that's not really a typical use case for most projects. The definition of "looks good" depends on your scene. If you just make an interior, you don't need massive view distances for fog and the cost that may come with it. If you want to recreate large landscapes (and have a correct influence on the sky), then obviously you need to push the fog further.

    • Directional light: 130,000 lux for PBSky
    • PBSky: nothing changed apart from the ground tint
    • Volumetric Clouds: Cloudy preset, slightly adjusted altitude range, with shadows on
    • Fog: 0 to 2000m altitude range, distance 50km, volumetric effect extending til 10km (but could be higher depending on the weather/quality required)
    • Grading: bit more contrast, slight adjustment of highlights

    upload_2021-11-6_17-25-21.png

    All the other shots are just variations on the directional light orientation, fog attenuation distances (to control the density). No magic involved. ;)
     
    Lex4art, ftejada, TerraUnity and 4 others like this.
  38. Ruchir

    Ruchir

    Joined:
    May 26, 2015
    Posts:
    934
    I really had no idea we could push the values of these distance parameters to such an extent and still get reliable performance, especially the volumetric fog distance. (I mean it's set to just 64m by default, so I just assumed it to be quite expensive when increased but never really tested it :p)
    Thanks for the sample though, it really changed how my scene looks now :)
    upload_2021-11-6_23-55-25.png
     

    Attached Files:

    Last edited: Nov 6, 2021
    Gokcan likes this.
  39. iamarugin

    iamarugin

    Joined:
    Dec 17, 2014
    Posts:
    889
    It would be great to have a spherical fog to use it with any planet center position for space simulators. It is a pretty popular genre, I don't understand why it is being ignored by Unity.
     
  40. HIBIKI_entertainment

    HIBIKI_entertainment

    Joined:
    Dec 4, 2018
    Posts:
    596

    To confirm this, our member was Indeed talking about Mie scattering and not Rayleigh scattering under the custom mode. Thabks for point that out, sorry for any confusion folks!
     
  41. newguy123

    newguy123

    Joined:
    Aug 22, 2018
    Posts:
    1,278
    @pierred_unity How can I make the sky "invisible" to the camera, but still get its lighting effects on my scene?

    For example I'm using recorder to output image sequence frames, and I want the sky to be masked out so we can comp the cg later with Resolve/Fusion
    On my cam, I'm setting the background to a black color. Is that the correct way to do it? I seem to be getting very jagged edges on the edges of my cg. where the cam "cuts" out the sky to black. I suspect it may be a recorder bug, but I'm not entirely sure I'm doing it correctly.

    Also, what if I have volumetric fog in my scene? How can I also cut that out, against the sky only, so I get the fog effect over the cg parts, but in the ksy parts its masked out in alpha for comping purposes?

    I've made a thread here if you could take a look please @pierred_unity
    https://forum.unity.com/threads/recorder-premultiplied-alpha-bug-png-and-exr.1195888/#post-7646998
     
    Last edited: Nov 11, 2021
  42. Enigma229

    Enigma229

    Joined:
    Aug 6, 2019
    Posts:
    136
    How can I use the Physical Sky but have an HDRI skybox visible for clouds?

    I’m using HDRP 10.7 so I don’t have access to the clouds feature.
     
  43. HIBIKI_entertainment

    HIBIKI_entertainment

    Joined:
    Dec 4, 2018
    Posts:
    596
    Unless you patched down this feature into your version but this would be a horrible experience to implement, you wouldn't be able to.


    You can decouple the visual environment ( the one you see) from the lighting environment ( sky the's used when calculating GI) but that's not what you'd want in this case.

    and other than other 3rd party options, that's pretty much your limit.

    for HDRIs with clouds and no sun, you can use the flow options to make animated cloud movements. it may be a reasonable solution for your particular project. it should work it your version.
     
  44. SebLazyWizard

    SebLazyWizard

    Joined:
    Jun 15, 2018
    Posts:
    234
    So after further investigation of HDRPs source code I found out that there is actually a spherical fog implemented that covers the entire planet, but it's disabled by default and you have to import HDRP as a local package in order to use it.

    Go to the HDRP package folder, then open up ...\Runtime\Lighting\AtmosphericScattering\Fog.cs, search for cb._PBRFogEnabled and set it to 1, that's it.

    The corresponding shader code for the "PBR Fog" can be found in AtmosphericScattering.hlsl which is located in the same directory as above.

    The PBR Fog is entirely controlled by the PBSky override settings, so fog settings don't affect it at all.

    I have no idea why it has been hidden in the source files for so long, it just works great out of the box.
    Here are some pictures with just the normal fog and with normal fog + pbr fog.
    screen_1920x1080_2021-11-27_21-16-38.jpg
    screen_1920x1080_2021-11-27_21-18-21.jpg
    screen_1920x1080_2021-11-27_21-25-06.jpg
    screen_1920x1080_2021-11-27_21-26-23.jpg

    Looks great right?
    Finally a proper way of full atmosphere rendering, which is not applied to the skybox only.

    So please Unity, make it available by default.
     
    Last edited: Dec 13, 2021
  45. SebLazyWizard

    SebLazyWizard

    Joined:
    Jun 15, 2018
    Posts:
    234
    I found the root of this particular artifact, it's caused by this code block in AtmosphericScattering.hlsl
    Code (CSharp):
    1.             // The sun disk hack causes some issues when applied to nearby geometry, so don't do that.
    2.             if (renderSunDisk && asint(light.angularDiameter) != 0 && light.distanceFromCamera <= tFrag)
    3.             {
    4.                 float c = dot(L, -V);
    5.  
    6.                 if (-0.99999 < c && c < 0.99999)
    7.                 {
    8.                     float alpha = 0.5 * light.angularDiameter;
    9.                     float beta  = acos(c);
    10.                     float gamma = min(alpha, beta);
    11.  
    12.                     // Make sure that if (beta = Pi), no rotation is performed.
    13.                     gamma *= (PI - beta) * rcp(PI - gamma);
    14.  
    15.                     // Perform a shortest arc rotation.
    16.                     float3   A = normalize(cross(L, -V));
    17.                     float3x3 R = RotationFromAxisAngle(A, sin(gamma), cos(gamma));
    18.  
    19.                     // Rotate the light direction.
    20.                     L = mul(R, L);
    21.                 }
    22.             }
    To be honest I have no clue what it is supposed to solve here, but there's no real visual difference when disabling it (except getting rid of the artifact ofc).

    So after commenting out the above code, it changed from this
    screen_1920x1080_2021-12-13_21-20-35.jpg
    to this
    screen_1920x1080_2021-12-13_21-21-35.jpg

    EDIT
    So I found the commit at which the mentioned code got implemented;
    https://github.com/Unity-Technologi...70c024aee8ad3b9d04ed7d03c1b44d2475803e49a82b6
    The changelog states;

    * Faster sun disk hack

    A hack for what?
    I don't see any issues without the said "hack", instead the hack introduces issues.
    It remains a mystery...

    EDIT 2
    Ok the effect of the hack becomes obvious when you use very large angular diameters for the directional light, it tries to fit the lighting to the size of the celestial body.
    Without it the light behaves as if it is infinity small.

    hack on
    screen_1920x1080_2021-12-13_22-55-26.jpg
    hack off
    screen_1920x1080_2021-12-13_22-54-27.jpg

    The angular diameter is set to 55 degrees here.

    So I would rather go for infinity small light sources than dealing with those ugly artifacts.
    The agular diameters for sun and moon are ~0.5 degrees so you wont notice any difference in this case.
     
    Last edited: Dec 13, 2021
    Reanimate_L, Ruchir, ftejada and 2 others like this.
  46. SebLazyWizard

    SebLazyWizard

    Joined:
    Jun 15, 2018
    Posts:
    234
    Here's something I've been working on to improve the PBS even further.
    I added support for normal mapping and reflections to the planet renderer.

    It's nothing too fancy since I try to keep it's rendering cost as low as possible, so the lighting is quite simplified, but still follows PBR rules ofc.

    This is how it looks by default.
    screen_1920x1080_2021-12-15_22-48-54.jpg
    And now with normal mapping and reflections.
    screen_1920x1080_2021-12-15_22-49-04.jpg
    Normal mapping and reflections only.
    screen_1920x1080_2021-12-15_22-50-21.jpg

    I'll probably share the source code and maps once it's finalised.

    Edit
    So here is just the changed shader code in PhysicallyBasedSky.shader, there are changes in other files required aswell, like the PBS editor, renderer etc to provide required data for the shader ofc.
    I might set up a git repository later, with all the improvements I made to the PBS, but for now this should be it.

    Changes are marked with //mod
    Code (CSharp):
    1. ...
    2. int _HasGroundMaskTexture;//mod
    3. float4x4 _InvPlanetRotation;//mod
    4. TEXTURECUBE(_GroundMaskTexture);//mod
    5. ...
    6. ...
    7.         if (rayIntersectsAtmosphere && !lookAboveHorizon) // See the ground?
    8.         {
    9.             float tGround = tEntry + IntersectSphere(R, cosChi, r).x;
    10.  
    11.             if (tGround < tFrag)
    12.             {
    13.                 // Closest so far.
    14.                 // Make it negative to communicate to EvaluatePbrAtmosphere that we intersected the ground.
    15.                 tFrag = -tGround;
    16.  
    17.                 radiance = 0;
    18.  
    19.                 float3 gP = O + tGround * -V;
    20.                 float3 gN = normalize(gP);
    21.  
    22.                 if (_HasGroundEmissionTexture)
    23.                 {
    24.                     float4 ts = SAMPLE_TEXTURECUBE(_GroundEmissionTexture, s_trilinear_clamp_sampler, mul(gN, (float3x3)_PlanetRotation));
    25.                     radiance += _GroundEmissionMultiplier * ts.rgb;
    26.                 }
    27.  
    28.                 float3 albedo = _GroundAlbedo.xyz;
    29.  
    30.                 if (_HasGroundAlbedoTexture)
    31.                 {
    32.                     albedo *= SAMPLE_TEXTURECUBE(_GroundAlbedoTexture, s_trilinear_clamp_sampler, mul(gN, (float3x3)_PlanetRotation)).rgb;
    33.                 }
    34.  
    35. //mod begin
    36.                 float3 normal = gN;
    37.                 float roughness = 0;
    38.                 float fresnel = 0;
    39.                 float reflectSize = 0;
    40.  
    41.                 if (_HasGroundMaskTexture)
    42.                 {
    43.                     float4 mask = SAMPLE_TEXTURECUBE(_GroundMaskTexture, s_trilinear_clamp_sampler, mul(gN, (float3x3)_PlanetRotation));
    44.                     normal = mul(normalize(mask.xyz * 2 - 1), (float3x3)_InvPlanetRotation);
    45.                     roughness = 1 - mask.w;// smooth to rough
    46.  
    47.                     float F0 = 0.04;
    48.                     fresnel = F0 + (1.0 - F0) * pow(1 - saturate(dot(V, normal)), 5);// do it once instead for each light, cheaper...
    49.  
    50.                     reflectSize = 1 / max(roughness * roughness, 0.001);// power factor for cheap approximation of the light-size inside the reflection
    51.                 }
    52.  
    53.                 float3 diffuse = float3(0, 0, 0);
    54.                 float3 specular = float3(0, 0, 0);
    55. //mod end
    56.  
    57.                 float3 gBrdf = INV_PI * albedo;
    58.  
    59.                 // Shade the ground.
    60.                 for (uint i = 0; i < _DirectionalLightCount; i++)
    61.                 {
    62.                     DirectionalLightData light = _DirectionalLightDatas[i];
    63.  
    64.                     // Use scalar or integer cores (more efficient).
    65.                     bool interactsWithSky = asint(light.distanceFromCamera) >= 0;
    66.  
    67.                     float3 L          = -light.forward.xyz;
    68.                     float3 intensity  = light.color.rgb;
    69.                     //float3 irradiance = SampleGroundIrradianceTexture(dot(gN, L));//mod disable
    70. //mod begin
    71.                     float NdotL = dot(normal, L);
    72.                     float3 irradiance = SampleGroundIrradianceTexture(NdotL);
    73.                     diffuse += irradiance * intensity;
    74.  
    75.                     if (_HasGroundMaskTexture)
    76.                     {
    77.                         float3 H = normalize(V + L);
    78.                         specular += pow(saturate(dot(normal, H)), reflectSize) * saturate(NdotL) * intensity;
    79.                     }
    80. //mod end
    81.                     //radiance += gBrdf * (irradiance * intensity);//mod disable // Scale from unit intensity to light's intensity
    82.                 }
    83. //mod begin
    84.                 radiance += diffuse * gBrdf;
    85.                 if (_HasGroundMaskTexture)
    86.                 {
    87.                     radiance = lerp(radiance, specular, (1 - roughness) * fresnel);// mix diffuse and specular
    88.                 }
    89. //mod end
    90.             }
    91.         }
    92.  
    Currently the input normal map (xyz channles of the mask) has to be in word space, I haven't implemented support for tangent space normal maps yet.
    I'll provide the required maps as soon as I set up the git repository.
     
    Last edited: Dec 16, 2021
  47. SebLazyWizard

    SebLazyWizard

    Joined:
    Jun 15, 2018
    Posts:
    234
    So here it is with all maps and files included; https://gitlab.com/bad-bug-busters/unity/improved-pbs

    I cleaned up the code and improved it's performance compared to the version in my previous post.
    The sun-disk-hack will be skipped in this version since it produces artifacts.
    PBS override default settings now account for an ozone layer as described here; https://forum.unity.com/threads/physically-based-sky.765962/page-3#post-7626310

    EDIT
    I pushed an update which enables the spherical PBR fog. (forgot to add it yesterday)
     
    Last edited: Dec 18, 2021
    ftejada, Gokcan, Deleted User and 4 others like this.
  48. SebLazyWizard

    SebLazyWizard

    Joined:
    Jun 15, 2018
    Posts:
    234
    I added parallax mapping support and uploaded a heightmap to the repository aswell.
    Parallax effect off
    screen_1920x1080_2021-12-19_19-38-54.jpg
    ...and on
    screen_1920x1080_2021-12-19_19-39-24.jpg
    Updated PBS editor
    pbs_editor.jpg
    I set the default Max Height to 6400 meters, since this is the height range of the original source that I used;
    https://visibleearth.nasa.gov/images/73934/topography


    Kinda answering myself here after I corrected the ozone contribution, which included the correction of DefaultAirAlbedo ("Air Tint" in PBS override) to;
    R = 0.7383267987
    G = 0.7305669199
    B = 0.9935882042

    More info in the related code comments in PhysicallyBasesdSky.cs
    Code (CSharp):
    1. //mod swap ... turns into extinction coefficient later on, misleading naming...
    2.         //const float k_DefaultAirScatteringR = 5.8f / 1000000; // at 680 nm, without ozone
    3.         //const float k_DefaultAirScatteringG = 13.5f / 1000000; // at 550 nm, without ozone
    4.         //const float k_DefaultAirScatteringB = 33.1f / 1000000; // at 440 nm, without ozone
    5.         const float k_DefaultAirScatteringR = 0.0000078556f; // with ozone
    6.         const float k_DefaultAirScatteringG = 0.0000184788f; // with ozone
    7.         const float k_DefaultAirScatteringB = 0.0000333136f; // with ozone
    8.  
    9.         const float k_DefaultAirScaleHeight = 8000;
    10.  
    11. //mod swap ... multiplicator to turn the above extinction- into scattering coefficient, ozone only absorbs light and doesnt scatter any, so we multiply it into the rayleigh coefficient (without ozone) again
    12.         //const float k_DefaultAirAlbedoR = 0.9f; // BS values to account for absorption
    13.         //const float k_DefaultAirAlbedoG = 0.9f; // due to the ozone layer. We assume that ozone
    14.         //const float k_DefaultAirAlbedoB = 1.0f; // has the same height distribution as air (most certainly WRONG).
    15.         const float k_DefaultAirAlbedoR = 0.7383267987f;
    16.         const float k_DefaultAirAlbedoG = 0.7305669199f;
    17.         const float k_DefaultAirAlbedoB = 0.9935882042f;
    PBS override "Air Density" values haven't changed since the quoted post.

    So let's compare the sky again, without any ozone...
    screen_1920x1080_2021-12-19_19-32-06.jpg
    ...and with correct ozone contribution
    screen_1920x1080_2021-12-19_19-32-48.jpg
     
    Last edited: Dec 20, 2021
  49. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    i'm curious why nobody from unity responded to your changes and finding. . . . .or why there's no plan to implement those into vanilla PBS Sky
     
    ftejada and SebLazyWizard like this.
  50. HIBIKI_entertainment

    HIBIKI_entertainment

    Joined:
    Dec 4, 2018
    Posts:
    596
    It's not always as easy for a larger entity to research, test, proof, integrate and pr this.
    My only guess. PBS sky isn't perfect but I'm guessing it's "functional enough" to have a lower priority of iterations as new teams are being formed and put into other systems based tasks
     
    Wilhye likes this.