TP2 : Textures

The deadline for this project is: Saturday, December 7th, 2013 (Midnight European Time)

Texture mapping

In order to create and map a texture, you need to take the following steps:

To make your life easier, all these steps are encapsulated inside the load and create methods of the GQTexture class.

At display, you specify the active texture unit (glActiveTexture), then connect the texture to it using the right texture ID (glBindTexture). Inside the shader, the texture units are named, and receive the correct value through a uniform (uniform sampler2D Tex2D receives the value 0 if you have to access the texture unit 0, for example). The bindNameTexture method in the classe GQShaderRef class encapsulates all these operations for you.

Of course, you also need to specify the texture coordinates on the object when you access the sampler using the GLSL function texture.

A textured sphere: the earth

For this practical, we will use the sphere model, for which it is easy to compute texture coordinates.

Day and Night

terre

First, we map the earth-by-day texture ((textureDay) onto the earth. Note that the texture is actually reversed compared to the actual earth. Feel free to reverse the texture coordinates to display a more realistic planet if you wish.

Then, we add the sun illuminating the planet. As in the first practical, you need to compute a diffuse coefficient, and use it to adapt the color of the texture between dark (night) and the texture (day). Remember that at least half the sphere should appear dark.

Try changing the position of the light source, and animating the sphere by rotating it.

Next, try loading the second texture ((textureNight), which represents the earth at night. Change the code in the fragment shader to replace dark with this texture (I suggest using the GLSL function mix).

Normal / Bump mapping

Next, we are going to add some relief to this sphere, using normal mapping, then bump mapping.

Normal Mapping

For normal mapping, we start with a texture map of the normals (stored in "earth3.png", and available in textureNormals). Start by visualizing this texture on the earth surface.

This texture contains modified normals, stored in local coordinates, tangent to the object surface. In order to use them, you need to convert the view vector and the light vector to the same coordinates.

bump