Graphics Reference
In-Depth Information
F Specular reflection color and power (shininess of the surface): Specular reflection
represents the amount of perfectly reflected light that bounces off the surface of an
object. The material's specular color represents the color of this reflected light,
and the specular power represents the exponent of the equation that determines
how shiny the surface is (the higher the value, the shinier the surface, and therefore,
the smaller the specular highlight). The specular amount is calculated using all three
input vectors.
F Emissive light color: The emissive lighting value is a constant that represents the
emitted light from the surface. This value is not based on any of the input vectors
and is not affected by the light color. The value of this constant is controlled via the
material properties.
From the three input vectors and the previous material properties, we determine the four
lighting output components: the ambient reflection, diffuse reflection, specular reflection,
and emissive lighting.
Getting ready
For this recipe, we need the vertices to include a normal vector and the supporting
changes from the previous recipe.
The completed project can be found in the companion code as
Ch02_02MaterialAndLighting .
How to do it…
The first thing we will do is make changes to Shaders\Common.hlsl to include a new
per material constant buffer and add directional light to the per frame constant buffer to
store the light's color and direction.
1.
First add a new structure for the directional light class; this must be placed
before the PerFrame structure.
// A simple directional light (e.g. the sun)
struct DirectionalLight
{
float4 Color;
float3 Direction;
};
2.
Now we will update the PerFrame structure to include the light.
cbuffer PerFrame: register (b1)
{
DirectionalLight Light;
float3 CameraPosition;
};
 
Search WWH ::




Custom Search