• 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
porters

Hardware Instancing - Optimization Query

9 posts in this topic

Hi all,

I am writing a structural CAD/Modelling type of application that utilizies hardware instancing extensively for rendering 3D models.

Basically there are typically thousands of beams/girders to draw each frame. These beams are generally comprised of standard structural sections, but for the purpose of this post, lets say that all my beams sections are made of I-sections (for the non-structural savvy folks, just picture a steel beam that is shaped like the capital letter 'I')

Now at first glance, it may seem that hardware instancing is a relatively straightforward choice when you are dealing with thousands of meshes that are geometrically very similar. As such, thats the approach i adopted. My application is performing fairly well for the most part, but when im dealing with large models that have hundreds of different sections, i run into performance issues.

Basically because there a lots of different types of I sections that exist. Each section has differences in flange width and thickness, as well as web depth and thickness. I am having to create a new mesh for each different type of I section, each frame. The reason i am doing it each frame is that i am concerned about the memory cost of storing hundreds of meshes, not to mention having to recreate them every time the graphics device needs to be reset. Having said that i have a feeling thats the way im going to have to go, unless someone more knowledgable than me can help me out with an alternative solution. Which brings me to my question...

Can you locally scale different components of a mesh? When i create my mesh, I'm basically retrieving the cross-section geometry data from a database, and then creating the mesh using that. The mesh has a standard length of 1 metre. When it comes to rendering the meshs, i use a world transform to 'stretch' the mesh to the right length. If i can somehow do something similar on a local scale, i could adjust things like flange thickness, width etc without having to create a new mesh for each type of I section. According to PIX, all my performance issues are steming from the constant locking and unlocking of buffers when im creating my meshes each frame, which is very understandable!

Can anyone suggest a better way to do what i want in a more efficient manner?

Thanks in advance.

Aaron.
0

Share this post


Link to post
Share on other sites
If you know ahead of time the vertices that will be scaled, you can add a vertex attribute that is either a 1 or a 0, with 1 meaning that it is affected by the scale parameter of that instance. Then in your shader you can apply the scaling selectively, by either having a 0 term, or a 1*scale term respectively.

In this case you could apply the scale in one of two ways - either as a constant buffer parameter (which allows you to batch all similar meshes together) or as an instance level attribute (which would let you batch all meshes that can use the base mesh as its representation).

In the latter case you will have to lock and update and unlock the instance buffer, while in the first case you will just have to update the constant buffer for each batch.

I hope that helps!
1

Share this post


Link to post
Share on other sites
Thanks for the reply Jason.

I think i understand what your saying, although it may be hard to implement in my case. Basically every vertex has to be scaled. Every type of I-section has different depths, widths, flange thinkness, and web thicknesses. Scaling the height, width and length of the mesh can be done easily with a scaling matrix, its more the flange and web thicknesses that i am struggling with.

So really i would have to do something like this:
1. Scale mesh with a scaling matrix to give correct height, width and length.
2. Flag all vertices save for a few to not be affected by further scaling.
3. Apply additional vertical scale to adjust flange thickness
4. Flag all vertices save for a few to not be affected by further scaling.
3. Apply additional horizontal scaling matrix that will adjust web thickness.

Is this possible with your suggestion?
0

Share this post


Link to post
Share on other sites
You could always add a multi-component vertex attribute that allows you to perform only certain operations on certain vertices. Think of it as something like vertex skinning - you have a number of integer attributes that simply say which scalings will affect each vertex. If I am understanding your scenario properly, then I think this will work for you...

Can you post a pic of the various scaling operations, or is it sensitive info?
0

Share this post


Link to post
Share on other sites
I'm not very familar with skinning, i don't use it in my application. I think i know what your saying though. I am thinking an integer vertex attribute that can be either 0,1 or 2. 0 indicating that all vertices are effected by scaling, 1 indicating that only relevant web vertices are effected by scaling, and 2 indicating that only relevant flange vertices are effected by scaling. I would then have to pass two matrices as part of my instance data. One matrix being the 'global' scaling matrix, and the other being the 'local' scaling matrix. The shader will apply the global scaling matrix to all vertices flagged as 0. I can then make the local transformation matrix only contain a scaling in the x and y direction. So my shader will apply the x scaling component to my vertices flagged as 1 (web), and apply the y scaling component to my vertices flagged as 2 (flange).

Is that essentially what your saying?

I've attached a pic below showing the scaling operations. I'm a bit reluctant to post code, but i dont think the code will tell you anything anyway. I'm just passing a transformation matrix to my shader at the moment, on a per-instance basis.

[img]http://imageshack.us/a/img96/6867/isectionscaling.png[/img]
0

Share this post


Link to post
Share on other sites
[quote name='porters' timestamp='1353028111' post='5001411']
I am having to create a new mesh for each different type of I section, each frame. The reason i am doing it each frame is that i am concerned about the memory cost of storing hundreds of meshes, not to mention having to recreate them every time the graphics device needs to be reset.
[/quote]

Have you considered that this is the part where you loose your performance (ie. recreating the data every frame). Your beam section has 12 vertices (if the corners aren't rounded) so one beam element has 24 vertices, which is pretty much next to nothing. Now if your vertex size is like 32 bytes and you have 1000 different beam meshes, your data amount is still less than 1mb!

So, why not try to use static meshes, which you don't recreate every frame?

Otherwise, the beams are typically defines as a set of parameters (4 in your case?), so it totally possible to define how each vertex is affected by those parameter. Probably you'd need to give each vertex a set of weights which tell how each parameter affects the position.

Cheers!
0

Share this post


Link to post
Share on other sites
You may be able to construct a girder in its entirely in a vertex shader, without using vertex buffers. If you pass the web,flange etc. data in as per instance data (e.g. read from a texture buffer), you can procedurally build a girder based on the SV_VertexID system value semantic. Either that, or tag parts of a mesh using a vertex weight map and scale and extrude based on that. Edited by eppo
2

Share this post


Link to post
Share on other sites
[quote name='eppo' timestamp='1353092458' post='5001604']
You may be able to construct a girder in its entirely in a vertex shader, without using vertex buffers. If you pass the web,flange etc. data in as per instance data (e.g. read from a texture buffer), you can procedurally build a girder based on the SV_VertexID system value semantic. Either that, or tag parts of a mesh using a vertex weight map and scale and extrude based on that.
[/quote]

Yup, that's the way I'd do it. Strikes me that if the position component is based on a formula anyway, then moving that formula to GPU-side is the way to go.
0

Share this post


Link to post
Share on other sites
Thanks guys. Yeah I had a think about it last night and it seems logical to just have a base beam mesh and pass the actual cross section geometry parameters to the shader, and let the shader do the work. Saves me having to create a mesh for each beam size, and also recreate the meshes each frame.

@kuana - yes I realize that's where the performance problems are steming from, as I mentioned in my earlier post. Thanks for the response.
0

Share this post


Link to post
Share on other sites
[quote]I am having to create a new mesh for each different type of I section, each frame. The reason i am doing it each frame is that i am concerned about the memory cost of storing hundreds of meshes, not to mention having to recreate them every time the graphics device needs to be reset.[/quote] You shouldn't have to recreate your mesh data every frame anyway, hundreds of meshes might not take up that much memory, if they aren't complex. I don't get why you are worried about that ? Nor why you are worried about device resets. If you need to rebuild your mesh data on a device reset then so be it. That is a rare event, where-as you say you would rather rebuild your mesh data ever frame to avoid having to do it occasionally. Your reasoning seems backwards to me.
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