Introduction to Computer Graphics Toshiya Hachisuka Lecturer - - PowerPoint PPT Presentation

introduction to computer graphics
SMART_READER_LITE
LIVE PREVIEW

Introduction to Computer Graphics Toshiya Hachisuka Lecturer - - PowerPoint PPT Presentation

Introduction to Computer Graphics Toshiya Hachisuka Lecturer Toshiya Hachisuka first last Leading the computer graphics group Office: I-REF 503 http://www.ci.i.u-tokyo.ac.jp/~hachisuka Today


slide-1
SLIDE 1

Introduction to Computer Graphics


 Toshiya Hachisuka

slide-2
SLIDE 2

Lecturer

  • Toshiya Hachisuka(蜂須賀 恵也)
  • Leading the computer graphics group
  • Office: I-REF 503
  • http://www.ci.i.u-tokyo.ac.jp/~hachisuka

first last

slide-3
SLIDE 3
  • Introduction to ray tracing
  • Basic ray-object intersection

Today

slide-4
SLIDE 4

LuxRender

slide-5
SLIDE 5

LuxRender

slide-6
SLIDE 6

How can we generate realistic images?

slide-7
SLIDE 7

Rendering

Light sources Shapes Materials Camera data Computation

Input data Image

slide-8
SLIDE 8

Interdisciplinary Nature

  • Computer Science
  • Algorithms
  • Computational geometry
  • Software engineering
  • Physics
  • Radiometry
  • Optics
  • Mathematics
  • Algebra
  • Calculus
  • Statistics
  • Perception
  • Art
slide-9
SLIDE 9

Ray Tracing - Concept

https://en.wikipedia.org/wiki/Ray_tracing_(graphics)#/media/File:Ray_trace_diagram.svg

slide-10
SLIDE 10

Ray Tracing [Appel 1968]

Generate images with shadows using ray tracing

slide-11
SLIDE 11

Ray Tracing [Whitted 1979]

Recursive ray tracing for reflections/refractions

slide-12
SLIDE 12

Whitted Ray Tracing Today

  • Runs realtime on a GPU!

http://alexrodgers.co.uk

slide-13
SLIDE 13

Whitted Ray Tracing Today

  • Runs realtime on a GPU!

http://alexrodgers.co.uk

You are going to implement something like this!

slide-14
SLIDE 14

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 ) }

slide-15
SLIDE 15

Ray Tracing - Data Structures

class object { bool intersect( ray ) } class ray { vector origin vector direction }

slide-16
SLIDE 16

Pinhole Camera

Film = Image Pinhole (the image is flipped)

slide-17
SLIDE 17

Pinhole Camera

Film Pinhole

slide-18
SLIDE 18

Camera Coordinate System

up from to

slide-19
SLIDE 19

Camera Coordinate System

~ u · ~ v = ~ v · ~ w = ~ w · ~ u = 0 ||~ u|| = ||~ v|| = ||~ w|| = 1

Orthonormal basis

~ e ~ v ~ u ~ w

slide-20
SLIDE 20

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||

slide-21
SLIDE 21

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

slide-22
SLIDE 22

Generating a Camera Ray

~ v ~ u ~ w y = film hpixel j + 0.5 res y z = distance to film (x, y, z)

Pixel location in the camera coordinates

x = film wpixel i + 0.5 res x

slide-23
SLIDE 23

Generating a Camera Ray

  • Film size is not equal to image resolution!

Film with 82 resolution Same film with 162 resolution

slide-24
SLIDE 24

Generating a Camera Ray

  • Pixel location in the world coordinates:
  • Camera ray in the world coordinates:
  • rigin = ~

e direction =

  • rigin − pixel

||origin − pixel|| pixel = x u + y v + z w + e

slide-25
SLIDE 25

Generating a Camera Ray

~ e ~ v ~ u ~ w

slide-26
SLIDE 26

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.]

slide-27
SLIDE 27

More Realistic Cameras

  • “Efficient Monte Carlo Rendering with Realistic Lenses”
  • Polynomial approximation of a lens system

[Hanika et al.]

slide-28
SLIDE 28

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 ) }

slide-29
SLIDE 29

Goal

~

  • ~

d ~ p ~ p = ~

  • + t~

d

What we want to know

~ n

slide-30
SLIDE 30

Ray-Sphere Intersection

  • Sphere with center and radius

~ c = (cx, cy, cz) r ||(~ p − ~ c)||2 = r2

slide-31
SLIDE 31

Ray-Sphere Intersection

  • Sphere with center and radius

~ c = (cx, cy, cz) r ~ p = ~

  • + t~

d ||(~ p − ~ c)||2 = r2

Substitute

slide-32
SLIDE 32

Ray-Sphere Intersection

  • Sphere with center and radius

~ c = (cx, cy, cz) r ~ p = ~

  • + t~

