Skip to content

jarek1992/raytracer_project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

357 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚀 Interactive C++ Path Tracing Engine

A high-performance, physically-based path tracing engine built with C++20. This project features a robust real-time diagnostic UI, sophisticated environmental lighting, and a professional post-processing pipeline.

[Image: Główny render Twojego silnika – np. scena z efektownym oświetleniem, odbiciami i bloomem]

🌟 Key Project Highlights:

  • Global Illumination Out-of-the-box: Full Monte Carlo Path Tracing that naturally handles indirect lighting, soft shadows, and color bleeding.
  • Physically Based Camera & Optics: Thin-lens simulation providing cinematic Depth of Field (Bokeh) and real-time focus pulling.
  • Production-Ready Post-Processing: Complete HDR pipeline featuring ACES Tone Mapping, physically-based Bloom, and Auto-Exposure.
  • High-Performance Scalability: O(logN) ray-traversal via custom BVH structures and 100% CPU utilization via OpenMP.
  • Interactive Diagnostic Suite: Real-time G-Buffer visualization (Normals, Albedo, Depth) and a live Luminance Histogram.
  • Intelligent State Synchronization: Decoupled UI and Render states using a Dirty Flag system, allowing for fluid parameter manipulation with smart accumulator management.

🛠 Core Technical Features

    Engine Specifications

    • Language: C++20 (utilizing modern standards: std::clamp, std::shared_ptr, and advanced lambdas).
    • Rendering Model: Progressive Path Tracing (real-time sample accumulation).
    • Integration Method: Monte Carlo (stochastic sampling of light paths).
      // ACES Tone Mapping to map HDR radiance to [0.0, 1.0] display range
      inline color apply_aces(color x) {
          const double a = 2.51;
          const double b = 0.03;
          const double c = 2.43;
          const double d = 0.59;
          const double e = 0.14;
          return color(
              std::clamp((x.x() * (a * x.x() + b)) / (x.x() * (c * x.x() + d) + e), 0.0, 1.0),
              // ... applied to all channels
          );
      }
      
    • Hardware Acceleration(CPU): OpenMP (parallelized computation across all available processor threads).
    •   #pragma omp parallel for schedule(dynamic)
        for (int j = 0; j < image_height; ++j) {
            // Pixel processing logic...
        }
      
    • Data Structures: BVH(Bounding Volume Hierarchy) – optimizes ray-object intersection tests from O(N) to O(logN).

      • IMAGE: Left: A complex mesh partitioned into AABBs (Axis-Aligned Bounding Boxes). Right: The resulting tree structure used for O(logN) traversal.

    • Memory Management: Dirty Flag System (needs_update, needs_ui_sync) – intelligent buffer reloading triggered only upon parameter changes.
        // Example of smart state synchronization
        if (ImGui::SliderFloat("Aperture", &cam.aperture, 0.0f, 0.5f)) {
            my_post.needs_update = true; // Trigger post-process recalculation
        }
        
        if (ImGui::IsItemDeactivatedAfterEdit()) {
            reset_accumulator(); // Only reset samples when user finishes interaction
        }
      
    Camera & Optics System
      Feature Description Key Parameters
      Thin Lens Model Simulation of a physical lens for realistic bokeh effects Aperture (f-stop), Focus Distance
      Dynamic FOV Full perspective control for architectural or macro shots Vertical FOV (degrees)
      Interactive Navigation Smooth 3D space movement and orientation LookAt, LookFrom, Up Vector
      Sample Jittering High-quality sub-pixel anti-aliasing Stratified Sampling (per pixel)

      IMAGE: Ray-Material Interaction: Demonstrating how surface roughness (Fuzz) affects the scattering of light rays, resulting in sharp reflections or soft, "frosted" appearances.

    Environment & Lighting Systems

    The engine provides a versatile lighting suite, allowing users to switch between physical sky simulations, image-based lighting, and studio backgrounds.

    • HDRI Maps(IBL):
    • For photorealistic reflections and complex ambient lighting, the engine supports industry-standard High Dynamic Range images.

      • Technology: Native support for 32-bit .hdr files (IBL) providing a massive range of luminance data.
      • 3-Axis Transformation: Full spherical orientation control using Yaw, Pitch, and Roll to align the environment with your scene geometry perfectly.
      • Asset Management: Integrated file observer allows for dynamic refreshing of the HDRI library. Add new maps to the directory and select them in-app without a restart.

    • Astronomical Daylight System:
    • This module simulates the sun's position and color based on real-world celestial mechanics. It offers two distinct modes of operation:

      • Astronomical Mode: Calculates the sun's position automatically using geographical and temporal data.
        • Parameters: Latitude (coordinates), Day of the Year (1-365), and Time of Day (0-24h).
        • Celestial Math: Implementation of solar declination, hour angle, azimuth, and elevation algorithms to ensure pinpoint accuracy.

      • Manual Mode: Provides direct control over the sun's direction vector for artistic lighting setups.
      • Auto-Sun Color: Dynamically adjusts the solar spectrum based on the altitude angle. It transitions from warm, golden hues during sunrise/sunset to cool, crisp white at the zenith, driven by the vertical Y component of the sun vector.

    • Solid Background:
    • Designed for product photography and clean architectural presentations.

      • Control: Full RGB spectrum selection via a precision color picker.
      • Intensity: Adjustable background radiance, allowing for neutral studio setups that don't overpower the scene's primary light sources.
    Material Library(PBR)
      Material Physical Property Key Features
      Lambertian Ideal Diffuse Simulates matte surfaces with perfect light scattering.
      Supported(Albedo Maps)
      Metal Specular Reflection Includes a Fuzz parameter to control surface roughness/blurriness of reflections.
      Supported (Fuzz/Color Maps)
      Dielectric Refraction Handles transparent materials like glass or water with IOR (Index of Refraction) and Total Internal Reflection.
      Procedural Tinting
      Emissive Light Emission Turns any geometry into a physical light source (Area Light) with adjustable radiance.
      Supported (Light Maps)

      IMAGE: kule obok siebie z roznymi materialami - diffused lambertian, bumped metal, glass(dielectric), emissive.

    • Technical Highlights & Material System
    • The engine's material system is built on physical principles, ensuring that every interaction between light and geometry behaves as it would in the real world.

      • Energy Conservation: Every material is mathematically constrained to ensure reflected light never exceeds incoming energy, preserving physical consistency and preventing "unrealistic glowing" artifacts.
      • Stochastic Importance Sampling: Reflection and refraction directions are calculated using Monte Carlo importance sampling. This enables the simulation of complex optical effects like soft reflections and frosted glass with high efficiency.
      • Ray-Material Interaction: Each material implements a unique scattering function. Based on physical constants (like IOR or Fuzz), the engine decides whether a ray is absorbed, reflected, or refracted.

    • Texture & Surface Mapping
      • Texture-Material Integration: The engine supports mapping textures to any geometric primitive. You can blend procedural or image-based textures with any PBR material(e.g., a textured metal or a patterned emissive surface).
      • Bump Mapping(Beta): Preliminary support for Bump Mapping is available for basic primitives(cube and sphere), allowing for fine-grained surface detail without increasing polygon count.
        • Note: Currently, Bump Mapping is not supported for .obj triangle meshes; this is planned for a future update.

    Cinematic Post-Process Pipeline

    Beyond path tracing, the engine includes a high-performance post-processing stack to achieve a production-ready look.

    IMAGE: raw image/image with post-production: ACES + BLOOM + EXPOSURE FIXES

    • ACES Tone Mapping:Implementation of the Academy Color Encoding System to transform High Dynamic Range (HDR) data into cinematic Low Dynamic Range (LDR) output.
    • Bloom Engine: A physically-inspired glow effect that extracts highlights and bleeds them into surrounding pixels using a configurable threshold and blur radius.
    • Exposure Control:
      • Auto-Exposure: Note: Dynamically calculates scene luminance to adjust brightness.
        • IMAGE: HISTOGRAM LUMINANCE - mały zrzut ekranu samej konsoli/histogramu obok opisu Auto-Exposure. To pokaże, że Twoja "automatyka" opiera się na rzeczywistych danych statystycznych obrazu.

      • EV Compensation: Photographic control allowing for ±5.0 stops of brightness adjustment.

🕹 Interactive UI Overview

    Diagnostic G-Buffer Visualizer

    Real-time inspection of internal engine passes to verify scene integrity.

      Albedo Pass Normal Pass Z-Depth Pass
      Raw material colors Surface orientation Spatial distance

      IMAGE: obrazek z rgb/albedo/normals/z-depth

    Real-Time Analytics & Control

    Professional tools for lighting and exposure management.

    [!TIP]
    Live Histogram & Channel Isolation
    Tutaj idealnie pasuje GIF pokazujący, jak zmieniasz ekspozycję suwakiem, a wykres histogramu „pływa” w czasie rzeczywistym.
    
    • Luminance Histogram: Monitor brightness distribution to prevent highlight clipping.
    • Debug Channels: Toggle R, G, B, and Luminance views for precise noise analysis.
      • Technical Detail: Controlled via debug_mode flags in the post-processing shader.

    Fluid Interaction System

    The engine features a deeply integrated communication layer between the Dear ImGui interface and the rendering core, focusing on a seamless user experience.

    IMAGE: G-Buffer GIF, jak przełączasz się między Normals a Final Render

    • Smart Accumulator Sync: To prevent constant frame flickering during UI interaction, the path-tracing accumulator only resets when a change is "finalized" (utilizing IsItemDeactivatedAfterEdit). This allows you to explore parameters smoothly, with the engine only committing to a full re-render once you release a slider.
    • Non-Blocking Real-Time Updates: Key parameters—including Sun Position, Light Intensity, and Focus Distance—provide immediate visual feedback, allowing for rapid look-dev and lighting adjustments without breaking the creative flow.
    • Architectural Console & Logging: A custom-built engine console provides categorized, filtered feedback directly within the viewport.
      • Smart Categorization: Logs are tagged as [System], [Config], or [Debug] for easy navigation and troubleshooting.
      • Anti-Spam Logic: Prevents log flooding during rapid parameter changes, ensuring that critical engine messages remain visible and the UI stays responsive even under heavy interaction.

🏗 Build & Requirements

    This project is built using modern C++ standards and relies on a few industry-standard libraries for window management and UI. Designed to be cross-platform, supporting Windows, Linux and macOS. It utilizes CMake for automated dependency management.
    Hardware & System Requirements

    • OS: Windows 10/11, macOS (Intel/Apple Silicon), or Linux.
    • CPU: Multi-core processor with OpenMP support (essential for real-time performance).
    • GPU: OpenGL 3.3 compatible (used for hardware-accelerated frame buffer display).
    Software Prerequisites

    • Compiler: A C++20 compliant compiler (e.g., MSVC 2019 v16.8+, GCC 10+, or Clang 10+).
    • Build System: CMake 3.16+ (or a configured IDE project like Visual Studio).
    Dependencies

    The project relies on the following libraries. Ensure they are installed or available in your environment:

    • SDL3: Used for window management and input handling.
    • OpenMP: Powers the multi-threaded rendering core.
    • Intel Open Image Denoise (OIDN): High-performance AI denoising.
    • OpenGL: Native graphics API for viewport rendering.
    • DearImGui & Glad: Integrated within the source tree.
    Build the Project

    • 1. Clone the repository:
      git clone --recursive https://github.com/jarek1992/raytracer_project.git
      

📈 Performance & Optimization

📸 Gallery & Showcase

🗺 Future Roadmap (Gdzie projekt zmierza).

🖥 Interface in Action

Tip: Tutaj wstaw GIF-a pokazującego jak przesuwasz slider godziny (słońce się porusza) lub jak zmieniasz tryby G-Buffera.

📊 Real-time Analytics

Tip: Tutaj wstaw screenshot z histogramem i aktywnymi kanałami RGB.

#RayTracer Image

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors