• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
PAndersson

Register renderables every frame?

15 posts in this topic

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?
0

Share this post


Link to post
Share on other sites
[quote name='PAndersson' timestamp='1342642715' post='4960630']
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?
[/quote]

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.
0

Share this post


Link to post
Share on other sites
You dont want to reupload/register data that doesnt change. Only update data that changes (like position).
0

Share this post


Link to post
Share on other sites
[quote name='Waterlimon' timestamp='1342646081' post='4960657']
You dont want to reupload/register data that doesnt change. Only update data that changes (like position).
[/quote]

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

Share this post


Link to post
Share on other sites
The principle holds, though: if the object isn't actually [i]definitely going away[/i] (or appearing), don't bother with changing its registration status. Do as little work as possible :-)
1

Share this post


Link to post
Share on other sites
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
0

Share this post


Link to post
Share on other sites
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.
1

Share this post


Link to post
Share on other sites
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
1

Share this post


Link to post
Share on other sites
[quote name='ZBethel' timestamp='1342661330' post='4960755']
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.
[/quote]

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.
0

Share this post


Link to post
Share on other sites
[quote name='L. Spiro' timestamp='1342655603' post='4960727']
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.[/quote]I guess that's implementation-dependent. The physics API I use does not allow that natively. Just pointing out.
0

Share this post


Link to post
Share on other sites
[quote name='speciesUnknown' timestamp='1342733436' post='4961071']
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.
[/quote]
[quote name='Hodgman' timestamp='1342755557' post='4961155']
There's no longstanding registration/link between renderable objects and the renderer.
[/quote]

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.


[quote name='DemonRad' timestamp='1342768770' post='4961205']
There is no physics API able to return a list of visible items? O_O
[/quote]
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
0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
[quote name='Hodgman' timestamp='1342755557' post='4961155']
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...
[/quote]

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.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0