Chapter 3. Rendering Meshes

In this chapter, we will cover the following topics:

  • Rendering a cube and sphere
  • Preparing the vertex and constant buffers for materials and lighting
  • Adding material and lighting
  • Using a right-handed coordinate system
  • Loading a static mesh from a file

Introduction

A mesh is technically just a vertex and index buffer that represents a 3D object, and if we look at what we have already covered, we can easily understand this. However, these objects nearly always require a number of additional properties, such as material (surface and lighting properties), textures, submeshes, bones, and animations. This is what Microsoft has done in the past with their ID3DX10Mesh interface; however, this is not available for Direct3D 11 (along with a number of other utility classes), and it is now recommended that you roll your own.

Note

There are other open source projects that provide the replacement functionality, part of which is used in the SharpDX Toolkit and part of which we will be using here. Most notable is the DirectX Tool Kit that is available at https://directxtk.codeplex.com/.

For our purpose, a mesh is the combination of submeshes, materials, object extent, bones, animations, and references to common assets such as textures and shaders. We will begin by working with these elements separately and then pulling them together within a mesh renderer.

With the addition of the graphics tools in Visual Studio 2012 and 2013, we now have the ability to compile shaders as part of our build, view, and edit image assets more efficiently and edit popular 3D model formats (OBJ, COLLADA, and Autodesk FBX) all within Visual Studio. There is also a new Shader Designer that allows us to design pixel shaders using Visual Shader Graphs that can be exported as HLSL source or as shader bytecode.

During this chapter, we will learn how to incorporate these tools with our C# Direct3D development, and learn how to load a static mesh from a Visual Studio compiled mesh object (CMO) file that has been compiled from one of the supported 3D model formats.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.131.212