Generate the vertex data for a sphere.
Use diffuse lighting and apply this texture
The specular lighting corresponds to the reflection of the light source on the surface. It depends on the point of view.
Vectors:
All these vectors are normalized.
The reflected specular intensity \(\vec{I_s}\) is calculated by \[\vec{I_s} = (\vec{R} \cdot{} \vec{V})^{\alpha}\vec{C_l}\] where \(\vec{C_l}\) is the color of the light and \(\alpha\) is the brightness of the material.
To calculate \(\vec{R}\) we use \[\vec{R} = 2(\vec{N} \cdot{} \vec{L})\vec{N}-\vec{L}\]
Modify your shaders to account for specular lighting.
Normal mapping consists in using a texture containing the normals to the surface. This allows to vary the normal with more details without adding these details to the 3D geometry of the object.
The components \((r, g, b)\) of the normal texture must be converted. the components of colors are included between 0 and 1 whereas the coordinates of a unit vector are between -1 and 1. one thus applies to each component the following transformation: \[ N_i = 2C_i - 1 \]
The normals contained in the texture are given in a reference frame tangent to the surface. This reference frame is composed of the three vectors:
\(\vec{N}\) and \(\vec{T}\) are part of the Vertex Data. \(\vec{B}\) can be computed by \[\vec{B} = \vec{N} \times{} \vec{T}\]
These vectors are in general known in the model space. To pass from the tangent space to the model space we use the matrix:\[ \left ( \begin{matrix} T_x & B_x & N_x \\ T_y & B_y & N_y \\ T_z & B_z & N_z \end{matrix} \right ) \]
To perform the inverse transformation, this matrix must be inverted. For an orthogonal matrix, this corresponds to doing the transpose: \[ \left ( \begin{matrix} T_x & B_x & N_x \\ T_y & B_y & N_y \\ T_z & B_z & N_z \end{matrix} \right )^{-1} = \left ( \begin{matrix} T_x & B_x & N_x \\ T_y & B_y & N_y \\ T_z & B_z & N_z \end{matrix} \right )^T = \left ( \begin{matrix} T_x & T_y & T_z \\ B_x & B_y & B_z \\ N_x & N_y & N_z \end{matrix} \right ) \]
Modify your shaders and C++ to use an additional texture that contains the normals.
normalize() to normalize a vectordot() for the scalar product of vectors
cross() for the cross product of vectors
length() gives the norm of a vectorpow(x, n) for \(x^n\)max(x, y) returns the greater of the two
values
clamp(vec, min, max) constrains the
components of vec between min and
max
transpose(mat) transpose a matrixinverse(mat) inverts a matrixreflect(I, N) computes the reflected
vector based on the incident and normal vector (I - 2.0 * dot(N, I) *
N).
Use the Height Map to apply a Parallax Mapping