- Home /
Get World Position of Screen Coordinate Using Depth Buffer
Using the depth buffer, how do I compute the world position of a screen coordinate (UV) in a fragment shader?
the answer comes from $$anonymous$$eijiro Takahashi / Unity Technologies Japan
https://github.com/keijiro/DepthToWorldPos/blob/master/Assets/DepthToWorldPos.shader
Answer by tanoshimi · Oct 23, 2016 at 07:44 PM
You don't need to do anything with the depth buffer to get world space position of a vertex - you can use the _Object2World macro:
output.position_in_world_space =
mul(_Object2World, input.vertex);
I want to get the world position of a screen coordinate using the depth buffer
Ok, then you can make use of the UNITY_OUTPUT_DEPTH macro: https://docs.unity3d.com/$$anonymous$$anual/SL-DepthTextures.html
Isn't that macro used to write to the depth buffer? I want to read from the depth buffer at a given screen position and calculate the world position.