Gradient mist with z pass in compositor when camera moves?

I have a room. My camera rotates from ceiling towards front wall and then moves into the depths towards this
front wall. I want more mist to be at the ceiling, almost no mist on the middle, and just a bit near the floor.
Elipse mask - not a solution because when camera moves mask stays where it is.
So is it possible in compositor to achieve lets say it gradientable depth mist? What will be the nodes setup?
Maybe there is a way to make z pass with gradient and not only to the depth but from up to bottom?

The way to do this is to use a position pass to scale the mist/depth data to give the gradient you want. Annoyingly, Cycles doesn’t have a position pass (I have no idea why) so you need to use a separate render layer with an overridden material that’s a geometry node (position output) and an emission to build it. Once you have that, you can apply ramps to that and the mist and arrive the gradient you want.

I’ve attached an example .blend that shows how to do it. (750 KB)


Great. I will check this as soon as i will be near the computer. Even that i have already found solution - probably simpliest - i duplicated my room, deleted all materials from it and made a volume material for this room. Texture coordinate-mapping-gradient texture-emission-volume output. But curious to check your file.