# zydak/vulkan-path-tracer architecture

> Architecture diagram of the GitHub repository zydak/vulkan-path-tracer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/zydak/vulkan-path-tracer
- Repository: https://github.com/zydak/vulkan-path-tracer

## Overview

##### Project type and purpose
- This is a native desktop, full-stack graphics application: an offline, physically-based path tracing renderer built on Vulkan with the Ray Tracing Pipeline extension.
- It provides an interactive editor UI (via ImGui), a scene loader (.gltf, .obj, .ptscene), a GPU-based ray tracer, and post-processing (denoiser, bloom, DOF, etc.) with output to screen and PNG files.

##### File structure
- Top-level:
- Gallery/ – sample renders and material-showcase images
- Vulkan-Helper/ – a submodule/library encapsulating Vulkan setup and shader compilation (Shaderc)
- PathTracer/ – the core application:
– premake5.lua, vk_layer_settings.txt, imgui.ini – build and runtime configs
– assets/ – scene geometry, HDR maps, lookup tables, .ptscene files
– src/ – C++ code (Application, Editor, PathTracer core, EnergyLossCalculator, PostProcessor, main)
– src/shaders/ – Ray Tracing and graphics shaders (.slang, .glsl)
- Build scripts: premake5.lua, setup.bat, premake5.exe
- External dependencies: Vulkan SDK, Shaderc, ImGui, OptiX, glTF/OBJ loaders

##### README for additional insights
- The project uses:
- Vulkan Ray Tracing (KHR_extension family)
- Energy-conserving BSSRDF with multiple lobes, anisotropy, volume scattering
- Post processing (bloom, chromatic aberration, AO, DOF)
- NVIDIA OptiX for denoising
- Editor for real-time scene tweaking and export

a. Main components
1. UI / Editor Layer
– ImGui-based scene inspector, material editor, render controls
2. Application Core
– Application.cpp: initializes Vulkan via Vulkan-Helper, handles window/input (GLFW), command loop
– Scene Manager: loads assets (.gltf/.obj/.ptscene), builds acceleration structures
3. Path Tracer Engine
– Ray Tracing Pipeline setup (rgen, rmiss, rchit, rtmiss shaders)
– EnergyLossCalculator module (BSSRDF, microfacet, volume scattering)
4. Post Processor
– Full-screen quad pass for bloom, tone mapping, chromatic aberration, DOF
– NVIDIA OptiX denoiser integration
5. Asset I/O
– Disk I/O for geometry, textures, HDR maps, lookup tables
– Scene serialization / export (PNG)

6. Vulkan-Helper Library
– Encapsulates instance/device creation, swapchain, descriptor set layouts, pipeline wrappers, shader compilation via Shaderc

7. External Systems
– Vulkan API (GPU driver)
– Shaderc (SPIR-V compiler)
– NVIDIA OptiX SDK

b. Relationships and interactions
- The Application Core calls Vulkan-Helper to initialize Vulkan, window and swapchain.
- UI Layer interacts with Scene Manager and Engine parameters at runtime.
- Scene Manager feeds Geometry + Material data to the Path Tracer Engine.
- The Path Tracer Engine dispatches ray tracing commands to the GPU via Vulkan.
- Engine outputs a raw image buffer, passed to Post Processor for effects.
- Post Processor writes to the swapchain for display and to disk for PNG export.
- OptiX denoiser is invoked after the raw path-traced buffer and before or as part of Post Processor.

c. Architectural patterns and design principles
- Modular separation: Editor, Engine, Post Processor, Helper Library
- Data-driven design: assets/lookupTables control shading behavior without code changes
- Pipeline abstraction: heavy use of Vulkan pipelines (ray tracing pipeline + graphics pipelines)
- Resource management: explicit descriptor sets and command buffers

d. Relevant technologies, frameworks, or libraries
- Vulkan SDK with KHR ray tracing extensions
- Shaderc for on-the-fly shader compilation
- ImGui for editor UI
- GLFW (or platform windowing)
- NVIDIA OptiX for denoising
- TinyGLTF / TinyOBJLoader (implied by .gltf/.obj support)

