Welcome! Todays Agenda: Primitives (contd.) Ray Tracing - - PowerPoint PPT Presentation

welcome today s agenda
SMART_READER_LITE
LIVE PREVIEW

Welcome! Todays Agenda: Primitives (contd.) Ray Tracing - - PowerPoint PPT Presentation

INFOGR Computer Graphics Jacco Bikker - April-July 2016 - Lecture 3: Ray Tracing (Introduction) Welcome! Todays Agenda: Primitives (contd.) Ray Tracing Intersections Assignment 2 Textures INFOGR


slide-1
SLIDE 1

INFOGR – Computer Graphics

Jacco Bikker - April-July 2016 - Lecture 3: “Ray Tracing (Introduction)”

Welcome!

slide-2
SLIDE 2

Today’s Agenda:

  • Primitives (contd.)
  • Ray Tracing
  • Intersections
  • Assignment 2
  • Textures
slide-3
SLIDE 3

INFOGR – Lecture 2 – “Graphics Fundamentals” 3

Previously in INFOGR

slide-4
SLIDE 4

Primitives

Implicit curves: 𝑔 𝑦, 𝑧 = 0 Circle: 𝑦2 + 𝑧2 − 𝑠2 = 0 Line: 𝐵𝑦 + 𝐶𝑧 + 𝐷 = 0 Slope-intersect form of a line: 𝑧 = 𝑏𝑦 + 𝑑 Normal of line 𝐵𝑦 + 𝐶𝑧 + 𝐷 = 0: 𝑂 = 𝐵 𝐶 Distance of line 𝐵𝑦 + 𝐶𝑧 + 𝐷 = 0 to the origin: |𝐷| (if 𝑂 = 1).

INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 4

slide-5
SLIDE 5

Primitives

Parametric representation

Parametric curve: 𝑦 𝑧 = 𝑕(𝑢) ℎ(𝑢) Example: line 𝑞0 = 𝑦𝑞0, 𝑧𝑞0 , 𝑞1 = (𝑦𝑞1, 𝑧𝑞1) 𝑦 𝑧 = 𝑦𝑞0 𝑧𝑞0 + 𝑢 𝑦𝑞1 − 𝑦𝑞0 𝑧𝑞1 − 𝑧𝑞0 Or 𝑞 𝑢 = 𝑞0 + 𝑢 𝑞1 − 𝑞0 , 𝑢 ∈ ℝ. p0 p1 In this example: 𝑞0 is the support vector; 𝑞1 − 𝑞0 is the direction vector. INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 5

slide-6
SLIDE 6

Slope-intercept:

𝑧 = 𝑏𝑦 + 𝑑 Implicit representation: −𝑏𝑦 + 𝑧 − 𝑑 = 0 𝐵𝑦 + 𝐶𝑧 + 𝐷 = 0 Parametric representation: 𝑞 𝑢 = 𝑞0 + 𝑢 𝑞1 − 𝑞0 p0 p1 ∆𝑦 ∆𝑧

Primitives

INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 6

slide-7
SLIDE 7

Circle - parametric

𝑦 𝑧 = 𝑦𝑑 + 𝑠 cos 𝜚 𝑧𝑑 + 𝑠 sin 𝜚

𝜚 = “phi”

𝜚 c 𝜚 𝑠 𝑦 𝑧 cos 𝜚 = 𝑦 𝑠 𝑡𝑗𝑜 𝜚 = 𝑧 𝑠 𝑢𝑏𝑜 𝜚 = 𝑧 𝑦

adjacent

  • pposite

SOH CAH TOA

Primitives

INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 7

slide-8
SLIDE 8

Circle – sphere (implicit)

Recall: the implicit representation for a circle with radius 𝑠 and center 𝑑 is: 𝑦 − 𝑑𝑦 2 + 𝑧 − 𝑑𝑧 2 − 𝑠2 = 0

  • r: ∥ p − c ∥ 2 − 𝑠2 = 0  ∥ 𝑞 − 𝑑 ∥ = 𝑠

