Skip to content

TECHNICANGEL/RacingEngine

Repository files navigation

Racing Engine - Pure Vulkan Ray Tracing

Custom racing game engine built from scratch with 100% ray tracing (no rasterization). Built with C++ and Vulkan 1.3 Ray Tracing extensions.

Status: ✅ RAY TRACING FUNCTIONAL

The engine is currently rendering in real-time using pure path tracing. No rasterization pipeline.

Requirements

  • Vulkan SDK 1.3+ (installed at C:\VulkanSDK\1.4.321.1)
  • CMake 3.20+
  • C++17 compiler (MSVC 2022 tested)
  • NVIDIA RTX GPU (3060 Ti confirmed working)
  • Windows (currently Windows-only)

Quick Start

1. Build the project

cd RacingEngine
mkdir build && cd build
cmake ..
cmake --build . --config Release

2. Run

cd Release
RacingEngine.exe

3. Controls

  • WASD - Move camera forward/left/back/right
  • QE - Move camera up/down
  • Mouse - Look around (FPS-style)
  • Shift - Move faster
  • ESC - Exit (or close window)

Project Structure

RacingEngine/
├── src/
│   ├── main.cpp                    # Main engine loop
│   ├── Camera.cpp/h                # FPS camera with WASD + mouse
│   ├── VulkanSwapchain.cpp/h       # Swapchain management
│   ├── VulkanRayTracing.cpp/h      # RT storage images & commands
│   ├── VulkanAcceleration.cpp/h    # BLAS/TLAS acceleration structures
│   └── VulkanRTPipeline.cpp/h      # RT pipeline & SBT
├── shaders/
│   ├── raygen.rgen                 # Ray generation shader
│   ├── miss.rmiss                  # Miss shader (sky)
│   ├── closesthit.rchit            # Closest hit shader
│   └── compiled/                   # SPIR-V compiled shaders
├── external/
│   ├── glfw/                       # Window management
│   ├── glm/                        # Math library
│   ├── stb/                        # Image loading
│   └── vma/                        # Vulkan memory allocator
└── build/                          # Build output

Implementation Progress

✅ Completed Features

  • Vulkan 1.3 initialization with validation layers
  • Swapchain for image presentation
  • Ray tracing storage images (RT output)
  • Acceleration structures (BLAS + TLAS)
  • Geometry system (triangle buffers with device addresses)
  • RT shaders (raygen, miss, closest hit)
  • RT pipeline with descriptor sets
  • Shader Binding Table (SBT)
  • Render loop with proper synchronization
  • Command buffers with image transitions

✅ Recently Completed

  • Free camera controls (WASD + mouse + QE for up/down)
  • FPS-style camera with mouse look
  • Real-time camera updates in ray tracing shaders
  • Multiple geometry objects (ground plane + cubes)
  • Per-object coloring based on instance ID
  • Multiple BLAS system for different objects
  • Improved lighting model (ambient + diffuse + specular)
  • Approximate normal calculation for ground and cubes
  • Sky ambient lighting with blue tint from above
  • Shadow rays for accurate shadowing
  • Multiple bounces for global illumination (reflection rays)
  • Recursion depth 4 supporting primary, shadow, and reflection rays

🚧 In Progress

  • Materials and textures (PBR workflow)
  • Diffuse bounces with importance sampling

📋 Planned Features

  • PBR materials (metallic/roughness workflow)
  • Path tracing with importance sampling
  • Denoising (temporal or spatial)
  • HDR environment maps
  • Vehicle physics (arcade-style)
  • Dynamic objects (animated cars)
  • Post-processing (tone mapping, bloom)

Technical Details

Ray Tracing Pipeline

  • API: Vulkan 1.3 with KHR ray tracing extensions

    • VK_KHR_ray_tracing_pipeline
    • VK_KHR_acceleration_structure
    • VK_KHR_deferred_host_operations
    • VK_KHR_buffer_device_address
  • Shaders: GLSL with ray tracing extensions compiled to SPIR-V

  • Acceleration: Separate BLAS for each object, single TLAS for scene

  • Output: Direct write to storage image, blit to swapchain

Current Rendering

  • Resolution: 1920x1080
  • Rays per pixel: 1 (single sample, no accumulation yet)
  • Max recursion depth: 4 (supports multiple bounces)
  • Scene: Ground plane (50x50 units) + 4 colored cubes
  • Objects: 5 geometry objects with individual BLAS
  • Lighting Model:
    • Ambient lighting (base illumination)
    • Diffuse lighting (Lambertian)
    • Specular highlights (Blinn-Phong, shininess 32)
    • Sky ambient (blue tint from above)
    • Shadow rays for accurate shadowing of direct light
    • Reflection rays for indirect lighting (global illumination)
  • Normals: Approximate normals (ground=up, cubes=dominant axis)
  • Global Illumination: Recursive reflection rays with 0.3 reflectivity

Performance Notes

On NVIDIA RTX 3060 Ti:

  • Real-time rendering at 1080p
  • Current scene (5 objects, ~100 triangles): High FPS
  • Camera movement is smooth and responsive
  • Ready for more complex scenes with materials and lighting

Building from Scratch

If you want to set up dependencies manually:

# Clone dependencies
cd external
git clone --depth 1 https://github.com/g-truc/glm.git
git clone --depth 1 https://github.com/glfw/glfw.git

# Download single-header libraries
mkdir -p stb vma
curl -o stb/stb_image.h https://raw.githubusercontent.com/nothings/stb/master/stb_image.h
curl -o vma/vk_mem_alloc.h https://raw.githubusercontent.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator/master/include/vk_mem_alloc.h

# Build
cd ..
mkdir build && cd build
cmake .. && cmake --build . --config Release

Architecture Decisions

Why Pure Ray Tracing?

This engine uses 100% ray tracing with no rasterization pipeline:

  • Simpler architecture (no vertex/fragment shaders)
  • Unified lighting model (no separate shadow passes)
  • True reflections and refractions
  • Better suited for photorealistic racing environments

Memory Management

  • Device-local buffers for geometry
  • Host-visible staging buffers for uploads
  • Device addresses for bindless access in RT shaders
  • Proper buffer usage flags for RT (VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR)

Roadmap

Next milestones:

  1. Implement free camera controlsDONE
  2. Add ground plane and basic environmentDONE
  3. Improve lighting modelDONE
  4. Add shadows via shadow raysDONE
  5. Implement multiple bounces for global illuminationDONE
  6. Load car model (glTF)
  7. Add materials and textures (PBR)
  8. Implement diffuse bounces with importance sampling
  9. Add temporal accumulation for cleaner image

License

Custom engine for educational purposes.

Credits

  • Vulkan SDK: LunarG
  • GLFW: Marcus Geelnard, Camilla Löwy
  • GLM: G-Truc
  • stb: Sean Barrett
  • VMA: AMD GPUOpen

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors