Page 1 of 1

Depth Buffer to texture

Posted: Tue Apr 13, 2010 3:19 pm
by slavik262
I swear this topic came up before, but I searched and can't seem to find it anywhere.

Is there any way to get access to the depth buffer and store it as a texture?

Posted: Tue Apr 13, 2010 9:37 pm
by Lonesome Ducky
I don't believe irrlicht can do this, no. But it can be easily achieved with shaders in irrlicht.

Posted: Tue Apr 13, 2010 9:45 pm
by slavik262
I'm using shaders anyways. How would you do this with shaders?

Posted: Tue Apr 13, 2010 11:05 pm
by Nadro
You need set render targed (floating point texture eg. ECF_R32F) and write linearized depth. After it, You will have ready depth texture.

Posted: Tue Apr 13, 2010 11:19 pm
by slavik262
Yes, but how would I go about writing the depth? Sorry, I'm fairly new to shaders.

Posted: Wed Apr 14, 2010 12:53 am
by BlindSide
XEffects provides this feature.

Posted: Wed Apr 14, 2010 6:44 pm
by slavik262
Thanks, but right now I'm not interested in using an entire other project simply to get one feature that I need. I'm not trying to disrespect XEffects... it looks great, but I'm compiling on MSVC and I don't want to have to rebuild Irrlicht or become acquainted with a new API for just a singular feature. Could you point me in the direction of help or provide an example of how to do this?

depth texture writing

Posted: Sun May 02, 2010 7:45 pm
by booltox
I def think this is possible with irrlicht. Its not a feature of the engine per-say but you can do it with custom shaders. Im using GLSL and I can share my work-in-progress with you. I don't have it done yet but I'm just sitting down to finish this today. The theory is simple enough, on the first pass you write the depth value to a color channel of a texture buffer and on the second pass you it to restore the depth value.

A quick search picks up this discussion of the topic (with shaders):

http://www.gamedev.net/community/forums ... _id=562668



-P

Re: Depth Buffer to texture

Posted: Wed Oct 03, 2012 1:31 pm
by vivekSivamRP
can any one explain how to Write Depth Values from Shaders to Frame Buffer in irrlicht ?

and Frame Buffer to Texture ? i'm in need for Depth Texture to do Shadow Mapping.

i'v gone through xeffects , as a beginner i could't grasp it.

Re: Depth Buffer to texture

Posted: Thu Oct 04, 2012 11:47 am
by mongoose7
You should go back to XEffects. I know you think shadow mapping is a walk in the park and you are just missing the signpost, but no, it is a serious undertaking.

Set a render target
Render depth values using a light as the camera
Set a render target
Render the scene using the Phong model, but only for pixels that are closest to the light (no intervening object parts)
Repeat for the next light

Blindside has done this for you. I think XEffects does not do the next part in the best way (it drains colour out of the scene instead of adding each light to the scene), but he has got you this far for free. The next part is to somehow combine the render targets you get from rendering per light.

Re: Depth Buffer to texture

Posted: Fri Oct 05, 2012 1:29 pm
by devsh
look up

"binding GL_DEPTH_COMPONENT texture to Frame Buffer" and you can bind the depth buffer as a texture to a GLSL shader
FOR FREE!!!

Re: Depth Buffer to texture

Posted: Sat Oct 06, 2012 4:49 am
by mongoose7
Ha-ha. I see you are itching for a fight.

I'll just say that, in this context, it really doesn't save much work. Besides, Blindside has written *working* code, which is always of enormous help in shader work. :-(

Have you thought of contributing to Irrlicht 2.0? I would have thought you'd have a lot to offer.

Re: Depth Buffer to texture

Posted: Mon Oct 08, 2012 1:01 pm
by vivekSivamRP
But devsh how can i use openGL codes like "GL DEPTH COMPONENT" etc in irrlicht ?
Presently i can see my Scene's Black And White image(depth values)through shader's 1st pass. But dono how to save Depth Values in the Buffer and get it as a texture for 2nd pass.

Re: Depth Buffer to texture

Posted: Thu Oct 18, 2012 7:17 pm
by devsh
need to edit COpenGLTexture.cpp

depthFBO attachment cannot be render buffer, needs to be a texture

you attach color buffers (MRTs) and an optional depth buffer to a FBO which is the thing that you set render targets with

native OpenGL reading is required here

you need to modify the driver so you can setTexture(i,depthFBOattachment) properly