Search Unity

URP: Transparent Mesh + Fog == ?

Discussion in 'Universal Render Pipeline' started by lclemens, Jul 30, 2020.

  1. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    761
    Suppose a gun has a muzzle flash made up of two intersecting planes with a transparent UV mapped texture using the URP/Unlit shader.

    upload_2020-7-29_17-11-48.png

    Everything is working perfectly... until.... fog is enabled.
    Window/Rendering/Lighting/Environment:

    upload_2020-7-29_17-3-57.png


    Now transparency starts to look a little wonky...

    upload_2020-7-29_17-1-25.png

    I tried messing around with many different settings in the Lighting dialog, the ForwardRenderer scriptable object, the URP scriptable objects, Graphics settings, Player settings, the shader settings in the Inspector, and even swapping shaders. I guess I haven't hit upon the right combination yet.

    The closest I've come is when the particle systems had the same problem (semi-transparent squares when fog is enabled), and I was able to fix those by changing their shader from URP/Unlit to URP/Particles/Unlit. Naturally, I tried changing the muzzle flash shader to URP/Particles/Unlit as well, but the result is that the muzzle flash disappears from the scene.

    I'm not sure if it's relevant, but I'm using Hybrid Renderer V2.

    I did some googling, and it seemed like a few people were having the problem in shaders that they were writing. I'm crossing my fingers and hoping that this can be solved without writing a custom shader....

    It's probably something obvious.... What am I missing?
     
  2. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    761
    *crickets chirping* :)

    Am I asking the wrong question? Maybe there is no way to prevent fog from breaking transparent materials?
     
  3. cultureulterior

    cultureulterior

    Joined:
    Mar 15, 2015
    Posts:
    68
    I might have run into this as well for my billboards (and I use hybrid too) I seem to remember solving it by enabling both alpha and alpha clip, and setting alpha clip to 0.1. That worked for me, might not work for you.
     
  4. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    761
    I tried alpha clipping before, but it seemed like not matter what value I use it doesn't affect anything. I tested with an alpha clip of 0.1 just now, but that didn't do anything. I tried setting "Blending Mode" to "Alpha" but that removes the transparency and produces a black background.
     
  5. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    761
    I think the Alpha Clipping is bugged. If I drag the slider back and forth a few times and let go of the slider after each drag, the mesh just disappears completely from view. Even in play mode - it's just gone. The only way to get it back is to switch to a different shader and then back again.
     
  6. Prog_Meisters

    Prog_Meisters

    Joined:
    Mar 25, 2013
    Posts:
    8
    Ever find a fix for this? I'm running into the exact same problem.
     
  7. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    761
    No, unfortunately I never found a fix. I had to disable fog :-(
     
  8. HEROTECH70

    HEROTECH70

    Joined:
    May 24, 2017
    Posts:
    74
    you need to enable the alpha channel on the texture and you need fade it on the edges of the flash
    otherwise fog will be rendererd on the black texture
     
  9. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    761
    I wasn't sure what you meant by "fade it on the edges of the flash". However, your post inspired me to play around with some settings and I found something that works!

    The trick was... I selected the tga file in the Project tab.

    upload_2021-11-26_11-36-3.png
    .
    Then in the inspector I set "Alpha Source" to "From Gray Scale"

    upload_2021-11-26_11-42-40.png

    That From-Gray-Scale settings was the "secret sauce" that made it all work! Before I did that, changing the alpha clipping did nothing. So with that done, we can now tweak the alpha-clipping by selecting the material and setting the alpha clipping via the inspector window.

    upload_2021-11-26_11-44-23.png

    As the slider is dragged, we can see it adjust the red outline around the object in the scene view.

    upload_2021-11-26_11-45-47.png

    And now....transparent objects working with fog in URP!!
     
    Last edited: Nov 26, 2021
  10. HEROTECH70

    HEROTECH70

    Joined:
    May 24, 2017
    Posts:
    74
    What I meant is you don't actually need to set alpha clipping, alpha from gray scale is a quick fix but not the real fix.

    I don't know if this is a bug with blending, I would imagine that if I set blending to additive I don't need the alpha channel which is probably used by the fog.
     
  11. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,042
    I recommend making a bug report for this. This shouldn't happen
     
  12. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    761
    I've definitely been setting "Blending Mode" to "Additive" the whole time, but the only thing that has worked so far is the "From Gray Scale" solution I posted above.

    upload_2021-12-7_18-1-28.png

    Maybe it's a setting in the Lighting or Scene or Environment window?? Here's what I have:

    upload_2021-12-7_18-6-57.png

    upload_2021-12-7_18-7-25.png