Fog of War & decals on translucent materials

Hello folks,
posting here after a question on the answer hub went unanswered. We’re currently working on an old-school RTS and we’re facing some technical challenges when it comes to the Fog of War which are conveniently summed up in the following image:

We’re currently using a deferred decal for the fog of war. The reasons why we’re doing it in a decal are:
1 - It needs to be spawned and controlled via code for modding reasons. We can’t rely on the users to do any operations on the terrain/entities materials or on the map.
2 - Some things need to be on top of the fog of war like rally point flags or movement cursors (an unlit particle effect spawned when the user right clicks on an area).

Initially I was using a post process material but there was no way for me to exclude particle systems or actors in general from being darkened (we’re already using the CustomDepth to highlight units behind buildings).

The problems that are visible in the pictures are basically two:
1 - The decal doesn’t work on translucent materials, like water.
2 - Roughness of underlying materials is still showing.

Ideally I’d like to go back to the post process solution but how can I draw actors on top of the darkened area?

In Project Settings/Rendering/Postprocessing set Custom Depth-Stencil Pass to Enabled with Stencil. Restart the editor.

Give the units that can go behind buildings and the actors you want to exclude from fog of war different CustomDepth Stencil Values. In a Post Process material, any one channel(all 4 have the same value) from a SceneTexture:CustomStencil node, and an If node, can be used to mask a post processing effect.

Thank you, we’re already doing this to use different colors for each player/team. CustomDepth doesn’t seem to affect particles (with separate translucency set on or off).

Do you need your particles to be emissive or cast shadows?

No, just standard unlit translucent particles.

How’s this work then?

In your post process material, set Blendable Location to Before Translucency. For any translucent material that you want ignored by the Fog, enable Separate Translucency, and disable it on the ones you want covered by it.

Oh, and translucent materials in 4.14 preview have the flag: allow custom depth writes. Though I think the first option looks a bit better, as, in the case of outlines, it will do translucency over outline color, instead of translucency over black using custom depth.

Hey there, I’ve pinged some people for response and they also said this post is a bit related.

I’ll see what else I can dig up.

Hi @ , Can you tell me how you achieved fog of war using decal if possible? Thank you