Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Make fog not affect whole (huge) game object?

Discussion in 'General Graphics' started by angiemon, May 14, 2022.

  1. angiemon

    angiemon

    Joined:
    Mar 26, 2018
    Posts:
    36
    Hi, potentially another noob question I was not able to find out, buuuut:

    Is there a way to have the fog not react to a gameobject as a whole (disregarding the distance)?
    What I mean is: I have a floor in my scene and use fog (it's an underwater scene, where blue fog is great)
    But when the floor is one single mesh, the whole thing gets affected by the fog, meaning the area near the camera is also bright and blueish!

    How I solved it right now is that the floor consists of multiple planes placed edge on edge to each other, which doesn't seem like the greatest solution in the world (polycountwise yes, although it doesn't add that much)


    However the bigger issue is this: we use a projector to apply a caustic effect (like shown in this tutorial
    ) which works per-object and has (not TOO bad, but still) visible seams at the border of each plane, so also not too great.

    (using one plane for the whole floor fixed this, but then the fog turned it light blue :( )

    A picture is worth a thousand words, sooo:


    What's probably important to mention is that this project still uses the BIRP and not URP (otherwise I would have bought this amazing caustics asset already that doesn't seem to be to object/UV reliant like the caustics projector is (for example little assets having little caustic effects), but sadly works with shader graph, so URP only)
    (The asset: https://www.reddit.com/r/Unity3D/co...urce=share&utm_medium=ios_app&utm_name=iossmf)

    Not sure yet if I wanna switch for this project and also I am in general interested in the fog issue :)

    Thanks guys!
     
    Last edited: May 14, 2022
  2. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,616
    What type of fog are you using? Both the built-in depth fog (in the Lighting window) and post-processing fog are based 100% on depth (relative to the camera) and nothing to do with separate objects. The fog is applied to the frame buffer after the view is rendered. At this point, separate objects and layers no longer exist.

    Both types of fog should have a something like a "start" and "end" value, so you should be able to adjust it to where the fog is not so thick/visible on closer objects.

    By, the way, an easy way to render caustics in the built-in renderer is to find an image of water caustics and use it was a light cookie on two different lights. Then simply have the lights rotate or move in opposite directions.
     
  3. angiemon

    angiemon

    Joined:
    Mar 26, 2018
    Posts:
    36
    Hi and sorry for the late reply!

    The problem was that the fog is vertex based, not pixel based. Meaning, I need more vertices to get the fog distributed correctly :)
    (The ground was just a huge plane which was a single poly)
    So, using the Multi Cut tool in Maya and adding a bunch of edgeloops saved the whole thing, added like 300 polys to the count instead of one, but a price I'm willing to pay that solved my problem :) So I can keep continuing using the BIRP for this project (for now ^^)

    Thanks for the light cookie advice! I meant to look into that for a long time now, can you really simulate water caustics that way? Because they're not just moving aroung, but actually the patterns of the "rings" if you will are deforming and stretching?
     
  4. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,616
    Is that the result that you are getting from Unity's built-in fog, or is that vertex-based fog an aspect of the underwater caustics shader that you are using? Unity's fog is based on the depth-buffer so it's per-pixel. I didn't think it was possible for Unity's fog to be per vertex, but there is an old thread where someone was experiencing a similar problem maybe.

    https://forum.unity.com/threads/fog-being-applied-per-vertex-instead-of-per-pixel-in-webgl.533248/

    If you are using Unity's built-in depth fog and it's only applying per-vertex for some reason, I guess you could also try Unity's post-processing deferred fog, but I suppose that only works in deferred rendering mode.

    If you can edit the underwater shader, one user in the thread above provides example shader code for pixel fog. Maybe you can incorporate in to your shader.
     
    angiemon likes this.