Practical 5 - Elements of solution

This page provides elements of solution for the Texturing practical.

Exercise 1: Wrapping and filtering

The interpretation of these texturing parameters was discussed in class, come back to us for more information.

Exercise 2: Load models with explicit texture coordinates

Make sure you modified your vertex shader with the attribute tex_coord provided by the loader.

When available in a .obj mesh, the loader will always send the following attributes:

in vec3 position;
in vec3 normal;
in vec2 tex_coord;

Look at the load function in core.py to locate when these data are added in the attributes dictionary.

Exercise 3: Phong and Texture

No solution for this exercise. The aim is to combine previous solutions for Phong illumination (see Practical 4 - Elements of solution) and what you have just done with texturing.

Tips would be:

  • write a new shader merging phong.[vert|frag] and texture.[vert|frag].

  • the illumination color and texture can simply be multiplied (an addition could induce saturation, i.e. color components overflowing 1.0 thus clipped at 1.0)

  • do not forget to add a light in your scene (yes, some of you did forget!)

Exercise 3: Multi-texturing

No solution for this exercise. Tips would be:

  • do not forget to set up the texture coordinates. They can be shared for the two texture images… or not.

  • in your fragment shader, compute a texture color from each sampler2D

  • there are many ways to combine these two texture colors to compute the output color of the fragment:
    • test simple operators like addition or multiplication

    • a common combination when one of the images contains transparent texels (as in flowers.png) is: out_color = mix(color1, color2, color2.a);. Analyse what is done here.