In ℝ3, we get: 𝑦 − 𝑑𝑦

2 + 𝑧 − 𝑑𝑧 2 + 𝑨 − 𝑑𝑨 2 − 𝑠2 = 0

  • r: ∥ 𝑞 − 𝑑 ∥= 𝑠

c 𝑞

Primitives

INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 8

slide-9
SLIDE 9

Line – plane (implicit)

Recall: the implicit representation for a line is: 𝐵𝑦 + 𝐶𝑧 + 𝐷 = 0 In ℝ3, we get a plane: 𝐵𝑦 + 𝐶𝑧 + 𝐷𝑨 + 𝐸 = 0 p1 p2

Primitives

INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 9

slide-10
SLIDE 10

Parametric surfaces

A parametric surface in ℝ3 needs two parameters: 𝑦 = 𝑔(𝑣, 𝑤), 𝑧 = 𝑕(𝑣, 𝑤), 𝑨 = ℎ(𝑣, 𝑤). For example, a sphere: 𝑦 = 𝑠 cos 𝜚 sin 𝜄, 𝑧 = 𝑠 sin 𝜚 sin 𝜄, 𝑨 = 𝑠 cos 𝜄. Doesn’t look very convenient (compared to the implicit form), but it will prove useful for texture mapping. 𝜚 𝜄

Primitives

INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 10

slide-11
SLIDE 11

Parametric planes

Recall the parametric line definition: 𝑞 𝑢 = 𝑞0 + 𝑢 𝑞1 − 𝑞0 For a plane, we need to parameters: 𝑞 𝑡, 𝑢 = 𝑞0 + 𝑡 𝑞1 − 𝑞0 + 𝑢(𝑞2 − 𝑞0)

  • r:

𝑞 𝑡, 𝑢 = 𝑞0 + 𝑡 𝑤 + 𝑢𝑥 where:

  • 𝑞0 is a point on the plane;
  • 𝑤 and 𝑥 are two linearly independent

vectors on the plane;

  • 𝑡, 𝑢 ∈ ℝ.

y

z

x

𝑤 𝑥 𝑞0

Primitives

INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 11

slide-12
SLIDE 12

Today’s Agenda:

  • Primitives (contd.)
  • Ray Tracing
  • Intersections
  • Assignment 2
  • Textures
slide-13
SLIDE 13
slide-14
SLIDE 14

PART 1: Introduction (today) PART 2: Shading (May 10) PART 3: Reflections, refraction, absorption (May 17) PART 4: Path Tracing (June 21)

INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 14

Ray Tracing

slide-15
SLIDE 15

Ray Tracing: World space

  • Geometry
  • Eye
  • Screen plane
  • Screen pixels
  • Primary rays
  • Intersections
  • Point light
  • Shadow rays

Light transport

  • Extension rays

Light transport INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 15

Ray Tracing

slide-16
SLIDE 16

Ray Tracing: World space

  • Geometry
  • Eye
  • Screen plane
  • Screen pixels
  • Primary rays
  • Intersections
  • Point light
  • Shadow rays

Light transport

  • Extension rays

Light transport INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 16

Ray Tracing

slide-17
SLIDE 17

Ray Tracing

INFOGR – Lecture 8 – “Ray Tracing”

slide-18
SLIDE 18

Ray Tracing: World space

  • Geometry
  • Eye
  • Screen plane
  • Screen pixels
  • Primary rays
  • Intersections
  • Point light
  • Shadow rays

Light transport

  • Extension rays

Light transport Note: We are calculating light transport backwards. INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 18

Ray Tracing

slide-19
SLIDE 19

Ray Tracing

INFOGR – Lecture 8 – “Ray Tracing”

slide-20
SLIDE 20

INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 20

Ray Tracing

slide-21
SLIDE 21

INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 21

Ray Tracing

slide-22
SLIDE 22

Physical basis

