Search Unity

Apply fog to skybox

Discussion in 'Universal Render Pipeline' started by Ranom, Jun 4, 2021.

  1. Ranom

    Ranom

    Joined:
    Oct 10, 2012
    Posts:
    49
    By default, fog is not rendered on the skybox:

    skybox no fog.PNG

    By adding a huge oriented-plane behind, I can achieve the desired effect:
    skybox fog.PNG

    I'm now thinking of adding a large inverted cube around the camera to handle this in all environments.

    Is there a better way to make the fog apply to the skybox?

    I saw in another post someone suggested modifying the Hidden/GlobalFog shader but I'm not sure how you can change the built in default shaders.
     
  2. Ranom

    Ranom

    Joined:
    Oct 10, 2012
    Posts:
    49
    For anyone thinking of doing the same, the cube around the camera is working really well. Simply flip which side is rendered on the material.
     
  3. GoGoGadget

    GoGoGadget

    Joined:
    Sep 23, 2013
    Posts:
    864
    An inverted cube around the camera sounds like a great way to achieve what you want, as long as you're mindful of culling distances.

    Just brought up one of my old projects with the Hidden/GlobalFog shader in it, the way that you would edit it to make it also apply to the skybox is simple (and would actually increase performance, technically):

    Code (CSharp):
    1. // Do not fog skybox
    2. if (rawDepth == _DistanceParams.y)
    3. fogFac = 1.0;
    Just delete those lines :)
     
  4. Bosozuki

    Bosozuki

    Joined:
    Dec 19, 2013
    Posts:
    63
    I came across this Unity example the other day. I have not tried it yet but is seems to affect the skybox in the pictures. Not sure if it will help you or not.

    Gradient fog
     
  5. Ranom

    Ranom

    Joined:
    Oct 10, 2012
    Posts:
    49
    Hi Bosozuki,

    Thanks for your response! This might be a silly question but where do I find the Hidden/GlobalFog shader to edit? Do you just copy it in to your project and make the changes and then it's automatically used?

    Oh and great link to the Gradient Fog example :)

    Thanks,

    Ranom
     
  6. Bosozuki

    Bosozuki

    Joined:
    Dec 19, 2013
    Posts:
    63
    I am not sure for that particular example. IF you have not I would clone the example repository into an empty project for the specific unity version the repository used last. I would then dig around in that particular example to see everything Unity modified for that example and try to replicate in a new project of the version of Unity you are using.

    I do not believe you need to edit Hidden/GlobalFog shader since it is using a custom hlsl file to create a node in shader graph to be used by a render feature.

    When I get a chance I will dig around the example myself
     
  7. ivank

    ivank

    Joined:
    Nov 16, 2013
    Posts:
    105
    Hi, just for @Ranom to confirm - I have just tried the gradientFog example @Bosozuki mentioned - it really works -> obscures completely the whole skybox (used Uni2021.1.6 + URP11).
    What would be great is to limit shader's "influence" just to narrower horizontal stripe along horizon, so that for example clouds in zenith would be still visible...but I have no clue yet how to achieve it.
     
    Bosozuki likes this.
  8. Ranom

    Ranom

    Joined:
    Oct 10, 2012
    Posts:
    49
    Thank you both for your input :) Good idea to replicate and play with the sample, I should have thought of that myself.
     
  9. fuzzy3d

    fuzzy3d

    Joined:
    Jun 17, 2009
    Posts:
    228