Skip to content

mslup/CUDA-Raycasting

Repository files navigation

GPU-Accelerated Ray Tracing Simulation

Overview

This C++ project, developed for the course on Graphic Processors in Computational Applications at the Faculty of Mathematics and Information Science at WUT, implements a ray tracing simulation using CUDA Toolkit 12.2. The project is compiled in Visual Studio 2022 and optimized for Release mode. Heavily inspired by TheCherno's series on ray tracing in C++.

By default, the simulation runs on GPU, offering an option in the Menu to switch to CPU. The scene includes 1000 spheres and 10 light sources.

Ray Tracing Mechanism

For each pixel, a ray is cast from the camera, and each ray corresponds to a separate thread. The simulation checks for sphere intersections, applying the Phong lighting model to calculate pixel colors.

In the shadow-enabled version (selectable in the menu), rays are reflected to all light sources. New rays are created, checking for additional sphere intersections on the path from the light source to the reflection point.

Camera Controls

Camera controls are outlined in the Menu under the Camera Controls section. The project incorporates projection and view matrices along with texture resizing for dynamic window size changes and automatic resolution adjustments

Adjustable Parameters

Environment

  • Sky color: Color of a pixel where the ray doesn't hit any sphere.
  • Ambient light color: Color of ambient light.
  • Sphere material: Parameters for the Phong lighting model (diffuse, specular, shininess, ambient).

Light Sources

  • Attenuation: Light strength, determining how light intensity changes with increasing distance from the object.
  • Light positions
  • Light colors
  • Disable lights

Demonstration

Zrzut ekranu 2024-01-17 223353 Zrzut ekranu 2024-01-17 224856 Zrzut ekranu 2024-01-17 184450

Todo

  • write from CUDA to texture buffer directly
  • further optimalization (kd-tree...)
  • physically based rendering

About

Raycasting of a 1,000 spheres using Phong reflection model written in C++ and CUDA

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages