PRayGround
PRayGround copied to clipboard
GPU ray tracing framework using NVIDIA OptiX 7 and 8
Languages | English | 日本語
PRayGround
PRayGround is a C++/CUDA library with OptiX 7 that provides you with an easy and scalable environment to have fun a interactive ray tracing on GPU. This includes wrapper libraries of OptiX 7 API, easy management system of device side data pointer in per-instance (shape, material, textures, bitmap...) basis, intuitive setup and looping functions, and easy build system via CMake that enables you to launch tons of rays by just modifying App.h/cpp, main.cpp and adding your ray tracing code.
This project still remain a huge room to improve its readability, performance, and scalability. I'd appreciate it if you advise me any things!
1920 x 1080, 100000spp, 592.9s on NVIDIA RTX 3090
:computer: Requirements
Before building the project, please be sure to check requirements and your environment, especially if the your version of the C++ compiler supports C++20.
- CUDA Toolkit (Tested : 11.1, 11.2, 11.3, 11.4)
- C++ compiler which supports C++20
- Linux (Tested : g++ 10.3.0)
- Windows (Tested : Visual Studio 2019, version 16.10.2)
- OptiX 7 and 8 (Tested : 7.3 to 8.0)
- CMake 3.0 minimum (Tested : cmake 3.16.3)
:inbox_tray: Cloning
git clone https://github.com/sketchbooks99/PRayGround.git
cd PRayGround
git submodule update --init --recursive
:hammer: How to build
Linux
Before a compilation, please be sure to export two environment variables CC and CXX. We recommend you to add them to your ~/.bashrc file as follows so that they are automatically exported when a terminal is launched.
export CC=gcc-10
export CXX=g++-10
Next, you can build with following command. Please be sure to set OptiX_INCLUDE in terminal command of ccmake or in the launched prompt.
cd <path/to/PRayGround>
mkdir build
cd build
ccmake .. -DOptiX_INCLUDE=<path/to/OptiX>/include
or
ccmake .. # and set OptiX_INCLUDE to the path of OptiX library include.
# You can generate a makefile with a standard step of CMake ( [C] Configure -> [G] Generate ).
make
After compiling got through, the execution file will be created in the build/bin directory.
cd bin
./<app-name>
Windows
On Windows, a recent version of Visual Studio 2019 which supports C++20 features is required.
For configuring sources, please use cmake-gui to generate the solution files.
Building steps are as follows.
-
Start up cmake-gui.
-
Set the
<path/to/PRayGround>for the source code location ( Where is the source code ). -
Set the
<path/to/PRayGround>/buildfor the binary location ( Where to build the binaries ). -
Press
Configurebutton at the bottom of the window. When a window popped up, be careful with the settings for the platform to build. You must select Visual Studio 16 2019 as the generator to use the recent features of C++, and specify the x64 for the generator platform because OptiX only supports 64-bit builds. -
Press
Finishbutton and configuration will start. If errors occur while configuring, it may be due toOptiX_INCLUDE_NOTFOUNDerror. If so, please setOptiX_INCLUDEto the path of Optix library include. On Windows, OptiX include directory may be located inC:ProgramData\NVIDIA Corporation\OptiX SDK <your version>. -
When configulation finished, press
Generate. -
Open the
PRayGround.slnsolution file in the build directory. -
Execute
Build Solutionin the IDE. When compilation is succeeded, the execution file will be created in thebuild/bin/Debug or Releasedirectory. You also can run the ray tracer by setting the<app-name>project as start up project.
Mac
Not supported.
:bulb: Create new application
You can create your custom application by just adding new directory in apps/ and modifying App.h/.cpp, main.cpp and CMakeLists.txt.
The procedure is as follows:
- Copy and paste
apps/empty_appdirectory toapps/and rename the directory. - Modifying the app-name in
CMakeLists.txtinside the app directory.
PRAYGROUND_add_executalbe(empty_app target_name # empty_app -> <your-app-name>
main.cpp
app.cpp
app.h
)
target_compile_definitions(
${target_name}
PRIVATE
APP_DIR="${CMAKE_CURRENT_SOURCE_DIR}"
)
target_link_libraries(${target_name} ${CUDA_LIBRARIES})
- Add line of
add_subdirectory(<your-app-name>)inPRayGround/CMakeLists.txt.
# Executable apps
add_subdirectory(apps/empty_app)
add_subdirectory(apps/<your-app-name>) # Add this line
- Enjoy coding!
- Build your application using CMake.
External libraries
- glad (MIT license) ... For OpenGL features
- GLFW (Zlib license) ... For OpenGL
- hapPLY (MIT license) ... For loading PLY mesh
- Dear ImGui (MIT license)... For easy GUI usage
- stb (MIT license)... To read/write image of PNG, JPG format
- tinyexr ... To read/write image of OpenEXR format
- tinyobjloader (MIT and ISC license) ... For loading OBJ mesh
:art: Examples
Warning
The 3D models and textures used in the examples are not contained in this repository.
Single GAS
Scene with single geometry acceleration structure

Path tracing
Scene rendered by path tracinig. This example also visualizes depth, normal, and albedo buffers.

Obj scene
Example to load .obj file.

Ray Tracing in One Weekend Series
Examples to reproduce Ray Tracing in One Weekend Series by PRayGround
| The Next Weekend | The Rest Of Your Life |
|---|---|
![]() |
![]() |
Dynamic scene update
Example to dynamically update the acceleration structure.

Motion blur

Denoiser
:warning: This example supported after OptiX 7.3
Optix denoiser example using normal and albedo buffers

Spectrum
Spectrum rendering

Volume
Volume rendering with NanoVDB

Curves
Scene rendered with curved mesh

Opacity micromap
:warning: This feature is supported after OptiX 7.6
Example to build opacity micromap from texture with alpha value


