Hey Guys,
I want to get the depth Information about different vertices in a 3d-scene. My idea is to filter out just the rendered Verticies by comparing the distance of one vertex with its screenposition-depthValue of the rendered scene. Therefor I write the scene in an fbo and take the vertex´ depth-information as a Value. But: the depthTexture just gives a pixel-Image with color informations which is not very concrete. Is there a way to get the real depth(distance to camera).
My first guess was the screenToWorld function. But this just gives me coordinates of the Screen-Plane.
I hope you understand the problem. Otherwise I can post some code.
The problem was discussed earlier here: https://forum.openframeworks.cc/t/vertex-rendering-information/15253/3
But I don’t want to use Shaders. I need the infos in the cpu and performance is not the problem because I don’t need this function every draw.
the information you get is in normalized device coordinates you need to turn it into world coordinates. To do that, first you need to turn the depth you get from 0…1 to -1…1 since that’s what open gl uses by default. then turn that into z in the real world. the easiest although not the fastest way to do it is to multiply a point with that depth by the inverse of the viewProjection matrix:
I tried your projection calculation on the mousePosition, but it gives me everywhere the same value and when I rotate the cam out of default it seems like it gives me the z=0 plane coordinates of world-projection without regarding the object.
In the other method I find it really strange that it just give me white everywhere, although I clearly can see the shape when I draw the texture:
Haven’t tested so there might be some wrong step but i think the following should give you world coordinates z. Be aware that readPixels is slow and using it to get the depth might make an application too slow to be usable