Lab 3 - Shaders

Mesh creation

Generate the vertex data for a sphere.

Diffuse lighting

Use diffuse lighting and apply this texture

Diffuse Texture

Specular lighting

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

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.

Normal Texture

Fonctions WGSL utiles:

Bonus:

Use the Height Map to apply a Parallax Mapping

Height Map