27
Ray Tracing In 2D: For each axis, find the 4 closest face velocity samples: (In 3D… Find 8 closest face velocities in each dimension) Velocity Interpolation http://reedbeta.com/blog/quadrilateral-interpolation-part-2/

•In 2D: For each axis, find the 4 closest face velocity ...cutler/classes/advancedgraphics/S19/lectures/11_ray... · For every object in the scene Find intersection with the ray

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: •In 2D: For each axis, find the 4 closest face velocity ...cutler/classes/advancedgraphics/S19/lectures/11_ray... · For every object in the scene Find intersection with the ray

Ray Tracing

• In 2D: For each axis, find the 4 closest face velocity samples:• (In 3D… Find 8 closest face velocities in each dimension)

Velocity Interpolation

http://reedbeta.com/blog/quadrilateral-interpolation-part-2/

Page 2: •In 2D: For each axis, find the 4 closest face velocity ...cutler/classes/advancedgraphics/S19/lectures/11_ray... · For every object in the scene Find intersection with the ray

• It might be simplest to think about one axis at a time• It doesn’t matter which axis you start with!

• Calculate u, the fraction of the distance along the horizontal axis, e.g., u=0.65

• Then calculate the top & bottom averages: orange = (1-u)*red + u*yellow bluegreen = (1-u)*cyan + u*green

• Calculate v, the fraction of the distance along the vertical axis, e.g., v=0.6

• Then calculate the final average:pukegreen = (1-v)*bluegreen + v*orange

Bilinear Interpolation

http://reedbeta.com/blog/quadrilateral-interpolation-part-2/

• Keyframing• Procedural Animation• Physically-Based Animation• Forward and Inverse Kinematics• Motion Capture

Last Time?

Two solutions

Page 3: •In 2D: For each axis, find the 4 closest face velocity ...cutler/classes/advancedgraphics/S19/lectures/11_ray... · For every object in the scene Find intersection with the ray

• Much harder requires solving the inverse of the non-linear function: find p such that S(p)Vl = Vw

Inverse Kinematics (IK)• Given the position of the

effecter in local coordinates Vl and the desired position Vw in world coordinates, what are the skeleton parameters p?

Vw

Vl

Why is this hard? Why is it non-linear?

Under-/Over- Constrained IK

“The good-looking textured light-sourced bouncy fun smart and stretchy page” Hugo Elias, http://freespace.virgin.net/hugo.elias/models/m_ik.htm

No solutions

One solution

Two solutions (2D) Many solutions

• Application: Robot Motion Planning

Page 4: •In 2D: For each axis, find the 4 closest face velocity ...cutler/classes/advancedgraphics/S19/lectures/11_ray... · For every object in the scene Find intersection with the ray

Searching Configuration Space

• Use gradient descent to walk from starting configuration to target

• Angle restrictions & collisions can introduce local minima

“The good-looking textured light-sourced bouncy fun smart and stretchy page” Hugo Elias, http://freespace.virgin.net/hugo.elias/models/m_ik2.htm

pose space shaded by distance to target

IK Challenge• Find a “natural” skeleton configuration for a given

collection of pose constraints• A vector constraint function C(p) = 0

collects all pose constraints • A scalar objective function g(p) measures the

quality of a pose, g(p) is minimum for most natural poses. Example g(p):– deviation from natural pose– joint stiffness– power consumption

Force: Newton (N) = kg * m / s2

Work: Joule (J) = N*m = kg * m2 / s2

Power: Watt (W) = J/s = kg * m2 / s3

Page 5: •In 2D: For each axis, find the 4 closest face velocity ...cutler/classes/advancedgraphics/S19/lectures/11_ray... · For every object in the scene Find intersection with the ray

Questions?

“Spacetime Constraints”, Witkin & Kass, SIGGRAPH 1988

Reading for Today: (pick one)

• “Real-Time Hand-Tracking with a Color Glove” SIGGRAPH 2009, Wang & Popović

Page 6: •In 2D: For each axis, find the 4 closest face velocity ...cutler/classes/advancedgraphics/S19/lectures/11_ray... · For every object in the scene Find intersection with the ray

• Rapid prototyping of realistic character motion from rough low-quality animations

• Obey the laws of physics & stay within space of naturally-occurring movements

