# hksfang/pathtracer architecture

> Architecture diagram of the GitHub repository hksfang/pathtracer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hksfang/pathtracer
- Repository: https://github.com/hksfang/pathtracer

## Overview

PathTracer is a desktop path-tracing renderer. Its documented workflow loads an XML scene, renders it, presents it in an interactive viewport, waits for completion, and saves a PNG image. The graph preserves scene description, shading and lighting, photon mapping, sampling, and parallel rendering as distinct concerns. Source excerpts are partial, so uncertain internal wiring—especially scene parsing and image encoding—is omitted.

Main entry points: [`Source/MyRendererV2.cpp`](https://github.com/hksfang/pathtracer/blob/main/Source/MyRendererV2.cpp) (Custom renderer), [`main.cpp`](https://github.com/hksfang/pathtracer/blob/main/main.cpp) (Application entry), [`Include/Provided/renderer.h`](https://github.com/hksfang/pathtracer/blob/main/Include/Provided/renderer.h) (Renderer state), [`Source/Provided/xmlload.cpp`](https://github.com/hksfang/pathtracer/blob/main/Source/Provided/xmlload.cpp) (XML scene loader)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Application flow"]
  node_main["Application entry<br/>[main.cpp]"]
end

subgraph group_scene["Scene and assets"]
  node_scene_loader["XML scene loader<br/>[xmlload.cpp]"]
  node_scene_model["Scene model<br/>[Scene.h]"]
  node_objects["Geometry<br/>[objects.cpp]"]
  node_materials["Materials<br/>[materials.cpp]"]
  node_lights["Lights<br/>[lights.cpp]"]
  node_textures["Textures<br/>[texture.cpp]"]
end

subgraph group_render["Rendering"]
  node_renderer["Custom renderer<br/>[MyRendererV2.cpp]"]
  node_photon_map["Photon mapping<br/>[photonmap.h]"]
  node_shade_info["Shading and rays<br/>[MyShadeInfo.cpp]"]
  node_sampling["Halton sampling<br/>[HaltonPoint2D.h]"]
  node_thread_pool["Render workers<br/>[ThreadPool.cpp]"]
  node_renderer_api["Renderer state<br/>[renderer.h]"]
end

subgraph group_presentation["Presentation"]
  node_viewport["Interactive viewport<br/>[viewport.cpp]"]
  node_image[("Rendered image<br/>[renderer.h]")]
end

node_user(("User"))
node_scene_file["Competition XML"]
node_png["Saved PNG"]

node_user -->|"runs"| node_main
node_main -->|"loads"| node_scene_file
node_main -->|"creates and loads"| node_renderer
node_renderer -->|"loads scene"| node_scene_loader
node_scene_loader -->|"populates"| node_scene_model
node_renderer -->|"intersects rays"| node_objects
node_renderer -->|"samples lighting"| node_lights
node_renderer -->|"samples materials"| node_materials
node_renderer -->|"builds and queries"| node_photon_map
node_renderer -->|"traces secondary rays"| node_shade_info
node_renderer -->|"generates samples"| node_sampling
node_renderer -->|"schedules tiles"| node_thread_pool
node_main -->|"opens"| node_viewport
node_viewport -->|"reads render state"| node_renderer_api
node_renderer -->|"updates"| node_renderer_api
node_renderer_api -->|"holds pixels"| node_image
node_main -->|"waits for completion"| node_renderer
node_main -->|"saves"| node_image
node_image -->|"writes"| node_png

click node_main "https://github.com/hksfang/pathtracer/blob/main/main.cpp"
click node_renderer "https://github.com/hksfang/pathtracer/blob/main/Source/MyRendererV2.cpp"
click node_scene_loader "https://github.com/hksfang/pathtracer/blob/main/Source/Provided/xmlload.cpp"
click node_scene_model "https://github.com/hksfang/pathtracer/blob/main/Include/Provided/Scene.h"
click node_objects "https://github.com/hksfang/pathtracer/blob/main/Source/objects.cpp"
click node_materials "https://github.com/hksfang/pathtracer/blob/main/Source/materials.cpp"
click node_lights "https://github.com/hksfang/pathtracer/blob/main/Source/lights.cpp"
click node_textures "https://github.com/hksfang/pathtracer/blob/main/Source/Provided/texture.cpp"
click node_photon_map "https://github.com/hksfang/pathtracer/blob/main/Include/Provided/photonmap.h"
click node_shade_info "https://github.com/hksfang/pathtracer/blob/main/Source/MyShadeInfo.cpp"
click node_sampling "https://github.com/hksfang/pathtracer/blob/main/Include/HaltonPoint2D.h"
click node_thread_pool "https://github.com/hksfang/pathtracer/blob/main/Source/Concurrency/ThreadPool.cpp"
click node_renderer_api "https://github.com/hksfang/pathtracer/blob/main/Include/Provided/renderer.h"
click node_viewport "https://github.com/hksfang/pathtracer/blob/main/Source/Provided/viewport.cpp"
click node_image "https://github.com/hksfang/pathtracer/blob/main/Include/Provided/renderer.h"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_user toneBlue
class node_scene_loader,node_scene_model,node_objects,node_materials,node_lights,node_textures toneAmber
class node_renderer,node_photon_map,node_shade_info,node_sampling,node_thread_pool,node_renderer_api toneMint
class node_viewport,node_image toneRose
class node_scene_file,node_png toneIndigo
```

## Components

### Application flow

- [Application entry](https://github.com/hksfang/pathtracer/blob/main/main.cpp): `main.cpp`

### Scene and assets

- [XML scene loader](https://github.com/hksfang/pathtracer/blob/main/Source/Provided/xmlload.cpp): `Source/Provided/xmlload.cpp`
- [Scene model](https://github.com/hksfang/pathtracer/blob/main/Include/Provided/Scene.h): `Include/Provided/Scene.h`
- [Geometry](https://github.com/hksfang/pathtracer/blob/main/Source/objects.cpp): `Source/objects.cpp`
- [Materials](https://github.com/hksfang/pathtracer/blob/main/Source/materials.cpp): `Source/materials.cpp`
- [Lights](https://github.com/hksfang/pathtracer/blob/main/Source/lights.cpp): `Source/lights.cpp`
- [Textures](https://github.com/hksfang/pathtracer/blob/main/Source/Provided/texture.cpp): `Source/Provided/texture.cpp`

### Rendering

- [Custom renderer](https://github.com/hksfang/pathtracer/blob/main/Source/MyRendererV2.cpp): `Source/MyRendererV2.cpp`
- [Photon mapping](https://github.com/hksfang/pathtracer/blob/main/Include/Provided/photonmap.h): `Include/Provided/photonmap.h`
- [Shading and rays](https://github.com/hksfang/pathtracer/blob/main/Source/MyShadeInfo.cpp): `Source/MyShadeInfo.cpp`
- [Halton sampling](https://github.com/hksfang/pathtracer/blob/main/Include/HaltonPoint2D.h): `Include/HaltonPoint2D.h`
- [Render workers](https://github.com/hksfang/pathtracer/blob/main/Source/Concurrency/ThreadPool.cpp): `Source/Concurrency/ThreadPool.cpp`
- [Renderer state](https://github.com/hksfang/pathtracer/blob/main/Include/Provided/renderer.h): `Include/Provided/renderer.h`

### Presentation

- [Interactive viewport](https://github.com/hksfang/pathtracer/blob/main/Source/Provided/viewport.cpp): `Source/Provided/viewport.cpp`
- [Rendered image](https://github.com/hksfang/pathtracer/blob/main/Include/Provided/renderer.h): `Include/Provided/renderer.h`

### Other components

- **User**
- **Competition XML**
- **Saved PNG**

## Connections

- User → Application entry: runs
- Application entry → Competition XML: loads
- Application entry → Custom renderer: creates and loads
- Custom renderer → XML scene loader: loads scene
- XML scene loader → Scene model: populates
- Custom renderer → Geometry: intersects rays
- Custom renderer → Lights: samples lighting
- Custom renderer → Materials: samples materials
- Custom renderer → Photon mapping: builds and queries
- Custom renderer → Shading and rays: traces secondary rays
- Custom renderer → Halton sampling: generates samples
- Custom renderer → Render workers: schedules tiles
- Application entry → Interactive viewport: opens
- Interactive viewport → Renderer state: reads render state
- Custom renderer → Renderer state: updates
- Renderer state → Rendered image: holds pixels
- Application entry → Custom renderer: waits for completion
- Application entry → Rendered image: saves
- Rendered image → Saved PNG: writes
