directx objects finalised paul taylor 2010. packing your objects
TRANSCRIPT
![Page 1: DirectX Objects Finalised Paul Taylor 2010. Packing Your Objects](https://reader036.vdocuments.us/reader036/viewer/2022062422/56649f045503460f94c188af/html5/thumbnails/1.jpg)
DirectX Objects Finalised
Paul Taylor 2010
![Page 2: DirectX Objects Finalised Paul Taylor 2010. Packing Your Objects](https://reader036.vdocuments.us/reader036/viewer/2022062422/56649f045503460f94c188af/html5/thumbnails/2.jpg)
Packing Your Objects
• http://www.fastmovevanlines.com/images/packing_box.jpg
![Page 3: DirectX Objects Finalised Paul Taylor 2010. Packing Your Objects](https://reader036.vdocuments.us/reader036/viewer/2022062422/56649f045503460f94c188af/html5/thumbnails/3.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
![Page 4: DirectX Objects Finalised Paul Taylor 2010. Packing Your Objects](https://reader036.vdocuments.us/reader036/viewer/2022062422/56649f045503460f94c188af/html5/thumbnails/4.jpg)
DirectX Buffers
Three types of bufferVertexIndexConstant
![Page 5: DirectX Objects Finalised Paul Taylor 2010. Packing Your Objects](https://reader036.vdocuments.us/reader036/viewer/2022062422/56649f045503460f94c188af/html5/thumbnails/5.jpg)
Vertex Buffers
• Contain per-vertex data• X Elements per Vertex
• Offset• Base Vertex Location
Vertex 0 Vertex 1
Position Colour TexCoords Position Colour TexCoords
![Page 6: DirectX Objects Finalised Paul Taylor 2010. Packing Your Objects](https://reader036.vdocuments.us/reader036/viewer/2022062422/56649f045503460f94c188af/html5/thumbnails/6.jpg)
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
![Page 7: DirectX Objects Finalised Paul Taylor 2010. Packing Your Objects](https://reader036.vdocuments.us/reader036/viewer/2022062422/56649f045503460f94c188af/html5/thumbnails/7.jpg)
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
![Page 8: DirectX Objects Finalised Paul Taylor 2010. Packing Your Objects](https://reader036.vdocuments.us/reader036/viewer/2022062422/56649f045503460f94c188af/html5/thumbnails/8.jpg)
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
![Page 9: DirectX Objects Finalised Paul Taylor 2010. Packing Your Objects](https://reader036.vdocuments.us/reader036/viewer/2022062422/56649f045503460f94c188af/html5/thumbnails/9.jpg)
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
![Page 10: DirectX Objects Finalised Paul Taylor 2010. Packing Your Objects](https://reader036.vdocuments.us/reader036/viewer/2022062422/56649f045503460f94c188af/html5/thumbnails/10.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
![Page 11: DirectX Objects Finalised Paul Taylor 2010. Packing Your Objects](https://reader036.vdocuments.us/reader036/viewer/2022062422/56649f045503460f94c188af/html5/thumbnails/11.jpg)
Index Buffers are great for reuse!
![Page 12: DirectX Objects Finalised Paul Taylor 2010. Packing Your Objects](https://reader036.vdocuments.us/reader036/viewer/2022062422/56649f045503460f94c188af/html5/thumbnails/12.jpg)
Warning!!!You can’t always share your Normals!
http://www.songho.ca/opengl/gl_vertexarray.html
![Page 13: DirectX Objects Finalised Paul Taylor 2010. Packing Your Objects](https://reader036.vdocuments.us/reader036/viewer/2022062422/56649f045503460f94c188af/html5/thumbnails/13.jpg)
Partitioning your worldhttp://www.collinslefebvrestoneberger.com/artists/Jens/ClearCut.jpg
![Page 14: DirectX Objects Finalised Paul Taylor 2010. Packing Your Objects](https://reader036.vdocuments.us/reader036/viewer/2022062422/56649f045503460f94c188af/html5/thumbnails/14.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
![Page 15: DirectX Objects Finalised Paul Taylor 2010. Packing Your Objects](https://reader036.vdocuments.us/reader036/viewer/2022062422/56649f045503460f94c188af/html5/thumbnails/15.jpg)
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)
![Page 16: DirectX Objects Finalised Paul Taylor 2010. Packing Your Objects](https://reader036.vdocuments.us/reader036/viewer/2022062422/56649f045503460f94c188af/html5/thumbnails/16.jpg)
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!
![Page 17: DirectX Objects Finalised Paul Taylor 2010. Packing Your Objects](https://reader036.vdocuments.us/reader036/viewer/2022062422/56649f045503460f94c188af/html5/thumbnails/17.jpg)
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
![Page 18: DirectX Objects Finalised Paul Taylor 2010. Packing Your Objects](https://reader036.vdocuments.us/reader036/viewer/2022062422/56649f045503460f94c188af/html5/thumbnails/18.jpg)
Binary Data Trees
http://mathworld.wolfram.com/images/eps-gif/CompleteBinaryTree_1000.gifhttp://www.gamedev.net/reference/programming/features/trees2/BuildTree1.gif
![Page 19: DirectX Objects Finalised Paul Taylor 2010. Packing Your Objects](https://reader036.vdocuments.us/reader036/viewer/2022062422/56649f045503460f94c188af/html5/thumbnails/19.jpg)
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.
![Page 20: DirectX Objects Finalised Paul Taylor 2010. Packing Your Objects](https://reader036.vdocuments.us/reader036/viewer/2022062422/56649f045503460f94c188af/html5/thumbnails/20.jpg)
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
![Page 21: DirectX Objects Finalised Paul Taylor 2010. Packing Your Objects](https://reader036.vdocuments.us/reader036/viewer/2022062422/56649f045503460f94c188af/html5/thumbnails/21.jpg)
Reordering the split
• If we split using the red/green line first, our tree would require no splitting
![Page 22: DirectX Objects Finalised Paul Taylor 2010. Packing Your Objects](https://reader036.vdocuments.us/reader036/viewer/2022062422/56649f045503460f94c188af/html5/thumbnails/22.jpg)
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
![Page 23: DirectX Objects Finalised Paul Taylor 2010. Packing Your Objects](https://reader036.vdocuments.us/reader036/viewer/2022062422/56649f045503460f94c188af/html5/thumbnails/23.jpg)
A short 2D Example
http://web.cs.wpi.edu/~matt/courses/cs563/talks/bsp/bsp.html
![Page 24: DirectX Objects Finalised Paul Taylor 2010. Packing Your Objects](https://reader036.vdocuments.us/reader036/viewer/2022062422/56649f045503460f94c188af/html5/thumbnails/24.jpg)
Creating a BSP Tree for Lines (Doom Style)
http://pauillac.inria.fr/~levy//bsp/
![Page 25: DirectX Objects Finalised Paul Taylor 2010. Packing Your Objects](https://reader036.vdocuments.us/reader036/viewer/2022062422/56649f045503460f94c188af/html5/thumbnails/25.jpg)
References
• http://msdn.microsoft.com/en-us/library/bb205133%28VS.85%29.aspx#Buffer_Resources