Reading for Today: (pick one)“Synthesis of Complex Dynamic Character Motion

from Simple Animation”, Liu & Popović, 2002

“Flexible Muscle-Based Locomotion for Bipedal Creatures”, Geijtenbeek, van de Panne,

van der Stappen, SIGGRAPH Asia 2013

Reading for Today: (pick one)

Page 7: •In 2D: For each axis, find the 4 closest face velocity ...cutler/classes/advancedgraphics/S19/lectures/11_ray... · For every object in the scene Find intersection with the ray

Today• Ray Casting

– Ray-Plane Intersection – Ray-Sphere Intersection – Point in Polygon

• Ray Tracing• Recursive Ray Tracing• Distribution Ray Tracing

Durer’s Ray Casting Machine• Albrecht Durer, 16th century

Page 8: •In 2D: For each axis, find the 4 closest face velocity ...cutler/classes/advancedgraphics/S19/lectures/11_ray... · For every object in the scene Find intersection with the ray

Ray CastingFor every pixel

Construct a ray from the eye

For every object in the scene

Find intersection with the ray

Keep if closest

Shade depending on light and normal vector

Finding the intersection and normal is the central

part of ray casting

• Surface/Scene Characteristics:– surface normal– direction to light– viewpoint

• Material Properties– color/texture– diffuse (matte)– specular (shiny)– …

• More later!

A Note on Local Shading

Specular spheres

NL

V

Diffuse sphere

Page 9: •In 2D: For each axis, find the 4 closest face velocity ...cutler/classes/advancedgraphics/S19/lectures/11_ray... · For every object in the scene Find intersection with the ray

Ray Representation?• Two vectors:

– Origin– Direction (normalized is better)

• Parametric line (explicit representation)– P(t) = origin + t * direction

origindirection

P(t)

3D Plane Representation?• Plane defined by

– Po = (x,y,z)– n = (A,B,C)

• Implicit plane equation– H(P) = Ax+By+Cz+D = 0

= n·P + D = 0• Point-Plane distance?

– If n is normalized, distance to plane, d = H(P)

– d is the signed distance!

HPo

normalP

P'H(p) = d < 0

H(p) = d > 0

Page 10: •In 2D: For each axis, find the 4 closest face velocity ...cutler/classes/advancedgraphics/S19/lectures/11_ray... · For every object in the scene Find intersection with the ray

Explicit vs. Implicit?• Ray equation is explicit P(t) = Ro + t * Rd

– Parametric– Generates points– Harder to verify that a point is on the ray

• Plane equation is implicit H(P) = n·P + D = 0– Solution of an equation– Does not generate points– Verifies that a point is on the plane

Ray-Plane Intersection• Intersection means both are satisfied• So, insert explicit equation of ray into

implicit equation of plane & solve for tP(t) = Ro + t * RdH(P) = n·P + D = 0n·(Ro + t * Rd) + D = 0t = -(D + n·Ro) / n·Rd

P(t)

Page 11: •In 2D: For each axis, find the 4 closest face velocity ...cutler/classes/advancedgraphics/S19/lectures/11_ray... · For every object in the scene Find intersection with the ray

Additional Housekeeping• Verify that intersection is closer than previous

• Verify that it is not out of range (behind eye)P(t) > tmin

P(t) < tcurrent

P(t)

Normal at Surface Intersection• Needed for shading

– diffuse: dot product between light and normal• Normal of a plane is constant!

normal

Page 12: •In 2D: For each axis, find the 4 closest face velocity ...cutler/classes/advancedgraphics/S19/lectures/11_ray... · For every object in the scene Find intersection with the ray

Ray-Triangle Intersection• Intersect with the plane… • Then use barycentric coordinates:

– P(α, β, γ) = αa + βb + γcwith α + β + γ =1

– If 0 < α < 1 & 0 < β < 1 & 0 < γ < 1then the point is inside the triangle!

RoRd

c

a b

P

How Do We Compute α, β, γ ?• Ratio of opposite sub-triangle area to total area

– α = Aa/A β = Ab/A γ = Ac/A• Use signed areas for points outside the triangle c

a b

P

AaA

But how do I know if the point is outside the triangle? That’s what I was trying to determine!

a b

P

AaA

α < 0 α > 0

c

Page 13: •In 2D: For each axis, find the 4 closest face velocity ...cutler/classes/advancedgraphics/S19/lectures/11_ray... · For every object in the scene Find intersection with the ray

Using Cramer’s Rule…

| | denotes the determinant

Can be copied mechanically

into code

• Used to solve for one variable at a time in system of equations

Sphere Representation?• Implicit sphere equation

– Assume centered at origin (easy to translate)– H(P) = P·P - r2 = 0

Rd Ro

Page 14: •In 2D: For each axis, find the 4 closest face velocity ...cutler/classes/advancedgraphics/S19/lectures/11_ray... · For every object in the scene Find intersection with the ray

Ray-Sphere Intersection• Insert explicit equation of ray into

implicit equation of sphere & solve for t P(t) = Ro + t*Rd H(P) = P·P - r2 = 0

(Ro + tRd) · (Ro + tRd) - r2 = 0

Rd·Rdt2 + 2Rd·Rot + Ro·Ro - r

2 = 0

Rd Ro

• Quadratic: at2 + bt + c = 0– a = 1 (remember, ||Rd|| = 1)– b = 2Rd·Ro– c = Ro·Ro – r2

• with discriminant

• and solutions

• What does it mean if there are no solutions, 1 solution, or 2 solutions?

Ray-Sphere Intersection

Page 15: •In 2D: For each axis, find the 4 closest face velocity ...cutler/classes/advancedgraphics/S19/lectures/11_ray... · For every object in the scene Find intersection with the ray

Questions?

depth normals local shading

Reading for Next Time (read both)

• "An improved illumination model for shaded display" Turner Whitted, 1980.

Page 16: •In 2D: For each axis, find the 4 closest face velocity ...cutler/classes/advancedgraphics/S19/lectures/11_ray... · For every object in the scene Find intersection with the ray

Today• Ray Casting• Ray Tracing

– Shadows– Reflection– Refraction

• Recursive Ray Tracing• Distribution Ray Tracing

Find the point to be shadedFor every light, Construct ray from point to light For every object find intersection of ray with object If no objects between point and light Add contribution from light

How Can We Add Shadows?

Page 17: •In 2D: For each axis, find the 4 closest face velocity ...cutler/classes/advancedgraphics/S19/lectures/11_ray... · For every object in the scene Find intersection with the ray

Mirror Reflection• Cast ray symmetric with

respect to the normal• Multiply by reflection

coefficient (color)

Reflection• Reflection angle = view angle• R = V – 2 (V · N) N

RVθV θR

N

V N N

V N N

V

Page 18: •In 2D: For each axis, find the 4 closest face velocity ...cutler/classes/advancedgraphics/S19/lectures/11_ray... · For every object in the scene Find intersection with the ray

Transparency• Cast ray in refracted direction• Multiply by transparency coefficient (color)

Qualitative Refraction

From “Color and Light in Nature” by Lynch and Livingston

Page 19: •In 2D: For each axis, find the 4 closest face velocity ...cutler/classes/advancedgraphics/S19/lectures/11_ray... · For every object in the scene Find intersection with the ray

RefractionI = N cos Өi – M sin Өi

M = (N cos Өi – I) / sin Өi

T = – N cos ӨT + M sin ӨT

= – N cos ӨT + (N cos Өi – I) sin ӨT / sin Өi

= – N cos ӨT + (N cos Өi – I) ηr

= [ ηr cos Өi – cos ӨT ] N – ηr I = [ ηr cos Өi – √(1 – sin2 ӨT )] N – ηr I = [ ηr cos Өi – √(1 – ηr

2 sin2 Өi )] N – ηr I = [ ηr cos Өi – √(1 – ηr

2 (1 – cos2 Өi ) )] N – ηr I = [ ηr (N · I) – √(1 – ηr

2 (1 – (N · I)2 ))] N – ηr I

I

T

Өi

ӨT

N

-N

MηT

ηi

• Total internal reflection when the square root is imaginary

• Don’t forget to normalize!

N cos Өi

– M sin Өi

Note: The math works the same tracing the ray either “forwards” or “backwards”, but it’s really easy to get confused and have get a sign error in the direction.

• Make sure you know whether you’re entering or leaving the transmissive material:

• What about intersecting transparent objects?

Refraction & the Sidedness of Objects

T

ηT = material index

ηi=1

N

T

ηT= 1

ηi = material index

N

II

Page 20: •In 2D: For each axis, find the 4 closest face velocity ...cutler/classes/advancedgraphics/S19/lectures/11_ray... · For every object in the scene Find intersection with the ray

Total Internal Reflection

From “Color and Light in Nature” by Lynch and Livingston

Today• Ray Casting• Ray Tracing• Recursive Ray Tracing• Distribution Ray Tracing

Page 21: •In 2D: For each axis, find the 4 closest face velocity ...cutler/classes/advancedgraphics/S19/lectures/11_ray... · For every object in the scene Find intersection with the ray

Stopping criteria:• Recursion depth

– Stop after a number of bounces

• Ray contribution– Stop if reflected /

transmitted contribution becomes too small

trace rayIntersect all objectscolor = ambient termFor every light

cast shadow ray color += local shading term

If mirrorcolor += colorrefl * trace reflected ray

If transparentcolor += colortrans * trace transmitted ray

Does it ever end?

Ray Tracing

The Ray Tree

R2

R1R3

L2L1

L3N1

N2

N3

T1

T3

Ni surface normalRi reflected rayLi shadow rayTi transmitted (refracted) ray

Eye

L1

T3R3

L3L2

T1R1

R2Eye

Complexity?

Page 22: •In 2D: For each axis, find the 4 closest face velocity ...cutler/classes/advancedgraphics/S19/lectures/11_ray... · For every object in the scene Find intersection with the ray

Ray Debugging• Visualize the ray tree for single image pixel

incomingreflected rayshadow raytransmitted (refracted) ray

Reading for Next Time (read both)

• "Distributed Ray Tracing", Cook, Porter, & Carpenter, SIGGRAPH 1984.

Page 23: •In 2D: For each axis, find the 4 closest face velocity ...cutler/classes/advancedgraphics/S19/lectures/11_ray... · For every object in the scene Find intersection with the ray

Today• Ray Casting• Ray Tracing• Recursive Ray Tracing• Distribution Ray Tracing

– Soft shadows– Antialiasing (getting rid of jaggies)– Glossy reflection– Motion blur– Depth of field (focus)

Shadows• one shadow ray per

intersection per point light source

no shadow rays

one shadow ray

Page 24: •In 2D: For each axis, find the 4 closest face velocity ...cutler/classes/advancedgraphics/S19/lectures/11_ray... · For every object in the scene Find intersection with the ray

Shadows & Light Sources

http://www.pa.uky.edu/~sciworks/light/preview/bulb2.htmclear bulb frosted bulb

http://3media.initialized.org/photos/2000-10-18/index_gall.htm

http://www.davidfay.com/index.php

Soft Shadows• multiple shadow

rays to sample area light source

one shadow ray

lots of shadow rays

Page 25: •In 2D: For each axis, find the 4 closest face velocity ...cutler/classes/advancedgraphics/S19/lectures/11_ray... · For every object in the scene Find intersection with the ray

Antialiasing – Supersampling• multiple

rays per pixel

point light

area light

jaggies w/ antialiasing

• one reflection ray per intersection

perfect mirror

Reflection

θθ

Page 26: •In 2D: For each axis, find the 4 closest face velocity ...cutler/classes/advancedgraphics/S19/lectures/11_ray... · For every object in the scene Find intersection with the ray

Glossy Reflection• multiple reflection

rays

polished surfaceθθ

Justin Legakis

Motion Blur• Sample

objects temporally

Rob Cook

Page 27: •In 2D: For each axis, find the 4 closest face velocity ...cutler/classes/advancedgraphics/S19/lectures/11_ray... · For every object in the scene Find intersection with the ray

Depth of Field• multiple rays per pixel

Justin Legakisfocal lengthfilm

Ray Tracing Algorithm Analysis• Ray casting• Lots of primitives• Recursive• Distributed Ray

Tracing Effects– Soft shadows– Anti-aliasing– Glossy reflection– Motion blur– Depth of field

cost ≈ height * width * num primitives * intersection cost * size of recursive ray tree * num shadow rays * num supersamples * num glossy rays * num temporal samples * num focal samples * . . .

can we reduce this?

these can serve double duty