How to fade out a opaque object

My goal is simple. I have a material with opaque surface, and I want to fade it away.
It looks very simple at first glance, I can just change opaque to translucent and using opacity to do that. But I want to keep the opaque setting because the object is human and I am using subsurface profile shading model.
So(from my guess) if I change to translucent the shading is no longer subsurface anymore(profile cannot be set and opacity no longer stand for the meaning in SS profile shading). I want the correct shading result of skin.
So in my mind there are possible two ways to do that but after a long time searching online and doc, neither of them is easily doable.

1.Same material and using scene color and manipulate the final output of material.
Two problems here: scene color(scene texture) cannot be used in opaque surface, and UE4 don’t provide final fragment(pixel) shader output access(manipulate final color of pixel)

2.Multi-pass and I use output of previous pass as a input of second pass. So I render skin with opaque surface first and next pass use that and scene color in a translucent surface and blend in emissive color channel using unlit shading model.
Two problems here: first similar to last solution which is not access to final pixel output, and second is UE4 don’t support multi-pass.

There is other similar and “looks work” method online. One can be use post effect and mark human to write custom depth map. Then this can be regard as a solution for getting final pixel value.
But in this case I don’t know how to transfer the scene color before rendering human to this post effect shader to do the final blend.

Any thoughts is very helpful.

P.S. Other common ways are just not helpful at all such as layered material(material function) which don’t support different shading model and is just a parameter blend. Otherwise it can be regarded as a multi-pass.

Two keys:

  1. I need to get(use in shader) or store(use in post-effect) scenecolor when render this human.
  2. I need a way to simply blend it with color with material output. So blend as base color input doesn’t work.

The last way I think is writing custom HLSL shader

More finding: custom G-Buffer is doable. But quite complicated and need change engine core code.

This may not be exactly what you want, but I managed to create a fade effect using masked opacity. Here are three different material instances. I apologize for the poor gif quality.

87091-gifcapture_ezgifopt.gif

I achieve this using [Noise][2] and [Pixel Depth][3]. Basically, each pixel is mapped to a noisy value X in [0,1]. Then I calculate the distance metric D = ( (PixelDepth - FadeStart) / FadeLength ) clamped to [0,1]. I set the opacity to 1 if X > D^FadePower and otherwise 0.

Here are imgur links showing the materials/functions used. First note the comments in this image of the [Noise Settings][7]. Performing a multiply on the position comes at a loss of resolution (bug!). To minimize such loss I use 4 separate noise nodes in the MF_Fade material function, which is a bit messy.

Using MF_Fade allows you to create material instances and tweak the noise scale on the fly (at a slight loss of resolution). Using MF_FadeSimple with a material instance would come at a higher loss of resolution. For lossless you can detach the position input in MF_FadeSimple and then tweak the noise settings on the node itself.

I am currently generating a bunch of tileable noise textures that I think will achieve better results. The resultant material will be simpler too. I’ll provide an update when I’m done.

  • [M_Fade][4]
  • [MF_Fade][5]
  • [MF_FadeSimple][6]

Thank you. After a long time searching and reading documentation, I finally using a working round exactly the same like you post. Using a noise texture of other similar texture and masked blend model to simulate this effect. Thank you.
And the other way which can truly simulate opaque fade out is customized G-BUFFER or customize material channel. Someone has done that but it involved a lot of work and need to change Engine source code. Anyway that you again.

Hi, i tried to do the same thing but i cant find your multiple xxxx (scalar) red node ? Same for the MF_Fade. Sorry im very new to UE4 but you’ve done the exact effect i want to put in my game. Thanks !

Hi Atomka,
Not sure if you find the way.

Step 1

203799-step1.png

Step 2

Is there any way of me applying this fade out technique when the player character enters a room? For example the player enters the room and a wall fades out, when leaving the room the wall fades back in.