4
$\begingroup$

I have a scene mainly with a big floor composed of adjacent rectangular cuboids (roads), and an equirectangular projection texture (environment texture, HDRI, skydome...) as the background.

original scene

I would like the floor and all other geometry to progressively fade off into the background with distance, preferably after a given distance point from the camera or non-linearly. This in order to make the horizon less edgy/crisp.

How to achieve this effect on EEVEE (preferably, but not necessarily without compositing)?

Thanks.


What I have tried so far:

VOLUME SCATTERING (FOG) 1

With volumetrics enabled, I plugged a volume scattering/absorption node into the World output node.

  • THE PROBLEM

The background is obscured by the fog. I think this wouldn't really fade geometry into the background anyways.

VOLUME SCATTERING (FOG) 2

With volumetrics enabled, I created a cube and fitted it over my scene geometry so it will be wrapped inside the cube. I made a material for it and removed its shader so nothing goes into the output surface socket. I did as above and plugged a volume scattering/absorption node into its output volume socket.

  • THE PROBLEM

Again, the background is obscured by the fog (so long as the cube is in the way of the active camera). Again, as above, this possibly wouldn't fade geometry into the background.

FADING MATERIALS INTO TRANSPARENCY

For the roads material (first, and then for every material subject to be faded into the background) with its settings Blend Mode set to either of Alpha Hashed or Alpha Blend, I used the Camera Data node View Z Depth socket to mix the original shader with a transparent BSDF by plugging it into a mix Shader Fac socket. I was able to adjust the starting distance point at which things start to fade with some math nodes.

  • THE PROBLEM

All of the alpha blend modes fail to cull geometry in the desired way. While some of them do not cull back faces, others do, but fail to cull occluded front faces, as if there were several shader passes involved instead of just one. So I always get to see some of the sides of my cuboids, when instead I would like to only see the top faces of them as it is the case with opaque blend mode. Other than that the fading effect appears to work fine.

COMPOSITING

I have attempted to composite the output by blending only the geometry with the background according to its depth.

  • THE PROBLEM

Apparently in order to have only the geometry rendered in a layer, one needs to set in Render settings->Film, Alpha to transparent instead of Sky, and there's no environment checkbox in the passes options of view layers. There's also no Environment socket in the render layers node in compositor. So even if I get all my geometry to render over a transparent background, I don't know of any means to blend it over the proper part of the original background, as the only means I know of, of getting the original background into compositing is through an Image node for which there are no input sockets or an apparent way (to me) of mapping it correctly, so I'm getting the wrong part of the background. If it matters, my background is in png format, not exr or hdr.

$\endgroup$

1 Answer 1

5
$\begingroup$

Rather than 'fade to transparency' you can, instead, 'fade to environment' with the fade acting between your mesh's actual shader and an Emission shader set to mimic the environment - this will avoid the problem of ‘backfaces’ or part-transparent faces showing through. This can be achieved with the following nodes :

fade to environment nodes

Everything within the 'frame' is dealing with mapping the environment onto the surface of the mesh while the Diffuse shader at the top is there to represent your mesh's actual shader.

The Environment texture (an Environment node set to your HDR image) is normally driven by the Generated coordinates but in this case we generate the coordinate based on the Incoming vector. This will shade the point on the mesh with the point in the environment that would have been shown if the mesh was transparent - so effectively making it appear transparent by projecting the environment onto the surface. This is achieved by Vector Subtracting the Incoming vector from 0 (to effectively reverse the ray’s direction). The output of the Environment node drives an Emission shader with its strength set to 1.0 to mimic the environment.

The other nodes calculate the 'fade' based on distance - but only for 'Camera' rays (since we don't want the 'fade' to affect how the mesh interacts with the rest of the lighting of the scene, only how it appears to the camera. The Divide controls how far away from the camera the scene should fade, while the Color Ramp affects the profile of the fade (change those to affect the 'hardness' and distance of the fade).

This can produce the following result :

Result

You would need to do the above for all of the materials in your scene that want to be affected by the fade (in the case of the above example, just the plain floor - so that it blends into the HDRI background of the scene (which provide the trees)).

$\endgroup$
4
  • $\begingroup$ I'm curious about the mixing factor. Would a fresnel node work well? $\endgroup$ May 1, 2019 at 16:31
  • $\begingroup$ @JohnDvorak Afraid not - the fresnel is based on angle of incidence compared to the normal but in this case we need to vary based on distance. $\endgroup$ May 1, 2019 at 16:40
  • $\begingroup$ Brilliancy! I have much to learn from your setup. Thanks for this, it does exactly what I want. Here's the effect: imgur.com/a/VFiXALz Do you happen to know how to disable it for the viewport? $\endgroup$
    – ecv
    May 2, 2019 at 22:30
  • 1
    $\begingroup$ Nice result - that does look much better than a hard cutoff. I don't think it's possible to specifically disable it for the viewport as that tries to show how it would appear as rendered. However, if you put everything that's in the 'frame' in the material into a node group (select it and press Ctrl+G) and then re-used that group in each of your materials then you'll only have one place to adjust the properties of the fade. This way you can adjust the distance to a large value to make them visible and back down to the proper distance when you want to render. $\endgroup$ May 3, 2019 at 5:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .