Depth Buffer to texture

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Depth Buffer to texture

Post 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?
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Post by Lonesome Ducky »

I don't believe irrlicht can do this, no. But it can be easily achieved with shaders in irrlicht.
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

I'm using shaders anyways. How would you do this with shaders?
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Post 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.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

Yes, but how would I go about writing the depth? Sorry, I'm fairly new to shaders.
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

XEffects provides this feature.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post 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?
booltox
Posts: 7
Joined: Thu Nov 05, 2009 5:35 am

depth texture writing

Post 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
vivekSivamRP
Posts: 66
Joined: Sat Sep 29, 2012 11:58 am

Re: Depth Buffer to texture

Post 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.
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Depth Buffer to texture

Post 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.
devsh
Competition winner
Posts: 2057
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Re: Depth Buffer to texture

Post 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!!!
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Depth Buffer to texture

Post 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.
vivekSivamRP
Posts: 66
Joined: Sat Sep 29, 2012 11:58 am

Re: Depth Buffer to texture

Post 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.
devsh
Competition winner
Posts: 2057
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Re: Depth Buffer to texture

Post 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
Post Reply