Try playing around with DepthFade node. Plug it into opacity and adjust FadeDistance with a scalar parameter. Not sure if that’s exactly what you need, but may work
Yes thats a similar effect to what i want, however is it possible to make it go the other way, instead of fading back onto itself, can you make it fade over the top of the other geometry?
If you want to affect all geometry, I guess you’d make their materials in the same way, so they also react to being close to other objects. If you make all the materials instances of the original, you can switch on and off the function with a simple blueprint that controls a material property dynamically, so that every object with any of those materials are affected simultaneously.
Can the material for this ‘cube’ be translucent? If so the effect is pretty easy. You want a custom version of depth fade that is biased in front of the surface rather than behind. It’s actually super easy to compute.
clamp((PixelDepth - DestDepth) / depthscale)
Where depth scale is the number of world units for your gradient. Then you need to goto the material properties and set “disable depth test” and use the above node as the opacity. Then you need to perform your darkening using a gradient similar to above and use a SceneTexture sample to fake the darkening. that will also probably require a reversed gradient to fade out the darkening effect before it gets to the cube’s depth.
I might have to do a little research into how to build materials, im not very familiar with the Material editor beyond making simple single color Materials.
If its easy to put together could you screenshot the solution, if not ill work it out.