Building a Ray Tracer

Not done yet!!!!

Vectors
Ray tracing
Path tracing

Vectors

Normalize

\hat{v} = \frac{\vec{v}}{\|\vec{v}\|}
v^=vv

Dot Product

\vec{v} \cdot \vec{w} = \|\vec{v}\| \|\vec{w}\|\cos{\theta}
vw=vwcosθ
\vec{v} \cdot \vec{w} = v_x w_x + v_y w_y + v_z w_z
vw=vxwx+vywy+vzwz
\rightarrow \vec{v} \cdot \vec{v} = \|\vec{v}\|
vv=v

Special Cases

\vec{v}
v
\vec{w} = 90^\circ \rightarrow \vec{v} \cdot \vec{w} = 0
w=90vw=0

The angle between

and

The dot product of a vector and itself

The dot product of a unit vector and itself

\rightarrow \vec{v} \cdot \vec{v} = 1
vv=1

Cross Product

\|\vec{v} \times \vec{w}\| = \|\vec{v}\| \|\vec{w}\| \sin{\theta}
v×w=vwsinθ
\vec{v} \times \vec{w} = (v_y w_z - v_z w_y)\vec{x} + (v_z w_x - v_x w_z)\vec{y} + (v_x w_y - v_y w_x)\vec{z}
v×w=(vywzvzwy)x+(vzwxvxwz)y+(vxwyvywx)z

Ray tracing

Summary

  • Algorithm
  • Ray-Scene Intersection
  • Ray Intersections
  • Lighting
  • Optimizations

General Algorithm

Image RayCast(Camera camera, Scene scene, int width, int height) {
  Image img = new Image(width, height);
  for (int i = 0; i < width; i++) {
    for (int j = 0; j < height; j++) {
      Ray ray = ConstructRayThroughPixel(camera, i, j);
      Intersection hit = FindIntersection(ray, scene);
      img[i][j] = GetColor(hit);
    }
  }
  return img;
}
\text{Ray} = P_0 + tV
Ray=P0+tV

Ray Intersections

Intersection FindIntersection(Ray ray, Scene scene) {
  min_t = inf;
  min_shape = NULL;
  for each primitive in scene {
    t = Intersect(ray, primitive);
    if (t > 0 and t < min_t) {
      min_shape = primitive;
      min_t = t;
    }
  }
  return Intersection(min_t, min_shape);
}

Path tracing

Why do we care?

Need I say more?

Sources

http://www.cs.virginia.edu/~gfx/Courses/2014/IntroGraphics/lectures/6-Ray%20Casting.pdf

http://www.cs.virginia.edu/~gfx/Courses/2014/IntroGraphics/lectures/7-Accelerate.pdf

http://www.cs.virginia.edu/~gfx/Courses/2014/IntroGraphics/lectures/8-DirectIllum.pdf

http://www.cs.virginia.edu/~gfx/Courses/2014/IntroGraphics/lectures/9-GlobalIllum.pdf

Building a Ray Tracer

By Michael Recachinas

Building a Ray Tracer

  • 244