Topic was automatically imported from the old Question2Answer platform.
Asked By
palhimanshu
Hi all,
I’m trying to get the depth & normal texture of a 3d scene from camera in Godot.
I’m trying to port some of my code from Unity to Godot.
In Unity3d, i just applied a very basic shader to camera via script and retrieved its render texture. (I followed this tutorial http://williamchyr.com/2013/11/unity-shaders-depth-and-normal-textures/)
How to do this correctly & efficiently in Godot?
I’ve looked at the documentation and the mentioned water shader tutorial, but they talk about applying shader to objects and not to a camera.
I had to create a MeshInstance with a Quad primitive (width and height set to 2), parent it to my camera, and set Geometry->Extra Cull Margin to its maximum. Then I applied the following shader to the quad:
That division by 100.0 at the end is because I needed to scale linear_depth to the camera’s view range. If your camera’s Far is set to some other value, you’ll need to divide by that instead.