Chair of Computer Graphics and Visualization

Sheet 2: Texture Coordinates & Sampling

Exercise: Texture Coordinates (10 points)

The updated classes from the previous sheet are prepared to support texturing. TODO markers in the code indicate missing components.

Texture coordinates are necessary to correctly map textures onto primitives such as planes, spheres, or triangles. The method Plane.intersect already computes texture coordinates for intersection points. In computer graphics, such coordinates are often visualized as RGB values — for debugging purposes. Usually, only u and v are displayed as red and green components.

The two leftmost images in Figure coords show a debug image and a scene without texture. You can toggle between both using the space bar.

For this exercise, implement texture coordinate computation for spheres using polar coordinates. The Sphere class accepts three parameters to control the mapping:

  1. Euler angles (Sphere.rotation): Rotate the direction vector r around the x-, y-, and z-axis in that exact order using rotation matrices.
  2. Compute the polar coordinates (ϕ, θ) and normalize (u, v) to the interval [0, 1].
  3. Scale the texture coordinates using Sphere.scale and then offset them using Sphere.bias.
Texture Debug: Plane only Scene without textures Texture Debug: Full scene

Figure: Debug textures of the plane (left), untextured scene (center), and scene with texture coordinates (right).

Exercise: Procedurally Generating a Texture (5 points)

Implement the method genCheckerboardTexture in the Texture class. For a correct result, the first texel (data[0]) must be black. A correct implementation will produce a checkerboard pattern.

Exercise: Texture Sampling (10 points)

To project the textures onto 2D surfaces, implement the corresponding texture sampling methods.

Familiarize yourself with the Texture class and the enumerators BorderMode and FilterMode.

Complete the methods marked with TODO so that the following combinations are supported:

Combinations of filter and border modes can be freely chosen. The textures in the scene use these combinations purposefully:

During ray traversal, the sampled texture values are automatically multiplied with the ambient and diffuse values of the Phong shading model. These equations do not need to be changed.

To test bilinear interpolation, simply change the filter mode of the checkerboard from NEAREST to BILINEAR.

Loading

Drag with the left mouse button or tab and drag to rotate the scene. Stop interacting to start the raytracing.