# Introduction to Ray Tracing

### Contents

1. Overview of main rendering algorithms
2. Ray tracing pipeline
3. Recursive ray tracing
4. What is possible

# Rendering

### or image synthesis

The process of generating a more or less photorealistic 2D image from a 3D scene as a view from a camera located in that 3D scene by means of a computer program.

• Efficiency
• Photorealism
• Efficiency
• Photorealism

# Rendering

### or image synthesis

The process of generating a more or less photorealistic 2D image from a 3D scene as a view from a camera located in that 3D scene by means of a computer program.

• Photorealism
• Efficiency
• Efficiency
• Photorealism

# Rendering

### or image synthesis

The process of generating a more or less photorealistic 2D image from a 3D scene as a view from a camera located in that 3D scene by means of a computer program.

• Efficiency
• Photorealism
• Photorealism
• Efficiency

# 4 Essential Building Blocks for Rendering

### Camera

• View point
• Viewing direction
• Field of view
• Resolution
• etc.

### Geometry

3D geometry of all objects in a scene

### Intersection Algorithms

ray - geometry intersection

### Light Sources

• Position
• Color
• Power
• etc.

(Repeatedly reflected light /
indirect illumination)

### Shading

• Color
• Texture
• Absorption
• Reflection
• Refraction
• Subsurface scattering
• etc.

(local property may vary over surface)

# Forward Light Transport

## Scene

• Shoot photons from the light sources into scene
• Reflect at geometry's surfaces (according to some reflection model)
• Wait until they are absorbed or hit the camera sensor (very seldom)
• Nature: massive parallel processing at the speed of light

# Backward Light Transport

## Scene

• Start at the camera

• Trace only paths that might transport light towards the camera

• May try to connect to occluded light sources

• Ray Tracing

# Basic Algorithm Overview

### Camera

`rt::ICamera`

### Geometry

```rt::IPrim
rt::CSolid```

### Intersection Algorithms

`rt::IPrim::intersect(Ray)`

### Light Sources

`rt::ILight`

### Shading

`rt::IShader`

## Scene

`rt::CScene`

## Ray

`rt::Ray`

# Basic Algorithm Overview

Ray-Generation

Ray-Geometry Intersection

Shading

Pixel Color

`rt::ICamera::InitRay()`
```rt::IShader::shade()
rt::ILight::illuminate()```
`rt::IPrim::intersect()`

# Basic Algorithm Overview

Ray-Generation

Ray-Geometry Intersection

Shading

Pixel Color

## Ray Generation

• One ray for every pixel
• Rays from camera origin along camera directions into the scene
`rt::ICamera::InitRay()`
`rt::Ray`

# Basic Algorithm Overview

Ray-Generation

Ray-Geometry Intersection

Shading

Pixel Color

## Ray Intersection

• Check if the ray intersects any geometry in the scene
• Ray-primitive algorithms for most of the geometrical primitives were developed in 1990s
`rt::IPrim::intersect()`
`rt::Ray`

# Basic Algorithm Overview

Ray-Generation

Ray-Geometry Intersection

Shading

Pixel Color

## Shading the Hit-Point

• Determine pixel color
• Energy (color) traveling along primary ray
• Needed:
• Local material color
• Object texture
• Reflection properties
• Local illumination at the hit-point
`rt::IShader::shade()`

# Basic Algorithm Overview

Ray-Generation

Ray-Geometry Intersection

Shading

Pixel Color

## Shading the Hit-Point

• Determine pixel color
• Energy (color) traveling along primary ray
• Needed:
• Local material color
• Object texture
• Reflection properties
• Local illumination at the hit-point
• Compute it through recursive tracing of rays to all the light sources in the scene
`rt::IShader::shade()`

# Basic Algorithm Overview

Ray-Generation

Ray-Geometry Intersection

Shading

Pixel Color

## Shading the Hit-Point

• Local illumination at the hit-point
• Compute it through recursive tracing of rays to all the light sources in the scene
• Check if the hit-point is occluded
• Sum-up the light from all un-occluded light sources
• Multiply it by the primitive's color
`rt::IPrim::intersect()`
`rt::IShader::shade()`

# Basic Algorithm Overview

Ray-Generation

Ray-Geometry Intersection

Shading

Pixel Color

## Shading the Hit-Point

• Local illumination at the hit-point
• Compute it through recursive tracing of rays to all the light sources in the scene
• Check if the hit-point is occluded
• Sum-up the light from all un-occluded light sources
• Multiply it by the primitive's color
`rt::IPrim::intersect()`

Update the resulting pixel color

`rt::IShader::shade()`

# Basic Algorithm Overview

Ray-Generation

Ray-Geometry Intersection

Shading

Pixel Color

## Shading the Hit-Point

• Local illumination at the hit-point
• Compute it through recursive tracing of rays to all the light sources in the scene
• Check if the hit-point is occluded
• Sum-up the light from all un-occluded light sources
• Multiply it by the primitive's color
`rt::ILight::illuminate()`
`rt::IShader::shade()`

# Basic Ray Tracing

## Features:

• Direct lightning
• Hard shadows

primary ray

shadow ray

# Recursive Ray Tracing

## Features:

• Direct lightning
• Hard shadows
• Reflection / Transmission

primary ray

shadow ray

transmitted ray

reflected ray

# Distributed (Stochastic) Ray Tracing

## Features:

• Direct lightning
• Soft shadows
• Glossy Reflection / Transmission
• Anti-aliasing
• Depth of field
• Motion blur
• Spectral rendering

primary ray

shadow ray

transmitted ray

reflected ray

# Path Tracing (Global Illumination)

## Features:

• Direct lightning + Indirect lightning
• Soft shadows
• Glossy Reflection / Transmission
• Anti-aliasing
• Depth of field
• Motion blur
• Spectral rendering

primary ray

shadow ray

transmitted ray

reflected ray

# Ray Tracing Features

## Advantages

### Automatic, simple and intuitive

• Easy to understand and implement
• Delivers “correct“ images by default

### Ray Tracing Incorporates Into a Single Framework

• Hidden surface removal
• Shadow computation
• Exact simulation of reflection and Refraction (Snell’s law)

## Limitations

• Easily gets inefficient for full global illumination computations
• Many reflections (exponential increase in number of rays)
• Indirect illumination requires many rays to sample all incoming  directions

# What is Possible?

### Models Physics of Global Light Transport

Dependable, physically-correct visualization

# What is Possible?

### Huge Models

Logarithmic scaling in scene size

~1 Billion Triangles

12,5 Millions Triangles

# What is Possible?

### Outdoor Environments

90 x 10^12 (trillion) triangles

# Ray Tracing in CG

### In The Past

Only used as an off-line technique

Was computationally far too demanding (minutes to hours per frame)

Believed to not be suitable for a HW implementation

### More Recently

Distributed Real-time ray tracing on PC

RPU: First full HW implementation

Commercial tools: Embree / OSPRey (Intel / CPU), OptiX (Nvidia / GPU)

Complete film industry has switched to ray tracing (Monte-Carlo)

# Rasterization

### Primitive operation of all interactive graphics!

Scan convert a single triangle at a time

### Sequentially processes every triangle individually

Can never access more than one triangle

# Ray Tracing

### Inspired by Nature!

Follow the path of many photons

Record those hitting the film in a camera

Made with Slides.com