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 / [Plugin Request] Z buffer access!

Author
Message
Inflictive
17
Years of Service
User Offline
Joined: 16th Jun 2009
Location: Altis
Posted: 8th Sep 2013 06:39
One of the major limitations of DBpro as a modern engine is it's lack of z-buffer access. Right now, the z-buffer automatically gets cleared at the end of the SYNC command. What we need is a plugin allowing the z-buffer to be stored in a persistent image so we can use in shaders.

This has been discussed in other threads such as:
http://forum.thegamecreators.com/?m=forum_view&t=201694&b=1

This could be as simple as removing the part of the sync command where it clears the z-buffer (which is possible as dbpro is open source.) I would do it myself except I have almost no idea how to recompile the dlls and things.

It is possible to make your own z-buffer by using an r32 bitmap (for effects like shadow mapping), or using a 64- or 128- bit image format for the main camera and then packing the color and depth data into different channels (for effects like SSAO). This works, but it is stupidly ineffecient especially when there is a much simpler and faster way to do it.
Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 8th Sep 2013 09:50
Backdrop off will disable auto clearing of the screen if that helps.

Inflictive
17
Years of Service
User Offline
Joined: 16th Jun 2009
Location: Altis
Posted: 8th Sep 2013 12:55
It still clears the z-buffer though, and even if it wasn't being cleared we would need a plugin to get access to it.
mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 8th Sep 2013 13:34
Someone have said that memblock 0 is main camera buffer.

Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 8th Sep 2013 14:47 Edited at: 9th Sep 2013 00:45
Are you sure that isn't bitmap 0?
And still so it is only the visible pixels, not things like the stencil buffer.

IDirect3DDevice9::GetDepthStencilSurface can supposedly be used. However, you would need to convert that surface to a IDirect3DTexture9 as is used internally by DBP "images". That can probably be done with relative ease. The question is whether the surface is invalidated whenever the scene is re-rendered. If so you could copy the surface I guess, so shouldn't be the end of the world.


"Why do programmers get Halloween and Christmas mixed up?"
mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 8th Sep 2013 15:24
Quote: "IDirect3DDevice9::GetDepthStencilSurface can supposedly be used"

Can you access to depth stencil shadow vertices?

Also is this help?


Inflictive
17
Years of Service
User Offline
Joined: 16th Jun 2009
Location: Altis
Posted: 9th Sep 2013 00:05 Edited at: 9th Sep 2013 00:07
Rudolpho gets it.

So if the z-buffer is normally stored in a "surface", you would have to convert it to a "texture" every frame anyway, so you might as well just stick a copy and paste operation right before the z-buffer is cleared in the sync command. For my purposes I could just make it use image ids from, say, 65502 to 65535, and then just remember those are reserved.

At this point all I need is some kind of tutorial about recompiling the dbpro dlls. Is there some way I can download all the source code at once with a .sln file?

@Mr. Handy No, that is the backbuffer, which controls the colors on the screen. I need the z-buffer, which controls the depth of geometry.
mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 9th Sep 2013 00:17
Source is somewhere on google code AFAIR

Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 9th Sep 2013 00:45
You can download the core as a subversion repository. It includes Visual Studio 2008 (I think) project files which can be converted to be opened with Visual Studio 2010 without much problems. In order to compile them all you need to do is link with the DirectX 9 August 2007 SDK and make sure that you manually include the Windows SDK before that to avoid annoying linker errors since the DX SDK attempts to include an older version of the Windows SDK, thereby blocking the inclusion of the newer one.


"Why do programmers get Halloween and Christmas mixed up?"
Inflictive
17
Years of Service
User Offline
Joined: 16th Jun 2009
Location: Altis
Posted: 9th Sep 2013 01:08 Edited at: 9th Sep 2013 01:27
A while ago I tried to download it as a "subversion repository" using silksvn but I the program seemed ridiculously complicated and I couldn't get anything done, then I noticed you can just browse it at

https://code.google.com/p/darkbasicpro/source/browse/

I'll take another shot at the "subversion" thing I guess

edit: Great success! I managed to download ALL the files at once with svn(had to use command prompt though... wierd...) Now for the hard part...
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 9th Sep 2013 02:11
Quote: "Now for the hard part..."


I thought that WAS the hard part.

Good luck!



