Way to create a gradient colored scene depending of distance from camera?

Hello,
I’m searching to color my scene in a global black and white gradient texture, so the elements nearer from the camera are white and becoming darker to black as they are farer from camera / in the background.

For anyone curious, this is to simulate Deep of field in After effect with creating a mask influing the strenght of the blur effect depending of color (the more the color of scene is black, the stronger the blur will be)

This is for a long +1 minute one shot sequence with camera angles moving a lot, so the gradient should adapt fluently depending of distance of things.
Is there any way to accompish something like this? Thanks a lot !

You can enable Depth and/or mist pass in render layers to get what you need.

z pass is depth.

Hi, thanks but i for the moment absolutely don’t see the process to achieve what i want with this info.

Also, i forgot to precise that i need this to work in the viewport render (for performance reason, the normal render is too long to do) So it’s why i think a global gradient texture for the whole scene that permanently adapt to camera’s position would be the best, if its possible?

And lastly i need it to work in Eevee, not Cycles. Ty to anyone that have an idea!

A material setup ike this can work, in both Eevee and Cycles.

My previous setup was really for the compositer.

1 Like

??? Listen to @AlphaChannel ! This is Z-usanne :wink: in Eevee (and a little compositing, because z-buffer is not saveable ??):
Z-usane

1 Like

Here is what you do in the compositer to access the Z and mist passes, or any other you have told Blender to render.

right hand screen is the depth pass which you can view and save in blenders own image viewer , where it says combined, that dropdown has the passes in it.

1 Like

@ Okidoki you can save it from here too or use fileout node of compositer

How ? Without compositor i got Combined Color for normal image, Combined Depth pure white, and Z-Buffer for perfect image as above, but Image save gives me only normal color…but in compositor i have to use from Depth: invert, normalize and connected to Composite node to get the shown saveable image.

no my bad, you are right, Ive just been wondering why all pixels are white.

Too bad, i already was wondering… an image to see but not to save :angry:

1 Like

yeah, anyways, OP has a couple of methods now…?

rendering to multilayer exr should contain the passes.

For anyone that would need to achieve the same kind of thing, i found that tuto that offer a really simple way to do it without using compositing : https://www.youtube.com/watch?v=PzQMgbSEynU