The photorealism quest An introduction to ray-tracing

advertisement

The photorealism quest

An introduction to ray-tracing

The basic idea

Cast a ray from the viewer’s eye through each pixel on the screen to see where it hits some object view-plane object eye of viewer

Apply illumination principles from physics to determine the intensity of the light that is reflected from that spot toward the eye

Example: a spherical object

• Mathematics problem: How can we find the spot where a ray hits a sphere?

• We apply our knowledge of vector-algebra

• Describe sphere’s surface by an equation

• Describe ray’s trajectory by an equation

• Then ‘solve’ this system of two equations

• There could be 0, 1, or 2 distinct solutions

Describing the sphere

• A sphere consists of points in space which lie at a fixed distance from a given center

• Let r denote this fixed distance (radius)

• Let c = ( c x

, c y

, c z

) be the sphere’s center

• If w = ( w x

, w y

, w z

) be any point in space, then distance( w , c ) is written ║ w – c ║

• Formula: ║ w – c ║= sqrt( ( w c )•( w c ) )

• Sphere is a set: { w ε R 3 | ( w c )•( w c ) = r }

Describing a ray

• A ray is a geometrical half-line in space

• It has a beginning point: b = ( b x

, b y

, b z

)

• It has a direction-vector: d = ( d x

, d y

, d z

)

• It can be described with a parameter t ≥ 0

• If w = ( w x

, w y

, w z

) is any point in space, then w will be on the half-line just in case w = b + t d for some choice of the parameter t ≥ 0 .

Computing the ‘hit’ time

• To find WHERE a ray hits a sphere, we think of w as a point traveling in space, and we ask: WHEN will w hit the shere?

• We can ‘substitute’ the formula for a point on the half-line into our formula for points that belong to the sphere’s surface, getting an equation that has t as its only variable

• It’s easy to ‘solve’ such an equation for t to find when w ‘hits’ the sphere’s surface

The algebra details

• Sphere:

• Half-line:

║ w – c ║ = r w = b + t d , t ≥ 0

• Substitution: ║ b + t d – c ║ = r

• Replacement: Let q = c – b

• Simplification: ║ t d – q ║ = r

• Square:

• Expand: t

(t

2 d d

– q

•d

)•(t

-2t d d –

•q q

+

) = r q

2

•q = r 2

• Transpose: t 2 d •d -2t d •q + ( q •q - r 2 ) = 0

Apply Quadratic Formula

• To solve: t 2 d •d -2t d •q + ( q •q - r 2 ) = 0

• Format: At 2 + Bt + C = 0

• Formula: t = -B/2A ± sqrt( B 2 – 4AC )/2A

• Notice: there could be 0, 1, or 2 hit times

• OK to use a simplifying assumption: d •d = 1

• Equation becomes: t 2 – 2t d • q + ( q • q – r 2 ) = 0

• Application: We want the ‘earliest’ hit-time: t = ( d • q ) - sqrt( ( d • q ) 2 – ( q • q – r 2 )

)

b

Interpretations

w2 w1 c half-line half-line

A half-line that begins inside the sphere will only ‘hit’ the spgere’s surface once

Second example: A planar surface

• Mathematical problem: How can we find the spot where a ray hits a plane?

• Again we can employ vector-algebra

• Any plane is determined by a two entities:

– a point (chosen arbitrarily) that lies in it, and

– a vector that is perpendicular (normal) to it

• Let p be the point and n be the vector

• Plane is the set: { w ε R 3 | ( w p )•n = 0 }

When does ray ‘hit’ plane?

• Plane:

• Half-line:

( w – p ) • n = 0 w = b + t d , t ≥ 0

• Substitution: ( b + t d – p ) • n = 0

• Replacement: Let q = p – b

• Simplification: (t d – q)•n = 0

• Expand: t d • n q • n = 0

• Solution: t = ( q • n )/( d • n )

p

Interpretations

half-line n d w

If a half-line begins from a point outside a given plane, then it can only hit that plane once (and it might possibly not even hit that plane at all half-line

Achromatic light

• Achromatic light: brightness, but no color

• Light can come from point-sources, and light can come from ambient sources

• Incident light shining on the surface of an object can react in three discernable ways:

– By being absorbed

– By being reflected

– By being transmitted (into the interior)

Illumination

• Besides knowing where a ray of light will hit a surface, we will also need to know whether that ray is reflected or absorbed

• If the ray of light is reflected by a surface, does it travel mainly in one direction? Or does it scatter off in several directions?

• Various surface materials react differently

Some terminology

• Scattering of light (“diffuse reradiation’)

– color may be affected by the surface

• Reflection of light (“specular reflection”)

– mirror-like shininess, color isn’t affected

Geometric ingredients

• Normal vector to the surface at a point

• Direction vector from point to viewer’s eye

• Direction vector from point to light-source

Download