Jump to content

  • Log In with Google      Sign In   
  • Create Account

Register renderables every frame?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
15 replies to this topic

#1 PAndersson   Members   -  Reputation: 394

Like
0Likes
Like

Posted 18 July 2012 - 02:18 PM

I was wondering if it is a good idea to design the rendering system so that each game entity and interface element that should be rendered registers its visual representation every frame, or should they register and unregister as appropriate? Give that the objects typically change a lot, as their positions move and the like, I'd imagine that first option would result in simpler logic and better performance. Or am I completely wrong with how rendering systems usually are designed here?

Sponsor:

#2 BeerNutts   Crossbones+   -  Reputation: 2999

Like
0Likes
Like

Posted 18 July 2012 - 03:01 PM

I was wondering if it is a good idea to design the rendering system so that each game entity and interface element that should be rendered registers its visual representation every frame, or should they register and unregister as appropriate? Give that the objects typically change a lot, as their positions move and the like, I'd imagine that first option would result in simpler logic and better performance. Or am I completely wrong with how rendering systems usually are designed here?


Do you mean, for example, when an entity goes off the screen, it un-registers with the rendering system, and when it comes back on screen, it re-registers? It probably depends on how many renderable entities you have. If you have thousands, then you would probably save some cycles by not loping through every entity in the rendering system.

Otherwise, I think it might be worse to unregister and re-register considering you would have to check if the object is on-screen every loop anyway, you' just adding more steps to the process.
My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

#3 Waterlimon   Crossbones+   -  Reputation: 2635

Like
0Likes
Like

Posted 18 July 2012 - 03:14 PM

You dont want to reupload/register data that doesnt change. Only update data that changes (like position).

o3o


#4 PAndersson   Members   -  Reputation: 394

Like
0Likes
Like

Posted 18 July 2012 - 03:49 PM

You dont want to reupload/register data that doesnt change. Only update data that changes (like position).


I'm not talking about reuploading entire meshes/textures, but perhaps re registering references to them.

#5 ApochPiQ   Moderators   -  Reputation: 16392

Like
1Likes
Like

Posted 18 July 2012 - 04:03 PM

The principle holds, though: if the object isn't actually definitely going away (or appearing), don't bother with changing its registration status. Do as little work as possible :-)

#6 omercan   Members   -  Reputation: 370

Like
0Likes
Like

Posted 18 July 2012 - 04:59 PM

I suggest to register your meshes once and to unregister them when it is really necessary (i.e. mesh is destructed). Split your game entity into several parts. It doesn't needs to be one class and also allows multiple and shared meshes on one entity.
Register many things as possible and use dynamic allocation as less as possible. I think you don't want to have a memory bottleneck because you add or remove something from a list (when you use one) EVERY FRAME!
But use a unregistered scheme for something little or something who appears and disappears very fast like a debug system.
I use this approach and liked it. Try it! :D

Edited by omercan, 19 July 2012 - 02:11 AM.

Reading, Reading, Reading... why do you read not more?
I have a blog: omercan1993.wordpress.com look there for more content :)
And I also do some art: omercan1993.deviantart.com
And whats about the Pear3DEngine? Never heard of it? Go and look!
Yeah, and currently I do this: SimuWorld

PS: Please look at this poll on my blog about scripting languages: A opinion poll about scripting language

#7 phantom   Moderators   -  Reputation: 7558

Like
1Likes
Like

Posted 18 July 2012 - 05:31 PM

Normally "renderable" are registered when they come into existance and then each frame are visiblity tested to see if they should be submitted for rendering or not.

#8 L. Spiro   Crossbones+   -  Reputation: 14240

Like
3Likes
Like

Posted 18 July 2012 - 05:53 PM

Objects should not be registered and unregistered.
Firstly, how often would you do this registration?
If not often enough, objects will be drawn even though they have drifted off the screen, and other objects have drifted onto the screen will not be drawn for a while and then suddenly appear on-screen.

If you register and unregister as often as is truly necessary then you have not saved any time.

Instead, use a spatial partitioning scheme such as an octree for 3D and quadtree for 2D (these can be exceptionally fast if done properly—instant insertion time, no node searching, no cache misses, no recursion) and process it every frame.
Only moving objects will register and unregister with the quad- or oc- tree, and this is done every frame, but insertion should be instantaneous, and the same quad- or oc- tree can be used for multiple subsystems, from graphics to collision detection.


L. Spiro
It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#9 ZBethel   Members   -  Reputation: 603

Like
1Likes
Like

Posted 18 July 2012 - 07:28 PM

Is adding a bunch of objects to a list every frame really going to cause performance issues? You don't need to allocate space for the array every frame, you could have an array that grows (like a variant of std::vector, or just use that). Besides, you could have one renderable for a set of instanced meshes if you're going to have tons of similar objects onscreen.

Edited by ZBethel, 18 July 2012 - 07:59 PM.


#10 speciesUnknown   Members   -  Reputation: 527

Like
0Likes
Like

Posted 19 July 2012 - 03:30 PM

Is adding a bunch of objects to a list every frame really going to cause performance issues? You don't need to allocate space for the array every frame, you could have an array that grows (like a variant of std::vector, or just use that). Besides, you could have one renderable for a set of instanced meshes if you're going to have tons of similar objects onscreen.


