Ivan Belyavtsev
10.06.2022
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 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]
\[[-\vec{\omega}, V_1-V_0, V_2-V_0]\begin{bmatrix} t \\ u \\ v \end{bmatrix} = P - V_0\]
[4]
\(\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]
\(|\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]
set_vertex_buffers
and
set_index_buffers
of raytracer
classtriangle
structintersection_shader
method of
raytracer
classtrace_ray
method of raytracer
class
to traverse geometry and call a closest hit shaderclosest_hit_shader
to raytracer
class
to return diffuse color