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 / For my thorough understanding...

Author
Message
CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 30th Sep 2011 03:10
Hi all,

In my effort to understand my code at a root level, I'd like it if someone could explain to me what the difference is (in terms of what the computer is doing) between CLONE OBJECT and INSTANCE OBJECT, and the ramifications for using each when it comes to memory allocation, etc. I'm always looking to make my programs faster and more efficient!

Malevolence: The Sword of Ahkranox
www.msoa-game.com
www.facebook.com/malevolencegame
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 30th Sep 2011 03:20 Edited at: 30th Sep 2011 03:23
As far as I know (in the memory reference) instancing refers to the original objects vertex data, index data, diffuse, ... One object used hundreds of times as an instance basically copies everything (not memory). I believe you can scale as well, not sure though. But one change does all....

EDIT: Just the same speed really on rendering, with little difference. Just less memory used.

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
revenant chaos
DBPro Master
19
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 30th Sep 2011 05:10
Hi CumQuaT.
Like WLGfx says, my understanding is that instancing tells the renderer to draw an object more than once (position and draw, re-position and draw again, re-position and draw again, and so on).
Instancing an object is much faster than cloning as well, so that means faster load times. Creating/deleting instances is usually fast enough to be performed in real-time, which is something that you usually shouldn't do with cloning.

Quote: "I believe you can scale as well, not sure though."

Yes, instanced objects can be scaled however you want.
Quote: "But one change does all...."
Actually instances can each be scaled independently without effecting the others. The main problem that I have run into is sometimes when the master (parent) object has it's visibility altered (excluded/hidden) some of the instances are effected as well (been a while, may have been fixed). If you run into that problem, an easy work around is to just keep the master object hidden away, and only use the instances in your world.

Quote: "Just the same speed really on rendering, with little difference."
Actually (at least from all of my own tests) instancing does produce a speed increase. Not really sure why, but mabey it is also able to re-use some of the object's matrices?

If you want to setup physics for an instanced object, you have to clone the object, set up it's rigid body, delete the object (while leaving the rigid body), and re-instance the object using the same object ID. That was once true for sparky's collision as well, but it now supports instanced objects without any extra work.

Animated objects (like characters) shouldn't be instanced, since they will all display the same frame as the parent object.
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 30th Sep 2011 07:37 Edited at: 30th Sep 2011 07:38
Quote: "Not really sure why, but mabey it is also able to re-use some of the object's matrices?"

Probably not, because the matrices store rotation/position/scaling, so if you have independent stuff like that, you have independent matrices.

I think it's just that there's a lot less communication between the GPU and CPU. With a non-instanced object, you need to tell the GPU not only what matrix and mesh to use, but also what shaders, what textures, and... likely other stuff that I'm forgetting.

The CPU and GPU are basically two separate machines running at different speeds, so sending data from the CPU to the GPU incurs some overhead. Instead of sending all this info about what shaders textures and models to use for every single object, you just give that information once, and then send a bunch of matrices (rotations/translations/scalings) over one by one.

So... I'd guess that it's because there's a lot less data to transfer to the GPU, and it's the GPU transfer overhead that hurts the framerate.

CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 30th Sep 2011 08:45
Interesting... I have quite a complex level load routine in Malevolence that clones a heap of objects from a base set, and whether I clone or instance the objects it seems to take the same amount of time to load... I might check some memory stats though to see if it changes things that way.

Very handy to know about the object frame thing though...

Thanks guys, I think I have a firmer understanding in my head now!

Malevolence: The Sword of Ahkranox
www.msoa-game.com
www.facebook.com/malevolencegame

Login to post a reply

Server time is: 2026-07-10 09:57:29
Your offset time is: 2026-07-10 09:57:29