Skip to content

Ray Tracing and Acceleration Data Structure

Viewing Rays

The 3D parametric line from the eye \(\mathbf o\in\mathbb R^3\) to a point \(\mathbf p\in\mathbb R^3\) is

\[p(t) = \mathbf o + t(\mathbf p-\mathbf o) = \mathbf o + t \mathbf d\]

We advance from \(\mathbf o\) along the vector \(\mathbf d := \mathbf p-\mathbf o\) a fractional distance \(t\) to find the point \(\mathbf p\).
\(\mathbf e\) is the ray's origin and \(\mathbf d\) is the ray's direction.

Basic Setup

Given a camera frame \(\mathbf o\), i.e. the eye point or view point, and \(\mathbf u, \mathbf v, \mathbf w\) for the basis. We specify that \(-\mathbf w = view\), \(\mathbf u\) points rightward from the \(view\) and \(\mathbf v\) points upward from the \(view\).

The viewing rays should start on the plane defined by the point \(\mathbf o\) and the vectors \(\mathbf u\) and \(\mathbf v\); the only remaining information required is where on the plane the image is supposed to be. We'll define the image dimensions with four numbers, for the four sides of the image: \(l\) and \(r\) are the positions of the left and right edges of the image, as measured from e along the \(\mathbf u\) direction; and \(b\) and \(t\) are the positions of the bottom and top edges of the image, as measured from e along the \(\mathbf v\) direction. Usually \(l < 0 < r\) and \(b < 0 < t\).

Therefore, the pixel at \((i,j)\) in the raster image has the position

\[u = l + (r-l)(i+0.5) / n_x; v = b + (t-b)(j + 0.5) / n_y\]

Ray casting

For an orthographic view, the ray's origin is generated from the image and are parallel with each other. Therefore, given \(u,v\)

\[\mathbf d(u, v) = -\mathbf w, \mathbf o(u, v) = \mathbf o + u \mathbf u + v\mathbf v\]

For an perspective view, the ray's origin is the camera origin and rays have different directions. Therefore, given \(u,v\)

\[\mathbf d(u, v)= -\mathbf w + u\mathbf u + v\mathbf v, \mathbf o(u, v) = \mathbf o\]