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.
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.