Fade distant geometry into the background (EEVEE) 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.
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 :

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 :

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