Powered by Free Banners
Inflictive
17
Years of Service
User Offline
Joined: 16th Jun 2009
Location: Altis
Posted: 9th Sep 2013 06:06 Edited at: 9th Sep 2013 06:36
Hmm, when you use the SET CAMERA TO IMAGE, does it use a surface or a texture? I'm thinking maybe dbpro images can be either.

edit - DOOD HOLY CRAP I GOT IT TO WORK i had to download some weird include files for windows server 2003 from some german forum but I COMPILED A DLL and replaced the original dll with it and IT WORKS! Now for the easy part!
Burning Feet Man
18
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 9th Sep 2013 09:30
I dare you to call your cut of DBPro the "Elite" version.

Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia
Inflictive
17
Years of Service
User Offline
Joined: 16th Jun 2009
Location: Altis
Posted: 9th Sep 2013 10:11 Edited at: 9th Sep 2013 10:23
Well, I haven't actually got the z-buffer access thing working yet, I just meant that I got a dll to compile and work, and I managed to modify a few commands through the source and have them work. As for the z-buffer I need to do more research into directx and stuff to see if it's even possible.

One thing i've found is it seems like the z-buffer surface of whatever camera is synced last does not seem to be cleared from memory after sync, currently trying to figure out if all cameras share a z-buffer, and if you can (and how to) convert it to a surface, probably in the same way that SET CAMERA TO IMAGE works.

edit: Wait wtf? I was just look at the official DXDSK Shadow mapping sample, and they use an R32f bitmap for it, not the depth map... Seems really ineffecient, but maybe that's a limitation of Directx9?
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 9th Sep 2013 12:18
Quite possibly.

I remember reading some articles about shadow mapping where the authors were complaining that they didn't have access to the Z-buffer. Unfortunately, it wasn't clear to me what language they were using - and like you I've wondered why the DX9 SDK examples don't use it unless it wasn't actually possible. That puzzles me a bit because I'm sure I've seen other articles which say that you should use the Z buffer which isn't very helpful if you can't actually use it.

I'll be very interested to see what you come up with.



Powered by Free Banners
mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 9th Sep 2013 13:25
May I repeat my question?

Can you access to depth stencil shadow vertices?

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 9th Sep 2013 14:25
Quote: "May I repeat my question?"


Yes - and you have.

Quote: "Can you access to depth stencil shadow vertices?"


What do you mean?

Do you mean this?

Shadow volume construction



Powered by Free Banners
mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 9th Sep 2013 14:59 Edited at: 9th Sep 2013 15:03
Oh yes. If I be able to get vertices of stencil shadow (which is mesh) I can calculate my own copy of stencil mesh, i.e. not updateable but way better than shadow map (cuz it is vector).

P.S. should I create my own thread about stencil shadow?

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 9th Sep 2013 19:41 Edited at: 9th Sep 2013 19:49
Quote: "If I be able to get vertices of stencil shadow (which is mesh) I can calculate my own copy of stencil mesh, i.e. not updateable but way better than shadow map (cuz it is vector)."


Yes. I don't know a simple way of doing that. I believe the DX9 SDK has an example so you could look at that code. I suspect it uses a DX built-in function though.

Quote: "P.S. should I create my own thread about stencil shadow?"


Probably. If you get it working efficiently I'm sure lots of people will find it very useful.

Edit Here's the shadow volume C++ code from the SDK. Have fun.



Powered by Free Banners
mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 9th Sep 2013 20:23
I hope that will be possible without hacking of DBP

Inflictive
17
Years of Service
User Offline
Joined: 16th Jun 2009
Location: Altis
Posted: 10th Sep 2013 07:45
I don't think dbpro (or maybe even directx, for that matter) supports having a d32 image stored as a texture. Trying to create a d32 bitmap in dbp results in failure. The only other idea I had is to memcopy the d32 z-buffer to an r32 image somewhere in the rendering code, and then find a way to disable the main render surface and just use the z-buffer, but at that point the speed increase is minimal (and I think dbp actually uses d24s8 so it would be hella tricky).

Now that I have source code access, I'm gonna see if I can at least figure out why the rendering is so cpu-bound (I had a thread about low gpu usage here a while ago).
mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 10th Sep 2013 09:52
In my experience, r32f z-buffer texture has minimal impact on overall fps, the real killers are bones and drawcalls.

Login to post a reply

Server time is: 2026-07-08 03:46:49
Your offset time is: 2026-07-08 03:46:49