• 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
Jack Lumber

Vertex attributes and buffers.

3 posts in this topic

Hello,

 

I'm new here and learning Direct3D. Usually I don't ask questions since Internet is already filled with answers, but failed to find a satisfying answer to the question I'm about to ask. Was thinking and thinking and couldn't find an appropriate solution... could be there's none. However, the problem.

 

 

Lets say I have a cube. In a file I could store vertex data in a compact way - 8 different vertex positions, 6 different vertex normals, 14 different texture coordinates, and finally, face definitions via respected indices. That should be the case of Wavefront OBJ file if I'm not mistaken. When reading documentation for IASetVertexBuffers I thought I was in luck and in the program can split the data in same manner in different vertex buffers, but apparently only one index buffer apply to all of them??

 

When loading OBJ files, then if vertex normal is different, then vertex should be duplicated. So, in memory I would have 24 vertices instead of 8, and when adding the texture coordinate attribute, I'd have them again 24 instead of 14. Bumping aside from these numbers for a moment, I managed to get to a decision that it's mesh designer's responsibility that sharp edges should have duplicated vertices / different vertex normals. But returning to the cube, is that waste considered okay since in reality I'm dealing with more complex objects than cubes and with smooth edges... unless I want to build a brick wall with individual bricks in it, lol. If so, I wouldn't even need to have cube texture unwrapped like the cross on a Bible, but just 6 sperate panes will do.

 

 

So, is that how it's meant to be or is there some better approach?

0

Share this post


Link to post
Share on other sites
I've never heard of multiple index buffers being used. So you're assumption is correct as far as I know - vertices need to be duplicated for sharp/discontinuous edges.
0

Share this post


Link to post
Share on other sites

yeah when blasting geometry at the GPU you generally format it so you have fat vertices each with their attributes (like position, normal, texture coordinate, color, etc) all packed together one after the other.  so you have one buffer of pos0, normal0, texcoord0, color0, pos1, normal1, texcoord1, color1, pos2, normal2.... you get the idea.  then another buffer that are indices for your triangles so like 0, 1, 2, 0, 2, 3, ... each index here then grabs the contiguous blob of data for the vertex at that index.

 

you'll find a lot of software like max and maya and formats like OBJ don't specify meshes this way.  they'll specify them as you describe where each face or triangle has separate indices for each vertex component.  so positions 0,1,2 and normals 6,1,3 and texcoords 4,3,1.

 

when you load data like this you do indeed have to duplicate vertices when the same vertex is referenced but with different attributes.  while this does mean potentially having many duplicate copies of attributes (like the texture coordinate 0,0 used by many vertices) it keeps things a bit simpler and avoids the GPU running all around memory gathering up the attributes from many different locations and also keeps the APIs a bit simpler as well.  in the general case of a big complex mesh created by an artist there's unlikely to be much savings in indexing attributes separately.

Edited by blackpawn
0

Share this post


Link to post
Share on other sites

Use CreateInputLayout to describe each vertex then IASetInputLayout. It requires something like

 

D3D11_INPUT_ELEMENT_DESC layoutPosColor[] =
{
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "COLOR", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
};

 

which describes each vertex. Here we have a 12 byte (4 float) position followed by a 12 byte vertex color. Then you SetVertexBuffer and either call Draw() to just draw them in the order you specified (requiring duplicate vertices) or SetIndexBuffer followed by DrawIndexed(). The second method allows you to only specify a vertex once and use it multiple times. The problem with this is that it will only have one set of texture coordinates an one normal. So if a vertex has two faces like the corner of a box each with different normals (the box is flat, not rounded at the corners) you have a problem.

 

To answer your question: yes, you need to specify extraneous data to do what you want. The box with 6 faces each with a different normal requires 24 vertices, each with a normal and texture coordinates.

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