In a word, no. Filling a preallocated list is incredibly cheap on modern hardware. It's an O(n) operation but you can cut down on that N by using some culling in the scene. What might be more of a concern is the order that things are added, because you might want to batch things up according to their material, or their mesh, etc. In the past, I've used std::multimap to sort things by their material, where materials consist of a pair of shaders, and a list of textures.

For a small game, the multimap solution (with a predicate based on the shader ID and then the texture ID's ) is plenty fast.
Don't thank me, thank the moon's gravitation pull! Post in My Journal and help me to not procrastinate!

#11 Hodgman   Moderators   -  Reputation: 31799

Like
4Likes
Like

Posted 19 July 2012 - 09:39 PM

What are you registering/deregistering items with? Is this equivalent to adding objects to a "will be rendered" list?

I rebuild my "objects to be rendered" list from scratch every frame, and throw it away at the end of the frame. There's no longstanding registration/link between renderable objects and the renderer.

Culling/collecting 2000 renderables, updating their state, sorting them on multiple conditions, and then executing the D3D commands required to draw them, takes about half a millisecond...

#12 Krohm   Crossbones+   -  Reputation: 3245

Like
0Likes
Like

Posted 20 July 2012 - 12:51 AM

Only moving objects will register and unregister with the quad- or oc- tree, and this is done every frame, but insertion should be instantaneous, and the same quad- or oc- tree can be used for multiple subsystems, from graphics to collision detection.

I guess that's implementation-dependent. The physics API I use does not allow that natively. Just pointing out.

#13 DemonRad   Members   -  Reputation: 290

Like
0Likes
Like

Posted 20 July 2012 - 01:19 AM

There is no physics API able to return a list of visible items? O_O

Peace and love, now I understand really what it means! Guardian Angels exist! Thanks!


#14 L. Spiro   Crossbones+   -  Reputation: 14240

Like
0Likes
Like

Posted 20 July 2012 - 04:42 AM

In the past, I've used std::multimap to sort things by their material, where materials consist of a pair of shaders, and a list of textures.

For a small game, the multimap solution (with a predicate based on the shader ID and then the texture ID's ) is plenty fast.

There's no longstanding registration/link between renderable objects and the renderer.


There is a better way this can be done which takes advantage of temporal coherence.
In my system, objects register just the information needed for sorting to a render queue (this part is standard in every rendering system). The objects will often register this data in the same order every frame since I am walking the octree (etc.) the same way every time.

This data is not sorted directly.
The render queue class responsible for sorting this data instead sorts indices into this data.
This improves sort bandwidth since I am only copying 32-bit values instead of structures, but it also allows temporal coherence.

The indices are not cleared every frame. If more objects appear, the indices for those objects are added to the end of the otherwise sorted indices.
If there are fewer objects, the indices are reset back to 0 1 2 3, etc.
And if the number of objects is the same the indices are left as-is.

Then an insertion sort is done over the indices.
In most cases the indices will already be in sorted order or at least very close, so this system outperforms quick sort and merge sort in virtually all situations.


This basically provides a way to submit objects to the render queue in any order, and as long as that order is mostly consistent then you can take advantage of temporal coherence.

I also keep multiple render queues. One for each shadow-casting light (shadow maps), one for opaque objects in the main render, one for alpha objects in the main render, etc.


There is no physics API able to return a list of visible items? O_O

Just because spatial partitioning schemes can be used to accelerate rendering does not mean that is all they can do.
In fact the actual system is completely unrelated and disconnected to/from rendering. When you “query” an octree for a list of objects within some kind of bounding area, the octree has no idea why you are asking for that list or what you intend to do with it. If you intend to use it as “a list of things in view” then fine. If you intend to use it as “a list of things that could potentially be in contact with a given object” then fine.


L. Spiro

Edited by L. Spiro, 21 July 2012 - 12:17 AM.

It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#15 NEXUSKill   Members   -  Reputation: 466

Like
0Likes
Like

Posted 20 July 2012 - 04:17 PM

The thing is, adding and removing stuff to a list is not that big a deal, buy you are asking the wrong question, the right question is:

Is performing visivility tests from each object more efficient than from a bigger container that has them?
So thats where it gets tricky, you have to do both, the big containers will perform more wide spectrum tests, like is camera on room A, then send room A to render and not the rest.
Then the stuff within the room must be tested against the camera frustrum, its really more efficient to give the frusturm a list and have it test all those objects than the other way around, plus its very hard for an object to test its own occlusion, in the end, you'll probably conclude that its GENERALLY the best way to go to test from bigger containers than from each object at a time.
Game making is godlike

LinkedIn profile: http://ar.linkedin.com/pub/andres-ricardo-chamarra/2a/28a/272



#16 PAndersson   Members   -  Reputation: 394

Like
0Likes
Like

Posted 20 July 2012 - 05:56 PM

What are you registering/deregistering items with? Is this equivalent to adding objects to a "will be rendered" list?

I rebuild my "objects to be rendered" list from scratch every frame, and throw it away at the end of the frame. There's no longstanding registration/link between renderable objects and the renderer.

Culling/collecting 2000 renderables, updating their state, sorting them on multiple conditions, and then executing the D3D commands required to draw them, takes about half a millisecond...


This is exactly what I meant, and since I most likely will use less than 2000 different objects I doubt my implementation will perform worse. Visibility culling of entire can be done by the registration stage, ie by storing them in a quad/oct-tree and only requsting objects in visible cells to register.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS