160 likes | 181 Views
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. object. view-plane. Apply illumination principles from physics to determine the intensity of the light that
E N D
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 object view-plane Apply illumination principles from physics to determine the intensity of the light that is reflected from that spot toward the eye eye of viewer
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 = ( cx, cy, cz ) be the sphere’s center • If w = ( wx, wy, wz ) 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ε R3 | (w-c)•(w-c) = r }
Describing a ray • A ray is a geometrical half-line in space • It has a beginning point: b = ( bx, by, bz ) • It has a direction-vector: d = ( dx, dy, dz ) • It can be described with a parameter t ≥ 0 • If w = ( wx, wy, wz ) is any point in space, then w will be on the half-line just in case w = b + td 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: ║ w – c║ = r • Half-line: w = b + td, t ≥ 0 • Substitution: ║b + td – c║ = r • Replacement: Let q = c – b • Simplification: ║ td – q ║ = r • Square: (td – q)•(td – q) = r2 • Expand: t2d•d -2td•q + q•q = r2 • Transpose: t2d•d -2td•q + (q•q - r2)= 0
Apply Quadratic Formula • To solve: t2d•d -2td•q + (q•q - r2)= 0 • Format: At2 + Bt + C = 0 • Formula: t = -B/2A ± sqrt( B2 – 4AC )/2A • Notice: there could be 0, 1, or 2 hit times • OK to use a simplifying assumption: d•d = 1 • Equation becomes: t2 – 2td•q + (q•q – r2) = 0 • Application: We want the ‘earliest’ hit-time: t = (d•q) - sqrt( (d•q)2 – (q•q – r2) )
Interpretations half-line w2 w1 b c 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ε R3 | (w-p)•n = 0 }
When does ray ‘hit’ plane? • Plane: (w – p)•n = 0 • Half-line: w = b + td, t ≥ 0 • Substitution: (b + td – p)•n = 0 • Replacement: Let q = p – b • Simplification: (td – q)•n = 0 • Expand: td•n - q•n = 0 • Solution: t = (q•n)/(d•n)
Interpretations half-line n p 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