x


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

more ▼

asked Apr 22 '11 at 08:43 AM

Quentin 3 gravatar image

Quentin 3
13 2 3 9

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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!

more ▼

answered Apr 22 '11 at 09:35 AM

taoa gravatar image

taoa
1.6k 8 13 35

I'll read it right now. Thank you for your answer ! Et merci pour le compliment =)

Apr 22 '11 at 02:00 PM Quentin 3

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 ?

Apr 28 '11 at 10:04 AM Quentin 3

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.

Apr 28 '11 at 12:26 PM taoa

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 ?

May 09 '11 at 09:04 PM Quentin 3
(comments are locked)
10|3000 characters needed characters left

You need rendertextures for that; see here. Your English is in fact quite good.

more ▼

answered Apr 22 '11 at 09:28 AM

Eric5h5 gravatar image

Eric5h5
81.5k 42 133 529

Thank you Eric, I'll read it right now ! =)

Apr 22 '11 at 01:59 PM Quentin 3
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3126
x79
x23

asked: Apr 22 '11 at 08:43 AM

Seen: 4363 times

Last Updated: Apr 22 '11 at 08:43 AM