I created a sphere in the scene (left) and created a sphere in a postprocess (right). I then got the depth of both of them yet they don’t look the same, they are slightly off, why?
https://playground.babylonjs.com/#BH3MRV#1
How do I make them similar?
I’m doing something wrong but I don’t know what
I saw this recently but haven’t used much code from it yet. I’m going to try using getRayFromScreenSpace
using getRayFromScreenSpace
produced the same results, but when I increased the radius to 600 the post process sphere started jittering.
https://playground.babylonjs.com/#BH3MRV#2
The intersect.x
value is not a z, it is a parameter that will let you compute the 3D coordinates of the intersecting point with the ray origin + ray direction.
When you have the intersection point, it is in world space so you need to convert it to view space to get the z value you are after:
https://playground.babylonjs.com/#BH3MRV#6
The right 1/2 sphere starts jittering because you set a too low value for minZ. Just try 0.1 as in the PG above.
2 Likes
Oh, thanks a ton, I really appreciate it. You just made my day 
1 Like
Wait then how would I convert it back to world space from view space do I just multiply by inverse of view matrix?
Yes, just use the inverse view matrix.
1 Like