Skip to content

Commit

Permalink
Added rtigo12 example.
Browse files Browse the repository at this point in the history
Based on rtigo10 but changed integrator to work like the MDL_renderer for throughput, pdf, and lights.
Replaced the GGX-Smith implementation to support direct lighting of glossy transparent materials.
That means singular light types will now show proper reflections on glossy transparent objects and even caustics when the roughness is not too smooth, because hitting backfaces will be directly lit from lights on the transmission side which adds radiance.
Added support for Specular and GGX_Smith BTDF materials.
Also homogeneous volume scattering is implemented in this example the same way as inside the MDL_renderer.
(See scene_rtigo12_*.txt files inside the data folder for examples.)
  • Loading branch information
droettger committed Feb 28, 2024
1 parent c44ed0d commit 9c2998c
Show file tree
Hide file tree
Showing 107 changed files with 61,306 additions and 7 deletions.
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,19 @@ To reduce the shader binding table size, where the previous examples used a hit

On top of that, by not supporting cutout opacity there is no need for anyhit programs in the whole pipeline. The shadow/visibility test ray type is implemented with just a miss shader, which also means there is no need to store hit records for the shadow ray type inside the shader binding table at all.

**rtigo12** is based on rtigo10 but changed the integrator to handle the throughput, pdf, and lights like the MDL_renderer.

The GGX-Smith BXDF implementation has been replaced with excerpts from the MDL SDK libbsdf to support direct lighting of glossy transparent materials as well. That means singular light types will now show proper reflections on glossy transparent objects and even caustics (when the roughness is not too smooth) because hitting backfaces will be directly lit from lights on the transmission side which adds radiance.
While changing that, support for Specular and GGX-Smith BTDF materials has been added.

Also homogeneous volume scattering is implemented in this example via a random walk through volumes with scattering coefficients the same way as inside the MDL_renderer. (See scene_rtigo12_*.txt files inside the data folder for example scenes.)

Note that mesh and rect lights are now defined with radiant exitance instead of radiant intensity, so with the diffuse EDF these are 1/PI darker than in rtigo10 but match the MDL_renderer.

![rtigo12 BXDF demo](./apps/rtigo12/rtigo12_demo.png)

![rtigo12 volume scattering bias](./apps/rtigo12/rtigo12_scattering_bias.png)

**MDL_renderer** is based on rtigo9 but replaced the previously few simple hardcoded BSDFs with NVIDIA Material Definition Language (MDL) shaders.

If you're not familiar with the **NVIDIA Material Definition Language**, please find the [MDL Introduction, Handbook, and Language Specifications](https://raytracing-docs.nvidia.com/mdl/index.html) on the [NVIDIA Ray Tracing Documentation](https://raytracing-docs.nvidia.com/) site.
Expand Down Expand Up @@ -338,13 +351,21 @@ The following command loads a generated OBJ file with 15,000 unit quads randomly

* `rtigo9_omm.exe -s system_rtigo9_leaf.txt -d scene_rtigo9_leaf.txt`

The rtigo12 example uses a slightly enhanced scene description format than rtigo9 and rtigo10 in that it added material parameters for the volume scattering color, scale and bias.
Above command lines for rtigo10 work as well, though mesh and rectangle lights will be 1/PI darker due to a change from radiant intensity to radiant exitance definition with diffuse EDFs.
The following scene files demonstrate all BXDF implementations and the volume scattering parameters and shows that volumetric shadows just work when placing lights and objects into surrounding objects with volume scattering.

* `rtigo12.exe -s system_rtigo12_demo.txt -d scene_rtigo12_demo.txt`
* `rtigo12.exe -s system_rtigo12_scattering_bias.txt -d scene_rtigo12_scattering_bias.txt`
* `rtigo12.exe -s system_rtigo12_volume_scattering.txt -d scene_rtigo12_volume_scattering.txt`

The MDL_renderer example uses the NVIDIA Material definition language for the shader generation.
The following scene only uses the *.mdl files and resources from the `data/mdl` folder you copied next to the executable after building the examples.
These show most of the fundamental MDL BSDFs, EDFs, VDFs, layers, mixers, modifiers, thin-walled geometry, textures, cutout opacity, base helper functions, etc.

* `MDL_renderer.exe -s system_mdl_demo.txt -d scene_mdl_demo.txt`

