Presentation is loading. Please wait.

Presentation is loading. Please wait.

DirectX Objects Finalised Paul Taylor 2010. Packing Your Objects

Similar presentations


Presentation on theme: "DirectX Objects Finalised Paul Taylor 2010. Packing Your Objects"— Presentation transcript:

1 DirectX Objects Finalised Paul Taylor 2010

2 Packing Your Objects http://www.fastmovevanlines.com/images/packing_box.jpg

3 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

4 DirectX Buffers Three types of buffer Vertex Index Constant

5 Vertex Buffers Contain per-vertex data X Elements per Vertex Offset Base Vertex Location Vertex 0Vertex 1 PositionColourTexCoordsPositionColourTexCoords

6 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 012 Vertex 0Vertex 1 PositionColourTexCoordsPositionColourTexCoords

7 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

8 The DirectX 10 Pipeline http://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

9 A Basic Packing Example SimpleVertex 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

10 Buffers can save time! Translate() Draw(Beef); Translate(…) Draw(Beef); Translate(…) Draw(Beef); http://obamarama.org/wp- content/uploads/2007/04/heres-the-beef.jpg http://barfblog.foodsafety.ksu.edu/HappyCow.jpg

11 Index Buffers are great for reuse!

12 Warning!!! You can’t always share your Normals! http://www.songho.ca/opengl/gl_vertexarray.html

13 Partitioning your world http://www.collinslefebvrestoneberger.com/artists/Jens/ ClearCut.jpg

14 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

15 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)

16 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!

17 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

18 Binary Data Trees http://mathworld.wolfram.com/images/eps- gif/CompleteBinaryTree_1000.gif http://www.gamedev.net/reference/programming /features/trees2/BuildTree1.gif

19 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.

20 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

21 Reordering the split If we split using the red/green line first, our tree would require no splitting

22 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

23 A short 2D Example http://web.cs.wpi.edu/~matt/courses/cs563/talks/bsp/bsp.html

24 Creating a BSP Tree for Lines (Doom Style) http://pauillac.inria.fr/~levy//bsp/

25 References http://msdn.microsoft.com/en- us/library/bb205133%28VS.85%29.aspx#Buffe r_Resources


Download ppt "DirectX Objects Finalised Paul Taylor 2010. Packing Your Objects"

Similar presentations


Ads by Google