Docsity

Recursive Ray Tracer: Texture Mapping and Data Structures for Ray Tracing, Slides of Computer Graphics

Partial preview of the text

Download Recursive Ray Tracer: Texture Mapping and Data Structures for Ray Tracing and more Slides Computer Graphics in PDF only on Docsity!

Lecture 22:

Recursive Ray Tracer2:

Texture Mapping and Data Structures

Review – Recursive Ray Tracer

• Basic concept (draw diagram)

• Three types of secondary rays

• Lighting equation

Supersampling

  • Left image: one ray per pixel (through pixel center)
  • Right image: 5 rays per pixel (corners + center)
    • Do weighted average of the rays to color in the pixel
  • Adaptive sampling
    • Supersampling: more samples where we need it (e.g., where

geometry or lighting changes drastically)

  • Subsampling: fewer samples where we don’t need detail (faster

computation)

  • Beam tracing: track a bundle of neighboring rays together

Supersampling

With Supersampling Without Supersampling

Texture Mapping with Ray Tracer

Texture Mapping

  • In general, we can think of texture mapping as a function that

“maps” between two domains, position on the surface of an object

(domain), and a pixel value from the texture image (co-domain)

 This is typically done in two steps:

  1. Map a point on the geometry to a point on a unit square
  2. Map the unit square onto a texture image
  1. Map a point on the geometry to a

point on a unit square

  • We have 4 geometric objects to consider in our ray tracer:
    • Cube
    • Sphere
    • Cone
    • Cylinder
  • Cube is pretty easy… The faces of the cube map nicely to a

unit square

Mapping a Cube - Tiling

• Note that we can allow for tiling if the face of a cube is

too large

  • If we map a single texture, it could stretch and look terrible
  • So a possible alternative is to use tiling

𝑤𝑡𝑒𝑥𝑡𝑢𝑟𝑒, ℎ𝑡𝑒𝑥𝑡𝑢𝑟𝑒

(0, 0) texture map

Mapping a Cylinder / Cone

  • Recall: the goal is to map a point in (x, y, z) into (u, v)
  • For a cylinder, we can break down the object into two

parts:

  • The cap, which we will treat as a square surface
  • The body, which we will unroll into a square (see below)
  • Cone is a special case of a cylinder, need to interpolate as

we go up from the base to the tip

P (^) x

𝑢 =.

z

P

𝑣

𝑢

P x

y

z

𝑣 =.

Mapping a Cylinder / Cone

  • Help on computing the u value:
  • We need to map all points on the surface to [0, 1]
  • The easiest way is to say 𝑢 =

𝜃 2𝜋 , and use the dot product to find 𝜃, but it’s hard to determine the signs (e.g. acos returns a value between 0 and 𝜋, same for atan)

  • For example, atan (1, 1) = atan (-1, -1) =

𝜋 2

  • So instead we use atan2 (x, y), which returns a values between −𝜋 and 𝜋. (Notice the discontinuity at 𝑢 = 0.5)

P (^) x

𝑢 =.

z

P

Texture Mapping Complex Geometry

  • Sometimes, texture mapping the polygons of

an object doesn’t get what you are looking for

Original Geometry (^) Texture each face separately (notice discontinuities)

Texture the object as a continuous object

Basic Idea

• Use a bounding sphere…

  • Find the ray’s intersection (in object space) with a bounding sphere, called P
  • Find P’s coordinate in the texture map’s (u, v) coordinate
  • Apply the texture to the point on the underlying geometry (the house)

Slightly More Advanced

  • Turns out that you don’t have to use a sphere as a bounding surface
  • You can use a cylinder or planar mappings for complex objects.

Each has drawbacks:

  • Sphere: warping at the “poles” of the object
  • Cylinder: discontinuities between cap and body of the cylinder
  • Planar: one dimension needs to be ignored
    • But can do cool tricks with this…
  • The problem is kind of hard. Since the object is in 3D, mapping it to

2D usually means some drawback

How to Speed Up My Ray Tracer?!