Graphics Reference
In-Depth Information
F For more information on HLSL constant buffer packing rules, refer to the following
link: http://msdn.microsoft.com/en-us/library/windows/desktop/
bb509632(v=vs.85).aspx
F For more details on how to use the packoffset HLSL keyword, refer to the following
link: http://msdn.microsoft.com/en-us/library/windows/desktop/
bb509581(v=vs.85).aspx
Adding material and lighting
The most important properties for a mesh, other than the vertices themselves, are material
and lighting. With the ability to specify the texture, color, and the way the surface behaves
with lighting, we can generate much more realistic scenes.
In the previous recipe, we have already added two of the three input vectors needed for
calculating the lighting:
F View direction (calculated from the camera's location)
F Surface normal
The final input vector is light direction. For this sample, we are going to create a simple
directional light, that is, a light that has a constant direction anywhere in the scene
(like the sun). We will define this light with a color and direction.
We also introduce the following material properties:
F Ambient light color: The ambient reflection is a constant ambient-lighting
value. This is a simple, approximate representation of light that has bounced
around a room and is lighting the back of the object, providing the indirect light.
This value is not based on any of the three input vectors and will be provided by
our material properties.
F Diffuse reflection color: Diffuse reflection is the reflection of light from a diffuse
surface where the ray is reflected from the surface in random directions. In a 3D
real-time rendering, we only approximate this light model. We will instead say that
the light is reflected from the surface equally in all directions ( Luna 2012 , p280 ).
This means that regardless of the viewer's angle, the amount of light reflected
from a point on the surface is constant.
F Material diffuse color: This is multiplied with the vertex color within the vertex
shader to give the final pixel-diffused color. The intensity of this value represents
the amount of direct light that the light provides to the surface and is determined
using the light direction and surface normal with Lambert's cosine law.
 
Search WWH ::




Custom Search