# sebh/unrealengineskyatmosphere architecture

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

- Interactive diagram: https://gitdiagram.com/sebh/unrealengineskyatmosphere
- Repository: https://github.com/sebh/unrealengineskyatmosphere

## Overview

#### Purpose and Entry Points
Windows/D3D11 research renderer accompanying the EGSR 2020 Unreal Sky Atmosphere technique. It compares the paper’s LUT-based ray-marched atmosphere against Bruneton 2017 precomputed scattering and a volumetric path tracer. Process startup and main loop begin in `Application/WinMain.cpp`, which drives `Application/Game.cpp`; `Sky.sln` builds the `Application` executable plus the DX11 platform layer.

#### Platform, Window, and GPU Device Boundary
`DX11Base/Dx11Device.cpp` and `DX11Base/Dx11Device.h` encapsulate Direct3D 11 device, context, swap chain, resource, and shader-facing setup. `DX11Base/WindowHelper.cpp` owns Win32 window lifecycle, while `DX11Base/WindowInput.h` exposes interaction state. This boundary isolates Windows/D3D11 infrastructure from atmosphere and scene rendering.

#### Application Orchestration and State
`Application/Game.cpp` is the frame-level coordinator: it manages camera/sun interaction, rendering mode selection, GPU passes, screenshots, and saved/loaded runtime state. `Application/DataRecord.cpp` supports persistence of application state. `Application/SkyAtmosphereCommon.cpp` / `Application/SkyAtmosphereCommon.h` define CPU-side atmospheric parameters and shared logic corresponding to GPU atmosphere inputs.

#### Atmosphere LUT Pipeline
The primary scalable technique precomputes and samples atmospheric lookup tables. `Application/RenderWithLuts.cpp` dispatches and uses these LUT-driven passes; shader stages are split by physical quantity:
- `Resources/SkyAtmosphereTransmittanceLut.hlsl`
- `Resources/SkyAtmosphereDirectIrradianceLut.hlsl`
- `Resources/SkyAtmosphereSingleScatteringLut.hlsl`
- `Resources/SkyAtmosphereMultipleScattering.hlsl`
- `Resources/SkyAtmosphereScatteringDensity.hlsl`
- `Resources/SkyAtmosphereIndirectIrradiance.hlsl`

Shared atmospheric equations, coordinate conventions, and constants reside in `Resources/SkyAtmosphereCommon.hlsl` and `Resources/SkyAtmosphereBruneton.hlsl`.

#### Sky Rendering Modes
`Application/RenderSky.cpp` selects sky rendering behavior and binds the appropriate shaders. The ray-marching implementation in `Resources/RenderSkyRayMarching.hlsl` builds the new method’s LUTs and evaluates the atmosphere. `Resources/RenderSkyPathTracing.hlsl` provides an alternate real-time volumetric path tracer for comparison; runtime mode toggling switches between ray marching and path tracing and disables the multiple-scattering approximation for path tracing. `Resources/RenderSkyCommon.hlsl` holds shared sky shading code.

#### Scene, Composition, and Diagnostics
Terrain establishes the visible ground/planet context through `Application/RenderTerrain.cpp` and `Resources/Terrain.hlsl`, using repository heightmap assets such as `Resources/heightmap0.exr`. Final fullscreen/post-processing work is in `Resources/PostProcess.hlsl`. GPU-side debug visualization is driven by `Application/GpuDebugRenderer.cpp` and `Resources/GpuDebugPrimitives.hlsl`.

#### Comparative and External Assets
The Bruneton reference implementation is represented by `Resources/Bruneton17/definitions.glsl` and `Resources/Bruneton17/functions.glsl`, with integration-facing atmospheric shader code in `Resources/SkyAtmosphereBruneton.hlsl`. External dependencies are Git submodules `imgui` (runtime UI) and `tinyexr` (EXR asset/image support). The project targets Windows, Visual Studio, a Windows SDK, and Direct3D 11; it has no indicated server, network, or cloud dependency.

Main entry points: [`Application/Game.cpp`](https://github.com/sebh/unrealengineskyatmosphere/blob/master/Application/Game.cpp) (Game frame coordinator), [`Application/RenderWithLuts.cpp`](https://github.com/sebh/unrealengineskyatmosphere/blob/master/Application/RenderWithLuts.cpp) (LUT renderer), [`Application/RenderSky.cpp`](https://github.com/sebh/unrealengineskyatmosphere/blob/master/Application/RenderSky.cpp) (Sky mode renderer), [`Application/RenderTerrain.cpp`](https://github.com/sebh/unrealengineskyatmosphere/blob/master/Application/RenderTerrain.cpp) (Terrain rendering)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Application"]
  node_entry["WinMain<br/>process entry<br/>[WinMain.cpp]"]
  node_game["Game frame coordinator<br/>application loop<br/>[Game.cpp]"]
  node_state["State persistence<br/>runtime state<br/>[DataRecord.cpp]"]
  node_atmosphere_params["Atmosphere parameters<br/>CPU atmosphere model"]
end

subgraph group_platform["Windows / D3D11"]
  node_window["Win32 window<br/>window lifecycle<br/>[WindowHelper.cpp]"]
  node_input["Window input<br/>interaction state<br/>[WindowInput.h]"]
  node_d3d11{{"D3D11 device layer<br/>GPU platform boundary<br/>[Dx11Device.cpp]"}}
end

subgraph group_lut["Atmosphere LUT Pipeline"]
  node_lut_renderer["LUT renderer<br/>atmosphere pass dispatcher<br/>[RenderWithLuts.cpp]"]
  node_transmittance["Transmittance LUT<br/>compute shader"]
  node_direct_irradiance["Direct irradiance LUT<br/>compute shader"]
  node_single_scattering["Single scattering LUT<br/>compute shader"]
  node_multiple_scattering["Multiple scattering LUT<br/>compute shader"]
  node_scattering_density["Scattering density<br/>compute shader"]
  node_indirect_irradiance["Indirect irradiance LUT<br/>compute shader"]
end

subgraph group_render["Scene &amp; Rendering"]
  node_sky_renderer["Sky mode renderer<br/>sky composition<br/>[RenderSky.cpp]"]
  node_ray_marching["LUT ray-marched sky<br/>sky shader"]
  node_path_tracing["Volumetric path-traced sky<br/>comparison shader"]
  node_terrain["Terrain rendering<br/>scene pass<br/>[RenderTerrain.cpp]"]
  node_postprocess["Post-processing<br/>fullscreen shader<br/>[PostProcess.hlsl]"]
  node_gpu_debug["GPU diagnostics<br/>debug renderer"]
end

subgraph group_reference["Comparison &amp; Dependencies"]
  node_bruneton["Bruneton 2017 reference<br/>reference atmosphere shaders<br/>[functions.glsl]"]
  node_imgui["imgui<br/>Git submodule"]
  node_tinyexr["tinyexr<br/>Git submodule"]
end

node_entry -->|"starts"| node_game
node_game -->|"drives"| node_window
node_window -->|"provides events"| node_input
node_game -->|"submits frames"| node_d3d11
node_game -->|"saves / loads"| node_state
node_game -->|"updates"| node_atmosphere_params
node_game -->|"runs LUT mode"| node_lut_renderer
node_game -->|"selects mode"| node_sky_renderer
node_game -->|"renders scene"| node_terrain
node_game -->|"renders diagnostics"| node_gpu_debug
node_game -->|"uses UI"| node_imgui
node_lut_renderer -->|"generates"| node_transmittance
node_lut_renderer -->|"generates"| node_direct_irradiance
node_lut_renderer -->|"generates"| node_single_scattering
node_lut_renderer -->|"iterates"| node_scattering_density
node_scattering_density -->|"feeds"| node_multiple_scattering
node_multiple_scattering -->|"feeds"| node_indirect_irradiance
node_atmosphere_params -->|"atmosphere inputs"| node_lut_renderer
node_lut_renderer -->|"supplies LUTs"| node_ray_marching
node_sky_renderer -->|"LUT mode"| node_ray_marching
node_sky_renderer -->|"path-tracing mode"| node_path_tracing
node_sky_renderer -.->|"reference mode"| node_bruneton
node_sky_renderer -->|"composites through"| node_postprocess
node_terrain -->|"scene color"| node_postprocess
node_postprocess -->|"presents"| node_d3d11
node_tinyexr -.->|"supports EXR assets"| node_terrain

click node_entry "https://github.com/sebh/unrealengineskyatmosphere/blob/master/Application/WinMain.cpp"
click node_game "https://github.com/sebh/unrealengineskyatmosphere/blob/master/Application/Game.cpp"
click node_state "https://github.com/sebh/unrealengineskyatmosphere/blob/master/Application/DataRecord.cpp"
click node_atmosphere_params "https://github.com/sebh/unrealengineskyatmosphere/blob/master/Application/SkyAtmosphereCommon.cpp"
click node_window "https://github.com/sebh/unrealengineskyatmosphere/blob/master/DX11Base/WindowHelper.cpp"
click node_input "https://github.com/sebh/unrealengineskyatmosphere/blob/master/DX11Base/WindowInput.h"
click node_d3d11 "https://github.com/sebh/unrealengineskyatmosphere/blob/master/DX11Base/Dx11Device.cpp"
click node_lut_renderer "https://github.com/sebh/unrealengineskyatmosphere/blob/master/Application/RenderWithLuts.cpp"
click node_transmittance "https://github.com/sebh/unrealengineskyatmosphere/blob/master/Resources/SkyAtmosphereTransmittanceLut.hlsl"
click node_direct_irradiance "https://github.com/sebh/unrealengineskyatmosphere/blob/master/Resources/SkyAtmosphereDirectIrradianceLut.hlsl"
click node_single_scattering "https://github.com/sebh/unrealengineskyatmosphere/blob/master/Resources/SkyAtmosphereSingleScatteringLut.hlsl"
click node_multiple_scattering "https://github.com/sebh/unrealengineskyatmosphere/blob/master/Resources/SkyAtmosphereMultipleScattering.hlsl"
click node_scattering_density "https://github.com/sebh/unrealengineskyatmosphere/blob/master/Resources/SkyAtmosphereScatteringDensity.hlsl"
click node_indirect_irradiance "https://github.com/sebh/unrealengineskyatmosphere/blob/master/Resources/SkyAtmosphereIndirectIrradiance.hlsl"
click node_sky_renderer "https://github.com/sebh/unrealengineskyatmosphere/blob/master/Application/RenderSky.cpp"
click node_ray_marching "https://github.com/sebh/unrealengineskyatmosphere/blob/master/Resources/RenderSkyRayMarching.hlsl"
click node_path_tracing "https://github.com/sebh/unrealengineskyatmosphere/blob/master/Resources/RenderSkyPathTracing.hlsl"
click node_terrain "https://github.com/sebh/unrealengineskyatmosphere/blob/master/Application/RenderTerrain.cpp"
click node_postprocess "https://github.com/sebh/unrealengineskyatmosphere/blob/master/Resources/PostProcess.hlsl"
click node_gpu_debug "https://github.com/sebh/unrealengineskyatmosphere/blob/master/Application/GpuDebugRenderer.cpp"
click node_bruneton "https://github.com/sebh/unrealengineskyatmosphere/blob/master/Resources/Bruneton17/functions.glsl"
click node_imgui "https://github.com/sebh/unrealengineskyatmosphere/tree/master/imgui"
click node_tinyexr "https://github.com/sebh/unrealengineskyatmosphere/tree/master/tinyexr"

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_game,node_state,node_atmosphere_params toneBlue
class node_window,node_input,node_d3d11 toneAmber
class node_lut_renderer,node_transmittance,node_direct_irradiance,node_single_scattering,node_multiple_scattering,node_scattering_density,node_indirect_irradiance toneMint
class node_sky_renderer,node_ray_marching,node_path_tracing,node_terrain,node_postprocess,node_gpu_debug toneRose
class node_bruneton,node_imgui,node_tinyexr toneIndigo
```

## Components

### Application

- [WinMain](https://github.com/sebh/unrealengineskyatmosphere/blob/master/Application/WinMain.cpp): process entry · `Application/WinMain.cpp`
- [Game frame coordinator](https://github.com/sebh/unrealengineskyatmosphere/blob/master/Application/Game.cpp): application loop · Coordinates input, modes, GPU passes, screenshots, and runtime state. · `Application/Game.cpp`
- [State persistence](https://github.com/sebh/unrealengineskyatmosphere/blob/master/Application/DataRecord.cpp): runtime state · `Application/DataRecord.cpp`
- [Atmosphere parameters](https://github.com/sebh/unrealengineskyatmosphere/blob/master/Application/SkyAtmosphereCommon.cpp): CPU atmosphere model · Shared CPU-side parameters supplied to atmosphere shaders. · `Application/SkyAtmosphereCommon.cpp`

### Windows / D3D11

- [Win32 window](https://github.com/sebh/unrealengineskyatmosphere/blob/master/DX11Base/WindowHelper.cpp): window lifecycle · `DX11Base/WindowHelper.cpp`
- [Window input](https://github.com/sebh/unrealengineskyatmosphere/blob/master/DX11Base/WindowInput.h): interaction state · `DX11Base/WindowInput.h`
- [D3D11 device layer](https://github.com/sebh/unrealengineskyatmosphere/blob/master/DX11Base/Dx11Device.cpp): GPU platform boundary · Owns device, context, swap chain, resources, and shader setup. · `DX11Base/Dx11Device.cpp`

### Atmosphere LUT Pipeline

- [LUT renderer](https://github.com/sebh/unrealengineskyatmosphere/blob/master/Application/RenderWithLuts.cpp): atmosphere pass dispatcher · `Application/RenderWithLuts.cpp`
- [Transmittance LUT](https://github.com/sebh/unrealengineskyatmosphere/blob/master/Resources/SkyAtmosphereTransmittanceLut.hlsl): compute shader · `Resources/SkyAtmosphereTransmittanceLut.hlsl`
- [Direct irradiance LUT](https://github.com/sebh/unrealengineskyatmosphere/blob/master/Resources/SkyAtmosphereDirectIrradianceLut.hlsl): compute shader · `Resources/SkyAtmosphereDirectIrradianceLut.hlsl`
- [Single scattering LUT](https://github.com/sebh/unrealengineskyatmosphere/blob/master/Resources/SkyAtmosphereSingleScatteringLut.hlsl): compute shader · `Resources/SkyAtmosphereSingleScatteringLut.hlsl`
- [Multiple scattering LUT](https://github.com/sebh/unrealengineskyatmosphere/blob/master/Resources/SkyAtmosphereMultipleScattering.hlsl): compute shader · `Resources/SkyAtmosphereMultipleScattering.hlsl`
- [Scattering density](https://github.com/sebh/unrealengineskyatmosphere/blob/master/Resources/SkyAtmosphereScatteringDensity.hlsl): compute shader · `Resources/SkyAtmosphereScatteringDensity.hlsl`
- [Indirect irradiance LUT](https://github.com/sebh/unrealengineskyatmosphere/blob/master/Resources/SkyAtmosphereIndirectIrradiance.hlsl): compute shader · `Resources/SkyAtmosphereIndirectIrradiance.hlsl`

### Scene & Rendering

- [Sky mode renderer](https://github.com/sebh/unrealengineskyatmosphere/blob/master/Application/RenderSky.cpp): sky composition · Selects LUT ray marching or volumetric path tracing. · `Application/RenderSky.cpp`
- [LUT ray-marched sky](https://github.com/sebh/unrealengineskyatmosphere/blob/master/Resources/RenderSkyRayMarching.hlsl): sky shader · `Resources/RenderSkyRayMarching.hlsl`
- [Volumetric path-traced sky](https://github.com/sebh/unrealengineskyatmosphere/blob/master/Resources/RenderSkyPathTracing.hlsl): comparison shader · Alternate mode without the multiple-scattering approximation. · `Resources/RenderSkyPathTracing.hlsl`
- [Terrain rendering](https://github.com/sebh/unrealengineskyatmosphere/blob/master/Application/RenderTerrain.cpp): scene pass · Renders ground context from heightmap assets. · `Application/RenderTerrain.cpp`
- [Post-processing](https://github.com/sebh/unrealengineskyatmosphere/blob/master/Resources/PostProcess.hlsl): fullscreen shader · `Resources/PostProcess.hlsl`
- [GPU diagnostics](https://github.com/sebh/unrealengineskyatmosphere/blob/master/Application/GpuDebugRenderer.cpp): debug renderer · `Application/GpuDebugRenderer.cpp`

### Comparison & Dependencies

- [Bruneton 2017 reference](https://github.com/sebh/unrealengineskyatmosphere/blob/master/Resources/Bruneton17/functions.glsl): reference atmosphere shaders · Comparative precomputed-scattering implementation. · `Resources/Bruneton17/functions.glsl`
- [imgui](https://github.com/sebh/unrealengineskyatmosphere/tree/master/imgui): Git submodule · Runtime UI dependency. · `imgui`
- [tinyexr](https://github.com/sebh/unrealengineskyatmosphere/tree/master/tinyexr): Git submodule · EXR image and asset support. · `tinyexr`

## Connections

- WinMain → Game frame coordinator: starts
- Game frame coordinator → Win32 window: drives
- Win32 window → Window input: provides events
- Game frame coordinator → D3D11 device layer: submits frames
- Game frame coordinator → State persistence: saves / loads
- Game frame coordinator → Atmosphere parameters: updates
- Game frame coordinator → LUT renderer: runs LUT mode
- Game frame coordinator → Sky mode renderer: selects mode
- Game frame coordinator → Terrain rendering: renders scene
- Game frame coordinator → GPU diagnostics: renders diagnostics
- Game frame coordinator → imgui: uses UI
- LUT renderer → Transmittance LUT: generates
- LUT renderer → Direct irradiance LUT: generates
- LUT renderer → Single scattering LUT: generates
- LUT renderer → Scattering density: iterates
- Scattering density → Multiple scattering LUT: feeds
- Multiple scattering LUT → Indirect irradiance LUT: feeds
- Atmosphere parameters → LUT renderer: atmosphere inputs
- LUT renderer → LUT ray-marched sky: supplies LUTs
- Sky mode renderer → LUT ray-marched sky: LUT mode
- Sky mode renderer → Volumetric path-traced sky: path-tracing mode
- Sky mode renderer → Bruneton 2017 reference: reference mode
- Sky mode renderer → Post-processing: composites through
- Terrain rendering → Post-processing: scene color
- Post-processing → D3D11 device layer: presents
- tinyexr → Terrain rendering: supports EXR assets