##### Elements
- UI → Application Core (commands/parameter changes)
- Application Core → Vulkan-Helper (init, commands)
- Application Core → Scene Manager → Path Tracer Engine
- Path Tracer Engine → Post Processor → Swapchain/PNG
- Path Tracer Engine → NVIDIA OptiX (for denoising)
- Disk → Asset I/O → Scene Manager
- CPU components (light blue)
- GPU pipelines/shaders (orange)
- External libraries/SDKs (gray)
- Labels for Vulkan extensions (e.g., VK_KHR_ray_tracing_pipeline) on the Path Tracer Engine

##### Final recommendations
- Shaders (.slang, .glsl) under the “GPU Shading Pipeline” sub-component
- Lookup tables directory feeding the EnergyLossCalculator
- Explicitly note the premake/build step feeding into the generated Visual Studio solution

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% CPU Components
    subgraph "CPU Components"
        direction TB
        UI["Editor UI\n(ImGui)"]:::cpu
        ApplicationCore["Application Core\n(initializes Vulkan, window/input, loop)"]:::cpu
        SceneManager["Scene Manager\n(loads assets, builds AS)"]:::cpu
        EnergyLossCalc["EnergyLossCalculator\n(BSSRDF, microfacet, volume)"]:::cpu
        AssetIO["Asset I/O\n(disk I/O, serialization)"]:::cpu
        PostProcessor["Post Processor\n(bloom, tone mapping, DOF, denoiser)"]:::cpu
        SwapchainOutput["Swapchain / PNG Export"]:::cpu
    end

    %% GPU Components
    subgraph "GPU Components"
        direction TB
        PathTracerEngine["Path Tracer Engine\n(VK_KHR_ray_tracing_pipeline)"]:::gpu
        GPUPipeline["GPU Shading Pipeline\n(.slang, .glsl)"]:::gpu
    end

    %% External Systems
    subgraph "External Systems"
        direction TB
        VulkanHelper["Vulkan-Helper Library"]:::cpu
        VulkanSDK["Vulkan SDK"]:::ext
        Shaderc["Shaderc Compiler"]:::ext
        OptiX["NVIDIA OptiX SDK"]:::ext
    end

    %% Connections
    UI -->|"commands/params"| ApplicationCore
    ApplicationCore -->|"init, commands"| VulkanHelper
    VulkanHelper --> VulkanSDK
    VulkanHelper --> Shaderc
    ApplicationCore --> SceneManager
    AssetIO --> SceneManager
    SceneManager -->|"geometry + materials"| PathTracerEngine
    EnergyLossCalc --> PathTracerEngine
    PathTracerEngine --> GPUPipeline
    PathTracerEngine -->|"raw image buffer"| PostProcessor
    PathTracerEngine -->|"invoke denoiser"| OptiX
    PostProcessor --> SwapchainOutput

    %% Click Events
    click UI "https://github.com/zydak/vulkan-path-tracer/blob/main/PathTracer/src/Editor.cpp"
    click ApplicationCore "https://github.com/zydak/vulkan-path-tracer/blob/main/PathTracer/src/Application.cpp"
    click SceneManager "https://github.com/zydak/vulkan-path-tracer/blob/main/PathTracer/src/PathTracer.cpp"
    click PathTracerEngine "https://github.com/zydak/vulkan-path-tracer/blob/main/PathTracer/src/PathTracer.cpp"
    click GPUPipeline "https://github.com/zydak/vulkan-path-tracer/tree/main/PathTracer/src/shaders/"
    click EnergyLossCalc "https://github.com/zydak/vulkan-path-tracer/blob/main/PathTracer/src/EnergyLossCalculator.cpp"
    click PostProcessor "https://github.com/zydak/vulkan-path-tracer/blob/main/PathTracer/src/PostProcessor.cpp"
    click AssetIO "https://github.com/zydak/vulkan-path-tracer/tree/main/PathTracer/assets/"
    click VulkanHelper "https://github.com/zydak/vulkan-path-tracer/tree/main/Vulkan-Helper/"

    %% Styles
    classDef cpu fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef gpu fill:#FFA500,stroke:#333,stroke-width:1px
    classDef ext fill:#D3D3D3,stroke:#333,stroke-width:1px
```
