introduction to computer graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...ray...
TRANSCRIPT
![Page 1: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/1.jpg)
Introduction to Computer Graphics
Toshiya Hachisuka
![Page 2: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/2.jpg)
Lecturer
• Toshiya Hachisuka
!
• Leading the computer graphics group
• Office: I-REF 503
• http://www.ci.i.u-tokyo.ac.jp/~hachisuka
![Page 3: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/3.jpg)
• Introduction to ray tracing
• Basic ray-object intersection
Today
![Page 4: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/4.jpg)
LuxRender
![Page 5: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/5.jpg)
LuxRender
![Page 6: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/6.jpg)
How can we generate realistic images?
![Page 7: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/7.jpg)
Rendering
Light sources
Shapes
Materials
Camera data
Computation
Input data Image
![Page 8: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/8.jpg)
Interdisciplinary Nature• Computer Science
• Algorithms
• Computational geometry
• Software engineering
• Physics
• Radiometry
• Optics
• Mathematics
• Algebra
• Calculus
• Statistics
• Perception
• Art
![Page 9: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/9.jpg)
Ray Tracing [Appel 1968]
Page
CS348B Lecture 2 Pat Hanrahan, Spring 2008
Ray Tracing in Computer Graphics
Appel 1968 - Ray casting
1. Generate an image by sending one ray per pixel
2. Check for shadows by sending a ray to the light
CS348B Lecture 2 Pat Hanrahan, Spring 2008
Ray Tracing in Computer Graphics
Whitted 1979
Recursive ray tracing (reflection and refraction)
Generate images with shadows using ray tracing
![Page 10: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/10.jpg)
Ray Tracing [Whitted 1979]
Recursive ray tracing for reflections/refractions
![Page 11: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/11.jpg)
Whitted Ray Tracing Today
• Runs realtime on a GPU!
Screenshot of a demo using NVIDIA’s OptiX
![Page 12: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/12.jpg)
Whitted Ray Tracing Today
• Runs realtime on a GPU!
http://alexrodgers.co.uk
![Page 13: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/13.jpg)
Whitted Ray Tracing Today
• Runs realtime on a GPU!
http://alexrodgers.co.uk
You are going to implement something like this!
![Page 14: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/14.jpg)
Ray Tracing - Pseudocode
for all pixels {
ray = generate_camera_ray( pixel )for all objects {
hit = intersect( ray, object )if “hit” is closer than “first_hit” {first_hit = hit}
}pixel = shade( first_hit )
}
![Page 15: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/15.jpg)
Ray Tracing - Data Structures
!class object {
bool intersect( ray )}!class ray {
vector originvector direction
}
![Page 16: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/16.jpg)
Pinhole Camera
Film = Image
Pinhole
(the image is flipped)
![Page 17: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/17.jpg)
Pinhole Camera
Film
Pinhole
![Page 18: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/18.jpg)
Camera Coordinate Systemup
from
to
![Page 19: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/19.jpg)
Camera Coordinate System
~u · ~v = ~v · ~w = ~w · ~u = 0||~u|| = ||~v|| = ||~w|| = 1
Orthonormal basis
~e
~v
~u~w
![Page 20: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/20.jpg)
Camera Coordinate System
• Given , , and
~v = ~w ⇥ ~u
Axes
Origin
~u =~Cup ⇥ ~w
|| ~Cup ⇥ ~w||
~e = ~Cfrom
~Cup ~Cfrom
~Cto
�w =
�Cfrom
� �Cto
|| �Cfrom
� �Cto
||
![Page 21: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/21.jpg)
Up vector?
• Imagine a stick on top your head
• The stick = up vector
• Up vector is not always equal to ~v
~v = up~v
up
![Page 22: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/22.jpg)
Generating a Camera Ray
~v
~u~w y = film h
pixel j + 0.5
res y
z = distance to film
(x, y, z)
Pixel location in the camera coordinates
x = film w
pixel i + 0.5
res x
![Page 23: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/23.jpg)
Generating a Camera Ray
• Film size is not equal to image resolution!
Film with 82 resolution Same film with 162 resolution
![Page 24: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/24.jpg)
Generating a Camera Ray
• Pixel location in the world coordinates:
!
!
• Camera ray in the world coordinates:
origin = ~e
direction =
origin� pixel
||origin� pixel||
pixel = x�u+ y�v + z �w + �e
![Page 25: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/25.jpg)
Generating a Camera Ray
~e
~v
~u~w
![Page 26: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/26.jpg)
More Realistic Cameras• “A realistic camera model for computer graphics”
• Ray tracing with actual lens geometry
• Distortion
Full Simulation Thin Lens Approximation
[Kolb et al.]
![Page 27: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/27.jpg)
More Realistic Cameras
• “Efficient Monte Carlo Rendering with Realistic Lenses”
• Polynomial approximation of a lens system
[Hanika et al.]
![Page 28: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/28.jpg)
Ray Tracing - Pseudocode
for all pixels {
ray = generate_camera_ray( pixel )for all objects {
hit = intersect( ray, object )if “hit” is closer than “first_hit” {first_hit = hit}
}pixel = shade( first_hit )
}
![Page 29: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/29.jpg)
Goal
~o
~d
~p~p = ~o+ t
~
d
What we want to know~n
![Page 30: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/30.jpg)
Ray-Sphere Intersection
• Sphere with center and radius~c = (cx
, cy
, cz
) r
||(~p� ~c)||2 = r2
![Page 31: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/31.jpg)
Ray-Sphere Intersection
• Sphere with center and radius~c = (cx
, cy
, cz
) r
~p = ~o+ t
~
d
||(~p� ~c)||2 = r2
Substitute
![Page 32: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/32.jpg)
Ray-Sphere Intersection
• Sphere with center and radius~c = (cx
, cy
, cz
) r
~p = ~o+ t
~
d
||(~p� ~c)||2 = r2
Substitute
(~o+ t
~
d� ~c) · (~o+ t
~
d� ~c) = r
2
||~v||2 = ~v · ~v
![Page 33: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/33.jpg)
Ray-Sphere Intersection
• Sphere with center and radius~c = (cx
, cy
, cz
) r
~p = ~o+ t
~
d
||(~p� ~c)||2 = r2
Substitute
(~o+ t
~
d� ~c) · (~o+ t
~
d� ~c) = r
2
~
d · ~dt2 + 2~d · (~o� ~c)t+ (~o� ~c) · (~o� ~c)� r
2 = 0
Quadratic equation of t Solve for t
||~v||2 = ~v · ~v
![Page 34: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/34.jpg)
Ray-Sphere Intersection
• can have (considering only real numbers)
• 0 solution : no hit point
• 1 solution : hit at the edge
• 2 solutions
• two negatives : hit points are behind
• two positives : hit points are front
• positive and negative : origin is in the sphere
t
![Page 35: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/35.jpg)
Ray-Sphere Intersection
• Two hit points - take the closest
~o
~d
~p0
~p1
![Page 36: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/36.jpg)
Normal Vector
~o
~d
~p~n =~p� ~c
r
~r ·�(~p� ~c) · (~p� ~c)� r2
�= 2(~p� ~c)
![Page 37: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/37.jpg)
Ray-Implicit Surface Intersection
• Generalized to any implicit surface
f(~p(t)) = 0
Intersection point:
||(~p(t)� ~c)||2 � r2 = 0
Solve
e.g.,
Normal vector:
~n =~r · f(~p(t))
||~r · f(~p(t))||
![Page 38: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/38.jpg)
Ray-Implicit Surface Intersection
• can be
• Linear: Plane
• Quadratic: Sphere
• Cubic: Bézier (cubic)
• Quartic: Phong tessellation
• ...and anything
f(~p(t)) = 0
![Page 39: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/39.jpg)
Ray-Implicit Surface Intersection
• Julia set
Sunflow
![Page 40: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/40.jpg)
Ray-Implicit Surface Intersection
• Procedural geometry
www.iquilezles.org
![Page 41: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/41.jpg)
Ray-Implicit Surface Intersection
• Subdivision surfaces
“Direct Ray Tracing of Full-Featured Subdivision Surfaces with Bezier Clipping”
![Page 42: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/42.jpg)
Triangle Mesh
• Approximate shapes with triangles
http://www.graphics.rwth-aachen.de/publication/149/
![Page 43: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/43.jpg)
Barycentric Coordinates
• Ratios of areas of the sub-triangles
~c~b
~a↵ =
� =
� =
AcAa Ab++
AcAa Ab++
AcAa Ab++Ac
Ab
Aa
![Page 44: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/44.jpg)
Barycentric Coordinates
• Parametric description of a point in a triangle
~p = ↵~a+ �~b+ �~c
0 < ↵ < 1
0 < � < 1
0 < � < 1
↵+ � + � = 1
~a
~b ~c
~p
![Page 45: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/45.jpg)
Barycentric Coordinates
• Interpolate values at the vertices
~na
~nb~nc
~np
~np = ↵~na + �~nb + �~ncNormalize it before use
![Page 46: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/46.jpg)
Interpolation
![Page 47: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/47.jpg)
Interpolation
![Page 48: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/48.jpg)
Ray-Triangle Intersection
• Calculate as fast as possible
!
• Modification of ray-plane intersection
• Direct methods
• Cramer’s rule
• Signed volumes
(t,↵,�, �)
![Page 49: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/49.jpg)
Ray-Triangle Intersection Cramer’s Rule
~p = ↵~a+ �~b+ �~c
![Page 50: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/50.jpg)
Ray-Triangle Intersection Cramer’s Rule
~p = ↵~a+ �~b+ �~c~o+ t
~
d
![Page 51: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/51.jpg)
Ray-Triangle Intersection Cramer’s Rule
~p = ↵~a+ �~b+ �~c~o+ t
~
d (1� � � �)~a+ �~b+ �~c
![Page 52: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/52.jpg)
Ray-Triangle Intersection Cramer’s Rule
~p = ↵~a+ �~b+ �~c~o+ t
~
d (1� � � �)~a+ �~b+ �~c
o
x
+ td
x
= (1� � � �)ax
+ �b
x
+ �c
x
oy + tdy = (1� � � �)ay + �by + �cy
oz + tdz = (1� � � �)az + �bz + �cz
3 equations for 3 unknowns
![Page 53: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/53.jpg)
Ray-Triangle Intersection Cramer’s Rule
~p = ↵~a+ �~b+ �~c~o+ t
~
d (1� � � �)~a+ �~b+ �~c2
4a
x
� b
x
a
x
� c
x
d
x
a
y
� b
y
a
y
� c
y
d
y
a
z
� b
z
a
z
� c
z
d
z
3
5
2
4�
�
t
3
5 =
2
4a
x
� o
x
a
y
� o
y
a
Z
� o
z
3
5
Solve the equation with Cramer’s Rule
det⇣~a,~b,~c
⌘=
⇣~a⇥~b
⌘· ~c
![Page 54: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/54.jpg)
Ray-Triangle Intersection Cramer’s Rule
!
• Accept the solution only if
tclosest
> t > 0
1 > � > 0
1 > � > 0
1 > 1� � � � > 0
tclosest
: the smallest positive t values so far
![Page 55: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/55.jpg)
Ray-Triangle Intersection
• There are many different approaches!
• Numerical precision
• Performance
• Storage cost
• SIMD friendliness
!
• Genetic programming for performancehttp://www.cs.utah.edu/~aek/research/triangle.pdf
![Page 56: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/56.jpg)
GLSL Sandbox
• Interactive coding environment for WebGL
• You write a program for each pixel in GLSL
• Automatically loop over all the pixels
• Uses programmable shader units on GPUs
http://glslsandbox.com
![Page 57: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/57.jpg)
GLSL implementationfor all pixels {
ray = generate_camera_ray( pixel )for all objects {
hit = intersect( ray, object )if “hit” is closer than “first_hit” {first_hit = hit}
}pixel = shade( first_hit )
}
![Page 58: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/58.jpg)
GLSL implementation
• Truth is…
• You can find ray tracing on GLSL sandbox
• “Copy & paste” is a good start, but make sure you understand what’s going on and describe what you did in your submission
![Page 59: Introduction to Computer Graphicsresearch.nii.ac.jp/~takayama/teaching/utokyo-iscg-2017/...Ray Tracing [Appel 1968] Page CS348B Lecture 2 Pat Hanrahan, Spring 2008 Ray Tracing in Computer](https://reader033.vdocuments.net/reader033/viewer/2022060210/5f049b047e708231d40eccb2/html5/thumbnails/59.jpg)
Next Timefor all pixels {
ray = generate_camera_ray( pixel )for all objects {
hit = intersect( ray, object )if “hit” is closer than “first_hit” {first_hit = hit}
}pixel = shade( first_hit )
}