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 04


We will use Linux and the following libraries:

Installing sources. In a terminal, do:
  1. Download the sources at
  2. If needed, edit the file to change paths
  3. To compile: qmake && make
  4. To run: ./tp04 models/
  5. To edit: use either your prefered text editor or qtcreator

Local Lighting

The goal of these exercises is to familiarize yourself with local lighting effects. You should obtain something like this:

Exercice 1: Understand the code

The source code contains the same files/classes as before
By default, the program loads a mesh and uses a simple shader to display it.
Output colors are normals in camera space.
The mesh is sent to the graphics card using vertex arrays objects, like in the previous assignment.

Have a look at the files viewer.* and shaders/constant.*
You should now have an idea of the effect of each function in theses files.

Exercice 2: Prepare a new shader

  1. Create new shader files called gouraud1.vert et gouraud1.frag
    1. you can simply copy/rename/paste the constant.vert and frag files
  2. Add them in the shader vectors (function createShaders)
  3. Send a light direction to your shader (function enableShader - constant for the whole mesh)

Exercice 3: Gouraud Shading and lambertian model

Observe that 3 matrices are sent to the shaders:

Uniform scaling:
no problem
Non-uniform scaling:
The obtained normal does not correspond
anymore to the real surface
  1. Apply a Gouraud shading (lighting per vertex), using the lambertian model

Exercice 4: Gouraud Shading and Phong model

  1. Add a new shader in the shader list gouraud2.vert et gouraud2.frag
  2. Modify the shaders to apply a Gouraud shading using the Phong model

Exercice 5: Phong Shading and Phong model

  1. Add a new shader in the shader list: phong.vert et phong.frag
  2. Apply a Phong shading to obtain a similar result

Exercice 6: Bonus

  1. Add a new shader in the shader list: toon.vert et toon.frag
  2. Try to modify the Phong shading (per fragment computation) to obtain a toon-shading effect
  3. Play with shading: create your own shading effect!