Is there any chance to get the Z depth in a postprocess shader?

I know that I can get that position on a regular material shader but obviously, postprocess shaders operate on a 2D space so I cannot get the Z (or world position).

Probably there is any chance to get it since it should be used in DOF and so but I didn’t find any way/sample I mean getting the Z Depth about postprocess there are lots of them here Babylon.js Playground

You will need to enable the depth renderer and pass the depth texture to your shader:


Thank you it worked unfortunately my intention was to calculate the velocities and I’m not sure why but I cannot reconstruct the actual word space coordinates from depth (I’ve found other topics with this question but none with a proper solution) . here is my try where I tried to print the actual coordinates in the centre of the screen and the previous coordinates in the border but without luck.

Thank you for any tip!

velocity is computed in Babylon for the motion blue post process, you could check with @julien-moreau how he is doing it :slight_smile:

I’m not quite sure what you want to compute in the shader…

Here’s what I could come up: it computes the velocities based on the current and previous position in the view space (so it’s a velocity based on the camera movements):

Note that you must do matrix*p to transform p by matrix, not p*matrix and the depth renderer must be setup in the “non linear” mode because the depth you use in NDC coordinates must be the non linear depth.


Hi @Escobar !
Did you have all required answers by @Evgeni_Popov to help you? :slight_smile:

1 Like

Sorry I’ve been out but I already marked @Evgeni_Popov reply as the correct solution (and love it!)