Ray tracing uses ray optics to simulate the behavior of light in a virtual environment. It does so by finding light transport paths:

  • From the ‘eye’
  • Through a pixel
  • Via scene surfaces
  • To one or more light sources.

At each surface, the light is modulated. The final value is deposited at the pixel (simulating reception by a sensor). INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 22

Ray Tracing

slide-23
SLIDE 23

Today’s Agenda:

  • Primitives (contd.)
  • Ray Tracing
  • Intersections
  • Assignment 2
  • Textures
slide-24
SLIDE 24

Intersections

Ray definition

A ray is an infinite line with a start point: 𝑞(𝑢) = 𝑃 + 𝑢𝐸, where 𝑢 > 0.

struct Ray { float3 O; // ray origin float3 D; // ray direction float t; // distance };

The ray direction is generally normalized. INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 24

slide-25
SLIDE 25

Ray setup

A ray is initially shot through a pixel on the screen plane. The screen plane is defined in world space: Camera position: E = (0,0,0) View direction: 𝑊 Screen center: C = 𝐹 + 𝑒𝑊 Screen corners: p0 = 𝐷 + −1, −1,0 , 𝑞1 = 𝐷 + 1, −1,0 , 𝑞2 = 𝐷 + (−1,1,0) From here:

  • Change FOV by altering 𝑒;
  • Transform camera by multiplying E, 𝑞0, 𝑞1, 𝑞2 with the camera matrix.

INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 25

Intersect

slide-26
SLIDE 26

Ray setup

Point on the screen: 𝑞 𝑣, 𝑤 = 𝑞0 + 𝑣 𝑞1 − 𝑞0 + 𝑤(𝑞2 − 𝑞0) Ray direction (before normalization): 𝐸 = 𝑞 𝑣, 𝑤 − 𝐹 Ray origin: 𝑃 = 𝐹 𝑞0 𝑞1 𝑞2 𝐹 INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 26

Intersect

𝑞2 − 𝑞0

slide-27
SLIDE 27

Ray intersection

Given a ray 𝑞(𝑢) = 𝑃 + 𝑢𝐸, we determine the smallest intersection distance 𝑢 by intersecting the ray with each of the primitives in the scene. Ray / plane intersection: Plane: p ∙ 𝑂 + 𝑒 = 0 Ray: 𝑞(𝑢) = 𝑃 + 𝑢𝐸 Substituting for 𝑞(𝑢), we get 𝑃 + 𝑢𝐸 ∙ 𝑂 + 𝑒 = 0 𝑢 = −(𝑃 ∙ 𝑂 + 𝑒)/(𝐸 ∙ 𝑂) 𝑄 = 𝑃 + 𝑢𝐸 𝑞0 𝑞1 𝑞2 𝐹 INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 27

Intersect

slide-28
SLIDE 28

Intersect

Ray intersection

Ray / sphere intersection: Sphere: 𝑞 − 𝐷 ∙ 𝑞 − 𝐷 − 𝑠2 = 0 Ray: 𝑞(𝑢) = 𝑃 + 𝑢𝐸 Substituting for 𝑞(𝑢), we get 𝑃 + 𝑢𝐸 − 𝐷 ∙ 𝑃 + 𝑢𝐸 − 𝐷 − 𝑠2 = 0 𝐸 ∙ 𝐸 𝑢2 + 2𝐸 ∙ 𝑃 − 𝐷 𝑢 + (𝑃 − 𝐷)2−𝑠2 = 0 𝑏𝑦2 + 𝑐𝑦 + 𝑑 = 0 → 𝑦 = −𝑐 ± 𝑐2 − 4𝑏𝑑 2𝑏 𝑏 = 𝐸 ∙ 𝐸 𝑐 = 2𝐸 ∙ (𝑃 − 𝐷) 𝑑 = 𝑃 − 𝐷 ∙ 𝑃 − 𝐷 − 𝑠2 𝑞0 𝑞1 𝑞2 𝐹 Negative: no intersections INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 28

slide-29
SLIDE 29

Ray Intersection

Efficient ray / sphere intersection:

void Sphere::IntersectSphere( Ray ray ) { vec3 c = this.pos - ray.O; float t = dot( c, ray.D ); vec3 q = c - t * ray.D; float p2 = dot( q, q ); if (p2 > sphere.r2) return; t -= sqrt( sphere.r2 – p2 ); if ((t < ray.t) && (t > 0)) ray.t = t; // or: ray.t = min( ray.t, max( 0, t ) ); }

Note: This only works for rays that start outside the sphere. O 𝐸 𝑑 t 𝑟 𝑞2

Intersect

INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 29

slide-30
SLIDE 30

Today’s Agenda:

  • Primitives (contd.)
  • Ray Tracing
  • Intersections
  • Assignment 2
  • Textures
slide-31
SLIDE 31

Deadline assignment 1:

Wednesday May 11, 23.59 Assignment 2: ”Write a basic ray tracer.”

  • Using the template
  • In a 1024x512 window
  • Two views, each 512x512
  • Left view: 3D
  • Right view: 2D slice

INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 31

Assignment 2

slide-32
SLIDE 32

Assignment 2: ”Write a basic ray tracer.” Steps:

  • 1. Create a Camera class; default: position (0,0,0),

looking at (0,0,-1).

  • 2. Create a Ray class
  • 3. Create a Primitive class and derive from it a

Sphere and a Plane class

  • 4. Add code to the Camera class to create a primary

ray for each pixel

  • 5. Implement Intersect methods for the primitives
  • 6. Per pixel, find the nearest intersection and plot a

pixel

  • 7. Add controls to move and rotate the camera
  • 8. Add a checkerboard pattern to the floor plane.
  • 9. Add reflections and shadow rays (next lecture).

INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 32

Assignment 2

For y = 0, visualize every 10th ray Visualize the intersection points

slide-33
SLIDE 33

Extra points:

  • Add additional primitives, e.g.:
  • Triangle, quad, box
  • Torus, cylinder
  • Fractal
  • Add textures to all primitives
  • Add a sky dome
  • Add refraction and absorption (next lecture)
  • One extra point for the fastest ray tracer
  • One extra point for the smallest ray tracer

meeting the minimum requirements. INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 33

Assignment 2

slide-34
SLIDE 34

Official:

  • Full details in the official assignment 2 document,

available today from the website.

  • Deadline: May 31st 2016, 23:59.
  • Small exhibition of noteworthy entries on

Thursday June 2nd and on the website. INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 34

Assignment 2

slide-35
SLIDE 35

Today’s Agenda:

  • Primitives (contd.)
  • Ray Tracing
  • Intersections
  • Assignment 2
  • Textures
slide-36
SLIDE 36

Textures

INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 36

Texturing a Plane

Given a plane: 𝑧 = 0 (i.e., with a normal vector (0,1,0) ). Two vectors on the plane define a basis: 𝑣 = (1,0,0) and 𝑤 = (0,0,1). Using these vectors, any point on the plane can be reached: 𝑄 = λ1𝑣 + λ2 𝑤. We can now use λ1, λ2to define a color at P: 𝐺(λ1, λ2) = ⋯ . 𝑣 𝑤 P

slide-37
SLIDE 37

Textures

Example: 𝐺(λ1, λ2) = sin(λ1) Another example: 𝐺(λ1, λ2) = ( int (2 ∗ λ1) + (int)λ2) & 1 INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 37

slide-38
SLIDE 38

Textures

Other examples (not explained here): Perlin noise Details: http://www.noisemachine.com/talk1 Voronoi / Worley noise Details: “A cellular texture basis function”, S. Worley, 1996. INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 38

slide-39
SLIDE 39

Textures

INFOGR – Lecture 3 – “Geometry”

slide-40
SLIDE 40

Textures

Obviously, not all textures can be generated procedurally. For the generic case, we lookup the color value in a pixel buffer. 𝑦 𝑧 = 𝑄 ∙ 𝑣 𝑄 ∙ 𝑤 Note that we find the pixel to read based on 𝑄; we don’t find a ‘𝑄’ for every pixel of the texture. 𝑣 𝑤 P ∗ 𝑈𝑥𝑗𝑒𝑢ℎ 𝑈ℎ𝑓𝑗𝑕ℎ𝑢

255 255

INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 40

slide-41
SLIDE 41

Textures

Retrieving a pixel from a texture: 𝑦 𝑧 = 𝑄 ∙ 𝑣 𝑄 ∙ 𝑤 ∗ 𝑈𝑥𝑗𝑒𝑢ℎ 𝑈ℎ𝑓𝑗𝑕ℎ𝑢 We don’t want to read outside the texture. To prevent this, we have two options:

  • 1. Clamping
  • 2. Tiling

Tiling is efficiently achieved using a bitmask. This requires texture dimensions that are a power of 2.

255 255

𝑦 𝑧 = 𝑑𝑚𝑏𝑛𝑞(𝑄 ∙ 𝑣, 0, 1) 𝑑𝑚𝑏𝑛𝑞(𝑄 ∙ 𝑤, 0,1) ∗ 𝑈𝑥𝑗𝑒𝑢ℎ 𝑈ℎ𝑓𝑗𝑕ℎ𝑢 𝑦 𝑧 = 𝑔𝑠𝑏𝑑(𝑄 ∙ 𝑣) 𝑔𝑠𝑏𝑑(𝑄 ∙ 𝑤) ∗ 𝑈𝑥𝑗𝑒𝑢ℎ 𝑈ℎ𝑓𝑗𝑕ℎ𝑢 INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 41

slide-42
SLIDE 42

Textures

Texture mapping: oversampling INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 42

slide-43
SLIDE 43

Textures

Texture mapping: undersampling INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 43

slide-44
SLIDE 44

Textures

Fixing oversampling

Oversampling: reading the same pixel from a texture multiple times. Symptoms: blocky textures. Remedy: bilinear interpolation: Instead of clamping the pixel location to the nearest pixel, we read from four pixels. 𝑥𝑞1 : (1 − 𝑔𝑠𝑏𝑑(𝑦)) ∗ (1 − 𝑔𝑠𝑏𝑑(𝑧)) 𝑥𝑞2 : 𝑔𝑠𝑏𝑑 𝑦 ∗ (1 − 𝑔𝑠𝑏𝑑 𝑧 ) 𝑥𝑞3 : 1 − 𝑔𝑠𝑏𝑑 𝑦 ∗ 𝑔𝑠𝑏𝑑(𝑧) 𝑥𝑞4 : 1 − (𝑥𝑄1 + 𝑥𝑄2 + 𝑥𝑄3) INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 44

slide-45
SLIDE 45

Textures

Fixing oversampling

INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 45

slide-46
SLIDE 46

Textures

Fixing undersampling

Undersampling: skipping pixels while reading from a texture. Symptoms: Moiré, flickering, noise. Remedy: MIP-mapping. The texture is reduced to 25% by averaging 2x2 pixels. This is repeated until a 1x1 image remains. When undersampling occurs, we switch to the next MIP level. INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 46

slide-47
SLIDE 47

Textures

INFOGR – Lecture 3 – “Geometry”

slide-48
SLIDE 48

Textures

INFOGR – Lecture 3 – “Geometry”

slide-49
SLIDE 49

Textures

Trilinear interpolation: blending between MIP levels. INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 49

slide-50
SLIDE 50

Today’s Agenda:

  • Primitives (contd.)
  • Ray Tracing
  • Intersections
  • Assignment 2
  • Textures
slide-51
SLIDE 51

INFOGR – Computer Graphics

Jacco Bikker - April-July 2016 - Lecture 3: “Ray Tracing (Introduction)”

END of “Ray Tracing (Introduction)”

next lecture: “Ray Tracing (Part 2)”