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

Animating multiple objects

6 posts in this topic

Hi, I posted this question a few days ago in game programming forum, but I'm stuck again so hopefully some of you guys here can help.
I need to animate many objects at the same time, I'm talking like 100+ objects on screen each being transformed (rotated, scaled, moved) with it's own transform matrix. Each object is just a simple indexed polygon with a texture on it. The way I have it set up now is: SetTransform(polygon1Matrix); DrawIndexedPrimitive(); repeat with polygon2Matrix for all the polygons. So in effect I have 1 DIP call per polygon. So not surprisingly after 10 polygons were added the framerate dropped noticably (I am using the debug libraries, but I still don't think 27 fps for 10-15 polys is acceptable on gtx 260). My question is, how can I animate each polygon without having to call a DIP for each matrix I set. Now the reason I'm reposting this question is because the answer I got in another forum was to squeeze a matrix that contains the transform into the vertex definition, then in the vertex shader multiply that matrix by the vertex position.. But I have spent the past 3 hours trying to do that, I realized that it's no easy task. There's no matrix flag in the FVF declaration, so I must fool the shader somehow by encoding my matrix into other components like the color, or texture, which I'm not exactly sure how to do. But this seems like a really awkward approach for something so common. I have seen this done in many many games, so there must be some way to do this without jumping through these hoops. Any thoughts?
0

Share this post


Link to post
Share on other sites
FVFs don't contain anything related to matrices; so you have to do that on your own.

Don't play with FVFs, play with vertex declarations instead. Here's an example:
[code]
D3DVERTEXELEMENT9 vPNT [ ] =
{
{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
{ 0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
{ 0, 20, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1 }, //world matrix, 1st row
{ 0, 32, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 2 }, //2nd row
{ 0, 44, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 3 } //3rd row
{ 0, 56, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 4 } //4th row
D3DDECL_END()
}; [/code]

Each frame, you may have to Lock & Unlock the corresponding vertex buffer to embed matrix information to a vertex.

I recommend you to google for Instancing. SDK has a great example about it as well.

Btw, using debug runtimes causes performance hit. Why don't you use Release?

hth.
-R
1

Share this post


Link to post
Share on other sites
Another approach may be to set an array of matrices in your shader. Depending on the complexity of your shader, even with version 2, you should be able to size that array to 30-40 matrices. In your vertex structure, assign a unique index for each object. In the shader, use that index to retrieve the appropriate matrix to transform your vertices - a method similar to skinned animation.

Then batch your object rendering into groups of 30-40 objects. Set the matrix array, render the objects, set another matrix array, etc.
1

Share this post


Link to post
Share on other sites
[quote name='programci_84' timestamp='1300259012' post='4786383']

Don't play with FVFs, play with vertex declarations instead. Here's an example:
...

[/quote]



Perfect, thanks programci, I wasn't even aware that they switched away from using FVFs because every example on the net still uses them. :)


[quote name = 'Buckeye']
[color=#1C2837][size=2]Another approach may be to set an array of matrices in your shader.[/size][/color]
[color=#1C2837][size=2][/quote][/size][/color]
[color=#1C2837][size=2]
[/size][/color]
[size="2"][color="#1C2837"]Thats also a great solution. This would save me the valuble Lock/Unlock and allows my vertices to be light, I'm going to try programci's approach first and then I'll compare it to this one. What does cause some inconvenience is that I guess I would have to somehow check the graphics card on each machine to find out what the max array size it allows, right? Or is that something that is determined by the version of shader?[/color][/size]
0

Share this post


Link to post
Share on other sites
[quote]What does cause some inconvenience is that I guess I would have to somehow check the graphics card on each machine to find out what the max array size it allows, right? Or is that something that is determined by the version of shader? [/quote]
You should check the capabilities of the graphics card capability in any case, but, yes, you'll have to check. You can use GetDeviceCaps and (if I remember) check the MaxVertexShaderConst value*. The SDK has a DirectX Caps Viewer you can use to check values. I'm not positive, but I believe a V2_0 card guarantees** 256 constant registers (can someone confirm that?). At 4 floats per register ( 1 matrix row per register ) that's 64 matrices. However, as you'll probably want to load some other variables (light direction, view/projection matrices, etc.), a modest vertex shader should handle 50 or so matrices pretty easily. E.g., I use ~52 bone matrices as a limit for my skinned mesh animation vertex shader.

EDIT: *MaxVertexShaderConst shows 256 slots on my V2 machine.

**If that guarantee is true, then you only need to check for >= Version 2 for the card to ensure your register limit.

[quote]the capabilities of the graphics card capability[/quote]
Sorry. That's from my Department of Redundancy Department. Edited by Buckeye
0

Share this post


Link to post
Share on other sites
Ok, great, thanks for pointing me in the right direction Buckeye :]. I actually just noticed an awesome DX9 reference stickied to this forum written by legalize which contains in depth info that you mentioned (like the number of register that are available in each shader version, available instructions etc), so I'll be checking it out. Thanks for all the help guys.
1

Share this post


Link to post
Share on other sites
[quote]an awesome DX9 reference stickied to this forum written by legalize which contains in depth info that you mentioned (like the number of register that are available in each shader version[/quote]
Good work. I'd forgotten those stickies. As you mentioned, his reference confirms that, if you check for version >= 2, then you can count on a minimum of 256 constant registers.
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