DirectX Objects Finalised Paul Taylor 2010. Packing Your Objects .
-
Upload
sabina-owen -
Category
Documents
-
view
216 -
download
0
Transcript of DirectX Objects Finalised Paul Taylor 2010. Packing Your Objects .
DirectX Objects Finalised
Paul Taylor 2010
Packing Your Objects
• http://www.fastmovevanlines.com/images/packing_box.jpg
DirectX Buffers
• A buffer contains Elements• Elements are basic structures such as– Colours– Integer– Float Values
• An Element can contain a maximum of four components e.g.– Colour B8 G8 R8 A8– Position X Y Z– Texture Coordinates– 4x Floats
DirectX Buffers
Three types of bufferVertexIndexConstant
Vertex Buffers
• Contain per-vertex data• X Elements per Vertex
• Offset• Base Vertex Location
Vertex 0 Vertex 1
Position Colour TexCoords Position Colour TexCoords
Index Buffers
• A String of 16 or 32 bit Indices• Each Index points to a location of an element in
an existing vertex buffer
• Offset (2)• Start Index Location (1)• Index Count (2)
Not used
Not used
Not used
0 1 2
Vertex 0 Vertex 1
Position Colour TexCoords Position Colour TexCoords
Constant Buffers
• New to Dx10• A SINGLE element buffer, no multi-element
abilities like vertex buffers• Supply the Shaders with an array of constant
values• Each stage can support 15x 4096 component
constant buffers
The DirectX 10 Pipelinehttp://msdn.microsoft.com/en-us/library/ee415715%28VS.85%29.aspx
A Constant Buffer can be used to capture the results of the Stream Output Stage
A Basic Packing ExampleSimpleVertex vertices[] ={ D3DXVECTOR3( 0.0f, 0.5f, 0.5f ), D3DXVECTOR3( 0.5f, -0.5f, 0.5f ), D3DXVECTOR3( -0.5f, -0.5f, 0.5f ), };D3D10_BUFFER_DESC bd; bd.Usage = D3D10_USAGE_DEFAULT; bd.ByteWidth = sizeof( SimpleVertex ) * 3; bd.BindFlags = D3D10_BIND_VERTEX_BUFFER
D3D10_SUBRESOURCE_DATA InitData; InitData.pSysMem = vertices;
CreateBuffer( &bd, &InitData, &g_pVertexBuffer );
UINT stride = sizeof( SimpleVertex ); UINT offset = 0;IASetVertexBuffers( 0, 1, &g_pVertexBuffer, &stride, &offset );Draw( 3, 0 );
http://obamarama.org/wp-content/uploads/2007/04/heres-the-beef.jpg
Buffers can save time!
Translate()Draw(Beef);
Translate(…)Draw(Beef);
Translate(…)Draw(Beef);
http://obamarama.org/wp-content/uploads/2007/04/heres-the-beef.jpghttp://barfblog.foodsafety.ksu.edu/HappyCow.jpg
Index Buffers are great for reuse!
Warning!!!You can’t always share your Normals!
http://www.songho.ca/opengl/gl_vertexarray.html
Partitioning your worldhttp://www.collinslefebvrestoneberger.com/artists/Jens/ClearCut.jpg
Binary Spacial Partitioning (BSP)
• In today's gaming world, there are two important reasons for dividing the world– Rendering without the Z-Buffer – Rendering Translucent (Alpha Blend) Polygons
Why?
• Modern games have so many polygons that stretching the z buffer to cover the entire object range would result in many visual glitches, as many polygons start falling into the same depth levels of the buffer.
• Translucent Polygons are created using a blend function which requires back-to-front rendering (Painters algorithm)
How?
• There are many differing ways and methods to create maps of polygons, especially static collections
• One of the most common, and a very efficient way is utilising BSP trees.– The first use of a BSP tree was Doom in 1993• It was only used in a 2D implementation!
A BSP is a specialised implementation of a Binary Data Tree
• Binary Trees are used because:• the ability to be efficiently traversed in both
directions• The ability to add data randomly during the
building of the tree• The speed in which a random location can be
found
Binary Data Trees
http://mathworld.wolfram.com/images/eps-gif/CompleteBinaryTree_1000.gifhttp://www.gamedev.net/reference/programming/features/trees2/BuildTree1.gif
The Principal to creating a BSP Tree
• Each polygon (3D) / line (2D) creates a dividing line / plane in the tree where every other Polygon/line is either in front or behind.
Cutting your Polygons
• The offending Polygon / Line must be cut into two parts
• It then becomes two separate polygons / lines
• One infront of the division, • the other behind
Reordering the split
• If we split using the red/green line first, our tree would require no splitting
Problems Creating BSP Lists
http://www.devmaster.net/articles/bsp-trees/http://beehivehairdresser.com/wp-content/uploads/2007/10/yin_yang.jpg
Minimising Polygon Cuts
Balancing the Tree
A short 2D Example
http://web.cs.wpi.edu/~matt/courses/cs563/talks/bsp/bsp.html
Creating a BSP Tree for Lines (Doom Style)
http://pauillac.inria.fr/~levy//bsp/
References
• http://msdn.microsoft.com/en-us/library/bb205133%28VS.85%29.aspx#Buffer_Resources