Computer graphics in Game development

Ivan Belyavtsev

01.10.2022

In the case of 1 ray per pixel without additional ray casting the complexity of ray tracing is rays number * (triangles number * MT algorithm cost + Closest Hit cost)

[2]

- Traversing bigger chunks of geometry at the same time
- Reducing the cost of the MT algorithm
- Using non-linear data structures

Obj file was parsed to a vector of shapes. Each shape has its own vertex and index buffers. Let’s use the each shape as a single chunk for traversing. How we can find the shape-ray intersection?

```
float3 invRaydir = float3(1.0) / ray.direction;
float3 t0 = (aabb_max - ray.position) * invRaydir;
float3 t1 = (aabb_min - ray.position) * invRaydir;
float3 tmin = min(t0, t1);
float3 tmax = max(t0, t1);
return maxelem(tmin) <= minelem(tmax);
```

[3]

- Top-level acceleration structures (TLAS)
- Bottom-level acceleration structures (BLAS)

**Surface area heuristic** (SAH):

\[C(A, B) = t_{trav}+p_{A}\sum_{i=1}^{N_A}t_{int}(a_i) + p_{B}\sum_{i=1}^{N_B}t_{int}(b_i)\]

where \(C\) - cost of traversing the node, \(p_{A}\) and \(p_{B}\) are the probabilities that the ray passes through the subvolumes \(A\) and \(B\) [4]

- Implement
`aabb`

class - Implement
`build_acceleration_structure`

method of`raytracer`

class - Adjust
`trace_ray`

method of`raytracer`

class to traverse the acceleration structure - Adjust
`ray_tracing_renderer`

class to build the acceleration structure

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.

Pharr M., Jakob W., Humphreys G. Physically
based rendering: From theory to implementation [Electronic resource].
2021. URL: https://pbr-book.org/.