Lecture #07. Ray intersection

Computer graphics in Game development

Ivan Belyavtsev

30.09.2022

Intersection function

Intersection function returns whether or not ray intersects an object. If the intersection exists, the intersection function will return an intersection point [1], [2]

From: [1]

Möller-Trumbore algorithm

From: [3]

Möller-Trumbore algorithm: ray definition

From ray definition: \[X = P+t\vec{\omega}\]

From barycentric coordinates: \[X = (1 - u - v)V_0 + uV_1 + vV_2\]

\[P+t\vec{\omega} = (1 - u - v)V_0 + uV_1 + vV_2\]

[4]

Möller-Trumbore algorithm: linear equations

\[[-\vec{\omega}, V_1-V_0, V_2-V_0]\begin{bmatrix} t \\ u \\ v \end{bmatrix} = P - V_0\]

[4]

Möller-Trumbore algorithm: Cramer’s rule

\(\vec{E_1} = V_1-V_0\), \(\vec{E_2} = V_2-V_0\), \(\vec{T} = P-V_0\)

\[\begin{bmatrix} t \\ u \\ v \end{bmatrix} = \frac{1}{|-\vec{\omega}, \vec{E_1}, \vec{E_2}|} \begin{bmatrix} |\vec{T} , \vec{E_1}, \vec{E_2}| \\ |-\vec{\omega}, \vec{T} , \vec{E_2}| \\ |-\vec{\omega}, \vec{E_1}, \vec{T}| \end{bmatrix}\]

[4]

Möller-Trumbore algorithm: Triple product

\(|\vec{A}, \vec{B}, \vec{C}| = - (\vec{A}\times\vec{C})\cdot\vec{B} = - (\vec{C}\times\vec{B})\cdot\vec{A}\)

\[\begin{bmatrix} t \\ u \\ v \end{bmatrix} = \frac{1}{(\vec{\omega}\times \vec{E_2}) \cdot \vec{E_1} } \begin{bmatrix} (\vec{T} \times \vec{E_1}) \cdot \vec{E_2} \\ (\vec{\omega} \times \vec{E_2}) \cdot \vec{T} \\ (\vec{T} \times \vec{E_1}) \cdot \vec{\omega} \end{bmatrix}\]

[4]

Lab: 2.02 Ray triangle intersection

  1. Implement set_vertex_buffers and set_index_buffers of raytracer class
  2. Implement a constructor of triangle struct
  3. Implement an intersection_shader method of raytracer class
  4. Adjust trace_ray method of raytracer class to traverse geometry and call a closest hit shader
  5. Fill triangles vector in build_acceleration_structure of raytracer class
  6. Add closest_hit_shader to raytracer class to return diffuse color

References

1.
Lefrançois M.-K., Gautron P. DX12 raytracing tutorial - part 2 [Electronic resource]. URL: https://developer.nvidia.com/rtx/raytracing/dxr/DX12-Raytracing-tutorial-Part-2.
2.
Parker S.G. et al. OptiX: A general purpose ray tracing engine // ACM SIGGRAPH 2010 papers. New York, NY, USA: Association for Computing Machinery, 2010.
3.
McGuire M. The graphics codex. 2.14 ed. Casual Effects, 2018.
4.
Möller T., Trumbore B. Fast, minimum storage ray-triangle intersection // J. Graph. Tools. USA: A. K. Peters, Ltd., 1997. Vol. 2, № 1. P. 21–28.