# muttimarcello/tiny_renderer architecture

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

- Interactive diagram: https://gitdiagram.com/muttimarcello/tiny_renderer
- Repository: https://github.com/muttimarcello/tiny_renderer

## Overview

Tiny Renderer is a compact C++ ray-tracing application. Its workflow is defined in `src/main.cpp`: configure a camera, objects, materials, scene, image, and directional light; call the renderer; then write a PPM image. The rendering and shading implementation is concentrated in `src/tools.cpp`, with types and interfaces declared in `src/tools.hpp`. The README documents sampling, recursive light transport, tone mapping, and multithreading; omitted source excerpts limit verification of some internal calls, so those links are documented rather than inferred from module names.

Main entry points: [`src/main.cpp`](https://github.com/muttimarcello/tiny_renderer/blob/main/src/main.cpp) (Render Setup), [`src/tools.cpp`](https://github.com/muttimarcello/tiny_renderer/blob/main/src/tools.cpp) (Recursive Ray Shading)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Application"]
  node_entry["Render Setup<br/>[main.cpp]"]
end

subgraph group_scene["Scene Model"]
  node_camera["Pinhole Camera<br/>[tools.cpp]"]
  node_geometry["Sphere Geometry<br/>[tools.cpp]"]
  node_scene_list["Hittable Scene<br/>[tools.cpp]"]
  node_diffuse["Lambertian Material<br/>[tools.cpp]"]
  node_metal["Metal Material<br/>[tools.cpp]"]
  node_lighting["Directional Light<br/>[tools.cpp]"]
end

subgraph group_render["Rendering"]
  node_renderer["Render Scheduler<br/>[tools.cpp]"]
  node_sampling["Pixel Sampling<br/>[tools.cpp]"]
  node_tracing["Recursive Ray Shading<br/>[tools.cpp]"]
  node_shadows["Shadow Testing<br/>[tools.cpp]"]
  node_parallel["Thread Workers<br/>[tools.cpp]"]
  node_math["Ray and Math Types<br/>[tools.hpp]"]
end

subgraph group_output["Image Output"]
  node_image[("Image Buffer<br/>[tools.cpp]")]
  node_tonemap["Tone Mapping<br/>[tools.cpp]"]
  node_ppm["PPM Writer<br/>[tools.cpp]"]
end

node_user(("Renderer User"))

node_user -->|"runs"| node_entry
node_entry -->|"configures"| node_camera
node_entry -->|"creates"| node_geometry
node_entry -->|"creates"| node_diffuse
node_entry -->|"creates"| node_metal
node_entry -->|"populates"| node_scene_list
node_entry -->|"creates"| node_lighting
node_entry -->|"allocates"| node_image
node_entry -->|"calls"| node_renderer
node_renderer -.->|"uses"| node_sampling
node_renderer -->|"dispatches"| node_parallel
node_parallel -.->|"renders pixels"| node_sampling
node_sampling -.->|"generates rays"| node_camera
node_sampling -.->|"evaluates rays"| node_tracing
node_tracing -->|"intersects"| node_scene_list
node_scene_list -->|"queries objects"| node_geometry
node_tracing -->|"uses illumination"| node_lighting
node_tracing -->|"tests visibility"| node_shadows
node_shadows -->|"casts shadow ray"| node_scene_list
node_tracing -.->|"scatters via"| node_diffuse
node_tracing -.->|"scatters via"| node_metal
node_tracing -->|"recurses"| node_tracing
node_sampling -.->|"stores pixels"| node_image
node_sampling -.->|"converts radiance"| node_tonemap
node_tonemap -.->|"encodes pixels"| node_image
node_entry -->|"writes image"| node_ppm
node_ppm -->|"reads buffer"| node_image

click node_entry "https://github.com/muttimarcello/tiny_renderer/blob/main/src/main.cpp"
click node_camera "https://github.com/muttimarcello/tiny_renderer/blob/main/src/tools.cpp"
click node_geometry "https://github.com/muttimarcello/tiny_renderer/blob/main/src/tools.cpp"
click node_scene_list "https://github.com/muttimarcello/tiny_renderer/blob/main/src/tools.cpp"
click node_diffuse "https://github.com/muttimarcello/tiny_renderer/blob/main/src/tools.cpp"
click node_metal "https://github.com/muttimarcello/tiny_renderer/blob/main/src/tools.cpp"
click node_lighting "https://github.com/muttimarcello/tiny_renderer/blob/main/src/tools.cpp"
click node_renderer "https://github.com/muttimarcello/tiny_renderer/blob/main/src/tools.cpp"
click node_sampling "https://github.com/muttimarcello/tiny_renderer/blob/main/src/tools.cpp"
click node_tracing "https://github.com/muttimarcello/tiny_renderer/blob/main/src/tools.cpp"
click node_shadows "https://github.com/muttimarcello/tiny_renderer/blob/main/src/tools.cpp"
click node_parallel "https://github.com/muttimarcello/tiny_renderer/blob/main/src/tools.cpp"
click node_math "https://github.com/muttimarcello/tiny_renderer/blob/main/src/tools.hpp"
click node_image "https://github.com/muttimarcello/tiny_renderer/blob/main/src/tools.cpp"
click node_tonemap "https://github.com/muttimarcello/tiny_renderer/blob/main/src/tools.cpp"
click node_ppm "https://github.com/muttimarcello/tiny_renderer/blob/main/src/tools.cpp"

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_entry,node_user toneBlue
class node_camera,node_geometry,node_scene_list,node_diffuse,node_metal,node_lighting toneAmber
class node_renderer,node_sampling,node_tracing,node_shadows,node_parallel,node_math toneMint
class node_image,node_tonemap,node_ppm toneRose
```

## Components

### Application

- [Render Setup](https://github.com/muttimarcello/tiny_renderer/blob/main/src/main.cpp): `src/main.cpp`

### Scene Model

- [Pinhole Camera](https://github.com/muttimarcello/tiny_renderer/blob/main/src/tools.cpp): `src/tools.cpp`
- [Sphere Geometry](https://github.com/muttimarcello/tiny_renderer/blob/main/src/tools.cpp): `src/tools.cpp`
- [Hittable Scene](https://github.com/muttimarcello/tiny_renderer/blob/main/src/tools.cpp): `src/tools.cpp`
- [Lambertian Material](https://github.com/muttimarcello/tiny_renderer/blob/main/src/tools.cpp): `src/tools.cpp`
- [Metal Material](https://github.com/muttimarcello/tiny_renderer/blob/main/src/tools.cpp): `src/tools.cpp`
- [Directional Light](https://github.com/muttimarcello/tiny_renderer/blob/main/src/tools.cpp): `src/tools.cpp`

### Rendering

- [Render Scheduler](https://github.com/muttimarcello/tiny_renderer/blob/main/src/tools.cpp): `src/tools.cpp`
- [Pixel Sampling](https://github.com/muttimarcello/tiny_renderer/blob/main/src/tools.cpp): `src/tools.cpp`
- [Recursive Ray Shading](https://github.com/muttimarcello/tiny_renderer/blob/main/src/tools.cpp): `src/tools.cpp`
- [Shadow Testing](https://github.com/muttimarcello/tiny_renderer/blob/main/src/tools.cpp): `src/tools.cpp`
- [Thread Workers](https://github.com/muttimarcello/tiny_renderer/blob/main/src/tools.cpp): `src/tools.cpp`
- [Ray and Math Types](https://github.com/muttimarcello/tiny_renderer/blob/main/src/tools.hpp): `src/tools.hpp`

### Image Output

- [Image Buffer](https://github.com/muttimarcello/tiny_renderer/blob/main/src/tools.cpp): `src/tools.cpp`
- [Tone Mapping](https://github.com/muttimarcello/tiny_renderer/blob/main/src/tools.cpp): `src/tools.cpp`
- [PPM Writer](https://github.com/muttimarcello/tiny_renderer/blob/main/src/tools.cpp): `src/tools.cpp`

### Other components

- **Renderer User**

## Connections

- Renderer User → Render Setup: runs (evidence: `README.md`)
- Render Setup → Pinhole Camera: configures (evidence: `src/main.cpp`)
- Render Setup → Sphere Geometry: creates (evidence: `src/main.cpp`)
- Render Setup → Lambertian Material: creates (evidence: `src/main.cpp`)
- Render Setup → Metal Material: creates (evidence: `src/main.cpp`)
- Render Setup → Hittable Scene: populates (evidence: `src/main.cpp`)
- Render Setup → Directional Light: creates (evidence: `src/main.cpp`)
- Render Setup → Image Buffer: allocates (evidence: `src/main.cpp`)
- Render Setup → Render Scheduler: calls (evidence: `src/main.cpp`)
- Render Scheduler → Pixel Sampling: uses (evidence: `README.md`)
- Render Scheduler → Thread Workers: dispatches (evidence: `src/tools.cpp`)
- Thread Workers → Pixel Sampling: renders pixels (evidence: `README.md`)
- Pixel Sampling → Pinhole Camera: generates rays (evidence: `README.md`)
- Pixel Sampling → Recursive Ray Shading: evaluates rays (evidence: `README.md`)
- Recursive Ray Shading → Hittable Scene: intersects (evidence: `src/tools.cpp`)
- Hittable Scene → Sphere Geometry: queries objects (evidence: `src/tools.cpp`)
- Recursive Ray Shading → Directional Light: uses illumination (evidence: `src/tools.cpp`)
- Recursive Ray Shading → Shadow Testing: tests visibility (evidence: `src/tools.cpp`)
- Shadow Testing → Hittable Scene: casts shadow ray (evidence: `src/tools.cpp`)
- Recursive Ray Shading → Lambertian Material: scatters via (evidence: `README.md`)
- Recursive Ray Shading → Metal Material: scatters via (evidence: `README.md`)
- Recursive Ray Shading → Recursive Ray Shading: recurses (evidence: `src/tools.cpp`)
- Pixel Sampling → Image Buffer: stores pixels (evidence: `README.md`)
- Pixel Sampling → Tone Mapping: converts radiance (evidence: `README.md`)
- Tone Mapping → Image Buffer: encodes pixels (evidence: `README.md`)
- Render Setup → PPM Writer: writes image (evidence: `src/main.cpp`)
- PPM Writer → Image Buffer: reads buffer (evidence: `src/tools.cpp`)