d ||(~ p − ~ c)||2 = r2

Substitute

(~

  • + t~

d − ~ c) · (~

  • + t~

d − ~ c) = r2 ||~ v||2 = ~ v · ~ v

slide-33
SLIDE 33

Ray-Sphere Intersection

  • Sphere with center and radius

~ c = (cx, cy, cz) r ~ p = ~

  • + t~

d ||(~ p − ~ c)||2 = r2

Substitute

(~

  • + t~

d − ~ c) · (~

  • + t~

d − ~ c) = r2 ~ d · ~ dt2 + 2~ d · (~

  • − ~

c)t + (~

  • − ~

c) · (~

  • − ~

c) − r2 = 0

Quadratic equation of t Solve for t

||~ v||2 = ~ v · ~ v

slide-34
SLIDE 34

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

slide-35
SLIDE 35

Ray-Sphere Intersection

  • Two hit points - take the closest

~

  • ~

d ~ p0 ~ p1

slide-36
SLIDE 36

Normal Vector

~

  • ~

d ~ p ~ n = ~ p − ~ c r ~ r ·

  • (~

p ~ c) · (~ p ~ c) r2 = 2(~ p ~ c)

slide-37
SLIDE 37

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))||

slide-38
SLIDE 38

Ray-Implicit Surface Intersection

  • can be
  • Linear: Plane
  • Quadratic: Sphere
  • Cubic: Bézier (cubic)
  • Quartic: Phong tessellation
  • ...and anything

f(~ p(t)) = 0

slide-39
SLIDE 39

Ray-Implicit Surface Intersection

  • Procedural geometry

www.iquilezles.org

slide-40
SLIDE 40

Ray-Implicit Surface Intersection

  • Subdivision surfaces

“Direct Ray Tracing of Full-Featured Subdivision Surfaces with Bezier Clipping”

slide-41
SLIDE 41

Triangle Mesh

  • Approximate shapes with triangles

http://www.graphics.rwth-aachen.de/publication/149/

slide-42
SLIDE 42

Barycentric Coordinates

  • Ratios of areas of the sub-triangles

~ c ~ b ~ a α = β = γ = Ac Aa Ab+ + Ac Aa Ab+ + Ac Aa Ab+ + Ac Ab Aa

slide-43
SLIDE 43

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

slide-44
SLIDE 44

Barycentric Coordinates

  • Interpolate values at the vertices 


~ na ~ nb ~ nc ~ np ~ np = ↵~ na + ~ nb + ~ nc

Normalize it before use

slide-45
SLIDE 45

Interpolation

slide-46
SLIDE 46

Interpolation

slide-47
SLIDE 47

Ray-Triangle Intersection

  • Calculate as fast as possible
  • Modification of ray-plane intersection
  • Direct methods
  • Cramer’s rule
  • Signed volumes

(t, α, β, γ)

slide-48
SLIDE 48

Ray-Triangle Intersection Cramer’s Rule

~ p = ↵~ a + ~ b + ~ c

slide-49
SLIDE 49

Ray-Triangle Intersection Cramer’s Rule

~ p = ↵~ a + ~ b + ~ c ~

  • + t~

d

slide-50
SLIDE 50

Ray-Triangle Intersection Cramer’s Rule

~ p = ↵~ a + ~ b + ~ c ~

  • + t~

d (1 − − )~ a + ~ b + ~ c

slide-51
SLIDE 51

Ray-Triangle Intersection Cramer’s Rule

~ p = ↵~ a + ~ b + ~ c ~

  • + t~

d (1 − − )~ a + ~ b + ~ c

  • x + tdx = (1 − β − γ)ax + βbx + γcx
  • y + tdy = (1 − β − γ)ay + βby + γcy
  • z + tdz = (1 − β − γ)az + βbz + γcz

3 equations for 3 unknowns

slide-52
SLIDE 52

Ray-Triangle Intersection Cramer’s Rule

~ p = ↵~ a + ~ b + ~ c ~

  • + t~

d (1 − − )~ a + ~ b + ~ c   ax − bx ax − cx dx ay − by ay − cy dy az − bz az − cz dz     β γ t   =   ax − ox ay − oy aZ − oz  

Solve the equation with Cramer’s Rule


det ⇣ ~ a,~ b,~ c ⌘ = ⇣ ~ a ×~ b ⌘ · ~ c

slide-53
SLIDE 53

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

slide-54
SLIDE 54

Ray-Triangle Intersection

  • There are many different approaches!
  • Numerical precision
  • Performance
  • Storage cost
  • SIMD friendliness
  • Genetic programming for performance

http://www.cs.utah.edu/~aek/research/triangle.pdf

slide-55
SLIDE 55

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

slide-56
SLIDE 56

GLSL implementation


 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 ) }

slide-57
SLIDE 57

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

slide-58
SLIDE 58

Next Time


 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 ) }