Translucent materials with prerendered backgrounds

Hi all, so I have a prerendered setup similar to old school games using a postprocess material and a custom depth map. The material simply compares the current scene depth value vs the prerendered depth value and picks a color/pixel either from the scene or the preredered image.

Material:

Result:

The problem I have is that this doesn’t work with objects that use translucent materials. e.g. If I wanted a translucent shadow blob/plane underneath my character it wont show because translucent objects dont write to the z-buffer it seems.

I tried changing the order/blend location the postprocess is applied, didn’t help. I also tried using a Masked material for my shadow blow and TemporalDitherAA as the opacity mask but it didn’t look great because of my chunky pixels (I use a lower screen percentage to render everything). Is there any known workaround for this?

Thanks!

I suggest having a look here: Post Process Materials | Unreal Engine 4.27 Documentation. It states that: PostProcessInput1 has the SeparateTranslucency (Alpha is mask).

Here is a reference to the link above.

Blendable Location Description
Before Tonemapping All lighting is provided in HDR with scene color when Scene Texture expression’s Post Process Input 0 is used. It fixes issues with temporal anti-aliasing (TAA) and GBuffer lookups. For example, issues that can happen when using depth and normals.
After Tonemapping This option indicates that post processing will take place after tonemapping and color grading has been completed. It is the preferred location for performance since the color is LDR and requires less precision and bandwidth. When this option is selected, the SceneTexture expression’s Post Process Inputs 2 and 3 are used to control where Scene Color is in the pipeline. Input 2 applies scene color before tonemapping. Input 3 applies scene color after tonemapping.
Before Translucency This is even earlier in the pipeline than ‘Before Tonemapping’ before translucency was combined with the scene color. Note that SeparateTranslucency is composited later than normal translucency.
Replacing the Tonemapper PostProcessInput0 provides the HDR scene color, PostProcessInput1 has the SeparateTranslucency (Alpha is mask), PostprocessInput2 has the low resolution bloom input.

If you ever wondered what PostProcessInput 1, 2, 3, 4… was used for, have a look here:

chongdashu

May '20

Based on the UE source code: https://github.com/EpicGames/UnrealE…Material.h#L20 (Accurate as of 4.24)

/** Named post process material slots. Inputs are aliased and have different semantics
* based on the post process material blend point, which is documented with the input.
*/
enum class EPostProcessMaterialInput : uint32
{
// Always Active. Color from the previous stage of the post process chain.
SceneColor = 0,

// Always Active.
SeparateTranslucency = 1,

// Replace Tonemap Only. Half resolution combined bloom input.
CombinedBloom = 2,

// Buffer Visualization Only.
PreTonemapHDRColor = 2,
PostTonemapHDRColor = 3,

// Active if separate velocity pass is used--i.e. not part of base pass; Not active during Replace Tonemap.
Velocity = 4
};

So I read all that and still wasn’t sure what to do with all of it lol

But I managed to hack in something together using Custom depth. I Set my shadow material to translucent, and enabled Custom Depth Write in both the material and the shadow mesh itself (Sphere)

Then in my Prerender/Postprocess material, I compare the custom depth value against my prerendered depth, if the custom is smaller (closer), do an alpha blend between PostProcessInput0 and the prerendered color. This works because PostProcessInput0 actually contains the shadow color in it.

However I wasn’t able to access the shadow Opacity from the shadow material so I have a hardcoded value for now. I tried Input1 but it was just black.

It also seems like if I move the shadow up, it doesn’t alpha blend correctly with the character but that’s expected because I’m explicitly blending with the background, so this still can’t be used with general transparent objects, but for now I just needed the shadow to work so it’s fine…

Any thoughts how to actually get to the alpha of the Shadow from the postprocess?

Is there an easier way to do this that I missed?

Hi there @vexe. Hope you’re well.

This topic has been moved from International to Programming & Scripting.

When posting, please review the categories to ensure your topic is posted in the most relevant space.

Thanks and happy developing! :slight_smile:

Hey thanks! Sorry I must’ve miss-clicked and selected the wrong category…

1 Like

Totally fine! That’s what I’m here for :slight_smile: