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

Scalable Vertex Transformations

5 posts in this topic

So I've been working on the collision detection portion of my 2D physics engine (just finished implementing GJK with simplex caching), however throughout the process I've been curious about the most efficient and scalable means for transforming my polygon vertices. Currently I transform only the cached support vertices of my simplex into world coordinates at the beginning of GJK (to get an updated copy of the simplex assuming the polygons have moved between frames), and then I transform each newly added support vertex into world coordinates. This equates to roughly 12 or so transformations per candidate collision pairs.

 

Though this seems more scalable than transforming all vertices of each polygon per frame, doing it all up front would allow me to take advantage of parallelization (whether on the GPU or not).

 

Any suggestions on when to transform vertices; as needed vs batched in parallel (pre-computation and perhaps again at render).

 

Thanks!

0

Share this post


Link to post
Share on other sites

Clarifying my question a little further. The root of the question really is, what is the best way (with respect to performance and/or best practice) to manage shape vertices in my physics engine. Store them all in local coordinate space (relative to the attached shape body) and then transform to global (or other coordinate spaces) as needed. --OR-- Store them all in global coordinate space and update *each* once, maybe twice(since they'll need to be updated anyways at render, why not do it all up front).

 

The first is definitely a lazy approach, taking advantage of the notion that perhaps some vertices don't even need to be updated per frame, and seems scalable in that not ALL vertices on a given shape are even used (with exception to rendering).

 

The second, while eager, allows parallelization by throwing all vertices and their respective transformations at the GPU which would be really quick, though somewhat wasteful (since some vertices aren't needed in given algorithms). Possibly quicker than sparse computations on the CPU? Additionally, this would clean up my internal code (such as GJK) without messy transformations everywhere.

 

I realize this is probably best determined with some benchmarking / tests and depends on what I'm using it for. Though I'm highly skeptical that no one has run into this question before.

Edited by RastaRunna
0

Share this post


Link to post
Share on other sites


Clarifying my question a little further. The root of the question really is, what is the best way (with respect to performance and/or best practice) to manage shape vertices in my physics engine. Store them all in local coordinate space (relative to the attached shape body) and then transform to global (or other coordinate spaces) as needed. --OR-- Store them all in global coordinate space and update *each* once, maybe twice(since they'll need to be updated anyways at render, why not do it all up front).

If I understood you correctly, then:

 

1. If a mesh is animated incrementally, then the errors made due to definite resolution numbers will accumulate, and that different from vertex to vertex. That means that the shape of the mesh will be lost over time. So usually, animated meshes start from a fixed form and get fully transformed in each frame.

 

2. Not animated meshes don't suffer from the problem mentioned above. So *they* can be stored w.r.t. the global co-ordinate system. This is in fact the reason why static and dynamic geometry is distinguished.

1

Share this post


Link to post
Share on other sites

Thanks haegarr for the reply. 

 

 

1. ... . So usually, animated meshes start from a fixed form and get fully transformed in each frame.

 

So does this generally tend to happen all up front pre-computation (or pre-use) of each of the vertices which would allow me to batch the transformations onto say the GPU; or only as the transformations are needed (during computation), which would likely not end up hitting all vertices, but also will have redundancies and not be as parallelized.

 

 

2. Not animated meshes don't suffer from the problem mentioned above. So *they* can be stored w.r.t. the global co-ordinate system. This is in fact the reason why static and dynamic geometry is distinguished.

 

Really good point; I'll definitely adopt this.

Edited by RastaRunna
0

Share this post


Link to post
Share on other sites


So does this generally tend to happen all up front pre-computation (or pre-use) of each of the vertices which would allow me to batch the transformations onto say the GPU; or only as the transformations are needed (during computation), which would likely not end up hitting all vertices, but also will have redundancies and not be as parallelized.

Yes, incremental computation will suffer from imprecision regardless whether it is done on CPU or GPU and also regardless whether it is done at runtime or in a pre-process step. (ATM I don't see why this should depend on data parallelization or such, so be patient with me if I tell you things you already know ;))

 

If you apply transformations incrementally

vn := vn-1 * T= ( ... ( ( v0 * T1 ) * T2 ) * ... ) * Tn

then the original mesh (symbolized by the vertex position v0) exists only at the beginning of the transformation chain. Each step transforms the mesh like you want plus a bit of inaccuracy (what you obviously don't want). After some steps (how many depends on several factors and cannot be predicted exactly) the shape of the mesh starts to look deformed, even if the transformations (intentionally should) only rotate and translate it.

 

If you instead do a single step transformation with concatenated incremental transformations 

vn' := v0 * Tn' = v0 * ( ... ( ( T1 * T2 ) * ... ) * Tn )

where, please notice, Tn' is tagged to distinguish it from Tn, then the computation always uses the original mesh for transformation.

 

Please notice that matrix multiplication is associative, so that the formulas for vn and vn' are mathematically (i.e. with indefinite precision) the same.

 

However, now the overall transformation Tn' is computed incrementally, and because this way of computation suffers from inaccuracy, you seem not to have won anything. But in fact you have won something, because there are mathematical rules that the transformation must obey, and these rules can be used to reduce the inaccuracies to a minimum. See, you don't have this possibility with the mesh, but only with the transformation.

1

Share this post


Link to post
Share on other sites

This is pretty interesting. I think the method I'm going for is more like the second one you mentioned (single step transformation with concatenated incremental transformations). However the root of my question really is:

 

Assuming then that I have the original mesh at the beginning of each frame, and some transformation Tn' which I would like to apply to it. There are different times throughout the current frame at which I need to apply that transformation to a given vertex in order to use it. For example, the transformation could be applied to every vertex and stored in a separate structure at the beginning of each frame to allow all other computations throughout the frame (such as collision detections, physics integration, and rendering) to use this same vertex. Or the transformation could be applied each time it is needed for a given vertex (via the same process of updating vertices, transform the original by current transform to get a transformed copy). Given these two times for updating, which is generally done. The first, irrespective of accuracy allows for parallelization, the second depends on the parallelizability of the context in which it is used.

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