introduction to computer graphics
play

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


  1. 
 Introduction to Computer Graphics Toshiya Hachisuka

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

  3. Today • Introduction to ray tracing • Basic ray-object intersection

  4. LuxRender

  5. LuxRender

  6. How can we generate realistic images?

  7. Rendering Input data Image Light sources Shapes Computation Materials Camera data

  8. Interdisciplinary Nature • Computer Science • Algorithms • Computational geometry • Software engineering • Physics • Radiometry • Optics • Mathematics • Algebra • Calculus • Statistics • Perception • Art

  9. Ray Tracing - Concept https://en.wikipedia.org/wiki/Ray_tracing_(graphics)#/media/File:Ray_trace_diagram.svg

  10. Ray Tracing [Appel 1968] Generate images with shadows using ray tracing

  11. Ray Tracing [Whitted 1979] Recursive ray tracing for reflections/refractions

  12. Whitted Ray Tracing Today • Runs realtime on a GPU! http://alexrodgers.co.uk

  13. Whitted Ray Tracing Today • Runs realtime on a GPU! You are going to implement something like this! http://alexrodgers.co.uk

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

  15. Ray Tracing - Data Structures class object { bool intersect( ray ) } class ray { vector origin vector direction }

  16. Pinhole Camera Pinhole Film = Image (the image is flipped)

  17. Pinhole Camera Pinhole Film

  18. Camera Coordinate System up from to

  19. Camera Coordinate System ~ v ~ u ~ w ~ e Orthonormal basis ~ u · ~ v = ~ v · ~ w = ~ w · ~ u = 0 || ~ u || = || ~ v || = || ~ w || = 1

  20. Camera Coordinate System • Given , , and C up ~ ~ ~ C from C to C from − � � C to � w = || � C from − � C to || ~ Axes C up × ~ w u = ~ || ~ w || C up × ~ ~ v = ~ w × ~ u e = ~ Origin ~ C from

  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

  22. Generating a Camera Ray ~ v x = film wpixel i + 0.5 res x ( x, y, z ) y = film hpixel j + 0.5 ~ u ~ w res y z = distance to film Pixel location in the camera coordinates

  23. Generating a Camera Ray • Film size is not equal to image resolution! Film with 8 2 resolution Same film with 16 2 resolution

  24. Generating a Camera Ray • Pixel location in the world coordinates: pixel = x � u + y � v + z � w + � e • Camera ray in the world coordinates: origin = ~ e origin − pixel direction = || origin − pixel ||

  25. Generating a Camera Ray ~ v ~ u ~ w ~ e

  26. More Realistic Cameras [Kolb et al.] • “A realistic camera model for computer graphics” • Ray tracing with actual lens geometry • Distortion Full Simulation Thin Lens Approximation

  27. More Realistic Cameras [Hanika et al.] • “Efficient Monte Carlo Rendering with Realistic Lenses” • Polynomial approximation of a lens system

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

  29. Goal ~ d ~ o o + t ~ ~ p = ~ ~ d p ~ n What we want to know

  30. Ray-Sphere Intersection • Sphere with center and radius c = ( c x , c y , c z ) ~ r c ) || 2 = r 2 || ( ~ p − ~

  31. Ray-Sphere Intersection • Sphere with center and radius c = ( c x , c y , c z ) ~ r c ) || 2 = r 2 || ( ~ p − ~ o + t ~ Substitute ~ p = ~ d

  32. Ray-Sphere Intersection • Sphere with center and radius c = ( c x , c y , c z ) ~ r c ) || 2 = r 2 v || 2 = ~ || ( ~ || ~ v · ~ p − ~ v o + t ~ Substitute p = ~ ~ d o + t ~ o + t ~ c ) = r 2 ( ~ c ) · ( ~ d − ~ d − ~

  33. Ray-Sphere Intersection • Sphere with center and radius c = ( c x , c y , c z ) ~ r c ) || 2 = r 2 v || 2 = ~ || ( ~ || ~ v · ~ p − ~ v o + t ~ Substitute ~ p = ~ d o + t ~ o + t ~ c ) = r 2 ( ~ c ) · ( ~ d − ~ d − ~ dt 2 + 2 ~ c ) − r 2 = 0 d · ~ ~ d · ( ~ c ) t + ( ~ c ) · ( ~ o − ~ o − ~ o − ~ Quadratic equation of t Solve for t

  34. Ray-Sphere Intersection • can have (considering only real numbers) t • 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

  35. Ray-Sphere Intersection • Two hit points - take the closest ~ d ~ o ~ p 1 ~ p 0

  36. Normal Vector ~ d ~ o n = ~ p − ~ c ~ ~ p r ~ c ) � r 2 � � ( ~ c ) · ( ~ = 2( ~ c ) p � ~ p � ~ p � ~ r ·

  37. Ray-Implicit Surface Intersection • Generalized to any implicit surface Intersection point: Solve f ( ~ p ( t )) = 0 c ) || 2 − r 2 = 0 e.g., || ( ~ p ( t ) − ~ Normal vector: ~ r · f ( ~ p ( t )) n = ~ || ~ r · f ( ~ p ( t )) ||

  38. Ray-Implicit Surface Intersection • can be f ( ~ p ( t )) = 0 • Linear: Plane • Quadratic: Sphere • Cubic: Bézier (cubic) • Quartic: Phong tessellation • ...and anything

  39. Ray-Implicit Surface Intersection • Procedural geometry www.iquilezles.org

  40. Ray-Implicit Surface Intersection • Subdivision surfaces “Direct Ray Tracing of Full-Featured Subdivision Surfaces with Bezier Clipping”

  41. Triangle Mesh • Approximate shapes with triangles http://www.graphics.rwth-aachen.de/publication/149/

  42. Barycentric Coordinates • Ratios of areas of the sub-triangles ~ A a a α = A a A b + A c + A b β = A a A b + A c + A c ~ γ = c ~ A a A b + A c + b

  43. Barycentric Coordinates • Parametric description of a point in a triangle a + �~ ~ p = ↵~ b + �~ c ~ a 0 < α < 1 0 < β < 1 ~ p 0 < γ < 1 α + β + γ = 1 ~ ~ c b

  44. Barycentric Coordinates • Interpolate values at the vertices 
 ~ n a ~ n p = ↵~ n a + �~ n b + �~ n c Normalize it before use ~ n p ~ n c ~ n b

  45. Interpolation

  46. Interpolation

  47. Ray-Triangle Intersection • Calculate as fast as possible ( t, α , β , γ ) • Modification of ray-plane intersection • Direct methods • Cramer’s rule • Signed volumes

  48. Ray-Triangle Intersection Cramer’s Rule a + �~ ~ p = ↵~ b + �~ c

  49. Ray-Triangle Intersection Cramer’s Rule o + t ~ a + �~ ~ ~ p = ↵~ b + �~ d c

  50. Ray-Triangle Intersection Cramer’s Rule o + t ~ a + �~ a + �~ (1 − � − � ) ~ b + �~ ~ ~ p = ↵~ b + �~ d c c

  51. Ray-Triangle Intersection Cramer’s Rule o + t ~ a + �~ a + �~ (1 − � − � ) ~ b + �~ ~ ~ p = ↵~ b + �~ d c c o x + td x = (1 − β − γ ) a x + β b x + γ c x o y + td y = (1 − β − γ ) a y + β b y + γ c y o z + td z = (1 − β − γ ) a z + β b z + γ c z 3 equations for 3 unknowns

  52. Ray-Triangle Intersection Cramer’s Rule o + t ~ a + �~ a + �~ (1 − � − � ) ~ b + �~ ~ p = ↵~ ~ b + �~ d c c       a x − b x a x − c x d x β a x − o x a y − b y a y − c y d y γ a y − o y  =      a z − b z a z − c z d z t a Z − o z Solve the equation with Cramer’s Rule 
 ⇣ ⌘ ⇣ ⌘ a, ~ a × ~ ~ b, ~ ~ · ~ det c = b c

  53. Ray-Triangle Intersection Cramer’s Rule • Accept the solution only if t closest > t > 0 1 > β > 0 1 > γ > 0 1 > 1 − β − γ > 0 t closest : the smallest positive t values so far

  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

  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

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

  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

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

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend