How tommybazar/tbraymarcherplugin works
Project Type & Purpose
• This is an Unreal Engine 5.4+ plugin (“TBRaymarcherPlugin”) providing real-time volume rendering (raymarching) of medical/volumetric data.
• It ships as a UE plugin with both runtime C++ modules and an editor module, plus HLSL (.usf) shader files, content assets (Blueprints, materials, curves, maps), and third-party libraries (DCMTK).
Top-Level Component Breakdown
A. Unreal Engine Host
– Core engine (Core, CoreUObject, Engine, InputCore)
– Editor (for asset import, UMG, Blueprint graph, project settings)
– Render subsystem (Render Thread, RHI Thread)
B. Plugin Modules (in Source/)
– VolumeTextureToolkit (Runtime): low-level volume‐texture creation, DICOM/MHD/RAW loaders
– VolumeTextureToolkitEditor (Editor): drag-and-drop importer, factory, asset creation UI
– RayUtils: utility functions (timers, raymarch helpers) used by other modules
– Raymarcher (Runtime):
• ARaymarchVolume actor (manages volume textures, lights array, clipping plane)
• Compute‐shader wrappers for precomputed illumination (“AddDirLight”, “ChangeDirLight”)
• Blueprint‐callable functions for loading volumes at runtime
• HLSL .usf compute shaders and material includes
– FractalMarcher (Runtime sample): example actor/screens for 2D/3D fractal visualization
– Tests: automated performance/actor tests
– VolumeTextureToolkitEditor: editor widgets and factory code
C. Content Assets (Content/)
– Blueprints: actor wrappers (BP_RaymarchVolume, BP_RaymarchLight, BP_ClipPlane), VR controllers, UI widgets
– Materials & Material Functions: M_Raymarch, M_Intensity_Raymarch, CommonInclude, transfer-function sampling .usf
– Maps: example showcase levels (desktop & VR)
– Meshes: unit cube, plane, subdivided meshes
Data & Interaction Flows
1. Editor Asset Import
Editor Module → DCMTK (third-party) → VolumeTextureToolkitEditor.UI → VolumeTextureToolkit → UVolumeAsset + UVolumeTexture assets in Content Browser
2. Game Initialization
Game Thread: Level spawns ARaymarchVolume actor (or Blueprint subclass) and ARaymarchLight / ARaymarchClipPlane
3. Runtime Volume Setup
ARaymarchVolume (game thread) calls VolumeTextureToolkit API → loads persistent or transient UVolumeTexture → assigns to Dynamic Material Instance
4. Illumination Precompute (Render Thread & RHI Thread)
• Compute Shader Passes (“AddDirLightShader.usf”, “ChangeDirLightShader.usf”)
• Shader dispatch per slice to build 3D light‐volume texture
5. Raymarching in Material
• Output rendered image to viewport
6. Blueprint & UI Interactions
• UMG Widgets (WBP_* in Content/Blueprints/Widgets) call Blueprint‐exposed C++ functions on ARaymarchVolume (SetWindowCenter, LoadNewFile, SetTFCurve) via Game Thread → triggers volume/material update → visible next frame
Key Architectural Patterns & Principles
• Modular plugin design: separate editor vs. runtime code (Editor module never ships to shipping build)
• C++ & HLSL separation: heavy logic in HLSL (.usf) files, C++ wraps shader dispatch and material parameter setup
• Shader reuse: shared functions in “RaymarcherCommon.usf” & “WindowedSampling.usf” used by both material shaders and compute shaders for consistency
• Blueprint‐exposed API: core classes (ARaymarchVolume, ARaymarchLight, ARaymarchClipPlane) expose UFUNCTION APIs for in-editor and runtime tweaking
• Thread separation: Game Thread → Render Thread → RHI Thread → GPU compute passes