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.

Code Snippets / Billboarding LOD example (DBP)

Author
Message
Yarbles
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Toronto
Posted: 9th Jun 2004 21:45 Edited at: 9th Jun 2004 21:54
This is an example of an idea I had for rendering high polygon objects that are far away as billboards (ie textures on planes facing the camera). This isn't exactly an original idea (I think some modern game engines use it, like for example Far Cry), but I haven't seen it done before with DBP so here it is!

The crux of the idea is that far away objects change the angle at which they face the camera very slowly because, well, they are so far away. So to capitalize on this fact, we can take a new "snapshot" of the object only after a certain angle difference threshold has been crossed and apply that texture to the billboard in it's place. This allows for complex objects to be rendered only once every so often instead of on each cycle. Now for the LOD part: When the camera gets close enough to the object, the real high detail object is shown instead of the billboard (in this example that is when last update=-999).

Now about DB Pro -
The good news: DBP has a command for rendering camera views to textures - SET CAMERA TO IMAGE. This command is exactly what we need. I just position the high detail object in a "dark room" at the correct angle and distance and snap a picture of it using that command.

The bad news: DBP has bug with the SET CAMERA TO IMAGE command that does not allow you to set that image as transparent in real-time. This bug essentially kills this method for mutilple objects in a gamespace, because without transparency it looks very bad. Mike has promised me that it will be fixed in update 5.4 though.

Here is the code:




You can download the example here (including exe):

http://yarbles.zapto.org/billboard.rar


Credit for the tree model goes to Joe Brown (aka IpakAgun)

Any questions, suggestions or improvements are welcome!

Mussi
21
Years of Service
User Offline
Joined: 27th Jan 2003
Location: Netherlands
Posted: 10th Jun 2004 20:17 Edited at: 10th Jun 2004 20:19
Quote: "This isn't exactly an original idea (I think some modern game engines use it, like for example Far Cry), but I haven't seen it done before with DBP so here it is!"


And I tought I'd invented a totaly new system

I'll give you a little tip on how to fix that transparency. set the backdrop to a color that doesn't show up in your model, like pink or something. make a memblock from the picture, check all pixels for that color, turn those colors into the transparent value(16581375) and make an image out of the memblock.

kinda slow but it's the best we can do atm.



Specs: AMD Athlon 1800, 256 DDRRam 266mhz, 80GB HD 7200rmp U133, Geforce 4 Ti4400 128mb
Yarbles
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Toronto
Posted: 19th Jun 2004 02:03
Thanx for the tip!

How far have you gotten with the technique? Have been able to apply it to a scene full of different objects like a forest?

Zeal
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 19th Jun 2004 08:59 Edited at: 19th Jun 2004 09:08
Holy crap this is a really good idea. Thanks a lot Yarbles good stuff!

*Edit - Can you really use this method to render 100s of trees though? Seems like all those images and all those 'set camera to image' commands would slow down when you get into the 100s of objects range. Or does this billboard system still blow away the old multi limb hide/show LOD method?

*Edit again - About transparency... If you set the backdrop color to black, and set the billboard transparency on, wouldnt the image be transparent?

All you need is zeal
D Man
21
Years of Service
User Offline
Joined: 3rd Oct 2002
Location: Germany
Posted: 19th Jun 2004 13:08
That's a really good idea!
I myself thought about how to reduce polygons in scenes, but I only came across LOD solutions instead of this simple, effective one.
Let's see how I can use this .
Thanks!

God is real, unless declared integer.
David T
Retired Moderator
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 19th Jun 2004 14:56 Edited at: 19th Jun 2004 20:24
This is what I get I'm afraid:

http://www.davidtattersall.me.uk/temp/dbpleak.jpg

Two strings walk into a bar. I'll have a pint says the first$%ASLDJ09920D"$"$D. Excuse my friend says the second, he isn't null terminated.
Zeal
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 19th Jun 2004 19:54 Edited at: 19th Jun 2004 20:17
David T file not found. Can you give us the jist of it?

BTW, doesnt this method eat up a lot of memory? I mean a image for every object means a lot of dynamic images. And thats bound to cost a lot of memory when you apply this method to high density scenes (forests, ect...).

*edit Oh yeah, I was wondering, does the set camera to image command auto crop the image? Like if you were looking at the tree from a mile away, would it know just to cut out the little 4x4 pixel area where the tree is? I suppose if it works like that memory might not be that big of an issue.

All you need is zeal
David T
Retired Moderator
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 19th Jun 2004 20:24 Edited at: 19th Jun 2004 20:25
Oops heh, forgot to type full filename! works now

Two strings walk into a bar. I'll have a pint says the first$%ASLDJ09920D"$"$D. Excuse my friend says the second, he isn't null terminated.
Zeal
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 19th Jun 2004 20:30
Dear god what the hell is that?

All you need is zeal
Yarbles
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Toronto
Posted: 19th Jun 2004 22:23 Edited at: 19th Jun 2004 22:30
Hey, nice to seem some interest in this thread. Thanks guys!

Just to let you all know my progress on this.. well what you see here is all I have. I was discouraged by the non-transparency bug with SET CAMERA TO IMAGE command, so I didn't pursue this idea any further for the time being. I think, I may just push on through regardless of the fact that I can't set transparency without going to the trouble that Mussi mentioned. It will still be an interesting test of the performance of a full billboarding engine in DBP.

Now to some of your questions...

Quote: "
Can you really use this method to render 100s of trees though? Seems like all those images and all those 'set camera to image' commands would slow down when you get into the 100s of objects range. Or does this billboard system still blow away the old multi limb hide/show LOD method?
"


To take care of the problem of too many SET CAMERA TO IMAGE calls per cycle, I think we can only use 5 (or however many determined to be optimal after testing) extra cameras in total, so there will be a max of 5 SET CAMERA TO IMAGE calls per cycle. Any objects that require a new snapshot and didn't get it in the current cycle, will be queued and taken care of in the next cycle. That is a more distributed approach that will spread the work over many cycles depending on the load.

Quote: "
About transparency... If you set the backdrop color to black, and set the billboard transparency on, wouldnt the image be transparent?
"


As I mentioned above, there is a bug in DBP with setting transparency for images generated from camera snapshots. Mussi has a work around for this, but it is really slow, and kinda defeats the purpose of this whole LOD idea (ie to speed things up ).

I listed this bug in the bugs forum, if you want more detail: http://www.thegamecreators.com/?m=forum_view&t=32331&b=15


Quote: "doesnt this method eat up a lot of memory? I mean a image for every object means a lot of dynamic images. And thats bound to cost a lot of memory when you apply this method to high density scenes "


Well, to save on image memory, I think we can implement our own mipmapping for the camera snapshots . So the farther away the object, the smaller the image resolution used to take the snapshot. For greatest efficiency, image resolution can be calculated exactly to match the amount of pixels displaying the object on the screen for a certain distance range, it will be based on screen resolution, distance, object size and camera FOV. Maybe one of you math geniuses can figure out a function for caclulating most effient image resolution based on those parameters?

btw.. I know that DBP has built in mipmapping with dx9, but that doesn't save any memory in our case (it actually increases the texture memory required), it will however ensure performance will be on par wether we implement our own mipmapping or not.


Quote: "This is what I get I'm afraid:"


That does look godawful! This is one of the things that really pisses me off about DBP and PC development in general. There is always some system configuration that pukes with your latest creation. This looks like it belongs in the DBP bugs forum, but can you list your system spec here please? And also check to make sure you have all the lastest video drivers etc. installed on your machine.

David T
Retired Moderator
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 19th Jun 2004 22:27
geforce ti4800
athlon 2800+
1 gig RAM
XP pro

I got that with DBPro on my old PCwhen using BSP. It does seem that there's always going to be something that glitches it

Two strings walk into a bar. I'll have a pint says the first$%ASLDJ09920D"$"$D. Excuse my friend says the second, he isn't null terminated.
Yarbles
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Toronto
Posted: 19th Jun 2004 22:33
hmmm... geforce ti4800

I think Ipak had one of those too.. we spent hours trying to get Axes of Evil to work right with it and DBC. That video card is evil!

David T
Retired Moderator
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 19th Jun 2004 22:36 Edited at: 19th Jun 2004 22:39
Quote: "That video card is evil! "


Yeah right :p it was the best going at the time

Two strings walk into a bar. I'll have a pint says the first$%ASLDJ09920D"$"$D. Excuse my friend says the second, he isn't null terminated.

Login to post a reply

Server time is: 2024-05-13 11:52:14
Your offset time is: 2024-05-13 11:52:14