Graphics Reference
In-Depth Information
the position of the viewer,
P
light
is the position of the light (
P
light
. w
= 0),
N
is the normal, and
H
is the half-plane vector. Because
P
light
.
w
= 0, the light
direction vector will be
P
light
.
xyz
. The half-plane vector
H
is computed
as ||
VP
light
+
VP
eye
||. As both the light source and viewer are at infinity, the
half-plane vector
H =
||
P
light
.
xyz
+ (0, 0, l)||.
Example 8-2 provides the vertex shader code that computes the lighting
equation for a directional light. The directional light properties are
described by a
directional_light struct
that contains the following
elements:
•
direction
—The normalized light direction in eye space.
•
halfplane
—The normalized half-plane vector
H
. This can be
precomputed for a directional light, as it does not change.
•
ambient_color
—The ambient color of the light.
•
diffuse_color
—The diffuse color of the light.
•
specular_color
—The specular color of the light.
The material properties needed to compute the vertex diffuse and specular
color are described by a
material_properties struct
that contains the
following elements:
•
ambient_color
—The ambient color of the material.
•
diffuse_color
—The diffuse color of the material.
•
specular_color
—The specular color of the material.
•
specular_exponent
—The specular exponent that describes the
shininess of the material and is used to control the shininess of the
specular highlight.
Example 8-2
Directional Light
#version 300 es
struct directional_light
{
vec3 direction; // normalized light direction in eye
// space
vec3 halfplane; // normalized half-plane vector
vec4 ambient_color;
vec4 diffuse_color;
vec4 specular_color;
};