Author: Romain Vergne (website)
Please cite my name and add a link to my web page if you use this course

Image synthesis and OpenGL: exercices 06

Setup

We will use Linux and the following libraries:

Installing sources. In a terminal, do:
  1. Download the sources at http://romain.vergne.free.fr/teaching/IS/data06/TP06.tgz
  2. If needed, edit the file main.pro to change paths
  3. To compile: qmake && make
  4. To run: ./tp06 file.off
  5. To edit: use either your preferred text editor or qtcreator

Appearance and details

The goal of these exercises is to familiarize yourself with OpenGL texture mappings.
First have a look at the set of given textures in textures/* and give a signification for each of them

Exercise 1: texture mapping

Goal: obtain a simple texture mapping, combined with a Phong shading:


Default:
  1. In the viewer, create 2 other textures (in the function createTextures as before)
  2. In the fragment shader, obtain the desired result

Exercise 2: normal mapping

Goal: perturb normals using the normal mapping method. The result should look like:

  1. Create a new shader called normal-mapping.vert/frag (function createShaders)
  2. Create a new texture ("textures/chesterfield-normal.png"), and send it the shader
  3. In the fragment shader compute the TBN matrix (the binormal is computed from the normal and the tangent)
  4. Use this TBN matrix to transform the normal (obtained from the normal map) from tangent to the camera space
    1. Note: the normal was remapped in the range [0,1] in order to be able to be stored in the texture
    2. You thus need to remap it in the range [-1,1] before use.
  5. Use this modified new normal to compute the shading


Exercise 3: environment mapping

Goal: test conversion functions based on normal/reflected and refracted vectors:


  1. Create a new shader called environment-mapping.vert/frag (function createShaders)
  2. Create a new texture ("textures/env1.jpg" - or env2.jpg or env3.jpg), and send it the fragment shader
  3. Create the conversion function from a 3D vector \( \mathbf{r} \) to a 2D coordinate \( (u,v) \) and use it to access the texture
  4. What kind of effect do you obtain when used with
    1. the normal vector (in world space - you may send it to the fragment shader)?
    2. the normal vector (in camera space)?
    3. the refracted view vector (refraction between the eye and the normal)?
    4. the reflected view vector (reflection between the eye and the normal)?




BONUS

Exercise 4: displacement mapping

Goal: displace vertex positions to increase the realism of the result:


  1. Create a new shader called displacement-mapping.vert/frag - simply copy the normal-map one (function createShaders)
  2. Create a new texture ("textures/chesterfield-height.png"), and send it the (vertex) shader
  3. Displace the vertex position towards the direction of its normal, according to the height value to obtain the displacement effect

Exercise 5: combination of effects

Goal: combine Phong and environment lighting with displacement/normal mapping to obtain complex renderings:


  1. Create a new shader called full-mapping.vert/frag (function createShaders)
  2. Activate and combine
  3. Note: combine Phong and mirror reflection according to the surface angle (according to the line of sight)

 
PREVIOUS: 06 - APPEARANCE
NEXT: 07 - ADVANCED LIGHTING