- Home /
Can you write a texture to the depth buffer before scene is rendered?
Is it possible to write to the depth buffer of the main camera using a texture from a source other than Unity, e.g., a Kinect depth map?
What I would like to do is, right after the depth buffer is cleared, write values into it, and then have Unity render the scene normally, taking into account the distances I've rendered into the depth buffer.
The depth map I'd be writing will probably come from a Unity extension.
Answer by soothing · Apr 02, 2015 at 09:43 PM
+1! DirectX 11 here. As a lame workaround, you could do your own depth clipping with custom shaders. But it would be much better to just write to the depth buffer.
Edit: Aha! I just found the following thread, which shows that you can use the :DEPTH semantic to write to the depth texture with a shader:
http://answers.unity3d.com/questions/778240/shader-writing-to-depth-issues.html
Thx. $$anonymous$$y current approach is to use a camera writing color to a texture, an identically placed camera writing depth to a texture and yet another camera that can see only a single quad, where I display a material that uses a shader to render pixels based on those two textures and the external depth map. I'm going to definitely study that answer, as it's probably faster than what I'm doing now.