Skip to content

Forward-Fax3/GraphicsProgrammingWithCpp

Repository files navigation

GraphicsProgrammingWithCpp

This project is a continued evolution of my previous OOPWithCpp repository, now named GraphicsProgrammingWithCpp to better reflect its focus to now become a GPU Ray Tracer learning project for a different module of my second year university course.

C++ sandbox/learning project focused on OOP-style architecture with a Vulkan renderer and an SDL3 + Dear ImGui application layer. Then a CPU Ray Tracer implementation as the main rendering backend which sends renderd Images to the Vulkan renderer for display. The project uses Cmake to generate Ninja build files with multiple SIMD builds (SSE4.2, AVX2, AVX512). All SIMD builds must be built as the StartProj will link against them based on CPU detection at runtime. The new additions have been to add GPU Ray-Tracer using the Vulkan ray tracing extensions.

Features

  • Vulkan rendering backend (uses VULKAN_SDK)
  • SDL3 windowing/input (OOPWithCpp/3rdParty/Projects/git/SDL)
  • Dear ImGui UI (OOPWithCpp/3rdParty/Projects/git/ImGui)
  • glm math (OOPWithCpp/3rdParty/HeaderOnly/git/GLM)
  • stb_image loading (OOPWithCpp/3rdParty/HeaderOnly/git/stbImage)
  • tinygltf_v3 for GLTF loading (OOPWithCpp/3rdParty/HeaderOnly/Src/TinyGLTF)
  • Vulkan Memory Allocator for GPU memory management (OOPWithCpp/3rdParty/HeaderOnly/git/VMAhpp)
  • Cmake workspace with multiple SIMD builds (SSE4.2, AVX2, AVX512)
  • Uses Ninja build system for fast builds (generated by Cmake)
  • CPU Ray Tracer rendering backend
  • Only Clang officially supported, but should be possible to build with MSVC as well (not tested)
  • GPU Ray Tracer rendering backend using Vulkan ray tracing extensions and Slang for shader programming

CPU Ray Tracer Features

  • spheres at the moment
  • basic materials (diffuse, metal, dielectric)
  • diffuse light sources
  • single and multithreaded rendering
  • simple split BVH acceleration structure
  • scenes
    • single red sphere
    • 2 grey spheres
    • Dielectric Test
    • Metal Test
    • earth
    • Ray Tracing in one weekend final render like scene

GPU Ray Tracer Features

  • GLTF scene loading (using tinygltf_v3)
  • Full ray tracing pipeline implemented in Slang (ray generation, miss, closest hit)
  • For now just a lambertian material, but the framework is there to add more materials and features (e.g. textures, normal maps, etc.)
  • BLAS Instancing for the TLAS (so you can have many instances of the same mesh without needing to build a new BLAS for each one)

Repository Layout

  • OOPWithCpp/ — main library/source
  • OOPWithCpp/3rdParty/ — third party dependencies (git submodules)
  • StartProj/ — console app that depends on the library builds
  • ShaderSrc/ — shader sources (Slang)
  • premake5.lua — build generation script
  • Bin/ — build outputs (generated)

Requirements

  • for linux:
    • Wayland compile libraries (e.g. libwayland-dev on Debian-based distros) this is not required to run the program, but it is required to build the SDL3 backend, so if you want to build the project you will need it.
  • for windows:
    • Vulkan SDK (e.g. from LunarG)
    • Visual Studio backend for clang
  • for both:
    • Vulkan SDK
    • a clang version that supports C++23
    • CMake 4.1+
    • Ninja
    • A GPU that supports Vulkan ray tracing extensions (e.g. NVIDIA RTX series, AMD RX 6000 series, Intel Arc series)

Getting Started (Cmake)

  • Clone the repository with git clone --recurse-submodules https://github.com/Forward-Fax3/GraphicsProgrammingWithCpp.git
  • build configurations:
    • clang_Debug
    • clang_Debug_Optimized
    • clang_Dist
  • startup project is StartProj, so make sure to set that as the startup project in your IDE after generating the build files with CMake.
  • To generate the build files with CMake, you can use the following command from the root of the repository:
    • cmake -S . -B Build -G Ninja -DCMAKE_BUILD_TYPE=Debug (for clang_Debug)
    • cmake -S . -B Build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo (for clang_Debug_Optimized)
    • cmake -S . -B Build -G Ninja -DCMAKE_BUILD_TYPE=Release (for clang_Dist)

Problems

  • If you resize the window before you have enabled the ray tracer, it will not update the ray tracer's resolution. Therefor making the image look distorted, this can be fixed by resizing the window again after enabling the ray tracer.
  • sometimes when moving the camera the whole program will soft lock up, this is due to a deadlock in the ray tracer's multi-threading implementation.
  • the GPU ray tracer is currently very basic and only supports a single lambertian material, there is no support for textures, normal maps, or any other material types yet. This is something that I plan to add in the future, but for now it is just a proof of concept.
  • Textures are not supported in the GPU ray tracer yet, this is something that I plan to add in the future.
  • There's some kind of wall anomalies which means the walls don't look right at the moment.
  • If you point the camera in the right spots it looks like the accumulation is not working correctly and individual pixels just get stuck this is probably an issue with not have the normal maps yet.

Notes

  • This File has been created with the assistance of AI. Though I have reviewed and edited it.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors