Graphics Reference
In-Depth Information
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.
Rendering a cube and sphere
In this recipe, we will be rendering a simple cube and generating and rendering a sphere and
a quad. We will explore the transformation of each of the objects within the 3D world space.
To prepare ourselves for materials and lighting, we will include a normal vector in our vertex
structure. The normal vector is a vector that indicates what direction is perpendicular to a
tangent on the surface of the object. For each fragment in the pixel shader, we can use the
normal vector to determine the angles between the viewer, light source, and surface.
This value is necessary so that we can calculate the impact of lighting.
Getting ready
For rendering our cube and sphere, we will first prepare ourselves by following the
ensuing steps:
1.
Begin by adding a new Direct3D project to our solution.
2.
Prepare the new project for rendering as per the Rendering primitives recipe in
Chapter 2 , Rendering with Direct3D , remembering to add the necessary references
and to add the build event to copy D3DCompile*.DLL to the output directory.
3.
We will utilize the GeometricPrimitives.cs source file for generating
our sphere. For this recipe, this ile can be found in this topic's code bundle,
Ch03_01CubeAndSphere , provided on Packt's website.
How to do it…
First we will update the vertex layout to support a normal vector.
1.
The input layout defined in D3DApp.CreateDeviceDependentResources needs
to be changed to include the normal vector; change the format of the position to
remove the fourth component (A32), and redefine the color to use a 4-component,
32-bit unsigned normalized integer (8 bits per component).
vertexLayout = ToDispose(new InputLayout(device,
 
Search WWH ::




Custom Search