For a lot more complex materials (this scene requires about 5.4 GB of VRAM), the following command line will work if you have **all(!)** the [NVIDIA MDL vMaterials 1.7, 2.0, 2.1, 2.2 and 2.2.1](https://developer.nvidia.com/vmaterials) installed on the system. The application should then automatically find the referenced materials via the two environment variables `MDL_SYSTEM_PATH` and `MDL_USER_PATH` set by the vMaterials installation script. If a material exists as reference but couldn't be compiled because it isn't found or had errors, the renderer will not put the geometry with that invalid shader into the render graph. Means without the vMaterials installed only the area light should work in that scene because that is using one of the *.mdl files from the data folder. The result should look similar to the MDL_renderer example screenshot above, where some parameter values had been tweaked.
For a lot more complex materials (this scene requires about 5.4 GB of VRAM), the following command line will work if you have **all(!)** the [NVIDIA MDL vMaterials 1.7, 2.0, 2.1, 2.2, 2.2.1 and 2.3](https://developer.nvidia.com/vmaterials) installed on the system. The application should then automatically find the referenced materials via the two environment variables `MDL_SYSTEM_PATH` and `MDL_USER_PATH` set by the vMaterials installation script. If a material exists as reference but couldn't be compiled because it isn't found or had errors, the renderer will not put the geometry with that invalid shader into the render graph. Means without the vMaterials installed only the area light should work in that scene because that is using one of the *.mdl files from the data folder. The result should look similar to the MDL_renderer example screenshot above, where some parameter values had been tweaked.

* `MDL_renderer.exe -s system_mdl_vMaterials.txt -d scene_mdl_vMaterials.txt`

Expand Down
11 changes: 11 additions & 0 deletions apps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ endif()
# It's using the same scene description as rtigo9, but cutoput opacity textures are ignored.
add_subdirectory( rtigo10 )

# Based on rtigo10 but changed integrator to work like the MDL_renderer for throughput, pdf, and lights.
# Note that mesh and rect lights are now defined with radiant exitance instead of radiant intensity,
# so with the diffuse EDF these are 1/PI darker than in rtigo10 but match the MDL_renderer.
# Replaced the GGX-Smith implementation with excerpts from the MDL SDK libbsdf to support direct lighting of glossy transparent materials.
# That means singular light types will now show proper reflections on glossy transparent objects
# and even caustics when the roughness is not too smooth, because hitting backfaces will be directly lit from lights
# on the transmission side which adds radiance.
# Added support for Specular and GGX_Smith BTDF materials.
# Also homogeneous volume scattering is implemented in this example the same way as inside the MDL_renderer. (See scene_rtigo12_*.txt files for examples.)
add_subdirectory( rtigo12 )

# Based on rtigo9, but replacing all material handling with MDL materials.
# The MDL SDK is used to generate the minimal amount of direct callable programs per MDL material shader.
# The closesthit and anyhit programs inside hit.cu call the valid direct callable programs to handle the input values
Expand Down
4 changes: 2 additions & 2 deletions apps/rtigo10/shaders/brdf_ggx_smith.cu
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ extern "C" __global__ void __closesthit__brdf_ggx_smith()
// This is the density function with respect to the light vector.
const float pdf = D_pdf.y / (4.0f * dot(wi, wm)); // Walter, Formula (38) and (14)

if (pdf <= 0.0 || isNull(bxdf))
if (pdf <= 0.0f || isNull(bxdf))
{
return;
}
Expand All @@ -240,7 +240,7 @@ extern "C" __global__ void __closesthit__brdf_ggx_smith()
optixTrace(sysData.topObject,
thePrd->pos, lightSample.direction, // origin, direction
sysData.sceneEpsilon, lightSample.distance - sysData.sceneEpsilon, 0.0f, // tmin, tmax, time
OptixVisibilityMask(0xFF),
OptixVisibilityMask(0xFF),
OPTIX_RAY_FLAG_DISABLE_ANYHIT | OPTIX_RAY_FLAG_DISABLE_CLOSESTHIT | OPTIX_RAY_FLAG_TERMINATE_ON_FIRST_HIT,
0, 0, TYPE_RAY_SHADOW, // The shadow ray type only uses the miss program.
isVisible);
Expand Down
6 changes: 3 additions & 3 deletions apps/rtigo10/shaders/shader_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ __forceinline__ __host__ __device__ float luminance(const float3& rgb)

__forceinline__ __host__ __device__ float intensity(const float3& rgb)
{
return (rgb.x + rgb.y + rgb.z) * 0.3333333333f;
return (rgb.x + rgb.y + rgb.z) * (1.0f / 3.0f);
}

__forceinline__ __host__ __device__ float cube(const float x)
Expand Down Expand Up @@ -329,8 +329,8 @@ __forceinline__ __device__ unsigned int binarySearchCDF(const float* cdf, const

// This function evaluates a Fresnel dielectric function when the transmitting cosine ("cost")
// is unknown and the incident index of refraction is assumed to be 1.0f.
// \param et The transmitted index of refraction.
// \param costIn The cosine of the angle between the incident direction and normal direction.
// \param et The transmitted index of refraction.
// \param cosIn The cosine of the angle between the incident direction and normal direction.
__forceinline__ __device__ float evaluateFresnelDielectric(const float et, const float cosIn)
{
const float cosi = fabsf(cosIn);
Expand Down
2 changes: 1 addition & 1 deletion apps/rtigo10/src/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ Device::Device(const int ordinal,

initDeviceProperties(); // OptiX

// Null all data which tracks the roo IAS build.
// Null all data which tracks the root IAS build.
m_d_iasRoot = 0;
m_instanceInputRoot = {};
m_accelBuildOptionsRoot = {};
Expand Down
283 changes: 283 additions & 0 deletions apps/rtigo12/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,283 @@
# Copyright (c) 2013-2022, NVIDIA CORPORATION. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of NVIDIA CORPORATION nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# FindCUDA.cmake is deprecated since CMake 3.10.
# Use FindCUDAToolkit.cmake added in CMake 3.17 instead.
cmake_minimum_required(VERSION 3.17)

project( rtigo12 )
message("\nPROJECT_NAME = " "${PROJECT_NAME}")

find_package(OpenGL REQUIRED)
find_package(GLFW REQUIRED)
find_package(GLEW REQUIRED)
find_package(CUDAToolkit 10.0 REQUIRED)
find_package(DevIL_1_8_0 REQUIRED)
find_package(ASSIMP REQUIRED)

# OptiX SDK 7.x and 8.x versions are searched inside the top-level CMakeLists.txt.
# Make the build work with all currently released OptiX SDK 7.x and 8.x versions.
if(OptiX80_FOUND)
set(OPTIX_INCLUDE_DIR "${OPTIX80_INCLUDE_DIR}")
elseif(OptiX77_FOUND)
set(OPTIX_INCLUDE_DIR "${OPTIX77_INCLUDE_DIR}")
elseif(OptiX76_FOUND)
set(OPTIX_INCLUDE_DIR "${OPTIX76_INCLUDE_DIR}")
elseif(OptiX75_FOUND)
set(OPTIX_INCLUDE_DIR "${OPTIX75_INCLUDE_DIR}")
elseif(OptiX74_FOUND)
set(OPTIX_INCLUDE_DIR "${OPTIX74_INCLUDE_DIR}")
elseif(OptiX73_FOUND)
set(OPTIX_INCLUDE_DIR "${OPTIX73_INCLUDE_DIR}")
elseif(OptiX72_FOUND)
set(OPTIX_INCLUDE_DIR "${OPTIX72_INCLUDE_DIR}")
elseif(OptiX71_FOUND)
set(OPTIX_INCLUDE_DIR "${OPTIX71_INCLUDE_DIR}")
elseif(OptiX70_FOUND)
set(OPTIX_INCLUDE_DIR "${OPTIX70_INCLUDE_DIR}")
else()
message(FATAL_ERROR "No OptiX SDK 7.x found.")
endif()
#message("OPTIX_INCLUDE_DIR = " "${OPTIX_INCLUDE_DIR}")

# OptiX SDK 7.5.0 and CUDA 11.7 added support for a new OptiX IR target, which is a binary intermediate format for the module input.
# The default module build target is PTX.
set(USE_OPTIX_IR FALSE)
set(OPTIX_MODULE_EXTENSION ".ptx")
set(OPTIX_PROGRAM_TARGET "--ptx")

if (OptiX80_FOUND OR OptiX77_FOUND OR OptiX76_FOUND OR OptiX75_FOUND)
# Define USE_OPTIX_IR and change the target to OptiX IR if the combination of OptiX SDK and CUDA Toolkit versions supports this mode.
if ((${CUDAToolkit_VERSION_MAJOR} GREATER 11) OR ((${CUDAToolkit_VERSION_MAJOR} EQUAL 11) AND (${CUDAToolkit_VERSION_MINOR} GREATER_EQUAL 7)))
set(USE_OPTIX_IR TRUE)
set(OPTIX_MODULE_EXTENSION ".optixir")
set(OPTIX_PROGRAM_TARGET "--optix-ir")
endif()
endif()

set( IMGUI
imgui/imconfig.h
imgui/imgui.h
imgui/imgui_impl_glfw_gl3.h
imgui/imgui_internal.h
imgui/stb_rect_pack.h
imgui/stb_textedit.h
imgui/stb_truetype.h
imgui/imgui.cpp
imgui/imgui_demo.cpp
imgui/imgui_draw.cpp
imgui/imgui_impl_glfw_gl3.cpp
)

# Reusing some routines from the NVIDIA nvpro-pipeline https://github.com/nvpro-pipeline/pipeline
# Not built as a library, just using classes and functions directly.
# Asserts replaced with my own versions.
set( NVPRO_MATH
# Math functions:
dp/math/Config.h
dp/math/math.h
dp/math/Matmnt.h
dp/math/Quatt.h
dp/math/Trafo.h
dp/math/Vecnt.h
dp/math/src/Math.cpp
dp/math/src/Matmnt.cpp
dp/math/src/Quatt.cpp
dp/math/src/Trafo.cpp
)

set( HEADERS
inc/Application.h
inc/Arena.h
inc/Camera.h
inc/CheckMacros.h
inc/Device.h
inc/LightGUI.h
inc/LoaderIES.h
inc/MaterialGUI.h
inc/MyAssert.h
inc/NVMLImpl.h
inc/Options.h
inc/Parser.h
inc/Picture.h
inc/Rasterizer.h
inc/Raytracer.h
inc/SceneGraph.h
inc/Texture.h
inc/Timer.h
inc/TonemapperGUI.h
)

set( SOURCES
src/Application.cpp
src/Arena.cpp
src/Assimp.cpp
src/Box.cpp
src/Camera.cpp
src/Device.cpp
src/LoaderIES.cpp
src/main.cpp
src/NVMLImpl.cpp
src/Options.cpp
src/Parser.cpp
src/Picture.cpp
src/Plane.cpp
src/Rasterizer.cpp
src/Raytracer.cpp
src/Rect.cpp
src/SceneGraph.cpp
src/Sphere.cpp
src/Texture.cpp
src/Timer.cpp
src/Torus.cpp
)

# Prefix the shaders with the full path name to allow stepping through errors with F8.
set( SHADERS
# Core shaders.
${CMAKE_CURRENT_SOURCE_DIR}/shaders/bxdf.cu
${CMAKE_CURRENT_SOURCE_DIR}/shaders/brdf_diffuse.cu
${CMAKE_CURRENT_SOURCE_DIR}/shaders/brdf_specular.cu
${CMAKE_CURRENT_SOURCE_DIR}/shaders/bsdf_specular.cu
${CMAKE_CURRENT_SOURCE_DIR}/shaders/btdf_specular.cu
${CMAKE_CURRENT_SOURCE_DIR}/shaders/brdf_ggx_smith.cu
${CMAKE_CURRENT_SOURCE_DIR}/shaders/bsdf_ggx_smith.cu
${CMAKE_CURRENT_SOURCE_DIR}/shaders/btdf_ggx_smith.cu
${CMAKE_CURRENT_SOURCE_DIR}/shaders/edf_diffuse.cu

${CMAKE_CURRENT_SOURCE_DIR}/shaders/exception.cu
${CMAKE_CURRENT_SOURCE_DIR}/shaders/miss.cu
${CMAKE_CURRENT_SOURCE_DIR}/shaders/raygeneration.cu

# Direct callables
${CMAKE_CURRENT_SOURCE_DIR}/shaders/lens_shader.cu
${CMAKE_CURRENT_SOURCE_DIR}/shaders/light_sample.cu
)

set( KERNELS
# Native CUDA kernels
${CMAKE_CURRENT_SOURCE_DIR}/shaders/compositor.cu
)

set( SHADERS_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/shaders/camera_definition.h
${CMAKE_CURRENT_SOURCE_DIR}/shaders/compositor_data.h
${CMAKE_CURRENT_SOURCE_DIR}/shaders/config.h
${CMAKE_CURRENT_SOURCE_DIR}/shaders/function_indices.h
${CMAKE_CURRENT_SOURCE_DIR}/shaders/bxdf_common.h
${CMAKE_CURRENT_SOURCE_DIR}/shaders/light_definition.h
${CMAKE_CURRENT_SOURCE_DIR}/shaders/material_definition.h
${CMAKE_CURRENT_SOURCE_DIR}/shaders/per_ray_data.h
${CMAKE_CURRENT_SOURCE_DIR}/shaders/random_number_generators.h
${CMAKE_CURRENT_SOURCE_DIR}/shaders/shader_common.h
${CMAKE_CURRENT_SOURCE_DIR}/shaders/system_data.h
${CMAKE_CURRENT_SOURCE_DIR}/shaders/transform.h
${CMAKE_CURRENT_SOURCE_DIR}/shaders/vector_math.h
${CMAKE_CURRENT_SOURCE_DIR}/shaders/vertex_attributes.h
)

# When using OptiX SDK 7.5.0 and CUDA 11.7 or higher, the modules can either be built from OptiX IR input or from PTX input.
# OPTIX_PROGRAM_TARGET and OPTIX_MODULE_EXTENSION switch the NVCC compilation between the two options.
NVCUDA_COMPILE_MODULE(
SOURCES ${SHADERS}
DEPENDENCIES ${SHADERS_HEADERS}
TARGET_PATH "${MODULE_TARGET_DIR}/rtigo12_core"
EXTENSION "${OPTIX_MODULE_EXTENSION}"
GENERATED_FILES PROGRAM_MODULES
NVCC_OPTIONS "${OPTIX_PROGRAM_TARGET}" "--machine=64" "--gpu-architecture=compute_50" "--use_fast_math" "--relocatable-device-code=true" "--generate-line-info" "-Wno-deprecated-gpu-targets" "-I${OPTIX_INCLUDE_DIR}" "-I${CMAKE_CURRENT_SOURCE_DIR}/shaders"
)

# The native CUDA Kernels will be translated to *.ptx unconditionally.
NVCUDA_COMPILE_MODULE(
SOURCES ${KERNELS}
DEPENDENCIES ${SHADERS_HEADERS}
TARGET_PATH "${MODULE_TARGET_DIR}/rtigo12_core"
EXTENSION ".ptx"
GENERATED_FILES KERNEL_MODULES
NVCC_OPTIONS "--ptx" "--machine=64" "--gpu-architecture=compute_50" "--use_fast_math" "--relocatable-device-code=true" "--generate-line-info" "-Wno-deprecated-gpu-targets" "-I${CMAKE_CURRENT_SOURCE_DIR}/shaders"
)

source_group( "imgui" FILES ${IMGUI} )
source_group( "nvpro_math" FILES ${NVPRO_MATH} )
source_group( "headers" FILES ${HEADERS} )
source_group( "sources" FILES ${SOURCES} )
source_group( "shaders" FILES ${SHADERS} )
source_group( "shaders_headers" FILES ${SHADERS_HEADERS} )
source_group( "prg" FILES ${PROGRAM_MODULES} )
source_group( "ptx" FILES ${KERNEL_MODULES} )

include_directories(
"."
"inc"
"imgui"
${GLEW_INCLUDE_DIRS}
${GLFW_INCLUDE_DIR}
${OPTIX_INCLUDE_DIR}
${CUDAToolkit_INCLUDE_DIRS}
${IL_INCLUDE_DIR}
${ASSIMP_INCLUDE_DIRS}
)

add_definitions(
# Disable warnings for file operations fopen etc.
"-D_CRT_SECURE_NO_WARNINGS"
)

if(USE_OPTIX_IR)
add_definitions(
# This define switches the OptiX program module filenames to either *.optixir or *.ptx extensions at compile time.
"-DUSE_OPTIX_IR"
)
endif()

add_executable( rtigo12
${IMGUI}
${NVPRO_MATH}
${HEADERS}
${SOURCES}
${SHADERS_HEADERS}
${SHADERS}
${PROGRAM_MODULES}
${KERNEL_MODULES}
)

target_link_libraries( rtigo12
OpenGL::GL
${GLEW_LIBRARIES}
${GLFW_LIBRARIES}
CUDA::cuda_driver
${IL_LIBRARIES}
${ILU_LIBRARIES}
${ILUT_LIBRARIES}
${ASSIMP_LIBRARIES}
)

if (UNIX)
target_link_libraries( rtigo12 dl )
endif()

set_target_properties( rtigo12 PROPERTIES FOLDER "apps")

Loading

0 comments on commit 9c2998c

Please sign in to comment.