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

Get Direct3D Rendering Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.