Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / ZBuffer pixel depth

Author
Message
Fallout
23
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 4th Jul 2010 13:06
Does anyone know if it's possible to get the depth (zbuffer) of a pixel. I'm not bothered if it's before the frame is rendered (I doubt this is possible, as it's probably calculated during the sync command) or for the previous sync.

Essentially, I want a fast way to calculate the 3D position in space of specific pixels, and I think the easiest way to do this is to get the zdepth and calculate it from there.

Any ideas?

Insert piccy sig here. Eh? Why didn't that work?!?! Must ring help-a-noob. What was the number again? .... where am I?
Serial Velocity
17
Years of Service
User Offline
Joined: 24th Aug 2008
Location:
Posted: 4th Jul 2010 14:21 Edited at: 4th Jul 2010 14:23
You can't extract the depth pixel from the depth buffer, which is a stupid limitation of the D3D9 driver. The only way you could get a depth value would be to recreate the depth buffer in a fullscreen shader.

This article may help:
http://mynameismjp.wordpress.com/2009/03/10/reconstructing-position-from-depth/

GDKUtilities, a utility library for DarkGDK, avaliable here
Fallout
23
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 4th Jul 2010 16:13
Thanks for that. That is a shame. I didn't really want to go down the shader route so I guess this is a dead end.

Insert piccy sig here. Eh? Why didn't that work?!?! Must ring help-a-noob. What was the number again? .... where am I?
paul5147
20
Years of Service
User Offline
Joined: 11th Jan 2006
Location: Hot & Sunny
Posted: 4th Jul 2010 19:21
Could you just not use the pick screen command,i know its a bit slow if you want to do every pixel on the screen , but for a few depth checks it works ok and gives the real world x,y,z position of that pixel,it might not be apropriate for what your doing but it it can come in usefull.
Fallout
23
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 4th Jul 2010 19:41
Thanks for the suggestion. I need to get 40,000 pixels (200x200 grid), from a complex 3D world. So I would have to ray cast. 40,000 ray casts per loop just isn't gonna work, unless someone can suggest a technique I haven't thought of.

Insert piccy sig here. Eh? Why didn't that work?!?! Must ring help-a-noob. What was the number again? .... where am I?
Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 4th Jul 2010 21:53 Edited at: 4th Jul 2010 21:54
You can lock the Z-buffer for access, it is not a 'stupid directx limitation' you just need to create the depth buffer with a flag which specifies it to be lockable.

This would most likely need a plugin both to create the buffer and to lock and unlock it.

An alternative is to render the scene to a texture and encoding the depth as a colour using a shader.

[b]
paul5147
20
Years of Service
User Offline
Joined: 11th Jan 2006
Location: Hot & Sunny
Posted: 4th Jul 2010 23:50
Just another idea along the shader route,i seem to remeber that evolved`s shadow map shader did something like this for its depth map image and stored all its data as the red chanel of an image,when i get home i`ll have a look and see if i can remember how it was done.
Math89
22
Years of Service
User Offline
Joined: 23rd Jan 2004
Location: UK
Posted: 5th Jul 2010 01:14
It is really easy to do. All you need is a shader outputting the z position of the pixel in camera space. If I remember correctly, this render can be saved in a bitmap having a negative number (-n for the n-th camera), and this bitmap can then be read using either memblocks or the point command.
The only limitation is that bitmaps in DBPro can only be in rgba8 format (or similar), which means that each channel can only hold 256 values. You may need to split the distance amongst the 4 colour channels in the shader, and reconstruct them in DBPro.
Fallout
23
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 5th Jul 2010 12:44
It is about time I got off my arse and learned about shaders. I know DBP pretty much inside out, but shaders are still a mistery. So I think I'll look into this on wednesday then. One thing I can't see working though is how DBP accesses the bitmap after it has been rendered by the shader. Where does the shader render it to? I'm guessing I would have to write a DLL that can access the area in memory the shader writes to, and convert it into an img or bmp that DBP could access. So that's another layer of complexity. I've not made DLLs either!

Insert piccy sig here. Eh? Why didn't that work?!?! Must ring help-a-noob. What was the number again? .... where am I?
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 7th Jul 2010 17:18
Quote: "One thing I can't see working though is how DBP accesses the bitmap after it has been rendered by the shader. Where does the shader render it to?"


You can send the camera output to an image and process that either within DBPro (slow) or with another shader (fast) - which is how shadow mapping and other shader effects work.

Login to post a reply

Server time is: 2026-07-25 08:29:53
Your offset time is: 2026-07-25 08:29:53