- Home /
Retrieving depth buffer of a frame
Hello everyone,
Im new to Unity3D, but I can already say that this is an amazing tool. Im currently working on a personal project on unity, and I have a question.
Is it possible to create a camera that would retrieve the depth buffer of the current frame when I send a request to it?
As I said before, I'm totally new to unity and even if I have already done a bunch of tutos I can't really see were to begin with this pb.
Im French and my English is far from perfect, if my question is not clear, feel free to say it ^^.
Thanks !
Quentin
Answer by taoa · Apr 22, 2011 at 09:35 AM
Yes it's totally possible.
One thing to know is that the depth texture must be 'drawn' by Unity before you can use it as a texture in your shaders/post processes/whatever.
However, as you might know, Unity has two modes of rendering : forward and deferred. If you choose deferred rendering, Unity already needs this depth texture for it's own internal use so it's already available.
In forward rendering though, you'll have to tell Unity to drawn this texture or it won't be available. You can use this to tell your main camera to draw it. You'll notice that here you can ask Unity to render the Normals texture as well. The same goes with the Normals texture concerning deferred rendering.
Once your texture is drawn, you can use it as a global shader property: _CameraDepthTexture
Et te biles pas pour ton anglais, il est des annes-lumires de bien des gens ici! ^^
EDIT: Eric's link to the Documentation is full of good stuff, covering what I just said ^_^ Go read it now!
I'll read it right now. Thank you for your answer ! Et merci pour le compliment =)
I still don't have the pro version so I can't use depth texture for the moment...
I'll have it soon and I just wanted to be sure : - Firstly I must create a shader which will render depth - Secondly I have to create a camera and use the depth texture mode - The returned texture will be screen wide and will contain the information I need ie. the "depth buffer"
Am I right ?
Do I have to create the shader or can I find it somewhere ?
The depth texture will be rendered with all objects that write in the depth buffer (ZWrite On - default). You don't need to make a special shader for this, just use Unity's own shaders. If your project is set to use deferred rendering you don't need to tell your game camera to render the depth texture, but you DO if you're using forward rendering.
Hello taoa, I'm sorry to ask for your help ... again, but I'm a little bit lost. I believe you are french (or speak french), is it possible to ask you some questions in french by mail ?
Your answer
Follow this Question
Related Questions
Shader works on Android but it is black on iOS 1 Answer
Problem with render order using 3 cameras! 2 Answers
Rendering different cameras with the same depth? 1 Answer
Face tracking using Intel RealSense Depth Camera D435 in Unity 0 Answers
"Motion vectors" and "depth with normals" from camera's target texture 1 Answer