Fog render over my sprites

Hello !

I’m trying to build a 3D games with 2D sprites in URP and i tried to add fog by a custom fog post processing effect.
The catch is that when i apply it, it overlaps my sprites where there is no 3D object behind and it looks really weird.

I understand that fog is a post processing effect that deals a lot with alpha but i don’t understand lighting and shaders so much so anyone has an idea on how to solve this ?

I think what’s happening is that the shader doesn’t detect my 2D sprite and only my terrain, hence it adds fog “on top” of the tree and making it lighter above the terrain.

Here is the fog shader : GitHub - CristianQiu/Unity-URP-Volumetric-Light: Unity package for versions 2022.3 and Unity 6. Adds support to render volumetric lighting for both the main and additional lights in URP. Compatible with URP render graph in Unity 6.

And here is a picture of my sprite’s shader graph :

Thanks !

image

Ok i don’t know how good this solution is and i think i will have issues later but i changed my sprites form transparent to opaque and assigned the alpha manually in the shader graph, this gave this result which is exactly what i wanted :

image

If anyone have suggestions to make this cleaner or thoughts on the issues i could encounter later, i would be glad to hear it.

Well, it does say so in the GitHub readme:

Known limitations

  • Transparent objects are not blended correctly with fog.

Looks like the fog is using the depth buffer to render but transparent objects don’t write to the depth buffer, they only read from it. The depth used for the fog will always be the nearest opaque object and transparent objects in-between will be ignored.

You need to change your transparent shader to use alpha-testing. This makes them behave like opaque objects (every pixel is either opaque or fully transparent), writing to the depth and work properly with this fog shader.

What you did sounds similar but is probably writing the same depth for the whole sprite, not just the non-transparent areas. This will likely lead to the reversed issue, where the fog is too weak in the fully-transparent areas of a foreground sprite.

Hello,

Thanks for your response, i understand what you mean and i tested it with my method and it seems to not have this kind of issue (see picture where everywhere else out of the green pixels is transparency).
Moreover, sprites overlapping each other is not an issue too.

Maybe there are other ones that i don’t experience at the moment and i will keep this thread updated if that’s the case.

1 Like