URP: Transparent Mesh + Fog == ?

Suppose a gun has a muzzle flash made up of two intersecting planes with a transparent UV mapped texture using the URP/Unlit shader.

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

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

Now transparency starts to look a little wonky…

6148361--671456--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?

1 Like

crickets chirping :slight_smile:

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

1 Like

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.

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.

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.

Ever find a fix for this? I’m running into the exact same problem.

No, unfortunately I never found a fix. I had to disable fog :frowning:

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

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.

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

7689619--962056--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.

7689619--962059--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.

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

And now…transparent objects working with fog in URP!!

1 Like

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.

I recommend making a bug report for this. This shouldn’t happen

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.

7717933--968152--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:

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

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