Download the sources at
http://romain.vergne.free.fr/teaching/IS/data06/TP06.tgz
If needed, edit the file main.pro to change paths
To compile: qmake && make
To run: ./tp06 file.off
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:
one shader has been added to the system (called
texture-mapping.{vert,frag} and performs a Phong shading using the Phong
model.
uv coordinates are already sent to the shader, as well as the tangents
the shader multiplies the diffuse component of the BRDF by the color
of an input texture to obtain a textured shading
In the viewer, create 2 other textures (in
the function createTextures as before)
a specular texture ("textures/chesterfield-specular.png") that
controls where highlights should have a lot of importance
an ambient occlusion texture ("textures/chesterfield-ao.png") that
approximates global illumination effects (cavity shadowing)
Note: the principle is the same as with the color texture. You will
have to modify the following functions
createTextures
deleteTextures
enableShaders
and of course the shader themselves
In the fragment shader, obtain the
desired result
Note 1: color is usually multiplied with the diffuse lighting
intensity (already done)
Note 2: ambient occlusion should be multiplied with the final
resulting color
Note 3: the specular map could either control the shininess (the
specular exponent) or the specular intensity
Exercise 2: normal mapping
Goal: perturb normals using the normal mapping method. The result should
look like:
Create a new shader called
normal-mapping.vert/frag (function createShaders)
Create a new texture
("textures/chesterfield-normal.png"), and send it the shader
In the fragment shader compute the TBN
matrix (the binormal is computed from the normal and the tangent)
Use this TBN matrix to transform the
normal (obtained from the normal map) from tangent to the camera space
Note: the normal was remapped in the range [0,1] in order to be able
to be stored in the texture
You thus need to remap it in the
range [-1,1] before use.
Use this modified new normal to
compute the shading
Exercise 3: environment mapping
Goal: test conversion functions based on normal/reflected and refracted
vectors:
Create a new shader called
environment-mapping.vert/frag (function createShaders)
Create a new texture ("textures/env1.jpg"
- or env2.jpg or env3.jpg), and send it the fragment shader
Create the conversion function from a 3D
vector \( \mathbf{r} \) to a 2D coordinate \( (u,v) \) and use it to
access the texture
\( u = \frac{atan(r_x,r_z)+\pi}{2\pi} \)
\( v = \frac{acos(-r_y)}{\pi} \)
What kind of effect do you obtain when
used with
the normal vector (in world space - you may send it to the fragment
shader)?
the normal vector (in camera space)?
the refracted view vector (refraction between the eye and the
normal)?
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:
Create a new shader called
displacement-mapping.vert/frag - simply copy the normal-map one
(function createShaders)
Create a new texture
("textures/chesterfield-height.png"), and send it the (vertex) shader
Displace the vertex position towards the
direction of its normal, according to the height value to obtain the
displacement effect
Note:
the normal should be perturbed with the normal mapping technique, as
in exercise 2
Exercise 5: combination of effects
Goal: combine Phong and environment lighting with displacement/normal
mapping to obtain complex renderings:
Create a new shader called
full-mapping.vert/frag (function createShaders)
Activate and combine
the normal mapping technique
the displacement mapping technique
the phong illumination
the reflection illumination
Note: combine Phong and mirror reflection
according to the surface angle (according to the line of sight)