├── .github └── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── build-problem.md │ ├── feature_request.md │ └── other.md ├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── CMakePresets.json ├── LICENSE ├── README.md ├── assets ├── 001-free-hdri-skies-com.hdr ├── BN0.bmp ├── Barce_Rooftop_C_3k.hdr ├── blackbody_texture.exr ├── colored_smoke.vdb ├── density_color_texture.exr ├── density_color_texture2.exr ├── dragon.vdb ├── dragon_with_xform.vdb └── fireball.vdb ├── build_windows.cmd ├── img ├── VPT_Banner.gif ├── platform.JPG ├── render_textures.JPG └── toolchain.JPG ├── instancer_hda ├── CMakeLists.txt ├── README.md ├── ROP_VPT_Instance.cpp ├── ROP_VPT_Instance.h ├── file_IO.cpp ├── file_IO.h ├── icon │ └── ROP_VPT_Instance.svg ├── scenes │ └── scene_1.hiplc └── volume_instance.h ├── source ├── CMakeLists.txt ├── CompileObj.cmake ├── Helpers.cmake ├── atmosphere │ ├── atmosphere.cpp │ ├── atmosphere.h │ ├── atmosphere_kernels.cu │ ├── constants.h │ └── definitions.h ├── bitmap_image.h ├── bvh │ ├── AABB.h │ ├── bvh.cpp │ ├── bvh.h │ ├── bvh_builder.cpp │ ├── bvh_builder.h │ ├── bvh_kernels.cu │ ├── octree.cpp │ └── octree.h ├── common │ ├── exception.h │ ├── helper_cuda.h │ ├── helper_functions.h │ ├── helper_gl.h │ ├── helper_image.h │ ├── helper_math.h │ ├── helper_string.h │ └── helper_timer.h ├── geometry │ ├── geometry.h │ ├── geometry_kernels.cu │ ├── plane.h │ └── sphere.h ├── gpu_vdb │ ├── camera.h │ ├── gpu_vdb.cpp │ ├── gpu_vdb.h │ └── matrix_math.h ├── hdr_loader.h ├── kernel_params.h ├── light.h ├── main.cpp ├── render_kernel.cu ├── texture_kernels.cu └── util │ ├── fileIO.cpp │ ├── fileIO.h │ ├── logger.cpp │ └── logger.h ├── thirdparty └── OpenImageDenoise │ ├── bin │ ├── OpenImageDenoise.dll │ ├── OpenImageDenoise_core.dll │ ├── OpenImageDenoise_device_cpu.dll │ └── OpenImageDenoise_device_cuda.dll │ ├── include │ └── OpenImageDenoise │ │ ├── config.h │ │ ├── oidn.h │ │ └── oidn.hpp │ ├── lib │ ├── OpenImageDenoise.lib │ ├── OpenImageDenoise_core.lib │ └── cmake │ │ └── OpenImageDenoise-2.1.0 │ │ ├── OpenImageDenoiseConfig.cmake │ │ ├── OpenImageDenoiseConfigVersion.cmake │ │ ├── OpenImageDenoiseTargets-release.cmake │ │ └── OpenImageDenoiseTargets.cmake │ └── share │ └── doc │ └── OpenImageDenoise │ ├── CHANGELOG.md │ ├── LICENSE.txt │ ├── README.md │ ├── readme.pdf │ ├── third-party-programs-DPCPP.txt │ ├── third-party-programs-oneDNN.txt │ ├── third-party-programs-oneTBB.txt │ └── third-party-programs.txt └── vcpkg.json /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help VPT 4 | title: "[BUG]" 5 | labels: bug 6 | assignees: sergeneren 7 | 8 | --- 9 | 10 | **Pre Report** 11 | Please make sure you have completed below checklist before submitting a report 12 | 13 | - [ ] Build VPT with DebugLevel "Log" 14 | - [ ] Run VPT to a log file [e.g "*.\vpt.exe fireball.ins >log.txt*" ] 15 | - [ ] Attach the log file here 16 | 17 | **Describe the bug** 18 | A clear and concise description of what the bug is. 19 | 20 | **To Reproduce** 21 | Steps to reproduce the behavior: 22 | 1. ... 23 | 2. ... 24 | 25 | **Expected behavior** 26 | A clear and concise description of what you expected to happen. 27 | 28 | **Screenshots** 29 | If applicable, add screenshots to help explain your problem. 30 | 31 | **Desktop (please complete the following information):** 32 | - GPU: [e.g. GTX 1080, RTX Series] 33 | - Driver version [ e.g. Game Ready driver, Studio Driver] 34 | 35 | **Additional context** 36 | Add any other context about the problem here. 37 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/build-problem.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Build Problem 3 | about: 'Create a report if you are unable to build VPT ' 4 | title: "[BUILD]" 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Pre Report** 11 | Before submitting a report please make sure you followed below checklist. 12 | 13 | - [ ] My OS is windows 10 14 | - [ ] Using CMake greater than 3.8.0 15 | - [ ] Using x64 platform 16 | - [ ] Passed vcpkg toolchain file to CMake 17 | - [ ] Vcpkg has all the correct libraries installed 18 | 19 | 20 | **Error Messages** 21 | Please attach the error messages here 22 | 23 | 24 | **Additional context** 25 | Add any other context about the problem here. 26 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: "[FEATURE]" 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/other.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Other 3 | about: 'For all other inquiries ' 4 | title: "[OTHER]" 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | [Bb]uild/ 2 | [Aa]ssets/backup 3 | [Aa]ssets/[Tt]emp 4 | thirdparty/gvdb-voxels/ 5 | 6 | instancer_hda/scenes/backup 7 | 8 | *.pdb -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "thirdparty/cuda-noise"] 2 | path = thirdparty/cuda-noise 3 | url = https://github.com/sergeneren/cuda-noise 4 | [submodule "vcpkg"] 5 | path = vcpkg 6 | url = https://github.com/microsoft/vcpkg 7 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.23.0 FATAL_ERROR) 2 | project(VPT LANGUAGES CXX CUDA) 3 | 4 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 5 | 6 | ################################################################## 7 | 8 | ## Set output directories 9 | 10 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) 11 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) 12 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) 13 | 14 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/lib) 15 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/lib) 16 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/bin) 17 | 18 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/lib) 19 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/lib) 20 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/bin) 21 | 22 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_BINARY_DIR}/lib) 23 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_BINARY_DIR}/lib) 24 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_BINARY_DIR}/bin) 25 | 26 | ################################################################## 27 | 28 | set(_VCPKG_INCLUDE_DIR "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include") 29 | set(_VCPKG_LIB_DIR "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib") 30 | set(_VCPKG_BIN_DIR "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/bin") 31 | 32 | option (BUILD_VPT "Builds Volumetric Path Tracer" ON) 33 | option (BUILD_INSTANCER "Builds Houdini plugin to save instance files" OFF) 34 | 35 | set(DebugLevel "Error" CACHE STRING "Choose a debug level that VPT will use in message display") 36 | set_property(CACHE DebugLevel PROPERTY STRINGS Error Warning Log) 37 | 38 | message(STATUS "Debug Level is ${DebugLevel}") 39 | if(${DebugLevel} STREQUAL "Error") 40 | add_definitions(-DLOG_LEVEL_ERROR) 41 | elseif(${DebugLevel} STREQUAL "Warning") 42 | add_definitions(-DLOG_LEVEL_WARNING) 43 | elseif(${DebugLevel} STREQUAL "Log") 44 | add_definitions(-DLOG_LEVEL_LOG) 45 | endif() 46 | 47 | 48 | if(BUILD_VPT) 49 | add_subdirectory(${CMAKE_SOURCE_DIR}/source) 50 | endif(BUILD_VPT) 51 | 52 | if(BUILD_INSTANCER) 53 | add_subdirectory(${CMAKE_SOURCE_DIR}/instancer_hda) 54 | endif(BUILD_INSTANCER) -------------------------------------------------------------------------------- /CMakePresets.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 4, 3 | "cmakeMinimumRequired": { 4 | "major": 3, 5 | "minor": 25, 6 | "patch": 0 7 | }, 8 | "configurePresets": [ 9 | { 10 | "name": "Default", 11 | "displayName": "Development Configuration", 12 | "description": "Default configuration for dev environment", 13 | "binaryDir": "${sourceDir}/build/", 14 | "cacheVariables": { 15 | "CMAKE_TOOLCHAIN_FILE": { 16 | "type": "FILEPATH", 17 | "value": "${sourceDir}/vcpkg/scripts/buildsystems/vcpkg.cmake" 18 | }, 19 | "BUILD_VPT": { 20 | "type": "BOOLEAN", 21 | "value": "ON" 22 | }, 23 | "OpenImageDenoise_DIR": "${sourceDir}/thirdparty/OpenImageDenoise/lib/cmake/OpenImageDenoise-2.1.0", 24 | "CMAKE_CONFIGURATION_TYPES": "RelWithDebInfo", 25 | "CMAKE_BUILD_TYPE": "RelWithDebInfo", 26 | "VCPKG_INSTALLED_DIR": "${sourceDir}/vcpkg/vcpkg_installed", 27 | "VCPKG_BUILD_TYPE": "release", 28 | "VCPKG_TARGET_TRIPLET": "x64-windows" 29 | } 30 | } 31 | ], 32 | "buildPresets": [ 33 | { 34 | "name": "Default", 35 | "configurePreset": "Default", 36 | "displayName": "Build RelWithDebInfo", 37 | "description": "Build RelWithDebInfo configuration", 38 | "configuration": "RelWithDebInfo" 39 | } 40 | ] 41 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2019, Sergen Eren 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | * Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Volumetric Path Tracer 2 | 3 | ![banner](https://github.com/sergeneren/Volumetric-Path-Tracer/blob/master/img/VPT_Banner.gif) 4 | 5 | VPT is a volumetric path tracer to render openvdb files on gpu using Cuda. It uses the [Ray Tracing Gems Vol 28.](https://github.com/Apress/ray-tracing-gems/tree/master/Ch_28_Ray_Tracing_Inhomogeneous_Volumes) as the base, and implements volume rendering algorithms from [PBRT](https://www.pbrt.org/). Features of VPT is listed below 6 | 7 | * Ability to render Open VDB files with thousands of ray depths on gpu 8 | * Realistic lighting with a procedural atmosphere and sun system 9 | * HDRI maps for environmental lighting 10 | * Point lights 11 | * Eric Bruneton style sky implementation 12 | * Depth of field 13 | * Volume emission 14 | * Ability to render planetary atmospheres 15 | * Instanced rendering of vdb files with custom file format (.ins) 16 | * BVH and Octree structures for fast ray traversal 17 | * Custom instance file writer plugin for Houdini written in HDK 18 | 19 | This repo is currently built and tested only under Windows. 20 | 21 | ## Release Notes 22 | 23 | v 1.0.2 Alpha 24 | 25 | *Please see the [releases](https://github.com/sergeneren/Volumetric-Path-Tracer/releases) section for release notes.* 26 | 27 | ## Installation, Build and Usage 28 | 29 | Use the `build_windows.cmd` file for building automatically on windows. Also see [this](https://sergeneren.com/2020/01/07/using-vpt/) detailed article for using VPT. 30 | This repo is tested with Cuda 12.1 and Nvidia Driver 546.65 31 | 32 | ## Author 33 | 34 | * **Sergen Eren** - [My website](https://sergeneren.com) 35 | 36 | ## Status 37 | :heavy_check_mark: This project is under active maintenance and development 38 | 39 | ## License 40 | This project is licensed under BSD 3-Clause License 41 | 42 | ## Acknowledgments 43 | * [PBRT](https://github.com/mmp/pbrt-v3/) - *Big thanks to Matt Pharr, Wenzel Jakob and Greg Humphreys* 44 | * [GVDB](https://github.com/NVIDIA/gvdb-voxels) - *Nvidia Sparse Voxel Database* 45 | * [Ray Tracing Gems](http://www.realtimerendering.com/raytracinggems/) - *Base of VPT* 46 | * [Walt Disney Animation Studios](https://www.disneyanimation.com/) - *Moana Cloud Dataset* 47 | -------------------------------------------------------------------------------- /assets/001-free-hdri-skies-com.hdr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergeneren/Volumetric-Path-Tracer/8708189867bebab06d75d1894746c4927e5800ec/assets/001-free-hdri-skies-com.hdr -------------------------------------------------------------------------------- /assets/BN0.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergeneren/Volumetric-Path-Tracer/8708189867bebab06d75d1894746c4927e5800ec/assets/BN0.bmp -------------------------------------------------------------------------------- /assets/Barce_Rooftop_C_3k.hdr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergeneren/Volumetric-Path-Tracer/8708189867bebab06d75d1894746c4927e5800ec/assets/Barce_Rooftop_C_3k.hdr -------------------------------------------------------------------------------- /assets/blackbody_texture.exr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergeneren/Volumetric-Path-Tracer/8708189867bebab06d75d1894746c4927e5800ec/assets/blackbody_texture.exr -------------------------------------------------------------------------------- /assets/colored_smoke.vdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergeneren/Volumetric-Path-Tracer/8708189867bebab06d75d1894746c4927e5800ec/assets/colored_smoke.vdb -------------------------------------------------------------------------------- /assets/density_color_texture.exr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergeneren/Volumetric-Path-Tracer/8708189867bebab06d75d1894746c4927e5800ec/assets/density_color_texture.exr -------------------------------------------------------------------------------- /assets/density_color_texture2.exr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergeneren/Volumetric-Path-Tracer/8708189867bebab06d75d1894746c4927e5800ec/assets/density_color_texture2.exr -------------------------------------------------------------------------------- /assets/dragon.vdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergeneren/Volumetric-Path-Tracer/8708189867bebab06d75d1894746c4927e5800ec/assets/dragon.vdb -------------------------------------------------------------------------------- /assets/dragon_with_xform.vdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergeneren/Volumetric-Path-Tracer/8708189867bebab06d75d1894746c4927e5800ec/assets/dragon_with_xform.vdb -------------------------------------------------------------------------------- /assets/fireball.vdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergeneren/Volumetric-Path-Tracer/8708189867bebab06d75d1894746c4927e5800ec/assets/fireball.vdb -------------------------------------------------------------------------------- /build_windows.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | setlocal 4 | 5 | git submodule init 6 | git submodule update 7 | 8 | if not exist ./vcpkg/vcpkg.exe ( 9 | call ./vcpkg/bootstrap-vcpkg.bat 10 | ) 11 | 12 | if not exist ./vcpkg/vcpkg.exe ( 13 | echo Unable to bootstrap vcpkg! 14 | exit 1 15 | ) 16 | 17 | if exist build rmdir /s /q build 18 | 19 | cmake --preset Default . 20 | if errorlevel 1 ( 21 | echo failed to configure 22 | exit 1 23 | ) 24 | 25 | 26 | cmake --build ./build --preset Default 27 | if errorlevel 1 ( 28 | echo failed to build 29 | exit 1 30 | ) 31 | 32 | echo Successfully built VPT! You can find the executable under build/bin directory -------------------------------------------------------------------------------- /img/VPT_Banner.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergeneren/Volumetric-Path-Tracer/8708189867bebab06d75d1894746c4927e5800ec/img/VPT_Banner.gif -------------------------------------------------------------------------------- /img/platform.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergeneren/Volumetric-Path-Tracer/8708189867bebab06d75d1894746c4927e5800ec/img/platform.JPG -------------------------------------------------------------------------------- /img/render_textures.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergeneren/Volumetric-Path-Tracer/8708189867bebab06d75d1894746c4927e5800ec/img/render_textures.JPG -------------------------------------------------------------------------------- /img/toolchain.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergeneren/Volumetric-Path-Tracer/8708189867bebab06d75d1894746c4927e5800ec/img/toolchain.JPG -------------------------------------------------------------------------------- /instancer_hda/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #add houdini cmake lists 2 | 3 | set(HOUDINI_CMAKE_DIR "C:/Program Files/Side Effects Software/Houdini 18.0.287/toolkit/cmake") 4 | list(APPEND CMAKE_PREFIX_PATH ${HOUDINI_CMAKE_DIR}) 5 | 6 | # Locate Houdini's libraries and header files. 7 | # Registers an imported library target named 'Houdini'. 8 | find_package( Houdini) 9 | 10 | file (GLOB Headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h" ) 11 | file (GLOB Sources "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" ) 12 | 13 | add_library(instancer_hda SHARED ${Headers} ${Sources}) 14 | target_link_libraries(instancer_hda Houdini) 15 | 16 | include_directories(${_VCPKG_INCLUDE_DIR}) 17 | 18 | message(STATUS "Houdini directory: ${Houdini_DIR}") 19 | 20 | houdini_configure_target( instancer_hda ) 21 | 22 | 23 | #copy icon to %HOME%/%HOUDINI_VERSION%/config/icons folder 24 | 25 | set(TARGET_FILE "${CMAKE_CURRENT_SOURCE_DIR}/icon/ROP_VPT_Instance.svg") 26 | set(TARGET_DIR "") 27 | 28 | houdini_get_default_install_dir(TARGET_DIR) 29 | 30 | set(TARGET_DIR "${TARGET_DIR}\\config\\icons") 31 | 32 | add_custom_command(TARGET instancer_hda 33 | POST_BUILD 34 | COMMAND ${CMAKE_COMMAND} -E copy "${TARGET_FILE}" "${TARGET_DIR}" 35 | COMMENT "Copying ${TARGET_FILE} to ${TARGET_DIR}") 36 | 37 | message(STATUS "${TARGET_FILE} will be copied to ${TARGET_DIR}") -------------------------------------------------------------------------------- /instancer_hda/README.md: -------------------------------------------------------------------------------- 1 | # Instancer HDA 2 | 3 | 4 | Instancer HDA is an *".ins"* file writer ROP plugin for Houdini. This file is used with VPT to render volume instances. 5 | 6 | 7 | ## Release Notes 8 | 9 | v 1.0.0 Alpha 10 | 11 | ## Installation 12 | 13 | Instancer HDA comes with VPT and no further installation is required. 14 | 15 | ### Build 16 | 17 | Build instancer_hda with release configuration and it will install itself as a post build step to *$(HOME)/$(Houdini_VERSION)/dso* directory. Currently houdini cmake directory is hardcoded for Houdini 18.0.287 but you can change it in CMake. 18 | 19 | 20 | ### Usage 21 | 22 | Create a point cloud with string attribute *"instancefile"* pointing to the vdb file you want to instance. 23 | 24 | For creating a transformation matrix Instancer uses the following attributes. 25 | 26 | * Point position is written as translation 27 | * Instancer uses pscale to set the scale of the instance 28 | * For rotations Instancer uses couple options 29 | * If *"orient"* quaternion attribute is present it is used with first priority 30 | * *"rot"* attribute is used if *"orient"* is not present secondary priority 31 | * If both quaternion attributes are missing, Instancer uses *"N"* and *"up"* to create an orient rotation 32 | * If none is present default values are written and VPT creates an identity matrix 33 | 34 | An example file is provided under scenes folder. 35 | 36 | ## Author 37 | 38 | * **Sergen Eren** - [My website](https://sergeneren.com) 39 | 40 | ## Status 41 | This library is under active maintenance 42 | 43 | ## License 44 | This project is licensed under BSD 3-Clause License 45 | -------------------------------------------------------------------------------- /instancer_hda/ROP_VPT_Instance.cpp: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------- 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are met : 5 | // 6 | // *Redistributions of source code must retain the above copyright notice, this 7 | // list of conditions and the following disclaimer. 8 | // 9 | // * Redistributions in binary form must reproduce the above copyright notice, 10 | // this list of conditions and the following disclaimer in the documentation 11 | // and/or other materials provided with the distribution. 12 | // 13 | // * Neither the name of the copyright holder nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | // DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 21 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | // DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 | // OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // Copyright(c) 2019, Sergen Eren 29 | // All rights reserved. 30 | //---------------------------------------------------------------------------------- 31 | // 32 | // Version 1.0: Sergen Eren, 03/12/2019 33 | // 34 | // File: Volume instance file exporter for VPT 35 | // 36 | //----------------------------------------------- 37 | 38 | 39 | #include "ROP_VPT_Instance.h" 40 | #include "file_IO.h" 41 | 42 | using namespace vpt_instance; 43 | 44 | static PRM_Name names[] = { 45 | PRM_Name("outputFile", "Output File"), 46 | PRM_Name("soppath", "SOP Path"), 47 | PRM_Name("render_light", "Render Light Instances") 48 | }; 49 | 50 | static PRM_Default theFileDefault(0, "$HIP/Outputs/VPT/defgeo.ins"); 51 | 52 | PRM_Template VPT_INS_ROP::myTemplateList[] = { 53 | PRM_Template(PRM_FILE_E, 1, &names[0], &theFileDefault , 0, 0 , 0 , &PRM_SpareData::fileChooserModeWrite), // file Output 54 | PRM_Template(PRM_STRING, PRM_TYPE_DYNAMIC_PATH, 1, &names[1], 0, 0, 0, 0, &PRM_SpareData::sopPath), // sop path 55 | PRM_Template(PRM_TOGGLE, 1, &names[2], PRMzeroDefaults), // render Light instance 56 | PRM_Template() // placeholder 57 | }; 58 | 59 | // End custom template list 60 | 61 | static PRM_Name MKPATH_PRM_NAME("mkpath", "Create Intermediate Directories"); 62 | static PRM_Name INITSIM_PRM_NAME("initsim", "Initialize Simulation OPs"); 63 | static PRM_Name ALFPROGRESS_PRM_NAME("alfprogress", "Alfred Style Progress"); 64 | 65 | static PRM_Template * getTemplates() 66 | { 67 | static PRM_Template *prmTemplate = 0; 68 | 69 | if (prmTemplate) 70 | { 71 | return prmTemplate; 72 | } 73 | 74 | prmTemplate = new PRM_Template[ROP_VPT_MAXPARMS + 1]; 75 | 76 | prmTemplate[ROP_VPT_RENDER] = theRopTemplates[ROP_RENDER_TPLATE]; 77 | prmTemplate[ROP_VPT_RENDERBACKGROUND] = theRopTemplates[ROP_RENDERBACKGROUND_TPLATE]; 78 | prmTemplate[ROP_VPT_RENDER_CTRL] = theRopTemplates[ROP_RENDERDIALOG_TPLATE]; 79 | prmTemplate[ROP_VPT_TRANGE] = theRopTemplates[ROP_TRANGE_TPLATE]; 80 | prmTemplate[ROP_VPT_FRANGE] = theRopTemplates[ROP_FRAMERANGE_TPLATE]; 81 | prmTemplate[ROP_VPT_TAKE] = theRopTemplates[ROP_TAKENAME_TPLATE]; 82 | prmTemplate[ROP_VPT_SOPOUTPUT] = VPT_INS_ROP::myTemplateList[0]; 83 | prmTemplate[ROP_VPT_SOPPATH] = VPT_INS_ROP::myTemplateList[1]; 84 | prmTemplate[ROP_VPT_LIGHT] = VPT_INS_ROP::myTemplateList[2]; 85 | 86 | prmTemplate[ROP_VPT_TPRERENDER] = theRopTemplates[ROP_TPRERENDER_TPLATE]; 87 | prmTemplate[ROP_VPT_PRERENDER] = theRopTemplates[ROP_PRERENDER_TPLATE]; 88 | prmTemplate[ROP_VPT_LPRERENDER] = theRopTemplates[ROP_LPRERENDER_TPLATE]; 89 | prmTemplate[ROP_VPT_TPREFRAME] = theRopTemplates[ROP_TPREFRAME_TPLATE]; 90 | prmTemplate[ROP_VPT_PREFRAME] = theRopTemplates[ROP_PREFRAME_TPLATE]; 91 | prmTemplate[ROP_VPT_LPREFRAME] = theRopTemplates[ROP_LPREFRAME_TPLATE]; 92 | prmTemplate[ROP_VPT_TPOSTFRAME] = theRopTemplates[ROP_TPOSTFRAME_TPLATE]; 93 | prmTemplate[ROP_VPT_POSTFRAME] = theRopTemplates[ROP_POSTFRAME_TPLATE]; 94 | prmTemplate[ROP_VPT_LPOSTFRAME] = theRopTemplates[ROP_LPOSTFRAME_TPLATE]; 95 | prmTemplate[ROP_VPT_TPOSTRENDER] = theRopTemplates[ROP_TPOSTRENDER_TPLATE]; 96 | prmTemplate[ROP_VPT_POSTRENDER] = theRopTemplates[ROP_POSTRENDER_TPLATE]; 97 | prmTemplate[ROP_VPT_LPOSTRENDER] = theRopTemplates[ROP_LPOSTRENDER_TPLATE]; 98 | prmTemplate[ROP_VPT_MKPATH] = theRopTemplates[ROP_MKPATH_TPLATE]; 99 | prmTemplate[ROP_VPT_INITSIM] = theRopTemplates[ROP_INITSIM_TPLATE]; 100 | prmTemplate[ROP_VPT_ALFPROGRESS] = PRM_Template(PRM_TOGGLE, 1, &ALFPROGRESS_PRM_NAME, PRMzeroDefaults); 101 | 102 | prmTemplate[ROP_VPT_MAXPARMS] = PRM_Template(); 103 | 104 | return prmTemplate; 105 | }; 106 | 107 | OP_TemplatePair * VPT_INS_ROP::getTemplatePair() 108 | { 109 | static OP_TemplatePair *ropPair = 0; 110 | 111 | if (ropPair) 112 | { 113 | return ropPair; 114 | } 115 | 116 | ropPair = new OP_TemplatePair(getTemplates()); 117 | 118 | return ropPair; 119 | }; 120 | 121 | OP_VariablePair * VPT_INS_ROP::getVariablePair() 122 | { 123 | static OP_VariablePair *varPair = 0; 124 | 125 | if (varPair) 126 | { 127 | return varPair; 128 | } 129 | 130 | varPair = new OP_VariablePair(ROP_Node::myVariableList); 131 | 132 | return varPair; 133 | }; 134 | 135 | // start, end and render frames are auto invoked by houdini 136 | 137 | int VPT_INS_ROP::startRender(int /*nframes*/, fpreal tstart, fpreal tend) 138 | { 139 | int rcode = 1; 140 | 141 | endTime = tend; 142 | startTime = tstart; 143 | 144 | if (INITSIM()) 145 | { 146 | initSimulationOPs(); 147 | OPgetDirector()->bumpSkipPlaybarBasedSimulationReset(1); 148 | } 149 | 150 | if (error() < UT_ERROR_ABORT) 151 | { 152 | if (!executePreRenderScript(tstart)) 153 | return 0; 154 | } 155 | 156 | return rcode; 157 | } 158 | 159 | 160 | ROP_RENDER_CODE VPT_INS_ROP::renderFrame(fpreal time, UT_Interrupt *) 161 | { 162 | 163 | SOP_Node *sop; 164 | UT_String soppath, savepath, name; 165 | 166 | OUTPUT(savepath, time); 167 | bool render_light = LIGHT(); 168 | 169 | if (!executePreFrameScript(time)) 170 | return ROP_ABORT_RENDER; 171 | 172 | // From here, establish the SOP that will be rendered, if it cannot 173 | // be found, return 0. 174 | // This is needed to be done here as the SOPPATH may be time 175 | // dependent (ie: OUT$F) or the perframe script may have 176 | // rewired the input to this node. 177 | 178 | sop = CAST_SOPNODE(getInput(0)); 179 | if (sop) 180 | { 181 | // If we have an input, get the full path to that SOP. 182 | sop->getFullPath(soppath); 183 | } 184 | else 185 | { 186 | // Otherwise get the SOP Path from our parameter. 187 | SOPPATH(soppath, time); 188 | } 189 | 190 | if (!soppath.isstring()) 191 | { 192 | addError(ROP_MESSAGE, "Invalid SOP path"); 193 | return ROP_ABORT_RENDER; 194 | } 195 | 196 | sop = getSOPNode(soppath, 1); 197 | if (!sop) 198 | { 199 | addError(ROP_COOK_ERROR, (const char *)soppath); 200 | return ROP_ABORT_RENDER; 201 | } 202 | OP_Context context(time); 203 | GU_DetailHandle gdh; 204 | gdh = sop->getCookedGeoHandle(context); 205 | 206 | GU_DetailHandleAutoReadLock gdl(gdh); 207 | const GU_Detail *gdp = gdl.getGdp(); 208 | 209 | if (!gdp) 210 | { 211 | addError(ROP_COOK_ERROR, (const char *)soppath); 212 | return ROP_ABORT_RENDER; 213 | } 214 | 215 | if (evalInt("mkpath", 0, 0)) { 216 | ROP_Node::makeFilePathDirs(savepath); 217 | } 218 | 219 | if (render_light) light_save(gdp, (const char*)savepath); 220 | else file_save(gdp, (const char *)savepath); 221 | 222 | if (ALFPROGRESS() && (endTime != startTime)) 223 | { 224 | fpreal fpercent = (time - startTime) / (endTime - startTime); 225 | int percent = (int)SYSrint(fpercent * 100); 226 | percent = SYSclamp(percent, 0, 100); 227 | fprintf(stdout, "ALF_PROGRESS %d%%\n", percent); 228 | fflush(stdout); 229 | } 230 | 231 | if (error() < UT_ERROR_ABORT) 232 | { 233 | if (!executePostFrameScript(time)) 234 | return ROP_ABORT_RENDER; 235 | } 236 | 237 | return ROP_CONTINUE_RENDER; 238 | } 239 | 240 | ROP_RENDER_CODE VPT_INS_ROP::endRender() 241 | { 242 | if (INITSIM()) 243 | OPgetDirector()->bumpSkipPlaybarBasedSimulationReset(-1); 244 | 245 | if (error() < UT_ERROR_ABORT) 246 | { 247 | if (!executePostRenderScript(endTime)) 248 | return ROP_ABORT_RENDER; 249 | } 250 | return ROP_CONTINUE_RENDER; 251 | } 252 | 253 | VPT_INS_ROP::~VPT_INS_ROP(){} 254 | 255 | 256 | OP_Node * VPT_INS_ROP::nodeConstructor(OP_Network *net, const char *name, OP_Operator *op) 257 | { 258 | return new VPT_INS_ROP(net, name, op); 259 | }; 260 | 261 | 262 | VPT_INS_ROP::VPT_INS_ROP(OP_Network *net, const char *name, OP_Operator *op) 263 | 264 | :ROP_Node(net, name, op) 265 | , endTime(0) 266 | 267 | {}; 268 | 269 | 270 | void newDriverOperator(OP_OperatorTable *table) 271 | { 272 | table->addOperator(new OP_Operator("VPT_Instance", 273 | "VPT Instance", 274 | VPT_INS_ROP::nodeConstructor, 275 | VPT_INS_ROP::getTemplatePair(), 276 | 0, 277 | 0, 278 | VPT_INS_ROP::getVariablePair(), 279 | OP_FLAG_GENERATOR)); 280 | }; 281 | -------------------------------------------------------------------------------- /instancer_hda/ROP_VPT_Instance.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------- 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are met : 5 | // 6 | // *Redistributions of source code must retain the above copyright notice, this 7 | // list of conditions and the following disclaimer. 8 | // 9 | // * Redistributions in binary form must reproduce the above copyright notice, 10 | // this list of conditions and the following disclaimer in the documentation 11 | // and/or other materials provided with the distribution. 12 | // 13 | // * Neither the name of the copyright holder nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | // DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 21 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | // DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 | // OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // Copyright(c) 2019, Sergen Eren 29 | // All rights reserved. 30 | //---------------------------------------------------------------------------------- 31 | // 32 | // Version 1.0: Sergen Eren, 03/12/2019 33 | // 34 | // File: Volume instance file exporter for VPT 35 | // 36 | //----------------------------------------------- 37 | 38 | 39 | #ifndef _ROP_VPT_INSTANCE_H_ 40 | #define _ROP_VPT_INSTANCE_H_ 41 | 42 | 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | 56 | #include 57 | #include 58 | #include 59 | 60 | #include 61 | #include 62 | #include 63 | #include 64 | 65 | #include 66 | 67 | #include 68 | 69 | #include 70 | #include 71 | #include 72 | #include 73 | 74 | #include 75 | 76 | 77 | 78 | namespace vpt_instance { 79 | 80 | 81 | enum { 82 | ROP_VPT_RENDER, 83 | ROP_VPT_RENDERBACKGROUND, 84 | ROP_VPT_RENDER_CTRL, 85 | ROP_VPT_TRANGE, 86 | ROP_VPT_FRANGE, 87 | ROP_VPT_TAKE, 88 | ROP_VPT_LIGHT, 89 | ROP_VPT_SOPPATH, 90 | ROP_VPT_SOPOUTPUT, 91 | 92 | //render parameters 93 | ROP_VPT_INITSIM, 94 | ROP_VPT_MKPATH, 95 | ROP_VPT_ALFPROGRESS, 96 | ROP_VPT_TPRERENDER, 97 | ROP_VPT_PRERENDER, 98 | ROP_VPT_LPRERENDER, 99 | ROP_VPT_TPREFRAME, 100 | ROP_VPT_PREFRAME, 101 | ROP_VPT_LPREFRAME, 102 | ROP_VPT_TPOSTFRAME, 103 | ROP_VPT_POSTFRAME, 104 | ROP_VPT_LPOSTFRAME, 105 | ROP_VPT_TPOSTRENDER, 106 | ROP_VPT_POSTRENDER, 107 | ROP_VPT_LPOSTRENDER, 108 | 109 | ROP_VPT_MAXPARMS 110 | }; 111 | 112 | 113 | class VPT_INS_ROP : public ROP_Node { 114 | 115 | 116 | public: 117 | static OP_TemplatePair *getTemplatePair(); 118 | static OP_VariablePair *getVariablePair(); 119 | static PRM_Template myTemplateList[]; 120 | static OP_Node *nodeConstructor(OP_Network *net, const char *name, OP_Operator *op); 121 | 122 | protected: 123 | 124 | VPT_INS_ROP(OP_Network *net, const char *name, OP_Operator *op); 125 | virtual ~VPT_INS_ROP(); 126 | 127 | protected: 128 | 129 | virtual int startRender(int nframes, fpreal s, fpreal e); 130 | virtual ROP_RENDER_CODE renderFrame(fpreal time, UT_Interrupt *boss); 131 | virtual ROP_RENDER_CODE endRender(); 132 | 133 | private: 134 | bool LIGHT() { return evalInt("render_light", 0 , 0 ); } 135 | void OUTPUT(UT_String &str, fpreal t) { return evalString(str, "outputFile", 0, t); } 136 | void SOPPATH(UT_String &str, fpreal t) { return evalString(str, "soppath", 0, t); } 137 | int INITSIM() { return evalInt("initsim", 0, 0); } 138 | int ALFPROGRESS() { return evalInt("alfprogress", 0, 0); } 139 | 140 | 141 | fpreal startTime; 142 | fpreal endTime; 143 | 144 | }; 145 | 146 | } 147 | 148 | #endif // !_ROP_VPT_INSTANCE_H_ 149 | -------------------------------------------------------------------------------- /instancer_hda/file_IO.cpp: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------- 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are met : 5 | // 6 | // *Redistributions of source code must retain the above copyright notice, this 7 | // list of conditions and the following disclaimer. 8 | // 9 | // * Redistributions in binary form must reproduce the above copyright notice, 10 | // this list of conditions and the following disclaimer in the documentation 11 | // and/or other materials provided with the distribution. 12 | // 13 | // * Neither the name of the copyright holder nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | // DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 21 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | // DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 | // OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // Copyright(c) 2019, Sergen Eren 29 | // All rights reserved. 30 | //---------------------------------------------------------------------------------- 31 | // 32 | // Version 1.0: Sergen Eren, 03/12/2019 33 | // 34 | // File: Volume instance file exporter main function file implementation 35 | // this function creates a json file with given point attributes 36 | // 37 | //----------------------------------------------- 38 | 39 | 40 | //#include "nlohmann/json.hpp" 41 | //using json = nlohmann::json; 42 | 43 | 44 | #include "file_IO.h" 45 | #include "volume_instance.h" 46 | 47 | #include 48 | #include 49 | #include 50 | #include 51 | 52 | 53 | namespace vpt_instance { 54 | 55 | 56 | GA_Detail::IOStatus file_save(const GU_Detail *gdp, const char *file_name) { 57 | 58 | UT_OFStream file(file_name); 59 | 60 | GA_ROHandleV3 pos_h(gdp, GA_ATTRIB_POINT, "P"); 61 | UT_Vector3F pos_val(0, 0, 0); 62 | 63 | GA_ROHandleV3 N_h(gdp, GA_ATTRIB_POINT, "N"); 64 | GA_ROHandleV3 up_h(gdp, GA_ATTRIB_POINT, "up"); 65 | GA_ROHandleV4 orient_h(gdp, GA_ATTRIB_POINT, "orient"); 66 | GA_ROHandleV4 rot_h(gdp, GA_ATTRIB_POINT, "rot"); 67 | 68 | GA_ROHandleF rad_h(gdp, GA_ATTRIB_POINT, "pscale"); 69 | fpreal32 rad_val(1); 70 | 71 | GA_ROHandleS vdb_h(gdp, GA_ATTRIB_POINT, "instancefile"); 72 | UT_String vdb_val(""); 73 | 74 | // First find out how many unique vdb files we need 75 | std::vector unique_vdb_files; 76 | GA_Offset lcl_start, lcl_end, ptoff; 77 | for (GA_Iterator lcl_it(gdp->getPointRange()); lcl_it.blockAdvance(lcl_start, lcl_end); ) { 78 | for (ptoff = lcl_start; ptoff < lcl_end; ++ptoff) { 79 | if (vdb_h.isValid()) { 80 | vdb_val = vdb_h.get(ptoff); 81 | unique_vdb_files.push_back(vdb_val.c_str()); 82 | } 83 | else { 84 | return false; 85 | } 86 | } 87 | } 88 | 89 | 90 | std::sort(unique_vdb_files.begin(), unique_vdb_files.end()); 91 | std::vector::iterator it = std::unique(unique_vdb_files.begin(), unique_vdb_files.end()); 92 | unique_vdb_files.resize(std::distance(unique_vdb_files.begin(), it)); 93 | 94 | 95 | file << unique_vdb_files.size() << std::endl; 96 | 97 | for (auto vdb : unique_vdb_files) { 98 | 99 | vdb_instance new_instance; 100 | new_instance.vdb_file = vdb; 101 | file << vdb << std::endl; 102 | 103 | int idx = 0; 104 | for (GA_Iterator lcl_it(gdp->getPointRange()); lcl_it.blockAdvance(lcl_start, lcl_end); ) { 105 | for (ptoff = lcl_start; ptoff < lcl_end; ++ptoff) { 106 | 107 | vdb_val = vdb_h.get(ptoff); 108 | 109 | if (vdb_val == UT_String(vdb)) { 110 | instance ins; 111 | 112 | // Check if pscale exists if not set it to 1 113 | if (rad_h.isValid()) { 114 | rad_val = rad_h.get(ptoff); 115 | } 116 | else rad_val = 1.0f; 117 | ins.scale = rad_val; 118 | 119 | // For rotations we first check if orient attribute is peresent 120 | 121 | UT_QuaternionF quat(0, 0, 0, 1); // this will set the instance rotation 122 | 123 | if (orient_h.isValid()) { 124 | quat = orient_h.get(ptoff); 125 | } 126 | else { // orient is not present. 127 | 128 | if (rot_h.isValid()) { // check if rot attribute is present 129 | quat = rot_h.get(ptoff); 130 | } 131 | else { // neither attributes are present we should construct our own quaternion 132 | UT_Vector3F up(0,1,0); 133 | if (up_h.isValid()) up = up_h.get(ptoff); 134 | 135 | UT_Vector3F normal(0,0,1); 136 | if (N_h.isValid()) normal = N_h.get(ptoff); 137 | 138 | UT_Matrix3F rot_matrix; 139 | rot_matrix.orient(normal, up); 140 | 141 | quat.updateFromRotationMatrix(rot_matrix); 142 | } 143 | } 144 | 145 | ins.rotation[0] = quat.x(); 146 | ins.rotation[1] = quat.y(); 147 | ins.rotation[2] = quat.z(); 148 | ins.rotation[3] = quat.w(); 149 | 150 | // Get the position of point and set instance position 151 | pos_val = pos_h.get(ptoff); 152 | ins.position[0] = pos_val.x(); 153 | ins.position[1] = pos_val.y(); 154 | ins.position[2] = pos_val.z(); 155 | 156 | new_instance.instances.push_back(ins); 157 | 158 | } 159 | 160 | } 161 | } 162 | 163 | 164 | new_instance.num_instances = new_instance.instances.size(); 165 | file << new_instance.num_instances << std::endl; 166 | for (int i = 0; i < new_instance.num_instances; ++i) { 167 | file << new_instance.instances.at(i).position[0]; 168 | file << " " << new_instance.instances.at(i).position[1]; 169 | file << " " << new_instance.instances.at(i).position[2]; 170 | 171 | file << " " << new_instance.instances.at(i).rotation[0]; 172 | file << " " << new_instance.instances.at(i).rotation[1]; 173 | file << " " << new_instance.instances.at(i).rotation[2]; 174 | file << " " << new_instance.instances.at(i).rotation[3]; 175 | 176 | file << " " << new_instance.instances.at(i).scale; 177 | 178 | file << std::endl; 179 | } 180 | 181 | } 182 | 183 | 184 | file.close(); 185 | return true; 186 | 187 | } 188 | 189 | GA_Detail::IOStatus light_save(const GU_Detail *gdp, const char *file_name) { 190 | 191 | UT_OFStream file(file_name); 192 | 193 | GA_ROHandleV3 pos_h(gdp, GA_ATTRIB_POINT, "P"); 194 | UT_Vector3F pos_val(0, 0, 0); 195 | GA_ROHandleV3 Cd_h(gdp, GA_ATTRIB_POINT, "Cd"); 196 | GA_ROHandleF power_h(gdp, GA_ATTRIB_POINT, "power"); 197 | 198 | file << "light" << std::endl; 199 | file << gdp->getNumPoints() << std::endl; 200 | 201 | GA_Offset lcl_start, lcl_end, ptoff; 202 | for (GA_Iterator lcl_it(gdp->getPointRange()); lcl_it.blockAdvance(lcl_start, lcl_end); ) { 203 | for (ptoff = lcl_start; ptoff < lcl_end; ++ptoff) { 204 | 205 | pos_val = pos_h.get(ptoff); 206 | 207 | file << pos_val.x() << " " << pos_val.y() << " " << pos_val.z() << " "; 208 | if (Cd_h.isValid()) { 209 | UT_Vector3F Cd = Cd_h.get(ptoff); 210 | file << Cd.r() << " " << Cd.g() << " " << Cd.b() << " "; 211 | }else file << 1 << " " << 1 << " " << 1 << " "; 212 | 213 | if (power_h.isValid()) { 214 | file << power_h.get(ptoff) << std::endl; 215 | }else file << 100 << std::endl; 216 | 217 | } 218 | } 219 | 220 | 221 | file.close(); 222 | return true; 223 | 224 | } 225 | 226 | 227 | } -------------------------------------------------------------------------------- /instancer_hda/file_IO.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------- 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are met : 5 | // 6 | // *Redistributions of source code must retain the above copyright notice, this 7 | // list of conditions and the following disclaimer. 8 | // 9 | // * Redistributions in binary form must reproduce the above copyright notice, 10 | // this list of conditions and the following disclaimer in the documentation 11 | // and/or other materials provided with the distribution. 12 | // 13 | // * Neither the name of the copyright holder nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | // DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 21 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | // DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 | // OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // Copyright(c) 2019, Sergen Eren 29 | // All rights reserved. 30 | //---------------------------------------------------------------------------------- 31 | // 32 | // Version 1.0: Sergen Eren, 03/12/2019 33 | // 34 | // File: Volume instance file exporter main function file 35 | // We only create this file to save clutter in VPT_Instance class 36 | // you can also implement this file in render_frame method 37 | // 38 | //----------------------------------------------- 39 | 40 | 41 | #ifndef _FILE_IO_H_ 42 | #define _FILE_IO_H_ 43 | 44 | #include 45 | #include 46 | #include 47 | 48 | #include 49 | 50 | 51 | namespace vpt_instance { 52 | 53 | 54 | GA_Detail::IOStatus file_save(const GU_Detail *gdp, const char *file_name); 55 | GA_Detail::IOStatus light_save(const GU_Detail *gdp, const char *file_name); 56 | 57 | 58 | } 59 | 60 | #endif // !_FILE_IO_H_ 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /instancer_hda/icon/ROP_VPT_Instance.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 11 | 14 | 17 | 18 | -------------------------------------------------------------------------------- /instancer_hda/scenes/scene_1.hiplc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergeneren/Volumetric-Path-Tracer/8708189867bebab06d75d1894746c4927e5800ec/instancer_hda/scenes/scene_1.hiplc -------------------------------------------------------------------------------- /instancer_hda/volume_instance.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------- 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are met : 5 | // 6 | // *Redistributions of source code must retain the above copyright notice, this 7 | // list of conditions and the following disclaimer. 8 | // 9 | // * Redistributions in binary form must reproduce the above copyright notice, 10 | // this list of conditions and the following disclaimer in the documentation 11 | // and/or other materials provided with the distribution. 12 | // 13 | // * Neither the name of the copyright holder nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | // DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 21 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | // DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 | // OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // Copyright(c) 2019, Sergen Eren 29 | // All rights reserved. 30 | //---------------------------------------------------------------------------------- 31 | // 32 | // Version 1.0: Sergen Eren, 03/12/2019 33 | // 34 | // File: Volume instance file structure 35 | // 36 | //----------------------------------------------- 37 | 38 | 39 | #ifndef _VOLUME_INSTANCE_H_ 40 | #define _VOLUME_INSTANCE_H_ 41 | 42 | #include 43 | #include 44 | #include 45 | #include 46 | 47 | 48 | struct instance { 49 | double position[3]; // x,y,z 50 | double rotation[4]; // x,y,z,w 51 | double scale = 0; 52 | }; 53 | 54 | struct vdb_instance { 55 | unsigned int num_instances = 0; 56 | std::string vdb_file; 57 | std::vector instances; 58 | }; 59 | 60 | #endif // !_VOLUME_INSTANCE_H_ 61 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /source/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 3 | find_package(glfw3 CONFIG REQUIRED) 4 | find_package(glew CONFIG REQUIRED) 5 | find_package(imgui CONFIG REQUIRED) 6 | find_package(OpenVDB CONFIG REQUIRED) 7 | find_package(OpenImageIO CONFIG REQUIRED) 8 | find_package(tinyexr CONFIG REQUIRED) 9 | find_package(tbb CONFIG REQUIRED) 10 | find_package(OpenImageDenoise CONFIG REQUIRED) 11 | 12 | include(${CMAKE_CURRENT_SOURCE_DIR}/Helpers.cmake) 13 | include(${CMAKE_CURRENT_SOURCE_DIR}/CompileObj.cmake) 14 | 15 | ################################################################## 16 | 17 | # set external directories 18 | 19 | set(THIRDPARTY_DIR "${CMAKE_SOURCE_DIR}/thirdparty") 20 | 21 | ##Set env mapping renders variable 22 | 23 | set( RENDER_ENV_TEXTURES OFF CACHE BOOL "Render env sampling textures after creation") 24 | if ( RENDER_ENV_TEXTURES ) 25 | add_definitions(-DRENDER_ENV_SAMPLE_TEXTURES=1) 26 | else() 27 | add_definitions(-DRENDER_ENV_SAMPLE_TEXTURES=0) 28 | endif() 29 | 30 | ## Set ASSET_PATH variable to assets folder and copy the folder to binary directory 31 | 32 | file( GLOB ASSET_FILES "${CMAKE_SOURCE_DIR}/assets/*.*") 33 | file( INSTALL ${ASSET_FILES} DESTINATION "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/assets") 34 | 35 | set(ASSET_DIR "./assets") 36 | add_definitions(-DASSET_PATH="${ASSET_DIR}/") 37 | 38 | ################################################################### 39 | 40 | 41 | ## Create example instance file 42 | 43 | file(MAKE_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) 44 | file(WRITE "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/fireball.ins" 45 | "1\n" 46 | "${ASSET_DIR}/fireball.vdb\n" 47 | "3\n" 48 | "0 200 0 0 0 0 1 20\n" 49 | "200 200 0 0 0 0 1 20\n" 50 | "-200 200 0 0 0 0 1 20") 51 | 52 | 53 | ## Create a cmd file to test vpt 54 | 55 | file(WRITE "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test_vpt.cmd" 56 | "echo on\n" 57 | "vpt.exe fireball.ins") 58 | 59 | 60 | ## Grab source files 61 | 62 | file( GLOB ATMOSPHERE 63 | "${CMAKE_CURRENT_SOURCE_DIR}/atmosphere/*.h" 64 | "${CMAKE_CURRENT_SOURCE_DIR}/atmosphere/*.cpp") 65 | 66 | 67 | file( GLOB HEADERS 68 | "*.h" 69 | "${CMAKE_CURRENT_SOURCE_DIR}/gpu_vdb/*.h") 70 | 71 | file ( GLOB COMMON 72 | "${CMAKE_CURRENT_SOURCE_DIR}/common/*.h" 73 | "${CMAKE_CURRENT_SOURCE_DIR}/common/*.cpp" ) 74 | 75 | file ( GLOB UTIL 76 | "${CMAKE_CURRENT_SOURCE_DIR}/util/*.h" 77 | "${CMAKE_CURRENT_SOURCE_DIR}/util/*.cpp" ) 78 | 79 | file ( GLOB GEOMETRY 80 | "${CMAKE_CURRENT_SOURCE_DIR}/geometry/*.h" 81 | "${CMAKE_CURRENT_SOURCE_DIR}/geometry/*.cpp" ) 82 | 83 | file ( GLOB BVH 84 | "${CMAKE_CURRENT_SOURCE_DIR}/bvh/*.h" 85 | "${CMAKE_CURRENT_SOURCE_DIR}/bvh/*.cpp" 86 | ) 87 | 88 | file ( GLOB CUDA_FUNCTIONS 89 | "${CMAKE_CURRENT_SOURCE_DIR}/bvh/*.cu" 90 | ) 91 | 92 | file( GLOB CUDA_SOURCES 93 | "*.cu" 94 | "${CMAKE_CURRENT_SOURCE_DIR}/atmosphere/*.cu" 95 | "${CMAKE_CURRENT_SOURCE_DIR}/geometry/*.cu") 96 | 97 | file( GLOB SOURCE_CPP 98 | "*.cpp" 99 | "${CMAKE_CURRENT_SOURCE_DIR}/gpu_vdb/*.cpp") 100 | 101 | file( GLOB IMGUI_IMPL_SOURCES 102 | "${CMAKE_CURRENT_SOURCE_DIR}/imgui/*.h" 103 | "${CMAKE_CURRENT_SOURCE_DIR}/imgui/*.cpp") 104 | 105 | set(SOURCE_FILES 106 | ${HEADERS} 107 | ${CUDA_SOURCES} 108 | ${CUDA_FUNCTIONS} 109 | ${SOURCE_CPP} 110 | ${BVH} 111 | ${IMGUI_IMPL_SOURCES} 112 | ${COMMON} 113 | ${ATMOSPHERE} 114 | ${GEOMETRY} 115 | ${UTIL}) 116 | 117 | ## Group source files 118 | 119 | source_group(Cuda FILES ${CUDA_SOURCES}) 120 | source_group(bvh FILES ${BVH} ${CUDA_FUNCTIONS}) 121 | source_group(Imgui FILES ${IMGUI_IMPL_SOURCES}) 122 | source_group(Helpers FILES ${COMMON} ${UTIL}) 123 | source_group(Atmosphere FILES ${ATMOSPHERE}) 124 | source_group(Geometry FILES ${GEOMETRY}) 125 | 126 | ## Add custom build command for cuda files 127 | 128 | find_program(CUDA_NVCC_EXECUTABLE nvcc) 129 | message ( STATUS "Build CUDA kernels: ${CUDA_SOURCES}" ) 130 | COMPILE_PTX ( SOURCES ${CUDA_SOURCES} 131 | TARGET_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} 132 | INCLUDE ${CMAKE_CURRENT_SOURCE_DIR} ${_VCPKG_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/common ${THIRDPARTY_DIR}/cuda-noise/include ${CMAKE_CURRENT_SOURCE_DIR}/gpu_vdb 133 | OPTIONS -arch=compute_61 -code=sm_61 --ptxas-options=-v -O3 --use_fast_math --maxrregcount=128) 134 | 135 | 136 | COMPILE_OBJ( 137 | SOURCES ${CUDA_FUNCTIONS} 138 | TYPE ${CMAKE_BUILD_TYPE} 139 | TARGET_PATH ${CMAKE_BINARY_DIR}/lib 140 | GENPATHS GEN_CUDA_FUNC_OBJS 141 | INCLUDE ${CMAKE_CURRENT_SOURCE_DIR} ${_VCPKG_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/common ${THIRDPARTY_DIR}/cuda-noise/include ${CMAKE_CURRENT_SOURCE_DIR}/gpu_vdb 142 | ) 143 | message(STATUS "Genrated cuda functions objects ${GEN_CUDA_FUNC_OBJS}") 144 | 145 | ################################################################### 146 | 147 | ################################################################### 148 | add_executable(vpt ${SOURCE_FILES}) 149 | target_link_libraries(vpt PRIVATE glfw GLEW::GLEW imgui::imgui cudart cuda OpenImageDenoise 150 | TBB::tbb OpenVDB::openvdb opengl32 OpenImageIO::OpenImageIO ${OIDN_LIBRARIES} ${_VCPKG_LIB_DIR}/tinyexr.lib ${GEN_CUDA_FUNC_OBJS}) 151 | 152 | set_target_properties(vpt PROPERTIES VS_GLOBAL_VcpkgEnabled true) 153 | set_target_properties(vpt PROPERTIES VS_GLOBAL_VcpkgEnableManifest true) 154 | target_compile_features(vpt PUBLIC cxx_std_17) 155 | 156 | set_target_properties(vpt PROPERTIES CUDA_ARCHITECTURES "61;75;86") 157 | 158 | 159 | file ( GLOB OIDN_DLLS "${THIRDPARTY_DIR}/OpenImageDenoise/bin/*.dll" ) 160 | add_custom_command( 161 | TARGET vpt PRE_BUILD 162 | COMMAND ${CMAKE_COMMAND} -E copy ${OIDN_DLLS} ${CMAKE_BINARY_DIR}/bin) 163 | 164 | include_directories(${_VCPKG_INCLUDE_DIR}) 165 | include_directories(${CMAKE_SOURCE_DIR}) 166 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/atmosphere) 167 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/common) 168 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/util) 169 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/gpu_vdb) 170 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/bvh) 171 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/geometry) 172 | include_directories(${THIRDPARTY_DIR}/cuda-noise/include) 173 | include_directories(${THIRDPARTY_DIR}/OpenImageDenoise/include) 174 | -------------------------------------------------------------------------------- /source/CompileObj.cmake: -------------------------------------------------------------------------------- 1 | 2 | #------------------------------------ CROSS-PLATFORM OBJ COMPILE 3 | 4 | FUNCTION( COMPILE_OBJ ) 5 | set(options "") 6 | set(oneValueArgs TARGET_PATH TYPE GENERATED GENPATHS) 7 | set(multiValueArgs OPTIONS SOURCES ARCHS INCLUDE) 8 | CMAKE_PARSE_ARGUMENTS( _FUNCTION "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) 9 | 10 | # Match the bitness of the ptx to the bitness of the application 11 | set( MACHINE "--machine=32" ) 12 | if( CMAKE_SIZEOF_VOID_P EQUAL 8) 13 | set( MACHINE "--machine=64" ) 14 | endif() 15 | unset ( CUBIN_FILES CACHE ) 16 | unset ( CUBIN_FILES_PATH CACHE ) 17 | unset ( EMBEDDED_FILES CACHE ) 18 | 19 | FOREACH(INCLUDE_DIR ${_FUNCTION_INCLUDE}) 20 | set ( INCL ${INCL} "-I\"${INCLUDE_DIR}\"" ) 21 | ENDFOREACH() 22 | 23 | set ( ARCHS -arch=sm_61 ) 24 | 25 | message(STATUS "Compiling for architecture ${ARCH}") 26 | 27 | file ( MAKE_DIRECTORY "${_FUNCTION_TARGET_PATH}" ) 28 | string (REPLACE ";" " " _FUNCTION_OPTIONS "${_FUNCTION_OPTIONS}") 29 | separate_arguments( _OPTS WINDOWS_COMMAND "${_FUNCTION_OPTIONS}" ) 30 | message ( STATUS "NVCC Options: ${_FUNCTION_OPTIONS}" ) 31 | message ( STATUS "NVCC Include: ${_FUNCTION_INCLUDE}" ) 32 | 33 | #Set initial options 34 | set(_OPTS ${_OPTS} -Xcompiler "/EHsc,/Od,/Zi,/RTC1" ${ARCHS}) 35 | 36 | #Set debug or relase linking 37 | if(_FUNCTION_TYPE MATCHES "Debug") 38 | set(_OPTS ${_OPTS} -Xcompiler "/MDd") 39 | else() 40 | set(_OPTS ${_OPTS} -Xcompiler "/MD") 41 | endif() 42 | 43 | set(_OPTS ${_OPTS} -w) 44 | 45 | FOREACH( input ${_FUNCTION_SOURCES} ) 46 | get_filename_component( input_ext ${input} EXT ) 47 | get_filename_component( input_without_ext ${input} NAME_WE ) 48 | if ( ${input_ext} STREQUAL ".cu" ) 49 | set(_EXT .lib) 50 | 51 | set( output "${input_without_ext}.lib" ) 52 | set( output_with_path "${_FUNCTION_TARGET_PATH}/${input_without_ext}${_EXT}" ) 53 | set( output_with_quote "\"${output_with_path}\"" ) 54 | LIST( APPEND OBJ_FILES ${output} ) 55 | LIST( APPEND OBJ_FILES_PATH ${output_with_path} ) 56 | 57 | message( STATUS "NVCC Compile: ${CUDA_NVCC_EXECUTABLE} ${MACHINE} --lib -cudart static ${DEBUG_FLAGS} ${_OPTS} ${input} -o ${output_with_path} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}") 58 | add_custom_command( 59 | OUTPUT ${output_with_path} 60 | MAIN_DEPENDENCY ${input} 61 | DEPENDS ${_FILE_DEPENDENCY} 62 | COMMAND ${CUDA_NVCC_EXECUTABLE} ${MACHINE} --compile ${DEBUG_FLAGS} ${OPT_FLAGS} ${_OPTS} ${input} ${INCL} -o ${output_with_quote} 63 | WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" 64 | ) 65 | 66 | endif() 67 | ENDFOREACH( ) 68 | 69 | set( ${_FUNCTION_GENERATED} ${OBJ_FILES} PARENT_SCOPE) 70 | set( ${_FUNCTION_GENPATHS} ${OBJ_FILES_PATH} PARENT_SCOPE) 71 | 72 | ENDFUNCTION() 73 | -------------------------------------------------------------------------------- /source/Helpers.cmake: -------------------------------------------------------------------------------- 1 | 2 | FUNCTION( COMPILE_PTX ) 3 | set(options "") 4 | set(oneValueArgs TARGET_PATH) 5 | set(multiValueArgs OPTIONS SOURCES INCLUDE) 6 | CMAKE_PARSE_ARGUMENTS( _FUNCTION "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) 7 | 8 | # Match the bitness of the ptx to the bitness of the application 9 | set( MACHINE "--machine=32" ) 10 | if( CMAKE_SIZEOF_VOID_P EQUAL 8) 11 | set( MACHINE "--machine=64" ) 12 | endif() 13 | 14 | set( DEBUG_PTX OFF CACHE BOOL "Enable CUDA debugging") 15 | if ( DEBUG_PTX ) 16 | set ( DEBUG_FLAGS "-G") 17 | else() 18 | set ( DEBUG_FLAGS "") 19 | endif() 20 | 21 | set( LINE_GENERATE OFF CACHE BOOL "Generate line information in ptx files") 22 | 23 | 24 | message(STATUS "_FUNCTION_INCLUDE: ${_FUNCTION_INCLUDE}") 25 | FOREACH(INCLUDE_DIR ${_FUNCTION_INCLUDE}) 26 | set ( INCL ${INCL} "-I\"${INCLUDE_DIR}\"" ) 27 | ENDFOREACH() 28 | 29 | message(STATUS "Compiling for architecture ${ARCH}") 30 | 31 | file ( MAKE_DIRECTORY "${_FUNCTION_TARGET_PATH}" ) 32 | string (REPLACE ";" " " _FUNCTION_OPTIONS "${_FUNCTION_OPTIONS}") 33 | separate_arguments( _OPTS WINDOWS_COMMAND "${_FUNCTION_OPTIONS}" ) 34 | message ( STATUS "NVCC Options: ${_FUNCTION_OPTIONS}" ) 35 | message ( STATUS "NVCC Include: ${_FUNCTION_INCLUDE}" ) 36 | 37 | set(_COMPILE_TYPE --ptx) 38 | 39 | if ( LINE_GENERATE ) 40 | set(_OPTS ${_OPTS} -lineinfo) 41 | endif() 42 | 43 | FOREACH( input ${_FUNCTION_SOURCES} ) 44 | get_filename_component( input_ext ${input} EXT ) 45 | get_filename_component( input_without_ext ${input} NAME_WE ) 46 | if ( ${input_ext} STREQUAL ".cu" ) 47 | set(_EXT .ptx) 48 | set( output "${input_without_ext}.ptx" ) 49 | set( embedded_file "${input_without_ext}_embed.c") 50 | set( output_with_path "${_FUNCTION_TARGET_PATH}/${input_without_ext}${_EXT}" ) 51 | 52 | message( STATUS "NVCC Compile: $${CUDA_NVCC_EXECUTABLE} ${MACHINE} ${_COMPILE_TYPE} ${DEBUG_FLAGS} ${OPT_FLAGS} ${_OPTS} ${input} ${INCL} -o ${output_with_path}") 53 | add_custom_command( 54 | OUTPUT ${output_with_path} 55 | MAIN_DEPENDENCY ${input} 56 | DEPENDS ${_FILE_DEPENDENCY} 57 | COMMAND ${CUDA_NVCC_EXECUTABLE} ${MACHINE} ${_COMPILE_TYPE} ${DEBUG_FLAGS} ${OPT_FLAGS} ${_OPTS} ${input} ${INCL} -o ${output_with_path} 58 | WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" 59 | ) 60 | 61 | endif() 62 | ENDFOREACH() 63 | 64 | ENDFUNCTION() 65 | 66 | 67 | -------------------------------------------------------------------------------- /source/atmosphere/atmosphere.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------- 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are met : 5 | // 6 | // *Redistributions of source code must retain the above copyright notice, this 7 | // list of conditions and the following disclaimer. 8 | // 9 | // * Redistributions in binary form must reproduce the above copyright notice, 10 | // this list of conditions and the following disclaimer in the documentation 11 | // and/or other materials provided with the distribution. 12 | // 13 | // * Neither the name of the copyright holder nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | // DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 21 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | // DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 | // OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // Copyright(c) 2019, Sergen Eren 29 | // All rights reserved. 30 | //---------------------------------------------------------------------------------- 31 | // 32 | // Version 1.0: Sergen Eren, 11/11/2019 33 | // 34 | // File: This is the header file for atmosphere class that implements 35 | // bruneton model sky in cuda. This file contains device side function 36 | // definitions and host side function declerations 37 | // 38 | //----------------------------------------------- 39 | 40 | 41 | #ifndef __ATMOSPHERE_H__ 42 | #define __ATMOSPHERE_H__ 43 | 44 | #define DEBUG_TEXTURES 45 | 46 | #include 47 | #include "texture_types.h" 48 | #include 49 | 50 | #include "atmosphere/definitions.h" 51 | #include "atmosphere/constants.h" 52 | 53 | enum atmosphere_error_t { 54 | 55 | ATMO_INIT_ERR, 56 | ATMO_INIT_FUNC_ERR, 57 | ATMO_RECOMPUTE_ERR, 58 | ATMO_FILL_TEX_ERR, 59 | ATMO_LAUNCH_ERR, 60 | ATMO_LOAD_FILE_ERR, 61 | ATMO_SAVE_FILE_ERR, 62 | ATMO_NO_ERR 63 | 64 | }; 65 | 66 | constexpr double kSolarIrradiance[48] = { 67 | 1.11776, 1.14259, 1.01249, 1.14716, 1.72765, 1.73054, 1.6887, 1.61253, 68 | 1.91198, 2.03474, 2.02042, 2.02212, 1.93377, 1.95809, 1.91686, 1.8298, 69 | 1.8685, 1.8931, 1.85149, 1.8504, 1.8341, 1.8345, 1.8147, 1.78158, 1.7533, 70 | 1.6965, 1.68194, 1.64654, 1.6048, 1.52143, 1.55622, 1.5113, 1.474, 1.4482, 71 | 1.41018, 1.36775, 1.34188, 1.31429, 1.28303, 1.26758, 1.2367, 1.2082, 72 | 1.18737, 1.14683, 1.12362, 1.1058, 1.07124, 1.04992 73 | }; 74 | 75 | constexpr double kOzoneCrossSection[48] = { 76 | 1.18e-27, 2.182e-28, 2.818e-28, 6.636e-28, 1.527e-27, 2.763e-27, 5.52e-27, 77 | 8.451e-27, 1.582e-26, 2.316e-26, 3.669e-26, 4.924e-26, 7.752e-26, 9.016e-26, 78 | 1.48e-25, 1.602e-25, 2.139e-25, 2.755e-25, 3.091e-25, 3.5e-25, 4.266e-25, 79 | 4.672e-25, 4.398e-25, 4.701e-25, 5.019e-25, 4.305e-25, 3.74e-25, 3.215e-25, 80 | 2.662e-25, 2.238e-25, 1.852e-25, 1.473e-25, 1.209e-25, 9.423e-26, 7.455e-26, 81 | 6.566e-26, 5.105e-26, 4.15e-26, 4.228e-26, 3.237e-26, 2.451e-26, 2.801e-26, 82 | 2.534e-26, 1.624e-26, 1.465e-26, 2.078e-26, 1.383e-26, 7.105e-27 83 | }; 84 | 85 | constexpr double kDobsonUnit = 2.687e20; 86 | constexpr double kMaxOzoneNumberDensity = 300.0 * kDobsonUnit / 15000.0; 87 | constexpr double kConstantSolarIrradiance = 1.5; 88 | constexpr double kRayleigh = 1.24062e-6; 89 | constexpr double kRayleighScaleHeight = 8000.0f; 90 | constexpr double kMieScaleHeight = 1200.0f; 91 | constexpr double kMieAngstromAlpha = 0.0; 92 | constexpr double kMieAngstromBeta = 5.328e-3; 93 | constexpr double kMieSingleScatteringAlbedo = 0.9; 94 | constexpr double kGroundAlbedo = 0.01; 95 | 96 | static double kDefaultLuminanceFromRadiance[] = { 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0 }; 97 | static double kDefaultLambdas[] = { 680.0, 550.0, 440.0 }; 98 | 99 | class atmosphere { 100 | 101 | 102 | private: 103 | 104 | #define kLambdaR 680.0 105 | #define kLambdaG 550.0 106 | #define kLambdaB 440.0 107 | 108 | #define kLambdaMin 360 109 | #define kLambdaMax 830 110 | 111 | 112 | public: 113 | 114 | atmosphere(); 115 | ~atmosphere(); 116 | 117 | atmosphere_error_t init(); 118 | atmosphere_error_t precompute(double* lambdas, double* luminance_from_radiance, bool blend, int num_scattering_orders); 119 | atmosphere_error_t recompute(); 120 | void update_model(); 121 | 122 | 123 | 124 | private: 125 | atmosphere_error_t clear_buffers(); 126 | void update_model(const float3 lambdas); 127 | 128 | atmosphere_error_t load_textures(); 129 | atmosphere_error_t save_textures(); 130 | 131 | void copy_transmittance_texture(); 132 | void copy_scattering_texture(); 133 | void copy_irradiance_texture(); 134 | void copy_single_scattering_texture(); 135 | 136 | void convert_spectrum_to_linear_srgb(double &r, double &g, double &b); 137 | atmosphere_error_t init_functions(CUmodule &cuda_module); 138 | atmosphere_error_t compute_transmittance(double* lambdas, double* luminance_from_radiance, bool blend, int num_scattering_orders); 139 | DensityProfile adjust_units(DensityProfile density); 140 | double coeff(double lambda, int component); 141 | void sky_sun_radiance_to_luminance(float3& sky_spectral_radiance_to_luminance, float3& sun_spectral_radiance_to_luminance); 142 | static double cie_color_matching_function_table_value(double wavelength, int column); 143 | static double interpolate(const std::vector& wavelengths, const std::vector& wavelength_function, double wavelength); 144 | static void compute_spectral_radiance_to_luminance_factors(const std::vector& wavelengths, const std::vector& solar_irradiance, double lambda_power, double& k_r, double& k_g, double& k_b); 145 | 146 | private: 147 | 148 | std::vector m_wave_lengths; 149 | std::vector m_solar_irradiance; 150 | 151 | double m_sun_angular_radius; 152 | double m_bottom_radius; 153 | double m_top_radius; 154 | 155 | DensityProfileLayer* m_rayleigh_density; 156 | std::vector m_rayleigh_scattering; 157 | 158 | DensityProfileLayer* m_mie_density; 159 | std::vector m_mie_scattering; 160 | std::vector m_mie_extinction; 161 | double m_mie_phase_function_g; 162 | 163 | std::vector m_absorption_density; 164 | std::vector m_absorption_extinction; 165 | 166 | std::vector m_ground_albedo; 167 | 168 | double sun_k_r, sun_k_g, sun_k_b; 169 | double sky_k_r, sky_k_g, sky_k_b; 170 | 171 | double m_max_sun_zenith_angle; 172 | double m_length_unit_in_meters; 173 | 174 | inline int num_precomputed_wavelengths() { return m_use_luminance == LUMINANCE::PRECOMPUTED ? 15 : 3; } 175 | bool m_combine_scattering_textures; 176 | bool m_half_precision = false; 177 | bool m_need_compute = true; 178 | 179 | public: 180 | 181 | float m_exposure; 182 | bool m_do_white_balance; 183 | bool m_use_constant_solar_spectrum = true; 184 | bool m_use_ozone = true; 185 | LUMINANCE m_use_luminance; 186 | AtmosphereParameters atmosphere_parameters; 187 | std::string texture_folder; 188 | std::string texture_folder_debug; 189 | bool debug_textures = false; 190 | 191 | private: 192 | 193 | CUmodule atmosphere_module; 194 | 195 | CUfunction transmittance_function; 196 | CUfunction direct_irradiance_function; 197 | CUfunction indirect_irradiance_function; 198 | CUfunction multiple_scattering_function; 199 | CUfunction scattering_density_function; 200 | CUfunction single_scattering_function; 201 | 202 | // Buffer cleaner functions 203 | CUfunction clear_transmittance_buffers_function; 204 | CUfunction clear_irradiance_buffers_function; 205 | CUfunction clear_scattering_buffers_function; 206 | }; 207 | 208 | #endif // ! __ATMOSPHERE_H__ 209 | -------------------------------------------------------------------------------- /source/atmosphere/constants.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2017 Eric Bruneton 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of the copyright holders nor the names of its 14 | * contributors may be used to endorse or promote products derived from 15 | * this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 | * THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | 31 | #ifndef ATMOSPHERE_CONSTANTS_H_ 32 | #define ATMOSPHERE_CONSTANTS_H_ 33 | 34 | 35 | enum LUMINANCE { 36 | // Render the spectral radiance at kLambdaR, kLambdaG, kLambdaB. 37 | NONE, 38 | // Render the sRGB luminance, using an approximate (on the fly) conversion 39 | // from 3 spectral radiance values only (see section 14.3 in A Qualitative and Quantitative 41 | // Evaluation of 8 Clear Sky Models). 42 | APPROXIMATE, 43 | // Render the sRGB luminance, precomputed from 15 spectral radiance values 44 | // (see section 4.4 in Real-time 46 | // Spectral Scattering in Large-scale Natural Participating Media). 47 | PRECOMPUTED 48 | }; 49 | 50 | const int TRANSMITTANCE_TEXTURE_WIDTH = 256; 51 | const int TRANSMITTANCE_TEXTURE_HEIGHT = 64; 52 | const int SCATTERING_TEXTURE_R_SIZE = 32; 53 | const int SCATTERING_TEXTURE_MU_SIZE = 128; 54 | const int SCATTERING_TEXTURE_MU_S_SIZE = 32; 55 | const int SCATTERING_TEXTURE_NU_SIZE = 8; 56 | 57 | const int SCATTERING_TEXTURE_WIDTH = SCATTERING_TEXTURE_NU_SIZE * SCATTERING_TEXTURE_MU_S_SIZE; 58 | const int SCATTERING_TEXTURE_HEIGHT = SCATTERING_TEXTURE_MU_SIZE; 59 | const int SCATTERING_TEXTURE_DEPTH = SCATTERING_TEXTURE_R_SIZE; 60 | 61 | const int IRRADIANCE_TEXTURE_WIDTH = 256; 62 | const int IRRADIANCE_TEXTURE_HEIGHT = 64; 63 | 64 | // The conversion factor between watts and lumens. 65 | const double MAX_LUMINOUS_EFFICACY = 683.0; 66 | 67 | // Values from "CIE (1931) 2-deg color matching functions", see 68 | // "http://web.archive.org/web/20081228084047/ 69 | // http://www.cvrl.org/database/data/cmfs/ciexyz31.txt". 70 | 71 | const double CIE_2_DEG_COLOR_MATCHING_FUNCTIONS[380] = { 72 | 360, 0.000129900000, 0.000003917000, 0.000606100000, 73 | 365, 0.000232100000, 0.000006965000, 0.001086000000, 74 | 370, 0.000414900000, 0.000012390000, 0.001946000000, 75 | 375, 0.000741600000, 0.000022020000, 0.003486000000, 76 | 380, 0.001368000000, 0.000039000000, 0.006450001000, 77 | 385, 0.002236000000, 0.000064000000, 0.010549990000, 78 | 390, 0.004243000000, 0.000120000000, 0.020050010000, 79 | 395, 0.007650000000, 0.000217000000, 0.036210000000, 80 | 400, 0.014310000000, 0.000396000000, 0.067850010000, 81 | 405, 0.023190000000, 0.000640000000, 0.110200000000, 82 | 410, 0.043510000000, 0.001210000000, 0.207400000000, 83 | 415, 0.077630000000, 0.002180000000, 0.371300000000, 84 | 420, 0.134380000000, 0.004000000000, 0.645600000000, 85 | 425, 0.214770000000, 0.007300000000, 1.039050100000, 86 | 430, 0.283900000000, 0.011600000000, 1.385600000000, 87 | 435, 0.328500000000, 0.016840000000, 1.622960000000, 88 | 440, 0.348280000000, 0.023000000000, 1.747060000000, 89 | 445, 0.348060000000, 0.029800000000, 1.782600000000, 90 | 450, 0.336200000000, 0.038000000000, 1.772110000000, 91 | 455, 0.318700000000, 0.048000000000, 1.744100000000, 92 | 460, 0.290800000000, 0.060000000000, 1.669200000000, 93 | 465, 0.251100000000, 0.073900000000, 1.528100000000, 94 | 470, 0.195360000000, 0.090980000000, 1.287640000000, 95 | 475, 0.142100000000, 0.112600000000, 1.041900000000, 96 | 480, 0.095640000000, 0.139020000000, 0.812950100000, 97 | 485, 0.057950010000, 0.169300000000, 0.616200000000, 98 | 490, 0.032010000000, 0.208020000000, 0.465180000000, 99 | 495, 0.014700000000, 0.258600000000, 0.353300000000, 100 | 500, 0.004900000000, 0.323000000000, 0.272000000000, 101 | 505, 0.002400000000, 0.407300000000, 0.212300000000, 102 | 510, 0.009300000000, 0.503000000000, 0.158200000000, 103 | 515, 0.029100000000, 0.608200000000, 0.111700000000, 104 | 520, 0.063270000000, 0.710000000000, 0.078249990000, 105 | 525, 0.109600000000, 0.793200000000, 0.057250010000, 106 | 530, 0.165500000000, 0.862000000000, 0.042160000000, 107 | 535, 0.225749900000, 0.914850100000, 0.029840000000, 108 | 540, 0.290400000000, 0.954000000000, 0.020300000000, 109 | 545, 0.359700000000, 0.980300000000, 0.013400000000, 110 | 550, 0.433449900000, 0.994950100000, 0.008749999000, 111 | 555, 0.512050100000, 1.000000000000, 0.005749999000, 112 | 560, 0.594500000000, 0.995000000000, 0.003900000000, 113 | 565, 0.678400000000, 0.978600000000, 0.002749999000, 114 | 570, 0.762100000000, 0.952000000000, 0.002100000000, 115 | 575, 0.842500000000, 0.915400000000, 0.001800000000, 116 | 580, 0.916300000000, 0.870000000000, 0.001650001000, 117 | 585, 0.978600000000, 0.816300000000, 0.001400000000, 118 | 590, 1.026300000000, 0.757000000000, 0.001100000000, 119 | 595, 1.056700000000, 0.694900000000, 0.001000000000, 120 | 600, 1.062200000000, 0.631000000000, 0.000800000000, 121 | 605, 1.045600000000, 0.566800000000, 0.000600000000, 122 | 610, 1.002600000000, 0.503000000000, 0.000340000000, 123 | 615, 0.938400000000, 0.441200000000, 0.000240000000, 124 | 620, 0.854449900000, 0.381000000000, 0.000190000000, 125 | 625, 0.751400000000, 0.321000000000, 0.000100000000, 126 | 630, 0.642400000000, 0.265000000000, 0.000049999990, 127 | 635, 0.541900000000, 0.217000000000, 0.000030000000, 128 | 640, 0.447900000000, 0.175000000000, 0.000020000000, 129 | 645, 0.360800000000, 0.138200000000, 0.000010000000, 130 | 650, 0.283500000000, 0.107000000000, 0.000000000000, 131 | 655, 0.218700000000, 0.081600000000, 0.000000000000, 132 | 660, 0.164900000000, 0.061000000000, 0.000000000000, 133 | 665, 0.121200000000, 0.044580000000, 0.000000000000, 134 | 670, 0.087400000000, 0.032000000000, 0.000000000000, 135 | 675, 0.063600000000, 0.023200000000, 0.000000000000, 136 | 680, 0.046770000000, 0.017000000000, 0.000000000000, 137 | 685, 0.032900000000, 0.011920000000, 0.000000000000, 138 | 690, 0.022700000000, 0.008210000000, 0.000000000000, 139 | 695, 0.015840000000, 0.005723000000, 0.000000000000, 140 | 700, 0.011359160000, 0.004102000000, 0.000000000000, 141 | 705, 0.008110916000, 0.002929000000, 0.000000000000, 142 | 710, 0.005790346000, 0.002091000000, 0.000000000000, 143 | 715, 0.004109457000, 0.001484000000, 0.000000000000, 144 | 720, 0.002899327000, 0.001047000000, 0.000000000000, 145 | 725, 0.002049190000, 0.000740000000, 0.000000000000, 146 | 730, 0.001439971000, 0.000520000000, 0.000000000000, 147 | 735, 0.000999949300, 0.000361100000, 0.000000000000, 148 | 740, 0.000690078600, 0.000249200000, 0.000000000000, 149 | 745, 0.000476021300, 0.000171900000, 0.000000000000, 150 | 750, 0.000332301100, 0.000120000000, 0.000000000000, 151 | 755, 0.000234826100, 0.000084800000, 0.000000000000, 152 | 760, 0.000166150500, 0.000060000000, 0.000000000000, 153 | 765, 0.000117413000, 0.000042400000, 0.000000000000, 154 | 770, 0.000083075270, 0.000030000000, 0.000000000000, 155 | 775, 0.000058706520, 0.000021200000, 0.000000000000, 156 | 780, 0.000041509940, 0.000014990000, 0.000000000000, 157 | 785, 0.000029353260, 0.000010600000, 0.000000000000, 158 | 790, 0.000020673830, 0.000007465700, 0.000000000000, 159 | 795, 0.000014559770, 0.000005257800, 0.000000000000, 160 | 800, 0.000010253980, 0.000003702900, 0.000000000000, 161 | 805, 0.000007221456, 0.000002607800, 0.000000000000, 162 | 810, 0.000005085868, 0.000001836600, 0.000000000000, 163 | 815, 0.000003581652, 0.000001293400, 0.000000000000, 164 | 820, 0.000002522525, 0.000000910930, 0.000000000000, 165 | 825, 0.000001776509, 0.000000641530, 0.000000000000, 166 | 830, 0.000001251141, 0.000000451810, 0.000000000000, 167 | }; 168 | 169 | // The conversion matrix from XYZ to linear sRGB color spaces. 170 | // Values from https://en.wikipedia.org/wiki/SRGB. 171 | 172 | const double XYZ_TO_SRGB[9] = { 173 | +3.2406, -1.5372, -0.4986, 174 | -0.9689, +1.8758, +0.0415, 175 | +0.0557, -0.2040, +1.0570 176 | }; 177 | 178 | #endif -------------------------------------------------------------------------------- /source/atmosphere/definitions.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef __DEFINITIONS_H__ 4 | #define __DEFINITIONS_H__ 5 | 6 | 7 | #define ALIGN(x) __align__(x) 8 | 9 | __device__ const float m = 1.0; 10 | __device__ const float nm = 1.0; 11 | __device__ const float rad = 1.0; 12 | __device__ const float sr = 1.0; 13 | __device__ const float watt = 1.0; 14 | __device__ const float lm = 1.0; 15 | 16 | __device__ const float PI = 3.14159265358979323846f; 17 | 18 | __device__ constexpr float km() { return 1000.0 * m; } 19 | __device__ constexpr float m2() { return m * m; } 20 | __device__ constexpr float m3() { return m * m * m; } 21 | __device__ constexpr float pi() { return PI / rad; } 22 | __device__ constexpr float deg() { return pi() / 180.0f; } 23 | __device__ constexpr float watt_per_square_meter() { return watt / m2() ; } 24 | __device__ constexpr float watt_per_square_meter_per_sr() { return watt / (m2() * sr); } 25 | __device__ constexpr float watt_per_square_meter_per_nm() { return watt / (m2() * nm); } 26 | __device__ constexpr float watt_per_square_meter_per_sr_per_nm() { return watt / (m2() * sr * nm); } 27 | __device__ constexpr float watt_per_cubic_meter_per_sr_per_nm() { return watt / (m3() * sr * nm); } 28 | __device__ constexpr float cd() { return lm / sr; } 29 | __device__ constexpr float kcd() { return 1000.0f * cd(); } 30 | __device__ constexpr float cd_per_square_meter() { return cd() / m2(); } 31 | __device__ constexpr float kcd_per_square_meter() { return kcd() / m2(); } 32 | 33 | struct ALIGN(16) DensityProfileLayer { 34 | 35 | __device__ __host__ DensityProfileLayer() : DensityProfileLayer(.0f, .0f, .0f, .0f, .0f) {} 36 | __device__ __host__ DensityProfileLayer(float width, float exp_term, float exp_scale, 37 | float linear_term, float const_term) 38 | : width(width), exp_term(exp_term), exp_scale(exp_scale), linear_term(linear_term), const_term(const_term) {} 39 | 40 | float width; 41 | float exp_term; 42 | float exp_scale; 43 | float linear_term; 44 | float const_term; 45 | }; 46 | 47 | struct ALIGN(16) DensityProfile { 48 | 49 | DensityProfileLayer layers[2]; 50 | 51 | }; 52 | 53 | struct ALIGN(16) AtmosphereParameters { 54 | 55 | float3 sky_spectral_radiance_to_luminance; 56 | float3 sun_spectral_radiance_to_luminance; 57 | 58 | float3 solar_irradiance; 59 | float angle; 60 | float bottom_radius; 61 | float top_radius; 62 | int use_luminance; 63 | DensityProfile rayleigh_density; 64 | float3 rayleigh_scattering; 65 | 66 | DensityProfile mie_density; 67 | float3 mie_scattering; 68 | float3 mie_extinction; 69 | float mie_phase_function_g; 70 | 71 | DensityProfile absorption_density; 72 | float3 absorption_extinction; 73 | 74 | float3 ground_albedo; 75 | float sun_angular_radius; 76 | float mu_s_min; 77 | float exposure; 78 | float3 white_point; 79 | 80 | // Buffers 81 | 82 | float4 *delta_irradience_buffer; 83 | float4 *delta_rayleigh_scattering_buffer; 84 | float4 *delta_mie_scattering_buffer; 85 | float4 *delta_scattering_density_buffer; 86 | float4 *delta_multiple_scattering_buffer; 87 | float4 *transmittance_buffer; 88 | float4 *irradiance_buffer; 89 | float4 *scattering_buffer; 90 | float4 *optional_mie_single_scattering_buffer; 91 | 92 | // Textures 93 | 94 | cudaTextureObject_t transmittance_texture; 95 | cudaTextureObject_t scattering_texture; 96 | cudaTextureObject_t irradiance_texture; 97 | cudaTextureObject_t single_mie_scattering_texture; 98 | 99 | }; 100 | 101 | #endif -------------------------------------------------------------------------------- /source/bvh/AABB.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------- 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are met : 5 | // 6 | // *Redistributions of source code must retain the above copyright notice, this 7 | // list of conditions and the following disclaimer. 8 | // 9 | // * Redistributions in binary form must reproduce the above copyright notice, 10 | // this list of conditions and the following disclaimer in the documentation 11 | // and/or other materials provided with the distribution. 12 | // 13 | // * Neither the name of the copyright holder nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | // DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 21 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | // DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 | // OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // Copyright(c) 2019, Sergen Eren 29 | // All rights reserved. 30 | //---------------------------------------------------------------------------------- 31 | // 32 | // Version 1.0: Sergen Eren, 28/11/2019 33 | // 34 | // File: Axis Aligned Bounding Box for bvh contruction 35 | // from https://github.com/henrikdahlberg/GPUPathTracer 36 | // 37 | //----------------------------------------------- 38 | 39 | #ifndef _AABB_H_ 40 | #define _AABB_H_ 41 | 42 | 43 | #include "cuda_runtime_api.h" 44 | #include "helper_math.h" 45 | 46 | struct AABB { 47 | 48 | __host__ __device__ AABB() { 49 | pmin = make_float3(M_INF); 50 | pmax = make_float3(-M_INF); 51 | } 52 | 53 | __host__ __device__ AABB(const float3 &p) { 54 | pmin = p; 55 | pmax = p; 56 | } 57 | __host__ __device__ AABB(const float3 &p1, const float3 &p2) { 58 | 59 | pmin = p1; 60 | pmax = p2; 61 | } 62 | 63 | __host__ __device__ const float3 &operator[](int i) const {return (i == 0) ? pmin : pmax; } 64 | 65 | __host__ __device__ float3 &operator[](int i) {return (i == 0) ? pmin : pmax; } 66 | 67 | __host__ __device__ bool operator==(const AABB &b) const { 68 | return ((b.pmin.x == pmin.x && b.pmax.x == pmax.x) && 69 | (b.pmin.y == pmin.y && b.pmax.y == pmax.y) && 70 | (b.pmin.z == pmin.z && b.pmax.z == pmax.z)); 71 | } 72 | 73 | __host__ __device__ bool operator!=(const AABB &b) const { 74 | return ((b.pmin.x != pmin.x || b.pmax.x != pmax.x) || 75 | (b.pmin.y != pmin.y || b.pmax.y != pmax.y) || 76 | (b.pmin.z != pmin.z || b.pmax.z != pmax.z)); 77 | } 78 | 79 | __host__ __device__ float3 Diagonal() const { return pmax - pmin; } 80 | 81 | __host__ __device__ float3 Centroid() const { return 0.5f*(pmax + pmin); } 82 | 83 | __host__ __device__ float SurfaceArea() const { 84 | float3 d = Diagonal(); 85 | return 2 * (d.x * d.y + d.y * d.z + d.z * d.x); 86 | } 87 | 88 | __host__ __device__ float Volume() const { 89 | float3 d = Diagonal(); 90 | return d.x * d.y * d.z; 91 | } 92 | 93 | __host__ __device__ int MaximumDimension() const { 94 | float3 d = Diagonal(); 95 | return (d.x > d.y && d.x > d.z) ? 0 : ((d.y > d.z) ? 1 : 2); 96 | } 97 | 98 | __host__ __device__ float3 Offset(const float3 &p) const { 99 | float3 o = p - pmin; 100 | if (pmax.x > pmin.x) o.x /= pmax.x - pmin.x; 101 | if (pmax.y > pmin.y) o.y /= pmax.y - pmin.y; 102 | if (pmax.z > pmin.z) o.z /= pmax.z - pmin.z; 103 | return o; 104 | } 105 | 106 | __host__ __device__ bool Intersect(const float3 origin, const float3 direction, float &tmin, float &tmax) const; 107 | __host__ __device__ bool Intersect_no_t(const float3 origin, const float3 direction) const; 108 | 109 | float3 pmin; 110 | float3 pmax; 111 | 112 | }; 113 | 114 | ////////////////////////////////////////////////////////////////////////// 115 | // Geometry inline functions 116 | ////////////////////////////////////////////////////////////////////////// 117 | 118 | 119 | __host__ __device__ inline AABB UnionP(const AABB &b, const float3 &p) { 120 | return AABB(make_float3(fminf(b.pmin.x, p.x), fminf(b.pmin.y, p.y), fminf(b.pmin.z, p.z)), 121 | make_float3(fmaxf(b.pmax.x, p.x), fmaxf(b.pmax.y, p.y), fmaxf(b.pmax.z, p.z))); 122 | } 123 | 124 | __host__ __device__ inline AABB UnionB(const AABB &b1, const AABB &b2) { 125 | return AABB(make_float3(fminf(b1.pmin.x, b2.pmin.x), fminf(b1.pmin.y, b2.pmin.y), fminf(b1.pmin.z, b2.pmin.z)), 126 | make_float3(fmaxf(b1.pmax.x, b2.pmax.x), fmaxf(b1.pmax.y, b2.pmax.y), fmaxf(b1.pmax.z, b2.pmax.z))); 127 | } 128 | 129 | __host__ __device__ inline AABB Intersection(const AABB &b1, const AABB &b2) { 130 | return AABB(make_float3(fmaxf(b1.pmin.x, b2.pmin.x), fmaxf(b1.pmin.y, b2.pmin.y), fmaxf(b1.pmin.z, b2.pmin.z)), 131 | make_float3(fminf(b1.pmax.x, b2.pmax.x), fminf(b1.pmax.y, b2.pmax.y), fminf(b1.pmax.z, b2.pmax.z))); 132 | } 133 | 134 | __host__ __device__ inline bool Overlaps(const AABB &b1, const AABB &b2) { 135 | bool x = (b1.pmax.x >= b2.pmin.x) && (b1.pmin.x <= b2.pmax.x); 136 | bool y = (b1.pmax.y >= b2.pmin.y) && (b1.pmin.y <= b2.pmax.y); 137 | bool z = (b1.pmax.z >= b2.pmin.z) && (b1.pmin.z <= b2.pmax.z); 138 | return (x && y && z); 139 | } 140 | 141 | __host__ __device__ inline bool Contains(const AABB &b, const float3 &p) { 142 | return (p.x >= b.pmin.x && p.x <= b.pmax.x && 143 | p.y >= b.pmin.y && p.y <= b.pmax.y && 144 | p.z >= b.pmin.z && p.z <= b.pmax.z); 145 | 146 | } 147 | 148 | __host__ __device__ inline void BoundingSphere(const AABB &b, float3* position, float* radius) { 149 | *position = (b.pmin + b.pmax) * 0.5f; 150 | *radius = Contains(b, *position) ? length(*position - b.pmax) : 0; 151 | } 152 | 153 | __host__ __device__ inline bool ContainsExclusive(const AABB &b, const float3 &p) { 154 | return (p.x >= b.pmin.x && p.x < b.pmax.x && 155 | p.y >= b.pmin.y && p.y < b.pmax.y && 156 | p.z >= b.pmin.z && p.z < b.pmax.z); 157 | } 158 | 159 | __host__ __device__ inline AABB Expand(const AABB &b, const float delta) { 160 | return AABB(b.pmin - make_float3(delta), 161 | b.pmax + make_float3(delta)); 162 | } 163 | 164 | __host__ __device__ inline bool AABB::Intersect_no_t(const float3 origin, const float3 direction) const { 165 | 166 | float3 directionInv = make_float3(1.0f / direction.x, 1.0f / direction.y, 1.0f / direction.z); 167 | 168 | float t1 = (pmin.x - origin.x) * directionInv.x; 169 | float t2 = (pmax.x - origin.x) * directionInv.x; 170 | float t3 = (pmin.y - origin.y) * directionInv.y; 171 | float t4 = (pmax.y - origin.y) * directionInv.y; 172 | float t5 = (pmin.z - origin.z) * directionInv.z; 173 | float t6 = (pmax.z - origin.z) * directionInv.z; 174 | float tmin = fmaxf(fmaxf(fminf(t1, t2), fminf(t3, t4)), fminf(t5, t6)); 175 | float tmax = fminf(fminf(fmaxf(t1, t2), fmaxf(t3, t4)), fmaxf(t5, t6)); 176 | if (tmax <= 0.0f) return false; // box is behind 177 | if (tmin > tmax) return false; // ray missed 178 | 179 | return true; 180 | } 181 | 182 | __host__ __device__ inline bool AABB::Intersect(const float3 origin, const float3 direction, float &tmin, float &tmax) const { 183 | 184 | float3 directionInv = make_float3(1.0f / direction.x, 1.0f / direction.y, 1.0f / direction.z); 185 | 186 | float t1 = (pmin.x - origin.x) * directionInv.x; 187 | float t2 = (pmax.x - origin.x) * directionInv.x; 188 | float t3 = (pmin.y - origin.y) * directionInv.y; 189 | float t4 = (pmax.y - origin.y) * directionInv.y; 190 | float t5 = (pmin.z - origin.z) * directionInv.z; 191 | float t6 = (pmax.z - origin.z) * directionInv.z; 192 | tmin = fmaxf(fmaxf(fminf(t1, t2), fminf(t3, t4)), fminf(t5, t6)); 193 | tmax = fminf(fminf(fmaxf(t1, t2), fmaxf(t3, t4)), fmaxf(t5, t6)); 194 | if (tmax <= 0.0f) return false; // box is behind 195 | if (tmin > tmax) return false; // ray missed 196 | 197 | 198 | if (tmin < 0) { 199 | tmin = tmax; 200 | if (tmin < 0) return false; 201 | } 202 | 203 | 204 | return true; 205 | } 206 | 207 | 208 | 209 | 210 | struct AABBUnion { 211 | __host__ __device__ AABB operator()(const AABB &b1, const AABB &b2) const { 212 | return UnionB(b1, b2); 213 | } 214 | }; 215 | 216 | 217 | struct OCTNode { 218 | 219 | __host__ __device__ bool isLeaf() { return !children; } 220 | 221 | int num_volumes = 0; 222 | int vol_indices[600]; 223 | 224 | float max_extinction = .0f; 225 | float min_extinction = M_INF; 226 | 227 | float voxel_size = M_INF; 228 | int depth = -1; 229 | bool has_children = false; 230 | 231 | OCTNode *children[8]; 232 | OCTNode *parent; 233 | AABB bbox = AABB(); 234 | }; 235 | 236 | 237 | #endif // !_AABB_H_ 238 | 239 | -------------------------------------------------------------------------------- /source/bvh/bvh.cpp: -------------------------------------------------------------------------------- 1 | #include "bvh.h" 2 | 3 | 4 | BVHNode* BVH::getRoot() { 5 | 6 | return BVHNodes; 7 | 8 | } -------------------------------------------------------------------------------- /source/bvh/bvh.h: -------------------------------------------------------------------------------- 1 | #ifndef _BVH_H_ 2 | #define _BVH_H_ 3 | 4 | #include 5 | #include "AABB.h" 6 | 7 | 8 | typedef unsigned long long MortonCode; 9 | 10 | 11 | struct BVHNode { 12 | 13 | __host__ __device__ inline bool IsLeaf() { return !leftChild && !rightChild; } 14 | 15 | int minId; 16 | int maxId; 17 | int volIndex; 18 | 19 | BVHNode *leftChild; 20 | BVHNode *rightChild; 21 | BVHNode *parent; 22 | 23 | AABB boundingBox; 24 | }; 25 | 26 | class BVH { 27 | 28 | public: 29 | BVH(){} 30 | virtual ~BVH(){} 31 | 32 | BVHNode* getRoot(); 33 | 34 | BVHNode *BVHNodes; 35 | BVHNode *BVHLeaves; 36 | int numVolumes; 37 | }; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /source/bvh/bvh_builder.cpp: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------- 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are met : 5 | // 6 | // *Redistributions of source code must retain the above copyright notice, this 7 | // list of conditions and the following disclaimer. 8 | // 9 | // * Redistributions in binary form must reproduce the above copyright notice, 10 | // this list of conditions and the following disclaimer in the documentation 11 | // and/or other materials provided with the distribution. 12 | // 13 | // * Neither the name of the copyright holder nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | // DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 21 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | // DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 | // OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // Copyright(c) 2019, Sergen Eren 29 | // All rights reserved. 30 | //---------------------------------------------------------------------------------- 31 | // 32 | // Version 1.0: Sergen Eren, 29/11/2019 33 | // 34 | // File: This is the implementation file for BVH_Builder class functions 35 | // 36 | //----------------------------------------------- 37 | 38 | #include "bvh_builder.h" 39 | #include "logger.h" 40 | #include 41 | 42 | extern "C" void BuildBVH(BVH& bvh, GPU_VDB* volumes, int numVolumes, AABB &sceneBounds, bool debug_bvh); 43 | extern "C" void build_octree(OCTNode *root, GPU_VDB *volumes, int num_volumes, int depth, bool debug); 44 | 45 | // Build the BVH that will be sent to the render kernel 46 | bvh_error_t BVH_Builder::build_bvh(std::vector vdbs, int num_volumes, AABB &sceneBounds) { 47 | 48 | 49 | // Build BVH 50 | volumes = new GPU_VDB[num_volumes]; 51 | 52 | checkCudaErrors(cudaMalloc(&volumes, num_volumes * sizeof(GPU_VDB))); 53 | checkCudaErrors(cudaMemcpy(volumes, vdbs.data(), num_volumes * sizeof(GPU_VDB), cudaMemcpyHostToDevice)); 54 | 55 | log("Building BVH structure...", VPT_LOG); 56 | BuildBVH(bvh, volumes, num_volumes, sceneBounds, m_debug_bvh); 57 | 58 | 59 | log("Building Octree root...", VPT_LOG); 60 | // Build octree 61 | octree.root_node = new OCTNode; 62 | // <3, 3, 3> Octree 63 | octree.root_node->depth = 4; 64 | 65 | for (int i = 0; i < num_volumes; ++i) { 66 | 67 | octree.root_node->bbox.pmax = fmaxf(octree.root_node->bbox.pmax, vdbs.at(i).Bounds().pmax); 68 | octree.root_node->bbox.pmin = fminf(octree.root_node->bbox.pmin, vdbs.at(i).Bounds().pmin); 69 | octree.root_node->vol_indices[i] = i; 70 | octree.root_node->num_volumes++; 71 | octree.root_node->max_extinction = fmaxf(octree.root_node->max_extinction, vdbs.at(i).vdb_info.max_density); 72 | octree.root_node->min_extinction = fminf(octree.root_node->min_extinction, vdbs.at(i).vdb_info.min_density); 73 | 74 | octree.root_node->has_children = true; 75 | } 76 | 77 | octree.root_node->bbox.pmax += make_float3(1.0f); 78 | octree.root_node->bbox.pmin -= make_float3(1.0f); 79 | 80 | if (m_debug_bvh) std::cout << "num volumes for root is " << octree.root_node->num_volumes << "\n"; 81 | 82 | if (m_debug_bvh) { 83 | printf("Root node bounds \npmin.x: %f, pmin.y: %f, pmin.z: %f \npmax.x: %f, pmax.y: %f, pmax.z: %f\n", 84 | octree.root_node->bbox.pmin.x, octree.root_node->bbox.pmin.y, octree.root_node->bbox.pmin.z, 85 | octree.root_node->bbox.pmax.x, octree.root_node->bbox.pmax.y, octree.root_node->bbox.pmax.z); 86 | } 87 | 88 | #ifdef LOG_LEVEL_LOG 89 | octree.m_debug = true; // make this true to debug octree nodes 90 | #endif 91 | 92 | checkCudaErrors(cudaMalloc(&root, sizeof(OCTNode))); 93 | checkCudaErrors(cudaMemcpy(root, octree.root_node, sizeof(OCTNode), cudaMemcpyHostToDevice)); 94 | 95 | log("Building Octree structure...", VPT_LOG); 96 | build_octree(root, volumes, vdbs.size(), /*octree depth*/ octree.root_node->depth - 1, octree.m_debug); // GPU path 97 | 98 | //octree.create_tree(vdbs, octree.root_node, 3); // CPU path 99 | 100 | cudaFree(volumes); 101 | volumes = nullptr; 102 | 103 | return BVH_NO_ERR; 104 | 105 | } -------------------------------------------------------------------------------- /source/bvh/bvh_builder.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------- 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are met : 5 | // 6 | // *Redistributions of source code must retain the above copyright notice, this 7 | // list of conditions and the following disclaimer. 8 | // 9 | // * Redistributions in binary form must reproduce the above copyright notice, 10 | // this list of conditions and the following disclaimer in the documentation 11 | // and/or other materials provided with the distribution. 12 | // 13 | // * Neither the name of the copyright holder nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | // DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 21 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | // DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 | // OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // Copyright(c) 2019, Sergen Eren 29 | // All rights reserved. 30 | //---------------------------------------------------------------------------------- 31 | // 32 | // Version 1.0: Sergen Eren, 29/11/2019 33 | // 34 | // File: This is the header file for bvh_builder class that takes a vector of 35 | // gpu_vdb volumes and creates an accompanying bvh to be sent to render kernel 36 | // 37 | //----------------------------------------------- 38 | 39 | 40 | 41 | 42 | #ifndef _BVH_BUILDER_H_ 43 | #define _BVH_BUILDER_H_ 44 | 45 | #include 46 | #include 47 | 48 | #include "bvh.h" 49 | #include "gpu_vdb.h" 50 | #include "bvh/octree.h" 51 | 52 | enum bvh_error_t { 53 | 54 | BVH_LAUNCH_ERR, 55 | BVH_NO_ERR 56 | }; 57 | 58 | 59 | class BVH_Builder { 60 | 61 | public: 62 | BVH_Builder() {}; 63 | ~BVH_Builder() { delete volumes; }; 64 | 65 | bvh_error_t build_bvh(std::vector vdbs, int num_volumes, AABB &sceneBounds); 66 | 67 | BVH bvh; 68 | OCTree octree; 69 | OCTNode *root; 70 | bool m_debug_bvh = false; 71 | 72 | private: 73 | 74 | GPU_VDB *volumes; 75 | 76 | }; 77 | 78 | #endif // !_BVH_BUILDER_H_ 79 | -------------------------------------------------------------------------------- /source/bvh/octree.cpp: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------- 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are met : 5 | // 6 | // *Redistributions of source code must retain the above copyright notice, this 7 | // list of conditions and the following disclaimer. 8 | // 9 | // * Redistributions in binary form must reproduce the above copyright notice, 10 | // this list of conditions and the following disclaimer in the documentation 11 | // and/or other materials provided with the distribution. 12 | // 13 | // * Neither the name of the copyright holder nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | // DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 21 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | // DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 | // OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // Copyright(c) 2019, Sergen Eren 29 | // All rights reserved. 30 | //---------------------------------------------------------------------------------- 31 | // 32 | // Version 1.0: Sergen Eren, 01/12/2019 33 | // 34 | // File: Implementation file for OCTree class functions 35 | // 36 | //----------------------------------------------- 37 | 38 | #include "bvh/octree.h" 39 | #include 40 | 41 | 42 | // Returns root node 43 | OCTNode* OCTree::getRoot() { 44 | 45 | return root_node; 46 | } 47 | 48 | // Divides a bounding box to 8 and calculates children bounding boxes based on an index 49 | // 50 | // +------------+ pmax 51 | // / 4 / 5 /| 52 | // /______/_____/ | 53 | // y / / /| | 54 | // | z +------------+ |/| 55 | // | / | 0 | 1 | / | 56 | // | / |______|_____|/| / 57 | // |/ | | | |/ 58 | // +------ > x | 2 | 3 | / 59 | // pmin +------------+ 60 | // 61 | // 62 | 63 | AABB OCTree::divide_bbox(int idx, float3 pmin, float3 pmax) { 64 | 65 | float3 min = make_float3(.0f); 66 | float3 max = make_float3(.0f); 67 | float half_x = (pmin.x + pmax.x)*0.5; 68 | float half_y = (pmin.y + pmax.y)*0.5; 69 | float half_z = (pmin.z + pmax.z)*0.5; 70 | 71 | if (idx == 0) { 72 | min = make_float3(pmin.x, half_y, pmin.z); 73 | max = make_float3(half_x, pmax.y, half_z); 74 | } 75 | 76 | if (idx == 1) { 77 | min = make_float3(half_x, half_y, pmin.z); 78 | max = make_float3(pmax.x, pmax.y, half_z); 79 | } 80 | 81 | if (idx == 2) { 82 | min = pmin; 83 | max = make_float3(half_x, half_y, half_z); 84 | } 85 | 86 | if (idx == 3) { 87 | min = make_float3(half_x, pmin.y, pmin.z); 88 | max = make_float3(pmax.x, half_y, half_z); 89 | } 90 | 91 | 92 | if (idx == 4) { 93 | min = make_float3(pmin.x, half_y, half_z); 94 | max = make_float3(half_x, pmax.y, pmax.z); 95 | } 96 | 97 | if (idx == 5) { 98 | min = make_float3(half_x, half_y, half_z); 99 | max = pmax; 100 | } 101 | 102 | if (idx == 6) { 103 | min = make_float3(pmin.x, pmin.y, half_z); 104 | max = make_float3(half_x, half_y, pmax.z); 105 | } 106 | 107 | if (idx == 7) { 108 | min = make_float3(half_x, pmin.y, half_z); 109 | max = make_float3(pmax.x, half_y, pmax.z); 110 | 111 | } 112 | 113 | return AABB(min, max); 114 | } 115 | 116 | void OCTree::create_tree(std::vector vdbs, OCTNode *root, int depth) 117 | { 118 | if (depth > 0) { 119 | if (root->num_volumes > 0) { 120 | for (int i = 0; i < 8; ++i) { 121 | 122 | root->children[i] = new OCTNode; 123 | root->children[i]->parent = root; 124 | float3 pmin = root->bbox.pmin; 125 | float3 pmax = root->bbox.pmax; 126 | root->children[i]->bbox = divide_bbox(i, pmin, pmax); 127 | 128 | int idx = 0; 129 | for (int y = 0; y < vdbs.size(); ++y) { 130 | if (Overlaps(root->children[i]->bbox, vdbs.at(y).Bounds())) { 131 | root->children[i]->num_volumes++; 132 | root->children[i]->vol_indices[idx] = y; 133 | root->children[i]->max_extinction = fmaxf(root->children[i]->max_extinction, vdbs.at(y).vdb_info.max_density); 134 | idx++; 135 | } 136 | } 137 | 138 | if (m_debug) { 139 | std::cout << "num volumes for child " << depth << "-" << i << " is " << root->children[i]->num_volumes << " "; 140 | if (root->children[i]->num_volumes > 0) { 141 | std::cout << "volume indices: "; 142 | for (int x = 0; x < root->children[i]->num_volumes; ++x) { 143 | std::cout << root->children[i]->vol_indices[x] << " "; 144 | 145 | } 146 | } 147 | std::cout << " max extinction: " << root->children[i]->max_extinction << "\n"; 148 | } 149 | 150 | create_tree(vdbs, root->children[i], depth - 1); 151 | 152 | } 153 | 154 | } 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /source/bvh/octree.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------- 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are met : 5 | // 6 | // *Redistributions of source code must retain the above copyright notice, this 7 | // list of conditions and the following disclaimer. 8 | // 9 | // * Redistributions in binary form must reproduce the above copyright notice, 10 | // this list of conditions and the following disclaimer in the documentation 11 | // and/or other materials provided with the distribution. 12 | // 13 | // * Neither the name of the copyright holder nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | // DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 21 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | // DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 | // OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // Copyright(c) 2019, Sergen Eren 29 | // All rights reserved. 30 | //---------------------------------------------------------------------------------- 31 | // 32 | // Version 1.0: Sergen Eren, 01/12/2019 33 | // 34 | // File: Header file for OCTree node and class that partitions a space by major axes 35 | // and creates an octree that holds volumetric meta attributes 36 | // 37 | //----------------------------------------------- 38 | 39 | 40 | #ifndef _OCTREE_H_ 41 | #define _OCTREE_H_ 42 | 43 | #include 44 | #include "AABB.h" 45 | #include "gpu_vdb/gpu_vdb.h" 46 | #include 47 | 48 | class OCTree { 49 | 50 | public: 51 | OCTree() {}; 52 | virtual ~OCTree() {}; 53 | 54 | OCTNode* getRoot(); 55 | AABB divide_bbox(int idx, float3 pmin, float3 pmax); 56 | void create_tree(std::vector vdbs, OCTNode *root, int depth); 57 | 58 | bool m_debug = false; 59 | OCTNode *root_node; 60 | 61 | }; 62 | 63 | #endif // !_OCTREE_H_ 64 | -------------------------------------------------------------------------------- /source/common/exception.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1993-2017 NVIDIA Corporation. All rights reserved. 3 | * 4 | * Please refer to the NVIDIA end user license agreement (EULA) associated 5 | * with this source code for terms and conditions that govern your use of 6 | * this software. Any use, reproduction, disclosure, or distribution of 7 | * this software and related documentation outside the terms of the EULA 8 | * is strictly prohibited. 9 | * 10 | */ 11 | 12 | /* CUda UTility Library */ 13 | #ifndef COMMON_EXCEPTION_H_ 14 | #define COMMON_EXCEPTION_H_ 15 | 16 | // includes, system 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | //! Exception wrapper. 24 | //! @param Std_Exception Exception out of namespace std for easy typing. 25 | template 26 | class Exception : public Std_Exception { 27 | public: 28 | //! @brief Static construction interface 29 | //! @return Alwayss throws ( Located_Exception) 30 | //! @param file file in which the Exception occurs 31 | //! @param line line in which the Exception occurs 32 | //! @param detailed details on the code fragment causing the Exception 33 | static void throw_it(const char *file, const int line, 34 | const char *detailed = "-"); 35 | 36 | //! Static construction interface 37 | //! @return Alwayss throws ( Located_Exception) 38 | //! @param file file in which the Exception occurs 39 | //! @param line line in which the Exception occurs 40 | //! @param detailed details on the code fragment causing the Exception 41 | static void throw_it(const char *file, const int line, 42 | const std::string &detailed); 43 | 44 | //! Destructor 45 | virtual ~Exception() throw(); 46 | 47 | private: 48 | //! Constructor, default (private) 49 | Exception(); 50 | 51 | //! Constructor, standard 52 | //! @param str string returned by what() 53 | explicit Exception(const std::string &str); 54 | }; 55 | 56 | //////////////////////////////////////////////////////////////////////////////// 57 | //! Exception handler function for arbitrary exceptions 58 | //! @param ex exception to handle 59 | //////////////////////////////////////////////////////////////////////////////// 60 | template 61 | inline void handleException(const Exception_Typ &ex) { 62 | std::cerr << ex.what() << std::endl; 63 | 64 | exit(EXIT_FAILURE); 65 | } 66 | 67 | //! Convenience macros 68 | 69 | //! Exception caused by dynamic program behavior, e.g. file does not exist 70 | #define RUNTIME_EXCEPTION(msg) \ 71 | Exception::throw_it(__FILE__, __LINE__, msg) 72 | 73 | //! Logic exception in program, e.g. an assert failed 74 | #define LOGIC_EXCEPTION(msg) \ 75 | Exception::throw_it(__FILE__, __LINE__, msg) 76 | 77 | //! Out of range exception 78 | #define RANGE_EXCEPTION(msg) \ 79 | Exception::throw_it(__FILE__, __LINE__, msg) 80 | 81 | //////////////////////////////////////////////////////////////////////////////// 82 | //! Implementation 83 | 84 | // includes, system 85 | #include 86 | 87 | //////////////////////////////////////////////////////////////////////////////// 88 | //! Static construction interface. 89 | //! @param Exception causing code fragment (file and line) and detailed infos. 90 | //////////////////////////////////////////////////////////////////////////////// 91 | /*static*/ template 92 | void Exception::throw_it(const char *file, const int line, 93 | const char *detailed) { 94 | std::stringstream s; 95 | 96 | // Quiet heavy-weight but exceptions are not for 97 | // performance / release versions 98 | s << "Exception in file '" << file << "' in line " << line << "\n" 99 | << "Detailed description: " << detailed << "\n"; 100 | 101 | throw Exception(s.str()); 102 | } 103 | 104 | //////////////////////////////////////////////////////////////////////////////// 105 | //! Static construction interface. 106 | //! @param Exception causing code fragment (file and line) and detailed infos. 107 | //////////////////////////////////////////////////////////////////////////////// 108 | /*static*/ template 109 | void Exception::throw_it(const char *file, const int line, 110 | const std::string &msg) { 111 | throw_it(file, line, msg.c_str()); 112 | } 113 | 114 | //////////////////////////////////////////////////////////////////////////////// 115 | //! Constructor, default (private). 116 | //////////////////////////////////////////////////////////////////////////////// 117 | template 118 | Exception::Exception() : Std_Exception("Unknown Exception.\n") {} 119 | 120 | //////////////////////////////////////////////////////////////////////////////// 121 | //! Constructor, standard (private). 122 | //! String returned by what(). 123 | //////////////////////////////////////////////////////////////////////////////// 124 | template 125 | Exception::Exception(const std::string &s) : Std_Exception(s) {} 126 | 127 | //////////////////////////////////////////////////////////////////////////////// 128 | //! Destructor 129 | //////////////////////////////////////////////////////////////////////////////// 130 | template 131 | Exception::~Exception() throw() {} 132 | 133 | // functions, exported 134 | 135 | #endif // COMMON_EXCEPTION_H_ 136 | -------------------------------------------------------------------------------- /source/common/helper_functions.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 1993-2013 NVIDIA Corporation. All rights reserved. 3 | * 4 | * Please refer to the NVIDIA end user license agreement (EULA) associated 5 | * with this source code for terms and conditions that govern your use of 6 | * this software. Any use, reproduction, disclosure, or distribution of 7 | * this software and related documentation outside the terms of the EULA 8 | * is strictly prohibited. 9 | * 10 | */ 11 | 12 | // These are helper functions for the SDK samples (string parsing, 13 | // timers, image helpers, etc) 14 | #ifndef COMMON_HELPER_FUNCTIONS_H_ 15 | #define COMMON_HELPER_FUNCTIONS_H_ 16 | 17 | #ifdef WIN32 18 | #pragma warning(disable : 4996) 19 | #endif 20 | 21 | // includes, project 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | // includes, timer, string parsing, image helpers 35 | #include // helper functions for image compare, dump, data comparisons 36 | #include // helper functions for string parsing 37 | #include // helper functions for timers 38 | 39 | #ifndef EXIT_WAIVED 40 | #define EXIT_WAIVED 2 41 | #endif 42 | 43 | #endif // COMMON_HELPER_FUNCTIONS_H_ 44 | -------------------------------------------------------------------------------- /source/common/helper_gl.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 NVIDIA Corporation. All rights reserved. 3 | * 4 | * Please refer to the NVIDIA end user license agreement (EULA) associated 5 | * with this source code for terms and conditions that govern your use of 6 | * this software. Any use, reproduction, disclosure, or distribution of 7 | * this software and related documentation outside the terms of the EULA 8 | * is strictly prohibited. 9 | * 10 | */ 11 | 12 | // These are helper functions for the SDK samples (OpenGL) 13 | #ifndef HELPER_GL_H 14 | #define HELPER_GL_H 15 | 16 | #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) 17 | #include 18 | #endif 19 | 20 | #if defined(__APPLE__) || defined(MACOSX) 21 | #include 22 | #else 23 | #include 24 | #ifdef __linux__ 25 | #include 26 | #endif /* __linux__ */ 27 | #endif 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | 39 | /* Prototypes */ 40 | namespace __HelperGL { 41 | static int isGLVersionSupported(unsigned reqMajor, unsigned reqMinor); 42 | static int areGLExtensionsSupported(const std::string &); 43 | #ifdef __linux__ 44 | 45 | #ifndef HELPERGL_EXTERN_GL_FUNC_IMPLEMENTATION 46 | #define USE_GL_FUNC(name, proto) proto name = (proto) glXGetProcAddress ((const GLubyte *)#name) 47 | #else 48 | #define USE_GL_FUNC(name, proto) extern proto name 49 | #endif 50 | 51 | USE_GL_FUNC(glBindBuffer, PFNGLBINDBUFFERPROC); 52 | USE_GL_FUNC(glDeleteBuffers, PFNGLDELETEBUFFERSPROC); 53 | USE_GL_FUNC(glBufferData, PFNGLBUFFERDATAPROC); 54 | USE_GL_FUNC(glBufferSubData, PFNGLBUFFERSUBDATAPROC); 55 | USE_GL_FUNC(glGenBuffers, PFNGLGENBUFFERSPROC); 56 | USE_GL_FUNC(glCreateProgram, PFNGLCREATEPROGRAMPROC); 57 | USE_GL_FUNC(glBindProgramARB, PFNGLBINDPROGRAMARBPROC); 58 | USE_GL_FUNC(glGenProgramsARB, PFNGLGENPROGRAMSARBPROC); 59 | USE_GL_FUNC(glDeleteProgramsARB, PFNGLDELETEPROGRAMSARBPROC); 60 | USE_GL_FUNC(glDeleteProgram, PFNGLDELETEPROGRAMPROC); 61 | USE_GL_FUNC(glGetProgramInfoLog, PFNGLGETPROGRAMINFOLOGPROC); 62 | USE_GL_FUNC(glGetProgramiv, PFNGLGETPROGRAMIVPROC); 63 | USE_GL_FUNC(glProgramParameteriEXT, PFNGLPROGRAMPARAMETERIEXTPROC); 64 | USE_GL_FUNC(glProgramStringARB, PFNGLPROGRAMSTRINGARBPROC); 65 | USE_GL_FUNC(glUnmapBuffer, PFNGLUNMAPBUFFERPROC); 66 | USE_GL_FUNC(glMapBuffer, PFNGLMAPBUFFERPROC); 67 | USE_GL_FUNC(glGetBufferParameteriv, PFNGLGETBUFFERPARAMETERIVPROC); 68 | USE_GL_FUNC(glLinkProgram, PFNGLLINKPROGRAMPROC); 69 | USE_GL_FUNC(glUseProgram, PFNGLUSEPROGRAMPROC); 70 | USE_GL_FUNC(glAttachShader, PFNGLATTACHSHADERPROC); 71 | USE_GL_FUNC(glCreateShader, PFNGLCREATESHADERPROC); 72 | USE_GL_FUNC(glShaderSource, PFNGLSHADERSOURCEPROC); 73 | USE_GL_FUNC(glCompileShader, PFNGLCOMPILESHADERPROC); 74 | USE_GL_FUNC(glDeleteShader, PFNGLDELETESHADERPROC); 75 | USE_GL_FUNC(glGetShaderInfoLog, PFNGLGETSHADERINFOLOGPROC); 76 | USE_GL_FUNC(glGetShaderiv, PFNGLGETSHADERIVPROC); 77 | USE_GL_FUNC(glUniform1i, PFNGLUNIFORM1IPROC); 78 | USE_GL_FUNC(glUniform1f, PFNGLUNIFORM1FPROC); 79 | USE_GL_FUNC(glUniform2f, PFNGLUNIFORM2FPROC); 80 | USE_GL_FUNC(glUniform3f, PFNGLUNIFORM3FPROC); 81 | USE_GL_FUNC(glUniform4f, PFNGLUNIFORM4FPROC); 82 | USE_GL_FUNC(glUniform1fv, PFNGLUNIFORM1FVPROC); 83 | USE_GL_FUNC(glUniform2fv, PFNGLUNIFORM2FVPROC); 84 | USE_GL_FUNC(glUniform3fv, PFNGLUNIFORM3FVPROC); 85 | USE_GL_FUNC(glUniform4fv, PFNGLUNIFORM4FVPROC); 86 | USE_GL_FUNC(glUniformMatrix4fv, PFNGLUNIFORMMATRIX4FVPROC); 87 | USE_GL_FUNC(glSecondaryColor3fv, PFNGLSECONDARYCOLOR3FVPROC); 88 | USE_GL_FUNC(glGetUniformLocation, PFNGLGETUNIFORMLOCATIONPROC); 89 | USE_GL_FUNC(glGenFramebuffersEXT, PFNGLGENFRAMEBUFFERSEXTPROC); 90 | USE_GL_FUNC(glBindFramebufferEXT, PFNGLBINDFRAMEBUFFEREXTPROC); 91 | USE_GL_FUNC(glDeleteFramebuffersEXT, PFNGLDELETEFRAMEBUFFERSEXTPROC); 92 | USE_GL_FUNC(glCheckFramebufferStatusEXT, PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC); 93 | USE_GL_FUNC(glGetFramebufferAttachmentParameterivEXT, PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC); 94 | USE_GL_FUNC(glFramebufferTexture1DEXT, PFNGLFRAMEBUFFERTEXTURE1DEXTPROC); 95 | USE_GL_FUNC(glFramebufferTexture2DEXT, PFNGLFRAMEBUFFERTEXTURE2DEXTPROC); 96 | USE_GL_FUNC(glFramebufferTexture3DEXT, PFNGLFRAMEBUFFERTEXTURE3DEXTPROC); 97 | USE_GL_FUNC(glGenerateMipmapEXT, PFNGLGENERATEMIPMAPEXTPROC); 98 | USE_GL_FUNC(glGenRenderbuffersEXT, PFNGLGENRENDERBUFFERSEXTPROC); 99 | USE_GL_FUNC(glDeleteRenderbuffersEXT, PFNGLDELETERENDERBUFFERSEXTPROC); 100 | USE_GL_FUNC(glBindRenderbufferEXT, PFNGLBINDRENDERBUFFEREXTPROC); 101 | USE_GL_FUNC(glRenderbufferStorageEXT, PFNGLRENDERBUFFERSTORAGEEXTPROC); 102 | USE_GL_FUNC(glFramebufferRenderbufferEXT, PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC); 103 | USE_GL_FUNC(glClampColorARB, PFNGLCLAMPCOLORARBPROC); 104 | USE_GL_FUNC(glBindFragDataLocationEXT, PFNGLBINDFRAGDATALOCATIONEXTPROC); 105 | 106 | #if !defined(GLX_EXTENSION_NAME) || !defined(GL_VERSION_1_3) 107 | USE_GL_FUNC(glActiveTexture, PFNGLACTIVETEXTUREPROC); 108 | USE_GL_FUNC(glClientActiveTexture, PFNGLACTIVETEXTUREPROC); 109 | #endif 110 | 111 | #undef USE_GL_FUNC 112 | #endif /*__linux__ */ 113 | } 114 | 115 | 116 | namespace __HelperGL { 117 | namespace __Int { 118 | static std::vector split(const std::string &str) 119 | { 120 | std::istringstream ss(str); 121 | std::istream_iterator it(ss); 122 | return std::vector (it, std::istream_iterator()); 123 | } 124 | 125 | /* Sort the vector passed by reference */ 126 | template static inline void sort(std::vector &a) 127 | { 128 | std::sort(a.begin(), a.end()); 129 | } 130 | 131 | /* Compare two vectors */ 132 | template static int equals(std::vector a, std::vector b) 133 | { 134 | if (a.size() != b.size()) return 0; 135 | sort(a); 136 | sort(b); 137 | 138 | return std::equal(a.begin(), a.end(), b.begin()); 139 | } 140 | 141 | template static std::vector getIntersection(std::vector a, std::vector b) 142 | { 143 | sort(a); 144 | sort(b); 145 | 146 | std::vector rc; 147 | std::set_intersection(a.begin(), a.end(), b.begin(), b.end(), 148 | std::back_inserter >(rc)); 149 | return rc; 150 | } 151 | 152 | static std::vector getGLExtensions() 153 | { 154 | std::string extensionsStr( (const char *)glGetString(GL_EXTENSIONS)); 155 | return split (extensionsStr); 156 | } 157 | } 158 | 159 | static int areGLExtensionsSupported(const std::string &extensions) 160 | { 161 | std::vector all = __Int::getGLExtensions(); 162 | 163 | std::vector requested = __Int::split(extensions); 164 | std::vector matched = __Int::getIntersection(all, requested); 165 | 166 | return __Int::equals(matched, requested); 167 | } 168 | 169 | static int isGLVersionSupported(unsigned reqMajor, unsigned reqMinor) 170 | { 171 | #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) 172 | if (glewInit() != GLEW_OK) 173 | { 174 | std::cerr << "glewInit() failed!" << std::endl; 175 | return 0; 176 | } 177 | #endif 178 | std::string version ((const char *) glGetString (GL_VERSION)); 179 | std::stringstream stream (version); 180 | unsigned major, minor; 181 | char dot; 182 | 183 | stream >> major >> dot >> minor; 184 | 185 | assert (dot == '.'); 186 | return major > reqMajor || (major == reqMajor && minor >= reqMinor); 187 | } 188 | 189 | static inline const char* glErrorToString(GLenum err) 190 | { 191 | #define CASE_RETURN_MACRO(arg) case arg: return #arg 192 | switch(err) 193 | { 194 | CASE_RETURN_MACRO(GL_NO_ERROR); 195 | CASE_RETURN_MACRO(GL_INVALID_ENUM); 196 | CASE_RETURN_MACRO(GL_INVALID_VALUE); 197 | CASE_RETURN_MACRO(GL_INVALID_OPERATION); 198 | CASE_RETURN_MACRO(GL_OUT_OF_MEMORY); 199 | CASE_RETURN_MACRO(GL_STACK_UNDERFLOW); 200 | CASE_RETURN_MACRO(GL_STACK_OVERFLOW); 201 | #ifdef GL_INVALID_FRAMEBUFFER_OPERATION 202 | CASE_RETURN_MACRO(GL_INVALID_FRAMEBUFFER_OPERATION); 203 | #endif 204 | default: break; 205 | } 206 | #undef CASE_RETURN_MACRO 207 | return "*UNKNOWN*"; 208 | } 209 | 210 | //////////////////////////////////////////////////////////////////////////// 211 | //! Check for OpenGL error 212 | //! @return bool if no GL error has been encountered, otherwise 0 213 | //! @param file __FILE__ macro 214 | //! @param line __LINE__ macro 215 | //! @note The GL error is listed on stderr 216 | //! @note This function should be used via the CHECK_ERROR_GL() macro 217 | //////////////////////////////////////////////////////////////////////////// 218 | inline bool sdkCheckErrorGL(const char *file, const int line) 219 | { 220 | bool ret_val = true; 221 | 222 | // check for error 223 | GLenum gl_error = glGetError(); 224 | 225 | if (gl_error != GL_NO_ERROR) 226 | { 227 | #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) 228 | char tmpStr[512]; 229 | // NOTE: "%s(%i) : " allows Visual Studio to directly jump to the file at the right line 230 | // when the user double clicks on the error line in the Output pane. Like any compile error. 231 | sprintf_s(tmpStr, 255, "\n%s(%i) : GL Error : %s\n\n", file, line, glErrorToString(gl_error)); 232 | fprintf(stderr, "%s", tmpStr); 233 | #endif 234 | fprintf(stderr, "GL Error in file '%s' in line %d :\n", file, line); 235 | fprintf(stderr, "%s\n", glErrorToString(gl_error)); 236 | ret_val = false; 237 | } 238 | 239 | return ret_val; 240 | } 241 | 242 | #define SDK_CHECK_ERROR_GL() \ 243 | if( false == sdkCheckErrorGL( __FILE__, __LINE__)) { \ 244 | exit(EXIT_FAILURE); \ 245 | } 246 | 247 | } /* of namespace __HelperGL*/ 248 | 249 | using namespace __HelperGL; 250 | 251 | #endif /*HELPER_GL_H*/ 252 | -------------------------------------------------------------------------------- /source/geometry/geometry.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------- 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are met : 5 | // 6 | // *Redistributions of source code must retain the above copyright notice, this 7 | // list of conditions and the following disclaimer. 8 | // 9 | // * Redistributions in binary form must reproduce the above copyright notice, 10 | // this list of conditions and the following disclaimer in the documentation 11 | // and/or other materials provided with the distribution. 12 | // 13 | // * Neither the name of the copyright holder nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | // DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 21 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | // DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 | // OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // Copyright(c) 2019, Sergen Eren 29 | // All rights reserved. 30 | //---------------------------------------------------------------------------------- 31 | // 32 | // Version 1.0: Sergen Eren, 18/12/2019 33 | // 34 | // File: General geometry class that parents geo types 35 | // 36 | //----------------------------------------------- 37 | 38 | 39 | #ifndef _GEOMETRY_H_ 40 | #define _GEOMETRY_H_ 41 | 42 | 43 | #include "cuda_runtime_api.h" 44 | #include "helper_math.h" 45 | 46 | __device__ __host__ inline bool find_discr( 47 | float a, 48 | float b, 49 | float c, 50 | float& x1, 51 | float& x2) 52 | { 53 | if (b == 0) { 54 | // Handle special case where the the two vector ray.dir and V are perpendicular 55 | // with V = ray.orig - sphere.centre 56 | if (a == 0) return false; 57 | x1 = 0; x2 = sqrt(-c / a); 58 | return true; 59 | } 60 | 61 | float discr = b * b - 4 * a * c; 62 | 63 | if (discr < 0) return false; 64 | 65 | float q = (b < 0.f) ? -0.5f * (b - sqrt(discr)) : -0.5f * (b + sqrt(discr)); 66 | x1 = q / a; 67 | x2 = c / q; 68 | 69 | return true; 70 | } 71 | 72 | 73 | 74 | class geometry { 75 | 76 | public: 77 | 78 | __device__ virtual int intersect(float3 ray_pos, float3 ray_dir, float& t_min, float& t_max) const = 0; 79 | __device__ virtual bool scatter(float3& ray_pos, float3& ray_dir, float t_min, float3& normal, float3& atten, Rand_state rand_state) const = 0; 80 | }; 81 | 82 | class sphere : public geometry { 83 | 84 | public: 85 | 86 | __device__ __host__ sphere() { 87 | center = make_float3(.0f); 88 | radius = 1.0f; 89 | color = make_float3(1.0f); 90 | roughness = .0f; 91 | } 92 | 93 | __device__ __host__ sphere(float3 c, float rad) { 94 | center = c; 95 | radius = rad; 96 | color = make_float3(1.0f); 97 | roughness = .0f; 98 | } 99 | 100 | __device__ __host__ sphere(float3 c, float rad, float3 col) { 101 | center = c; 102 | radius = rad; 103 | color = col; 104 | roughness = 1.0f; 105 | } 106 | 107 | __device__ __host__ sphere(float3 c, float rad, float3 col, float r) { 108 | center = c; 109 | radius = rad; 110 | color = col; 111 | roughness = r; 112 | } 113 | 114 | __device__ virtual int intersect(float3 ray_pos, float3 ray_dir, float& t_min, float& t_max) const { 115 | 116 | float3 orig = ray_pos - center; 117 | 118 | float A = ray_dir.x * ray_dir.x + ray_dir.y * ray_dir.y + ray_dir.z * ray_dir.z; 119 | float B = 2 * (ray_dir.x * orig.x + ray_dir.y * orig.y + ray_dir.z * orig.z); 120 | float C = orig.x * orig.x + orig.y * orig.y + orig.z * orig.z - radius * radius; 121 | 122 | if (!find_discr(A, B, C, t_min, t_max)) return 0; 123 | 124 | if (t_min > t_max) { 125 | float tempt = t_max; 126 | t_max = t_min; 127 | t_min = tempt; 128 | } 129 | 130 | if (t_min < 0) { 131 | t_min = t_max; 132 | if (t_min < 0) return 0; 133 | } 134 | 135 | return 1; 136 | 137 | }; 138 | 139 | 140 | __device__ virtual bool scatter(float3& ray_pos, float3& ray_dir, float t_min, float3& normal, float3& atten, Rand_state rand_state) const { 141 | 142 | ray_dir = normalize(ray_dir); 143 | ray_pos += ray_dir * t_min; 144 | normal = normalize((ray_pos - center) / radius); 145 | float3 nl = dot(normal, ray_dir) < 0 ? normal : normal * -1; 146 | 147 | float phi = 2 * M_PI * rand(&rand_state); 148 | float r2 = rand(&rand_state); 149 | float r2s = sqrtf(r2); 150 | 151 | float3 w = normalize(nl); 152 | float3 u = normalize(cross((fabs(w.x) > .1 ? make_float3(0, 1, 0) : make_float3(1, 0, 0)), w)); 153 | float3 v = cross(w, u); 154 | 155 | float3 hemisphere_dir = normalize(u * cosf(phi) * r2s + v * sinf(phi) * r2s + w * sqrtf(1 - r2)); 156 | float3 ref = reflect(ray_dir, nl); 157 | ray_dir = lerp(ref, hemisphere_dir, roughness); 158 | 159 | ray_pos += ray_dir * 0.1; 160 | 161 | atten *= color; 162 | 163 | return true; 164 | } 165 | 166 | 167 | float3 center; 168 | float radius; 169 | float3 color; 170 | float roughness; 171 | 172 | }; 173 | 174 | class sphere_light : public geometry { 175 | 176 | public: 177 | 178 | __device__ __host__ sphere_light() { 179 | center = make_float3(.0f); 180 | radius = 1.0f; 181 | color = make_float3(1.0f); 182 | } 183 | 184 | __device__ __host__ sphere_light(float3 c, float rad) { 185 | center = c; 186 | radius = rad; 187 | color = make_float3(1.0f); 188 | } 189 | 190 | __device__ __host__ sphere_light(float3 c, float rad, float3 col) { 191 | center = c; 192 | radius = rad; 193 | color = col; 194 | } 195 | 196 | 197 | __device__ virtual int intersect(float3 ray_pos, float3 ray_dir, float& t_min, float& t_max) const { 198 | 199 | float3 orig = ray_pos - center; 200 | 201 | float A = ray_dir.x * ray_dir.x + ray_dir.y * ray_dir.y + ray_dir.z * ray_dir.z; 202 | float B = 2 * (ray_dir.x * orig.x + ray_dir.y * orig.y + ray_dir.z * orig.z); 203 | float C = orig.x * orig.x + orig.y * orig.y + orig.z * orig.z - radius * radius; 204 | 205 | if (!find_discr(A, B, C, t_min, t_max)) return 0; 206 | 207 | if (t_min > t_max) { 208 | float tempt = t_max; 209 | t_max = t_min; 210 | t_min = tempt; 211 | } 212 | 213 | if (t_min < 0) { 214 | t_min = t_max; 215 | if (t_min < 0) return 0; 216 | } 217 | 218 | return 1; 219 | 220 | }; 221 | 222 | 223 | __device__ virtual bool scatter(float3& ray_pos, float3& ray_dir, float t_min, float3& normal, float3& atten, Rand_state rand_state) const { 224 | 225 | atten = color; 226 | 227 | return false; 228 | } 229 | 230 | 231 | float3 center; 232 | float radius; 233 | float3 color; 234 | 235 | }; 236 | 237 | class geometry_list { 238 | 239 | public: 240 | 241 | __device__ geometry_list() {}; 242 | __device__ geometry_list(sphere* l, int n) { list = l; list_size = n; }; 243 | 244 | __device__ int intersect(float3 ray_pos, float3 ray_dir, float& t_min, float& t_max) const { 245 | 246 | int idx = -1; 247 | float temp_tmin = FLT_MAX; 248 | for (int i = 0; i < list_size; i++) { 249 | 250 | if (list[i].intersect(ray_pos, ray_dir, t_min, t_max)) { 251 | 252 | if (t_min < temp_tmin) { 253 | temp_tmin = t_min; 254 | idx = i; 255 | } 256 | 257 | } 258 | 259 | } 260 | 261 | t_min = temp_tmin; 262 | 263 | return idx; 264 | 265 | } 266 | 267 | __device__ bool scatter(float3& ray_pos, float3& ray_dir, float t_min, float3& normal, float3& atten, Rand_state rand_state) const { 268 | 269 | float t_max; 270 | int idx = this->intersect(ray_pos, ray_dir, t_min, t_max); 271 | 272 | if (idx > -1) { 273 | 274 | list[idx].scatter(ray_pos, ray_dir, t_min, normal, atten, rand_state); 275 | return true; 276 | 277 | } 278 | 279 | return false; 280 | 281 | } 282 | 283 | sphere *list = NULL; 284 | int list_size = 0; 285 | 286 | }; 287 | 288 | 289 | 290 | #endif // !_GEOMETRY_H_ -------------------------------------------------------------------------------- /source/geometry/geometry_kernels.cu: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------- 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are met : 5 | // 6 | // *Redistributions of source code must retain the above copyright notice, this 7 | // list of conditions and the following disclaimer. 8 | // 9 | // * Redistributions in binary form must reproduce the above copyright notice, 10 | // this list of conditions and the following disclaimer in the documentation 11 | // and/or other materials provided with the distribution. 12 | // 13 | // * Neither the name of the copyright holder nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | // DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 21 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | // DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 | // OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // Copyright(c) 2019, Sergen Eren 29 | // All rights reserved. 30 | //---------------------------------------------------------------------------------- 31 | // 32 | // Version 1.0.1: Sergen Eren, 18/12/2019 33 | // 34 | // File: Geometry creation and processing kernels 35 | // 36 | //----------------------------------------------- 37 | 38 | #define DDA_STEP_TRUE 39 | 40 | #define _USE_MATH_DEFINES 41 | #include 42 | 43 | #include 44 | #include 45 | 46 | // Cuda includes 47 | #include 48 | #include 49 | #include 50 | #include "helper_math.h" 51 | 52 | typedef unsigned char uchar; 53 | typedef unsigned int uint; 54 | typedef unsigned short ushort; 55 | typedef unsigned long ulong; 56 | typedef unsigned long long uint64; 57 | 58 | // Internal includes 59 | #include "kernel_params.h" 60 | #include "atmosphere/definitions.h" 61 | #include "atmosphere/constants.h" 62 | #include "gpu_vdb.h" 63 | #include "camera.h" 64 | #include "light.h" 65 | #include "bvh/bvh.h" 66 | //#include "geometry/sphere.h" 67 | #include "geometry/geometry.h" 68 | 69 | #define BLACK make_float3(0.0f, 0.0f, 0.0f) 70 | #define WHITE make_float3(1.0f, 1.0f, 1.0f) 71 | #define RED make_float3(1.0f, 0.0f, 0.0f) 72 | #define GREEN make_float3(0.0f, 1.0f, 0.0f) 73 | #define BLUE make_float3(0.0f, 0.0f, 1.0f) 74 | #define EPS 0.001f 75 | 76 | #define INV_2_PI 1.0f / (2.0f * M_PI) 77 | #define INV_4_PI 1.0f / (4.0f * M_PI) 78 | #define INV_PI 1.0f / M_PI 79 | 80 | 81 | extern "C" __global__ void create_geometry_list(sphere **d_list, geometry_list **d_geo_list){ 82 | 83 | if (threadIdx.x == 0 && blockIdx.x == 0) { 84 | float3 center = make_float3(100, 320, -200); 85 | float radius = 100; 86 | 87 | d_list[0] = new sphere(center , radius, make_float3(0.18f), .001f); 88 | d_list[1] = new sphere(center+make_float3(0, 150 , 0) , radius, make_float3(0.18f), .001f); 89 | 90 | *d_geo_list = new geometry_list(*d_list, 2); 91 | 92 | } 93 | } 94 | 95 | // Test to see if geo_list is filled right 96 | extern "C" __global__ void test_geometry_list( 97 | const camera cam, 98 | const light_list lights, 99 | const GPU_VDB * gpu_vdb, 100 | const sphere & sphere, 101 | const geometry_list * *geo_list, 102 | BVHNode * root_node, 103 | OCTNode * oct_root, 104 | const AtmosphereParameters atmosphere, 105 | const Kernel_params kernel_params) { 106 | 107 | if (threadIdx.x == 0 && blockIdx.x == 0) { 108 | float t_min, t_max; 109 | if ((*geo_list)->intersect(make_float3(0, 320, -200), make_float3(1, 0, 0), t_min, t_max)) printf("geometry test OK...\n"); 110 | else printf("Error! geometry didn't create properly. \n"); 111 | } 112 | } -------------------------------------------------------------------------------- /source/geometry/plane.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------- 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are met : 5 | // 6 | // *Redistributions of source code must retain the above copyright notice, this 7 | // list of conditions and the following disclaimer. 8 | // 9 | // * Redistributions in binary form must reproduce the above copyright notice, 10 | // this list of conditions and the following disclaimer in the documentation 11 | // and/or other materials provided with the distribution. 12 | // 13 | // * Neither the name of the copyright holder nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | // DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 21 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | // DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 | // OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // Copyright(c) 2019, Sergen Eren 29 | // All rights reserved. 30 | //---------------------------------------------------------------------------------- 31 | // 32 | // Version 1.0: Sergen Eren, 08/12/2019 33 | // 34 | // File: 4 point plane with gpu intersection routine 35 | // 36 | //----------------------------------------------- 37 | 38 | #ifndef _PLANE_H_ 39 | #define _PLANE_H_ 40 | 41 | #include "cuda_runtime_api.h" 42 | #include "helper_math.h" 43 | 44 | 45 | struct triangle { 46 | 47 | __device__ __host__ triangle(float3 vtx0, float3 vtx1, float3 vtx2):v0(vtx0), v1(vtx1),v2(vtx2) {} 48 | __device__ __host__ triangle():v0(make_float3(0)), v1(make_float3(0,1,0)),v2(make_float3(1,0,0)) {} 49 | 50 | __device__ __host__ ~triangle(){} 51 | 52 | __device__ __host__ bool intersect(float3 ray_pos, float3 ray_dir , float &t) const{ 53 | 54 | float3 e1 = v1 - v0; 55 | float3 e2 = v2 - v0; 56 | 57 | float3 P = cross(ray_dir, e2); 58 | float det = dot(e1, P); 59 | 60 | // Not culling back-facing triangles 61 | if (det > -M_EPSILON && det < M_EPSILON) { 62 | return false; 63 | } 64 | 65 | float invDet = 1.0f / det; 66 | float3 T = ray_pos - v0; 67 | float u = dot(T, P)*invDet; 68 | 69 | if (u < 0.0f || u > 1.0f) { 70 | return false; 71 | } 72 | 73 | float3 Q = cross(T, e1); 74 | float v = dot(ray_dir, Q)*invDet; 75 | 76 | if (v < 0.0f || u + v > 1.0f) { 77 | return false; 78 | } 79 | 80 | float t0 = dot(e2, Q) * invDet; 81 | 82 | if (t0 > M_EPSILON && t0 < t) { 83 | t = t0; 84 | return true; 85 | } 86 | 87 | return true; 88 | 89 | 90 | } 91 | 92 | float3 v0; 93 | float3 v1; 94 | float3 v2; 95 | 96 | }; 97 | 98 | 99 | 100 | struct plane { 101 | 102 | __device__ __host__ plane(float3 p0, float3 p1, float3 p2, float3 p3) { 103 | 104 | tri1 = triangle(p0, p1, p2); 105 | tri2 = triangle(p0, p3, p2); 106 | 107 | } 108 | __device__ __host__ plane() { 109 | 110 | float3 p0 = make_float3(0, 0, 0); 111 | float3 p1 = make_float3(100, 0, 0); 112 | float3 p2 = make_float3(0, 100, 0); 113 | float3 p3 = make_float3(100, 100, 0); 114 | 115 | tri1 = triangle(p0, p1, p2); 116 | tri2 = triangle(p0, p3, p2); 117 | 118 | } 119 | 120 | __device__ __host__ ~plane(){} 121 | 122 | __device__ __host__ bool intersect(float3 ray_pos, float3 ray_dir, float &t) const{ 123 | 124 | if (tri1.intersect(ray_pos, ray_dir, t)) return true; 125 | if (tri2.intersect(ray_pos, ray_dir, t)) return true; 126 | 127 | return false; 128 | 129 | } 130 | 131 | triangle tri1; 132 | triangle tri2; 133 | 134 | }; 135 | 136 | 137 | #endif // !_PLANE_H_ 138 | -------------------------------------------------------------------------------- /source/geometry/sphere.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------- 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are met : 5 | // 6 | // *Redistributions of source code must retain the above copyright notice, this 7 | // list of conditions and the following disclaimer. 8 | // 9 | // * Redistributions in binary form must reproduce the above copyright notice, 10 | // this list of conditions and the following disclaimer in the documentation 11 | // and/or other materials provided with the distribution. 12 | // 13 | // * Neither the name of the copyright holder nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | // DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 21 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | // DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 | // OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // Copyright(c) 2019, Sergen Eren 29 | // All rights reserved. 30 | //---------------------------------------------------------------------------------- 31 | // 32 | // Version 1.0: Sergen Eren, 13/12/2019 33 | // 34 | // File: Sphere class with intersection routine 35 | // 36 | //----------------------------------------------- 37 | 38 | 39 | #ifndef _SPHERE_H_ 40 | #define _SPHERE_H_ 41 | 42 | 43 | #include "cuda_runtime_api.h" 44 | #include "helper_math.h" 45 | 46 | 47 | 48 | __device__ __host__ inline bool find_discr( 49 | float a, 50 | float b, 51 | float c, 52 | float& x1, 53 | float& x2) 54 | { 55 | if (b == 0) { 56 | // Handle special case where the the two vector ray.dir and V are perpendicular 57 | // with V = ray.orig - sphere.centre 58 | if (a == 0) return false; 59 | x1 = 0; x2 = sqrt(-c / a); 60 | return true; 61 | } 62 | 63 | float discr = b * b - 4 * a * c; 64 | 65 | if (discr < 0) return false; 66 | 67 | float q = (b < 0.f) ? -0.5f * (b - sqrt(discr)) : -0.5f * (b + sqrt(discr)); 68 | x1 = q / a; 69 | x2 = c / q; 70 | 71 | return true; 72 | } 73 | 74 | 75 | class sphere { 76 | public: 77 | 78 | __device__ __host__ sphere(){ 79 | center = make_float3(.0f); 80 | radius = 1.0f; 81 | color = make_float3(1.0f); 82 | roughness = .0f; 83 | } 84 | 85 | __device__ __host__ sphere(float3 c, float rad){ 86 | center = c; 87 | radius = rad; 88 | color = make_float3(1.0f); 89 | roughness = .0f; 90 | } 91 | 92 | __device__ __host__ ~sphere(){} 93 | 94 | __device__ __host__ bool intersect(float3 ray_pos, float3 ray_dir, float &t_min, float &t_max) const { 95 | 96 | float3 orig = ray_pos - center; 97 | 98 | float A = ray_dir.x * ray_dir.x + ray_dir.y * ray_dir.y + ray_dir.z * ray_dir.z; 99 | float B = 2 * (ray_dir.x * orig.x + ray_dir.y * orig.y + ray_dir.z * orig.z); 100 | float C = orig.x * orig.x + orig.y * orig.y + orig.z * orig.z - radius * radius; 101 | 102 | if (!find_discr(A, B, C, t_min, t_max)) return false; 103 | 104 | if (t_min > t_max) { 105 | float tempt = t_max; 106 | t_max = t_min; 107 | t_min = tempt; 108 | } 109 | 110 | if (t_min < 0) { 111 | t_min = t_max; 112 | if (t_min < 0) return false; 113 | } 114 | 115 | return true; 116 | 117 | } 118 | 119 | float3 center; 120 | float radius; 121 | float3 color; 122 | float roughness; 123 | }; 124 | 125 | 126 | 127 | 128 | #endif // !_SPHERE_H_ 129 | -------------------------------------------------------------------------------- /source/gpu_vdb/camera.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------- 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are met : 5 | // 6 | // *Redistributions of source code must retain the above copyright notice, this 7 | // list of conditions and the following disclaimer. 8 | // 9 | // * Redistributions in binary form must reproduce the above copyright notice, 10 | // this list of conditions and the following disclaimer in the documentation 11 | // and/or other materials provided with the distribution. 12 | // 13 | // * Neither the name of the copyright holder nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | // DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 21 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | // DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 | // OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // Copyright(c) 2019, Sergen Eren 29 | // All rights reserved. 30 | //---------------------------------------------------------------------------------- 31 | // 32 | // Version 1.0: Sergen Eren, 28/10/2019 33 | // 34 | // File: This is the header file for Camera class 35 | // 36 | //----------------------------------------------- 37 | 38 | #ifndef __CAMERA_H__ 39 | #define __CAMERA_H__ 40 | 41 | 42 | #include 43 | #include 44 | 45 | typedef curandStatePhilox4_32_10_t Rand_state; 46 | #define rand(state) curand_uniform(state) 47 | 48 | 49 | __device__ float vanDerCorput(Rand_state *local_rand_state, int base = 2) { 50 | 51 | int n = int(rand(local_rand_state) * 100); 52 | float rand_int = 0, denom = 1, invBase = 1.f / base; 53 | 54 | while (n) { 55 | 56 | denom *= base; 57 | rand_int += (n%base) / denom; 58 | n *= invBase; 59 | 60 | } 61 | return rand_int; 62 | } 63 | 64 | 65 | __device__ float3 random_in_unit_disk(Rand_state *local_rand_state) { 66 | 67 | float3 p; 68 | do { 69 | 70 | p = 2.0f * make_float3(vanDerCorput(local_rand_state), vanDerCorput(local_rand_state, 3), 0) - make_float3(1.0f, 1.0f, 0.0f); 71 | 72 | } while (dot(p, p) >= 1.0); 73 | return p; 74 | 75 | } 76 | 77 | class ray 78 | { 79 | public: 80 | __device__ ray() {}; 81 | __device__ ray(const float3& a, const float3& b, float ti = 0.0) { A = a; B = b; _time = ti; }; 82 | __device__ float3 origin() const { return A; } 83 | __device__ float3 direction() const { return B; } 84 | __device__ float time() const { return _time; } 85 | __device__ float3 point_at_parameter(float t) const { return A + t * B; } 86 | 87 | float3 A; 88 | float3 B; 89 | float _time; 90 | }; 91 | 92 | 93 | 94 | class camera 95 | { 96 | public: 97 | __host__ __device__ camera(): 98 | time0(.0f), time1(1.0f), 99 | origin(make_float3(.0f, .0f, .0f)), 100 | lower_left_corner(make_float3(.0f, .0f, .0f)), 101 | horizontal(make_float3(-1.0f, .0f, .0f)), 102 | vertical(make_float3(.0f, 1.0f, .0f)), 103 | u(make_float3(1.0f, .0f, .0f)), 104 | v(make_float3(.0f, 1.0f, .0f)), 105 | w(make_float3(.0f, .0f, 1.0f)), 106 | lens_radius(25.0f){} 107 | 108 | 109 | 110 | __host__ __device__ void update_camera(float3 lookfrom, float3 lookat, float3 vup, float vfov, float aspect, float aperture) { 111 | 112 | focus_dist = length(lookfrom - lookat); 113 | lens_radius = aperture / 2.0f; 114 | float theta = vfov * float(M_PI) / 180.0f; 115 | float half_height = tan(theta / 2.0f); 116 | float half_width = aspect * half_height; 117 | origin = lookfrom; 118 | 119 | w = normalize(lookfrom - lookat); 120 | u = normalize(cross(vup, w)); 121 | v = cross(w, u); 122 | 123 | lower_left_corner = origin - half_width * focus_dist*u - half_height * focus_dist*v - focus_dist * w; 124 | 125 | horizontal = 2.0f*half_width*focus_dist*u; 126 | 127 | vertical = 2.0f*half_height*focus_dist*v; 128 | 129 | } 130 | 131 | __device__ ray get_ray(float s, float t, Rand_state *local_rand_state) const{ 132 | float3 rd = lens_radius * random_in_unit_disk(local_rand_state); 133 | float3 offset = u * rd.x + v * rd.y; 134 | float time = time0 + curand_uniform(local_rand_state) * (time1 - time0); 135 | return ray(origin + offset, lower_left_corner + s * horizontal + t * vertical - origin - offset, time); 136 | } 137 | 138 | 139 | float time1, time0; 140 | float3 origin; 141 | float focus_dist; 142 | float3 lower_left_corner; 143 | float3 horizontal; 144 | float3 vertical; 145 | float3 u, v, w; 146 | float lens_radius; 147 | bool viz_dof; 148 | }; 149 | 150 | #endif -------------------------------------------------------------------------------- /source/gpu_vdb/gpu_vdb.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------- 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are met : 5 | // 6 | // *Redistributions of source code must retain the above copyright notice, this 7 | // list of conditions and the following disclaimer. 8 | // 9 | // * Redistributions in binary form must reproduce the above copyright notice, 10 | // this list of conditions and the following disclaimer in the documentation 11 | // and/or other materials provided with the distribution. 12 | // 13 | // * Neither the name of the copyright holder nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | // DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 21 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | // DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 | // OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // Copyright(c) 2019, Sergen Eren 29 | // All rights reserved. 30 | //---------------------------------------------------------------------------------- 31 | // 32 | // Version 1.0: Sergen Eren, 25/10/2019 33 | // 34 | // File: This is the header file for GPU_VDB that converts and loads 35 | // a vdb file to CUDA 3d texture and loads it into gpu 36 | // 37 | //----------------------------------------------- 38 | 39 | #ifndef _GPU_VDB_H_ 40 | #define _GPU_VDB_H_ 41 | 42 | #include "cuda.h" 43 | #include "cuda_runtime_api.h" 44 | 45 | #include "texture_types.h" 46 | #include "matrix_math.h" 47 | #include 48 | 49 | #include "helper_math.h" 50 | #include "bvh/AABB.h" 51 | 52 | #define ALIGN(x) __align__(x) 53 | 54 | #define NOHIT 1.0e10f 55 | 56 | 57 | // Transform matrix for gpu_vdb instance 58 | 59 | struct ALIGN(16) VDB_INFO { 60 | 61 | float voxelsize; 62 | int3 dim; 63 | float3 bmin; 64 | float3 bmax; 65 | float max_density; 66 | float min_density; 67 | 68 | bool has_color; 69 | bool has_emission; 70 | bool matte; 71 | 72 | cudaTextureObject_t density_texture; 73 | cudaTextureObject_t emission_texture; 74 | cudaTextureObject_t color_texture; 75 | 76 | }; 77 | 78 | 79 | class GPU_VDB { 80 | 81 | public: 82 | __host__ ~GPU_VDB(); 83 | __host__ GPU_VDB(); 84 | __host__ GPU_VDB(const GPU_VDB& copy); 85 | 86 | // Device functions 87 | __device__ float3 rayBoxIntersect(float3 ray_pos, float3 ray_dir) const { 88 | 89 | // World space to object space 90 | ray_pos = xform.transpose().inverse().transform_point(ray_pos); 91 | ray_dir = xform.transpose().inverse().transform_vector(ray_dir); 92 | 93 | float ht[8]; 94 | ht[0] = (vdb_info.bmin.x - ray_pos.x) / ray_dir.x; 95 | ht[1] = (vdb_info.bmax.x - ray_pos.x) / ray_dir.x; 96 | ht[2] = (vdb_info.bmin.y - ray_pos.y) / ray_dir.y; 97 | ht[3] = (vdb_info.bmax.y - ray_pos.y) / ray_dir.y; 98 | ht[4] = (vdb_info.bmin.z - ray_pos.z) / ray_dir.z; 99 | ht[5] = (vdb_info.bmax.z - ray_pos.z) / ray_dir.z; 100 | ht[6] = fmax(fmax(fmin(ht[0], ht[1]), fmin(ht[2], ht[3])), fmin(ht[4], ht[5])); 101 | ht[7] = fmin(fmin(fmax(ht[0], ht[1]), fmax(ht[2], ht[3])), fmax(ht[4], ht[5])); 102 | ht[6] = (ht[6] < 0) ? 0.0f : ht[6]; 103 | 104 | return make_float3(ht[6], ht[7], (ht[7] < ht[6] || ht[7] < 0) ? NOHIT : 0); 105 | 106 | } 107 | 108 | __device__ bool inVolumeBbox(float3 ray_pos) const { 109 | 110 | // World space to object space 111 | ray_pos = xform.transpose().inverse().transform_point(ray_pos); 112 | 113 | float3 min = vdb_info.bmin; 114 | float3 max = vdb_info.bmax; 115 | 116 | return ray_pos.x >= min.x && ray_pos.y >= min.y && ray_pos.z >= min.z && ray_pos.x < max.x && ray_pos.y < max.y && ray_pos.z < max.z; 117 | } 118 | 119 | // Host functions 120 | __host__ bool loadVDB(std::string file_name, std::string density_channel, std::string emission_channel="", std::string color_channel=""); 121 | 122 | __host__ VDB_INFO * get_vdb_info() ; 123 | 124 | __host__ GPU_VDB * clone(); 125 | 126 | // Host and device functions 127 | __host__ __device__ mat4 get_xform() const { return this->xform; } 128 | 129 | __host__ __device__ void set_xform(mat4 &matrix) { this->xform = matrix; } 130 | 131 | __host__ __device__ AABB Bounds() const { 132 | 133 | // OOB to AABB conversion from 134 | // https://zeux.io/2010/10/17/aabb-from-obb-with-component-wise-abs/ 135 | 136 | float3 center = (vdb_info.bmax + vdb_info.bmin) * 0.5; 137 | float3 extent = (vdb_info.bmax - vdb_info.bmin) * 0.5; 138 | 139 | float3 new_center = xform.transpose().transform_point(center); 140 | float3 new_extent = xform.abs().transpose().transform_vector(extent); 141 | 142 | AABB bounding_box(new_center - new_extent, new_center + new_extent); 143 | 144 | return bounding_box; 145 | 146 | } 147 | 148 | VDB_INFO vdb_info; 149 | 150 | private: 151 | 152 | mat4 xform; 153 | 154 | }; 155 | 156 | 157 | class GPU_PROC_VOL : public GPU_VDB { 158 | 159 | 160 | public: 161 | 162 | __host__ GPU_PROC_VOL(); 163 | __host__ GPU_PROC_VOL(const GPU_PROC_VOL& copy); 164 | __host__ ~GPU_PROC_VOL(); 165 | 166 | __host__ bool create_volume(float3 min, float3 max, float res, int noise_type, float scale); 167 | 168 | private: 169 | 170 | CUmodule texture_module; 171 | CUfunction fill_buffer_function; 172 | float *device_density_buffer; 173 | float resolution; 174 | int3 dimensions; 175 | }; 176 | 177 | 178 | #endif //endif _GPU_VDB_H_ -------------------------------------------------------------------------------- /source/hdr_loader.h: -------------------------------------------------------------------------------- 1 | // 2 | // utility code to load HDR image files in Radiance's RGBE-encoded ".hdr" file format 3 | // 4 | 5 | #include 6 | #include 7 | 8 | static const char *find_identifier(const char *line, const char *identifier) 9 | { 10 | const size_t l = strlen(identifier); 11 | for (size_t i = 0; i < l; ++i) 12 | if (line[i] != identifier[i]) 13 | return NULL; 14 | 15 | return &line[l]; 16 | } 17 | 18 | /* header information */ 19 | typedef struct { 20 | unsigned int rx, ry; /* resolution */ 21 | float gamma; 22 | float exposure; 23 | int xyz; /* color space is XYZ or RGB? */ 24 | char comment[128]; 25 | } hdr_image_header_t; 26 | 27 | /* error codes than can be reported */ 28 | typedef enum { 29 | HDR_SUCCESS = 0, 30 | HDR_ERROR_INVALID_HEADER = 1, 31 | HDR_ERROR_READING_HEADER = 2, 32 | HDR_ERROR_READING_PIXELS = 3, 33 | HDR_ERROR_ALLOCATION_FAILURE = 5, 34 | HDR_ERROR_WRITING_HEADER = 6, 35 | HDR_ERROR_WRITING_PIXELS = 7, 36 | HDR_ERROR_NUM_CODES = 9 37 | } hdr_error_code_t; 38 | 39 | 40 | static const char *s_rle_rgbe = "32-bit_rle_rgbe"; 41 | static const char *s_rle_xyze = "32-bit_rle_xyze"; 42 | 43 | static hdr_error_code_t hdr_read_image_header( 44 | hdr_image_header_t * const header, FILE * const fp) 45 | { 46 | rewind(fp); 47 | #define LINE_SIZE 2048 48 | char linebuf[LINE_SIZE]; 49 | 50 | const char *line = fgets(linebuf, LINE_SIZE, fp); 51 | if (!line) 52 | return HDR_ERROR_INVALID_HEADER; 53 | 54 | if (line[0] != '#' && line[1] != '?') 55 | return HDR_ERROR_INVALID_HEADER; 56 | 57 | memset(header, 0, sizeof(hdr_image_header_t)); 58 | header->gamma = 1.0f; 59 | header->exposure = 1.0f; 60 | 61 | while (1) { 62 | line = fgets(linebuf, LINE_SIZE, fp); 63 | 64 | if (line[0] == '#') 65 | continue; 66 | 67 | const char *c; 68 | if ((c = find_identifier(line, "EXPOSURE="))) 69 | { 70 | float f = 1.0f; 71 | if (sscanf_s(c, "%f", &f)) 72 | header->exposure = f; 73 | } 74 | else if ((c = find_identifier(line, "GAMMA="))) 75 | { 76 | float f = 1.0f; 77 | if (sscanf_s(c, "%f", &f)) 78 | header->gamma = f; 79 | } 80 | else if ((c = find_identifier(line, "FORMAT="))) 81 | { 82 | if (strncmp(c, s_rle_xyze, strlen(s_rle_xyze)) == 0) 83 | header->xyz = 1; 84 | else if (strncmp(c, s_rle_rgbe, strlen(s_rle_rgbe)) == 0) 85 | header->xyz = 0; 86 | else 87 | return HDR_ERROR_INVALID_HEADER; 88 | } 89 | else if (line[0] == '-' || line[0] == '+') 90 | { 91 | //!! extract flips, order? 92 | const char *x = strchr(line, 'X'); 93 | if (!x || (x <= line) || !sscanf_s(x + 1, "%u", &header->rx)) 94 | return HDR_ERROR_INVALID_HEADER; 95 | 96 | const char *y = strchr(line, 'Y'); 97 | if (!y || (y <= line) || !sscanf_s(y + 1, "%u", &header->ry)) 98 | return HDR_ERROR_INVALID_HEADER; 99 | 100 | break; 101 | } 102 | } 103 | 104 | return HDR_SUCCESS; 105 | } 106 | 107 | /* read unencoded scanline */ 108 | static hdr_error_code_t hdr_read_image_scanline( 109 | unsigned char *const rgbe_buf, 110 | const unsigned int len, 111 | FILE *const fp) 112 | { 113 | if (fread(rgbe_buf, 4, len, fp) != len) 114 | return HDR_ERROR_READING_PIXELS; 115 | 116 | return HDR_SUCCESS; 117 | } 118 | 119 | /* read run length encoded scanline */ 120 | static hdr_error_code_t hdr_read_image_scanline_rle( 121 | unsigned char *const rgbe_buf, 122 | const unsigned int len, 123 | FILE *const fp) 124 | { 125 | int c = fgetc(fp); 126 | if (c == EOF) 127 | return HDR_ERROR_READING_PIXELS; 128 | 129 | if (c != 2) /* not really rle? */ 130 | { 131 | ungetc(c, fp); 132 | return hdr_read_image_scanline(rgbe_buf, len, fp); 133 | } 134 | 135 | rgbe_buf[1] = fgetc(fp); /* green */ 136 | rgbe_buf[2] = fgetc(fp); /* blue */ 137 | c = fgetc(fp); 138 | 139 | if (rgbe_buf[1] != 2 || (rgbe_buf[2] & 128)) { /* not rle? */ 140 | rgbe_buf[0] = 2; 141 | rgbe_buf[3] = c; 142 | return hdr_read_image_scanline(rgbe_buf + 4, len - 1, fp); 143 | } 144 | 145 | const unsigned int l = rgbe_buf[2] << 8 | c; 146 | if (l != len) 147 | return HDR_ERROR_READING_PIXELS; 148 | 149 | for (unsigned int i = 0; i < 4; ++i) /* components */ 150 | { 151 | for (unsigned pos = 0; pos < len;) /* position in scanline */ 152 | { 153 | int num = fgetc(fp); 154 | if (num == EOF) 155 | return HDR_ERROR_READING_PIXELS; 156 | 157 | if (num > 128) /* run start? */ 158 | { 159 | num &= 127; 160 | const int val = fgetc(fp); 161 | if (val == EOF) 162 | return HDR_ERROR_READING_PIXELS; 163 | if (pos + num > len) 164 | return HDR_ERROR_READING_PIXELS; 165 | 166 | for (int j = 0; j < num; ++j) 167 | { 168 | rgbe_buf[pos * 4 + i] = val; 169 | ++pos; 170 | } 171 | } 172 | else /* non-run: read num chars */ 173 | { 174 | if (pos + num > len) 175 | return HDR_ERROR_READING_PIXELS; 176 | 177 | for (int j = 0; j < num; ++j) 178 | { 179 | const int val = fgetc(fp); 180 | if (val == EOF) 181 | return HDR_ERROR_READING_PIXELS; 182 | 183 | rgbe_buf[pos * 4 + i] = val; 184 | ++pos; 185 | } 186 | } 187 | } 188 | } 189 | return HDR_SUCCESS; 190 | } 191 | 192 | /* convert RGBE to floating point color */ 193 | static void hdr_rgbe_to_color( 194 | float rgb[3], 195 | const unsigned char *const rgbe) 196 | { 197 | if (rgbe[3] == 0) 198 | rgb[0] = rgb[1] = rgb[2] = 0.0f; 199 | else 200 | { 201 | union { 202 | float f; 203 | unsigned int i; 204 | } u; 205 | 206 | u.i = (((int)rgbe[3] - 9) << 23) & 0x7f800000; 207 | 208 | rgb[0] = (float)(rgbe[0] + 0.5f) * u.f; 209 | rgb[1] = (float)(rgbe[1] + 0.5f) * u.f; 210 | rgb[2] = (float)(rgbe[2] + 0.5f) * u.f; 211 | } 212 | } 213 | 214 | static hdr_error_code_t hdr_read_image_pixels_float( 215 | const hdr_image_header_t * const header, 216 | float * const pixels, 217 | FILE * const fp, 218 | const bool rgba) 219 | { 220 | /* small/large scanlines cannot be run-length encoded */ 221 | const int rle = !(header->rx < 8 || header->rx > 0x7fff); 222 | const unsigned int ncomp = rgba ? 4 : 3; 223 | 224 | unsigned char *rgbe_buf = (unsigned char *)malloc(header->rx * 4); 225 | 226 | for (unsigned int j = 0; j < header->ry; ++j) 227 | { 228 | hdr_error_code_t code; 229 | if (rle) 230 | code = hdr_read_image_scanline_rle(rgbe_buf, header->rx, fp); 231 | else 232 | code = hdr_read_image_scanline(rgbe_buf, header->rx, fp); 233 | if (code != HDR_SUCCESS) 234 | { 235 | free(rgbe_buf); 236 | return code; 237 | } 238 | 239 | for (unsigned int i = 0; i < header->rx; ++i) 240 | hdr_rgbe_to_color( 241 | pixels + ncomp * (j * header->rx + i), 242 | rgbe_buf + 4 * i); 243 | } 244 | free(rgbe_buf); 245 | 246 | return HDR_SUCCESS; 247 | } 248 | 249 | static bool load_hdr_float4(float **pixels, unsigned int *rx, unsigned int *ry, const char *filename) 250 | { 251 | *pixels = NULL; 252 | *rx = *ry = 0; 253 | FILE* fp = NULL; 254 | fopen_s(&fp, filename, "rb"); 255 | if (!fp) 256 | return false; 257 | 258 | hdr_image_header_t header; 259 | if (hdr_read_image_header(&header, fp) != HDR_SUCCESS) { 260 | fclose(fp); 261 | return false; 262 | } 263 | 264 | *pixels = (float *)calloc(header.rx * header.ry, sizeof(float) * 4); 265 | 266 | if (hdr_read_image_pixels_float(&header, *pixels, fp, true) != HDR_SUCCESS) { 267 | fclose(fp); 268 | free(*pixels); 269 | return false; 270 | } 271 | 272 | fclose(fp); 273 | *rx = header.rx; 274 | *ry = header.ry; 275 | 276 | return true; 277 | } 278 | 279 | -------------------------------------------------------------------------------- /source/kernel_params.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------- 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are met : 5 | // 6 | // *Redistributions of source code must retain the above copyright notice, this 7 | // list of conditions and the following disclaimer. 8 | // 9 | // * Redistributions in binary form must reproduce the above copyright notice, 10 | // this list of conditions and the following disclaimer in the documentation 11 | // and/or other materials provided with the distribution. 12 | // 13 | // * Neither the name of the copyright holder nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | // DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 21 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | // DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 | // OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // Copyright(c) 2019, Sergen Eren 29 | // All rights reserved. 30 | //---------------------------------------------------------------------------------- 31 | // 32 | // Version 1.0: Sergen Eren, 26/3/2019 33 | // 34 | // File: Custom path trace kernel header: 35 | // Performs custom path tracing 36 | // 37 | //----------------------------------------------- 38 | 39 | struct Kernel_params { 40 | 41 | //Debug 42 | bool render; 43 | bool debug; 44 | 45 | // Display 46 | uint2 resolution; 47 | float exposure_scale; 48 | unsigned int *display_buffer; 49 | float4 *raw_buffer; 50 | float3 *blue_noise_buffer; 51 | 52 | float3 *emission_texture; 53 | float emission_scale; 54 | float emission_pivot; 55 | 56 | float3 *density_color_texture; 57 | 58 | // Progressive rendering state 59 | unsigned int iteration; 60 | float3 *accum_buffer; 61 | float *depth_buffer; 62 | 63 | // Limit on path length 64 | unsigned int max_interactions; // Accumulation buffer count 65 | int ray_depth; // Max number of bounces 66 | int volume_depth; // Max number of volume bounces 67 | 68 | //Volume parameters ( No absorbtion coefficient) 69 | 70 | float min_extinction; // Extinction minorant (for residual ratio tracking) 71 | float phase_g1; // Phase function anisotropy (.0f means isotropic phase function) 72 | float phase_g2; // Phase function anisotropy for double lobe phase functions 73 | float phase_f; // Anistropy factor for double henyey_greeinstein 74 | 75 | float3 albedo; // sigma_s / sigma_t 76 | float3 extinction; // sigma_t 77 | float3 transmittance; // At which depth transmittance gets this value 78 | float tr_depth; // Multiply transmittance density factor (transmittance step size regulator) 79 | float density_mult; // Tracking density multiplier 80 | 81 | // Environment 82 | unsigned int environment_type; 83 | float azimuth; 84 | float elevation; 85 | float3 sun_color; 86 | float3 sky_color; 87 | float sun_mult; 88 | float sky_mult; 89 | double energy_inject; 90 | cudaTextureObject_t env_tex; 91 | 92 | // Procedural sky texture 93 | int env_sample_tex_res; 94 | cudaTextureObject_t sky_tex; 95 | cudaTextureObject_t env_func_tex; 96 | cudaTextureObject_t env_cdf_tex; 97 | cudaTextureObject_t env_marginal_func_tex; 98 | cudaTextureObject_t env_marginal_cdf_tex; 99 | float env_marginal_int; 100 | 101 | // Debug parameters 102 | 103 | float3 *debug_buffer; 104 | float3 *cost_buffer; 105 | // Integrators 106 | 107 | int integrator; 108 | 109 | }; 110 | -------------------------------------------------------------------------------- /source/light.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------- 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are met : 5 | // 6 | // *Redistributions of source code must retain the above copyright notice, this 7 | // list of conditions and the following disclaimer. 8 | // 9 | // * Redistributions in binary form must reproduce the above copyright notice, 10 | // this list of conditions and the following disclaimer in the documentation 11 | // and/or other materials provided with the distribution. 12 | // 13 | // * Neither the name of the copyright holder nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | // DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 21 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | // DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 | // OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // Copyright(c) 2019, Sergen Eren 29 | // All rights reserved. 30 | //---------------------------------------------------------------------------------- 31 | // 32 | // Version 1.0: Sergen Eren, 25/10/2019 33 | // 34 | // File: This is the header file for GPU_VDB that converts and loads 35 | // a vdb file to CUDA 3d texture and loads it into gpu 36 | // 37 | //----------------------------------------------- 38 | 39 | 40 | 41 | #ifndef __LIGHT_H__ 42 | #define __LIGHT_H__ 43 | 44 | 45 | #include 46 | #include 47 | #define _USE_MATH_DEFINES 48 | #include 49 | 50 | 51 | typedef curandStatePhilox4_32_10_t Rand_state; 52 | #define rand(state) curand_uniform(state) 53 | 54 | 55 | __device__ inline float henyey_greenstein( 56 | float cos_theta, 57 | float g) 58 | { 59 | 60 | float denominator = 1 + g * g - 2 * g * cos_theta; 61 | 62 | return M_PI_4 * (1 - g * g) / (denominator * sqrtf(denominator)); 63 | 64 | } 65 | __device__ inline float power_heuristic(int nf, float fPdf, int ng, float gPdf) 66 | { 67 | float f = nf * fPdf, g = ng * gPdf; 68 | return (f*f) / (f*f + g * g); 69 | } 70 | 71 | class light { 72 | 73 | public: 74 | __host__ __device__ light():pos(make_float3(.0f)), dir(make_float3(.0f)), power(1.0f), color(make_float3(1.0f)) {} 75 | __host__ __device__ ~light() {}; 76 | __host__ __device__ virtual int get_type() const=0; 77 | 78 | float3 pos; 79 | float3 dir; 80 | float power; 81 | float3 color; 82 | 83 | enum light_type { 84 | __INIT__ = 0, 85 | POINT_LIGHT = 1, 86 | AREA_LIGHT = 2 87 | }; 88 | 89 | }; 90 | 91 | 92 | 93 | class point_light : public light { 94 | 95 | public: 96 | 97 | __host__ __device__ point_light(){} 98 | __host__ __device__ point_light(float3 p, float3 cl, float pow) { 99 | pos = p; 100 | color = cl; 101 | power = pow; 102 | } 103 | 104 | __device__ float3 Le(Rand_state &randstate, float3 ray_pos, float3 ray_dir, float phase_g1, float3 tr, float max_density, float density_mult, float tr_depth) const { 105 | 106 | float3 Ld = make_float3(.0f); 107 | float3 wi; 108 | float phase_pdf = .0f; 109 | float eq_pdf = .0f; 110 | 111 | 112 | // Sample point light with phase pdf 113 | wi = normalize(pos - ray_pos); 114 | float cos_theta = dot(ray_dir, wi); 115 | phase_pdf = henyey_greenstein(cos_theta, phase_g1); 116 | float sqr_dist = length(pos * pos - ray_pos * ray_pos); 117 | float falloff = 1 / sqr_dist; 118 | 119 | float3 Li = color * power * tr * phase_pdf * falloff; 120 | 121 | return Li; 122 | 123 | // Sample point light with equiangular pdf 124 | 125 | float delta = dot(pos - ray_pos, ray_dir); 126 | float D = length(ray_pos + ray_dir * delta - pos); 127 | 128 | float inv_max_density = 1.0f / max_density; 129 | float inv_density_mult = 1.0f / density_mult; 130 | 131 | float max_t = .0f; 132 | max_t -= logf(1 - rand(&randstate)) * inv_max_density * inv_density_mult * tr_depth; 133 | 134 | float thetaA = atan2f(.0f - delta, D); 135 | float thetaB = atan2f(max_t - delta, D); 136 | 137 | float t = D * tanf(lerp(thetaA, thetaB, rand(&randstate))); 138 | 139 | eq_pdf = D / ((thetaB - thetaA) * (D*D + t * t)); 140 | float3 Leq = color * power * tr * eq_pdf * falloff; 141 | 142 | float weight = power_heuristic(1, phase_pdf, 1, eq_pdf); 143 | 144 | Ld = (Li + Leq) * weight; 145 | 146 | return Ld; 147 | 148 | } 149 | 150 | __host__ __device__ int get_type() const { return POINT_LIGHT; } 151 | 152 | }; 153 | 154 | 155 | 156 | class light_list { 157 | 158 | public: 159 | __host__ __device__ light_list(unsigned int n_l){ 160 | num_lights = n_l; 161 | } 162 | __host__ __device__ ~light_list() {} 163 | 164 | unsigned int num_lights; 165 | point_light *light_ptr; 166 | 167 | }; 168 | 169 | 170 | 171 | 172 | #endif -------------------------------------------------------------------------------- /source/texture_kernels.cu: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------- 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are met : 5 | // 6 | // *Redistributions of source code must retain the above copyright notice, this 7 | // list of conditions and the following disclaimer. 8 | // 9 | // * Redistributions in binary form must reproduce the above copyright notice, 10 | // this list of conditions and the following disclaimer in the documentation 11 | // and/or other materials provided with the distribution. 12 | // 13 | // * Neither the name of the copyright holder nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | // DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 21 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | // DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 | // OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // Copyright(c) 2019, Sergen Eren 29 | // All rights reserved. 30 | //---------------------------------------------------------------------------------- 31 | // 32 | // Version 1.0: Sergen Eren, 02/11/2019 33 | // 34 | // File: Kernels to calculate and load the procedural sky value and cdf textures 35 | // 36 | //----------------------------------------------- 37 | 38 | #define _USE_MATH_DEFINES 39 | #include 40 | #include 41 | #include 42 | 43 | // Cuda includes 44 | #include 45 | #include 46 | #include 47 | #include "helper_math.h" 48 | 49 | 50 | // Internal includes 51 | #include "kernel_params.h" 52 | #include "cuda_noise.cuh" 53 | 54 | #define INV_2_PI 1.0f / (2.0f * M_PI) 55 | #define INV_4_PI 1.0f / (4.0f * M_PI) 56 | #define INV_PI 1.0f / M_PI 57 | 58 | 59 | typedef curandStatePhilox4_32_10_t Rand_state; 60 | #define rand(state) curand_uniform(state) 61 | 62 | 63 | 64 | extern "C" __global__ void glow(const Kernel_params kernel_params, float treshold , const int width, const int height) { 65 | 66 | int x = blockIdx.x * blockDim.x + threadIdx.x; 67 | int y = blockIdx.y * blockDim.y + threadIdx.y; 68 | if (x >= width || y >= height) return; 69 | const unsigned int idx = y * width + x; 70 | 71 | // TODO gaussian blur and add glow effect to display buffer 72 | 73 | 74 | } 75 | 76 | extern "C" __global__ void fill_volume_buffer( float *buffer, const int3 dims, const float scale, const int noise_type) { 77 | 78 | int x = blockIdx.x * blockDim.x + threadIdx.x; 79 | int y = blockIdx.y * blockDim.y + threadIdx.y; 80 | int z = blockIdx.z * blockDim.z + threadIdx.z; 81 | 82 | if (x >= dims.x || y >= dims.y || z >= dims.z) return; 83 | 84 | const unsigned int idx = x + dims.x * (y + dims.y * z); 85 | 86 | Rand_state rand_state; 87 | 88 | int seed = 123; 89 | float du = 1.0f / (float)dims.x; 90 | 91 | float dx = cudaNoise::randomFloat(482 + floor(rand(&rand_state) * 2) * 47 + seed) / (float)dims.x; 92 | float dy = cudaNoise::randomFloat(472 + floor(rand(&rand_state) * 2) * 38 + seed) / (float)dims.y; 93 | float dz = cudaNoise::randomFloat(348 + floor(rand(&rand_state) * 2) * 14 + seed) / (float)dims.z; 94 | 95 | float3 pos = make_float3(x+dx, y+dy, z+dz); 96 | 97 | switch (noise_type) 98 | { 99 | case(0): 100 | buffer[idx] = cudaNoise::perlinNoise(pos, scale, seed); 101 | break; 102 | case(1): 103 | buffer[idx] = cudaNoise::simplexNoise(pos, scale, seed); 104 | break; 105 | case(2): 106 | buffer[idx] = cudaNoise::worleyNoise(pos, scale, seed, 300.1f, 4, 4, 1.0f); 107 | break; 108 | case(3): 109 | buffer[idx] = cudaNoise::repeaterPerlin(pos, scale, seed, 128, 1.9f, 0.5f); 110 | break; 111 | case(4): 112 | buffer[idx] = cudaNoise::repeaterPerlinAbs(pos, scale, seed, 128, 1.9f, 0.5f); 113 | break; 114 | case(5): 115 | buffer[idx] = cudaNoise::fractalSimplex(pos, scale, seed, du, 512, 1.5f, 0.95f); 116 | break; 117 | case(6): 118 | buffer[idx] = cudaNoise::repeaterTurbulence(pos, 0.2f, scale, seed, 0.8f, 32, cudaNoise::BASIS_PERLIN, cudaNoise::BASIS_PERLIN); 119 | break; 120 | case(7): 121 | buffer[idx] = cudaNoise::cubicValue(pos, scale, seed); 122 | break; 123 | case(8): 124 | buffer[idx] = cudaNoise::spots(pos, scale, seed, 0.1f, 0, 8, 1.0f, cudaNoise::SHAPE_STEP); 125 | break; 126 | } 127 | 128 | } -------------------------------------------------------------------------------- /source/util/fileIO.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------- 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are met : 5 | // 6 | // *Redistributions of source code must retain the above copyright notice, this 7 | // list of conditions and the following disclaimer. 8 | // 9 | // * Redistributions in binary form must reproduce the above copyright notice, 10 | // this list of conditions and the following disclaimer in the documentation 11 | // and/or other materials provided with the distribution. 12 | // 13 | // * Neither the name of the copyright holder nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | // DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 21 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | // DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 | // OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // Copyright(c) 2019, Sergen Eren 29 | // All rights reserved. 30 | //---------------------------------------------------------------------------------- 31 | // 32 | // Version 1.0: Sergen Eren, 15/12/2019 33 | // 34 | // File: This is the header file for fileIO operations. 35 | // these functions load and save several types of files with cuda buffers. 36 | // 37 | //----------------------------------------------- 38 | 39 | 40 | #ifndef _FILEIO_H_ 41 | #define _FILEIO_H_ 42 | 43 | #include 44 | #include "texture_types.h" 45 | #include 46 | #include 47 | 48 | // Saves a jpg with given float3 buffer 49 | bool save_texture_jpg(float3 *buffer, std::string filename, const int width, const int height); 50 | 51 | // Saves a jpg with given float4 buffer ignores w component 52 | bool save_texture_jpg(float4 *buffer, std::string filename, const int width, const int height); 53 | 54 | // Saves a png with given float3 buffer ignores alpha 55 | bool save_texture_png(float3 *buffer, std::string filename, const int width, const int height); 56 | 57 | // Saves a png with given float4 buffer 58 | bool save_texture_png(float4 *buffer, std::string filename, const int width, const int height); 59 | 60 | // Saves a tga with given float3 buffer ignores alpha 61 | bool save_texture_tga(float3 *buffer, std::string filename, const int width, const int height); 62 | 63 | // Saves a tga with given float4 buffer 64 | bool save_texture_tga(float4 *buffer, std::string filename, const int width, const int height); 65 | 66 | // Saves an exr with given float3 buffer 67 | bool save_texture_exr(float3 *buffer, std::string filename, const int width, const int height, bool flip); 68 | 69 | // Saves an exr with given float4 buffer 70 | bool save_texture_exr(float4 *buffer, std::string filename, const int width, const int height, bool flip); 71 | 72 | // Saves an exr with given float3 buffer and Z depth 73 | bool save_texture_exr(float3 *buffer, float *depth, std::string filename, const int width, const int height, bool flip); 74 | 75 | // Saves an exr with given float4 buffer and Z depth 76 | bool save_texture_exr(float4 *buffer, float *depth, std::string filename, const int width, const int height, bool flip); 77 | 78 | // Loads an exr to a float3 buffer 79 | bool load_texture_exr(float3 **buffer, std::string filename, int &width, int &height, bool flip); 80 | 81 | // Loads an exr to a float4 buffer 82 | bool load_texture_exr(float4 **buffer, std::string filename, int &width, int &height, bool flip); 83 | 84 | // Loads an exr to a float3 buffer and sends it to gpu 85 | bool load_texture_exr_gpu(float3 **buffer, std::string filename, int &width, int &height, bool flip); 86 | 87 | // Loads an exr to a float4 buffer and sends it to gpu 88 | bool load_texture_exr_gpu(float4 **buffer, std::string filename, int &width, int &height, bool flip); 89 | 90 | // Loads an bmp to a float3 buffer 91 | bool load_texture_bmp(float3 **buffer, std::string filename, int &width, int &height, bool flip); 92 | 93 | // Loads an bmp to a float3 buffer and sends it to gpu 94 | bool load_texture_bmp_gpu(float3 **buffer, std::string filename, int &width, int &height, bool flip); 95 | 96 | #endif // !_FILEIO_H_ 97 | -------------------------------------------------------------------------------- /source/util/logger.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "logger.h" 3 | 4 | void log(const char * message, unsigned int level) 5 | { 6 | 7 | if (level == 0) { 8 | fprintf(stderr, "Error! %s\n", message); 9 | } 10 | if (level == 1) { 11 | #if defined(LOG_LEVEL_WARNING) || defined(LOG_LEVEL_LOG) 12 | printf("Warning: %s\n", message); 13 | #endif 14 | } 15 | if (level == 2) { 16 | #if defined(LOG_LEVEL_LOG) 17 | printf("%s\n", message); 18 | #endif 19 | } 20 | 21 | } 22 | 23 | void log(std::string message, unsigned int level) 24 | { 25 | 26 | if (level == VPT_ERROR) { 27 | fprintf(stderr, "Error! %s\n", message.c_str()); 28 | } 29 | if (level == VPT_WARNING) { 30 | #if defined(LOG_LEVEL_WARNING) || defined(LOG_LEVEL_LOG) 31 | printf("Warning: %s\n", message.c_str()); 32 | #endif 33 | } 34 | if (level == VPT_LOG) { 35 | #if defined(LOG_LEVEL_LOG) 36 | printf("%s\n", message.c_str()); 37 | #endif 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /source/util/logger.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------- 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are met : 5 | // 6 | // *Redistributions of source code must retain the above copyright notice, this 7 | // list of conditions and the following disclaimer. 8 | // 9 | // * Redistributions in binary form must reproduce the above copyright notice, 10 | // this list of conditions and the following disclaimer in the documentation 11 | // and/or other materials provided with the distribution. 12 | // 13 | // * Neither the name of the copyright holder nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | // DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 21 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | // DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 | // OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // Copyright(c) 2019, Sergen Eren 29 | // All rights reserved. 30 | //---------------------------------------------------------------------------------- 31 | // 32 | // Version 1.0: Sergen Eren, 16/12/2019 33 | // 34 | // File: Log file writer for VPT 35 | // 36 | //----------------------------------------------- 37 | 38 | 39 | #ifndef _LOGGER_H_ 40 | #define _LOGGER_H_ 41 | 42 | #include 43 | 44 | enum LogLevel{ 45 | VPT_ERROR = 0, 46 | VPT_WARNING = 1, 47 | VPT_LOG = 2 48 | }; 49 | 50 | 51 | void log(const char* message, unsigned int level); 52 | void log(std::string message, unsigned int level); 53 | 54 | 55 | 56 | #endif // !_LOGGER_H_ 57 | -------------------------------------------------------------------------------- /thirdparty/OpenImageDenoise/bin/OpenImageDenoise.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergeneren/Volumetric-Path-Tracer/8708189867bebab06d75d1894746c4927e5800ec/thirdparty/OpenImageDenoise/bin/OpenImageDenoise.dll -------------------------------------------------------------------------------- /thirdparty/OpenImageDenoise/bin/OpenImageDenoise_core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergeneren/Volumetric-Path-Tracer/8708189867bebab06d75d1894746c4927e5800ec/thirdparty/OpenImageDenoise/bin/OpenImageDenoise_core.dll -------------------------------------------------------------------------------- /thirdparty/OpenImageDenoise/bin/OpenImageDenoise_device_cpu.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergeneren/Volumetric-Path-Tracer/8708189867bebab06d75d1894746c4927e5800ec/thirdparty/OpenImageDenoise/bin/OpenImageDenoise_device_cpu.dll -------------------------------------------------------------------------------- /thirdparty/OpenImageDenoise/bin/OpenImageDenoise_device_cuda.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergeneren/Volumetric-Path-Tracer/8708189867bebab06d75d1894746c4927e5800ec/thirdparty/OpenImageDenoise/bin/OpenImageDenoise_device_cuda.dll -------------------------------------------------------------------------------- /thirdparty/OpenImageDenoise/include/OpenImageDenoise/config.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Intel Corporation 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | #pragma once 5 | 6 | #define OIDN_VERSION_MAJOR 2 7 | #define OIDN_VERSION_MINOR 1 8 | #define OIDN_VERSION_PATCH 0 9 | #define OIDN_VERSION 20100 10 | #define OIDN_VERSION_STRING "2.1.0" 11 | 12 | /* #undef OIDN_API_NAMESPACE */ 13 | /* #undef OIDN_STATIC_LIB */ 14 | 15 | #if defined(OIDN_API_NAMESPACE) 16 | #define OIDN_API_NAMESPACE_BEGIN namespace { 17 | #define OIDN_API_NAMESPACE_END } 18 | #define OIDN_API_NAMESPACE_USING using namespace ; 19 | #define OIDN_API_EXTERN_C 20 | #define OIDN_NAMESPACE ::oidn 21 | #define OIDN_NAMESPACE_C _oidn 22 | #define OIDN_NAMESPACE_BEGIN namespace { namespace oidn { 23 | #define OIDN_NAMESPACE_END }} 24 | #else 25 | #define OIDN_API_NAMESPACE_BEGIN 26 | #define OIDN_API_NAMESPACE_END 27 | #define OIDN_API_NAMESPACE_USING 28 | #if defined(__cplusplus) 29 | #define OIDN_API_EXTERN_C extern "C" 30 | #else 31 | #define OIDN_API_EXTERN_C 32 | #endif 33 | #define OIDN_NAMESPACE oidn 34 | #define OIDN_NAMESPACE_C oidn 35 | #define OIDN_NAMESPACE_BEGIN namespace oidn { 36 | #define OIDN_NAMESPACE_END } 37 | #endif 38 | 39 | #define OIDN_NAMESPACE_USING using namespace OIDN_NAMESPACE; 40 | 41 | #if defined(OIDN_STATIC_LIB) 42 | #define OIDN_API_IMPORT OIDN_API_EXTERN_C 43 | #define OIDN_API_EXPORT OIDN_API_EXTERN_C 44 | #elif defined(_WIN32) 45 | #define OIDN_API_IMPORT OIDN_API_EXTERN_C __declspec(dllimport) 46 | #define OIDN_API_EXPORT OIDN_API_EXTERN_C __declspec(dllexport) 47 | #else 48 | #define OIDN_API_IMPORT OIDN_API_EXTERN_C 49 | #define OIDN_API_EXPORT OIDN_API_EXTERN_C __attribute__((visibility ("default"))) 50 | #endif 51 | 52 | #if defined(OpenImageDenoise_EXPORTS) 53 | #define OIDN_API OIDN_API_EXPORT 54 | #else 55 | #define OIDN_API OIDN_API_IMPORT 56 | #endif 57 | 58 | #if defined(_WIN32) 59 | #define OIDN_DEPRECATED(msg) __declspec(deprecated(msg)) 60 | #else 61 | #define OIDN_DEPRECATED(msg) __attribute__((deprecated(msg))) 62 | #endif 63 | 64 | #if !defined(OIDN_DEVICE_CPU) 65 | #define OIDN_DEVICE_CPU 66 | #endif 67 | #if !defined(OIDN_DEVICE_SYCL) 68 | /* #undef OIDN_DEVICE_SYCL */ 69 | #endif 70 | #if !defined(OIDN_DEVICE_CUDA) 71 | #define OIDN_DEVICE_CUDA 72 | #endif 73 | #if !defined(OIDN_DEVICE_HIP) 74 | /* #undef OIDN_DEVICE_HIP */ 75 | #endif 76 | 77 | #define OIDN_FILTER_RT 78 | #define OIDN_FILTER_RTLIGHTMAP 79 | -------------------------------------------------------------------------------- /thirdparty/OpenImageDenoise/lib/OpenImageDenoise.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergeneren/Volumetric-Path-Tracer/8708189867bebab06d75d1894746c4927e5800ec/thirdparty/OpenImageDenoise/lib/OpenImageDenoise.lib -------------------------------------------------------------------------------- /thirdparty/OpenImageDenoise/lib/OpenImageDenoise_core.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergeneren/Volumetric-Path-Tracer/8708189867bebab06d75d1894746c4927e5800ec/thirdparty/OpenImageDenoise/lib/OpenImageDenoise_core.lib -------------------------------------------------------------------------------- /thirdparty/OpenImageDenoise/lib/cmake/OpenImageDenoise-2.1.0/OpenImageDenoiseConfig.cmake: -------------------------------------------------------------------------------- 1 | ## Copyright 2023 Intel Corporation 2 | ## SPDX-License-Identifier: Apache-2.0 3 | 4 | 5 | ####### Expanded from @PACKAGE_INIT@ by configure_package_config_file() ####### 6 | ####### Any changes to this file will be overwritten by the next CMake run #### 7 | ####### The input file was Config.cmake.in ######## 8 | 9 | get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE) 10 | 11 | macro(set_and_check _var _file) 12 | set(${_var} "${_file}") 13 | if(NOT EXISTS "${_file}") 14 | message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !") 15 | endif() 16 | endmacro() 17 | 18 | macro(check_required_components _NAME) 19 | foreach(comp ${${_NAME}_FIND_COMPONENTS}) 20 | if(NOT ${_NAME}_${comp}_FOUND) 21 | if(${_NAME}_FIND_REQUIRED_${comp}) 22 | set(${_NAME}_FOUND FALSE) 23 | endif() 24 | endif() 25 | endforeach() 26 | endmacro() 27 | 28 | #################################################################################### 29 | 30 | set(OIDN_DEVICE_CPU ON) 31 | set(OIDN_DEVICE_SYCL OFF) 32 | set(OIDN_DEVICE_CUDA ON) 33 | set(OIDN_DEVICE_HIP OFF) 34 | 35 | set(OIDN_FILTER_RT ON) 36 | set(OIDN_FILTER_RTLIGHTMAP ON) 37 | 38 | set(OIDN_STATIC_LIB OFF) 39 | 40 | if(OIDN_STATIC_LIB AND OIDN_DEVICE_CPU) 41 | include(CMakeFindDependencyMacro) 42 | find_dependency(TBB) 43 | endif() 44 | 45 | include("${CMAKE_CURRENT_LIST_DIR}/OpenImageDenoiseTargets.cmake") 46 | 47 | check_required_components(OpenImageDenoise) 48 | -------------------------------------------------------------------------------- /thirdparty/OpenImageDenoise/lib/cmake/OpenImageDenoise-2.1.0/OpenImageDenoiseConfigVersion.cmake: -------------------------------------------------------------------------------- 1 | # This is a basic version file for the Config-mode of find_package(). 2 | # It is used by write_basic_package_version_file() as input file for configure_file() 3 | # to create a version-file which can be installed along a config.cmake file. 4 | # 5 | # The created file sets PACKAGE_VERSION_EXACT if the current version string and 6 | # the requested version string are exactly the same and it sets 7 | # PACKAGE_VERSION_COMPATIBLE if the current version is >= requested version, 8 | # but only if the requested major version is the same as the current one. 9 | # The variable CVF_VERSION must be set before calling configure_file(). 10 | 11 | 12 | set(PACKAGE_VERSION "2.1.0") 13 | 14 | if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION) 15 | set(PACKAGE_VERSION_COMPATIBLE FALSE) 16 | else() 17 | 18 | if("2.1.0" MATCHES "^([0-9]+)\\.") 19 | set(CVF_VERSION_MAJOR "${CMAKE_MATCH_1}") 20 | if(NOT CVF_VERSION_MAJOR VERSION_EQUAL 0) 21 | string(REGEX REPLACE "^0+" "" CVF_VERSION_MAJOR "${CVF_VERSION_MAJOR}") 22 | endif() 23 | else() 24 | set(CVF_VERSION_MAJOR "2.1.0") 25 | endif() 26 | 27 | if(PACKAGE_FIND_VERSION_RANGE) 28 | # both endpoints of the range must have the expected major version 29 | math (EXPR CVF_VERSION_MAJOR_NEXT "${CVF_VERSION_MAJOR} + 1") 30 | if (NOT PACKAGE_FIND_VERSION_MIN_MAJOR STREQUAL CVF_VERSION_MAJOR 31 | OR ((PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "INCLUDE" AND NOT PACKAGE_FIND_VERSION_MAX_MAJOR STREQUAL CVF_VERSION_MAJOR) 32 | OR (PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "EXCLUDE" AND NOT PACKAGE_FIND_VERSION_MAX VERSION_LESS_EQUAL CVF_VERSION_MAJOR_NEXT))) 33 | set(PACKAGE_VERSION_COMPATIBLE FALSE) 34 | elseif(PACKAGE_FIND_VERSION_MIN_MAJOR STREQUAL CVF_VERSION_MAJOR 35 | AND ((PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "INCLUDE" AND PACKAGE_VERSION VERSION_LESS_EQUAL PACKAGE_FIND_VERSION_MAX) 36 | OR (PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "EXCLUDE" AND PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION_MAX))) 37 | set(PACKAGE_VERSION_COMPATIBLE TRUE) 38 | else() 39 | set(PACKAGE_VERSION_COMPATIBLE FALSE) 40 | endif() 41 | else() 42 | if(PACKAGE_FIND_VERSION_MAJOR STREQUAL CVF_VERSION_MAJOR) 43 | set(PACKAGE_VERSION_COMPATIBLE TRUE) 44 | else() 45 | set(PACKAGE_VERSION_COMPATIBLE FALSE) 46 | endif() 47 | 48 | if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION) 49 | set(PACKAGE_VERSION_EXACT TRUE) 50 | endif() 51 | endif() 52 | endif() 53 | 54 | 55 | # if the installed or the using project don't have CMAKE_SIZEOF_VOID_P set, ignore it: 56 | if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "" OR "8" STREQUAL "") 57 | return() 58 | endif() 59 | 60 | # check that the installed version has the same 32/64bit-ness as the one which is currently searching: 61 | if(NOT CMAKE_SIZEOF_VOID_P STREQUAL "8") 62 | math(EXPR installedBits "8 * 8") 63 | set(PACKAGE_VERSION "${PACKAGE_VERSION} (${installedBits}bit)") 64 | set(PACKAGE_VERSION_UNSUITABLE TRUE) 65 | endif() 66 | -------------------------------------------------------------------------------- /thirdparty/OpenImageDenoise/lib/cmake/OpenImageDenoise-2.1.0/OpenImageDenoiseTargets-release.cmake: -------------------------------------------------------------------------------- 1 | #---------------------------------------------------------------- 2 | # Generated CMake target import file for configuration "Release". 3 | #---------------------------------------------------------------- 4 | 5 | # Commands may need to know the format version. 6 | set(CMAKE_IMPORT_FILE_VERSION 1) 7 | 8 | # Import target "OpenImageDenoise_core" for configuration "Release" 9 | set_property(TARGET OpenImageDenoise_core APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE) 10 | set_target_properties(OpenImageDenoise_core PROPERTIES 11 | IMPORTED_IMPLIB_RELEASE "${_IMPORT_PREFIX}/lib/OpenImageDenoise_core.lib" 12 | IMPORTED_LOCATION_RELEASE "${_IMPORT_PREFIX}/bin/OpenImageDenoise_core.dll" 13 | ) 14 | 15 | list(APPEND _cmake_import_check_targets OpenImageDenoise_core ) 16 | list(APPEND _cmake_import_check_files_for_OpenImageDenoise_core "${_IMPORT_PREFIX}/lib/OpenImageDenoise_core.lib" "${_IMPORT_PREFIX}/bin/OpenImageDenoise_core.dll" ) 17 | 18 | # Import target "OpenImageDenoise" for configuration "Release" 19 | set_property(TARGET OpenImageDenoise APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE) 20 | set_target_properties(OpenImageDenoise PROPERTIES 21 | IMPORTED_IMPLIB_RELEASE "${_IMPORT_PREFIX}/lib/OpenImageDenoise.lib" 22 | IMPORTED_LINK_DEPENDENT_LIBRARIES_RELEASE "OpenImageDenoise_core" 23 | IMPORTED_LOCATION_RELEASE "${_IMPORT_PREFIX}/bin/OpenImageDenoise.dll" 24 | ) 25 | 26 | list(APPEND _cmake_import_check_targets OpenImageDenoise ) 27 | list(APPEND _cmake_import_check_files_for_OpenImageDenoise "${_IMPORT_PREFIX}/lib/OpenImageDenoise.lib" "${_IMPORT_PREFIX}/bin/OpenImageDenoise.dll" ) 28 | 29 | # Commands beyond this point should not need to know the version. 30 | set(CMAKE_IMPORT_FILE_VERSION) 31 | -------------------------------------------------------------------------------- /thirdparty/OpenImageDenoise/lib/cmake/OpenImageDenoise-2.1.0/OpenImageDenoiseTargets.cmake: -------------------------------------------------------------------------------- 1 | # Generated by CMake 2 | 3 | if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.8) 4 | message(FATAL_ERROR "CMake >= 2.8.0 required") 5 | endif() 6 | if(CMAKE_VERSION VERSION_LESS "2.8.3") 7 | message(FATAL_ERROR "CMake >= 2.8.3 required") 8 | endif() 9 | cmake_policy(PUSH) 10 | cmake_policy(VERSION 2.8.3...3.25) 11 | #---------------------------------------------------------------- 12 | # Generated CMake target import file. 13 | #---------------------------------------------------------------- 14 | 15 | # Commands may need to know the format version. 16 | set(CMAKE_IMPORT_FILE_VERSION 1) 17 | 18 | # Protect against multiple inclusion, which would fail when already imported targets are added once more. 19 | set(_cmake_targets_defined "") 20 | set(_cmake_targets_not_defined "") 21 | set(_cmake_expected_targets "") 22 | foreach(_cmake_expected_target IN ITEMS OpenImageDenoise_weights OpenImageDenoise_common OpenImageDenoise_core OpenImageDenoise) 23 | list(APPEND _cmake_expected_targets "${_cmake_expected_target}") 24 | if(TARGET "${_cmake_expected_target}") 25 | list(APPEND _cmake_targets_defined "${_cmake_expected_target}") 26 | else() 27 | list(APPEND _cmake_targets_not_defined "${_cmake_expected_target}") 28 | endif() 29 | endforeach() 30 | unset(_cmake_expected_target) 31 | if(_cmake_targets_defined STREQUAL _cmake_expected_targets) 32 | unset(_cmake_targets_defined) 33 | unset(_cmake_targets_not_defined) 34 | unset(_cmake_expected_targets) 35 | unset(CMAKE_IMPORT_FILE_VERSION) 36 | cmake_policy(POP) 37 | return() 38 | endif() 39 | if(NOT _cmake_targets_defined STREQUAL "") 40 | string(REPLACE ";" ", " _cmake_targets_defined_text "${_cmake_targets_defined}") 41 | string(REPLACE ";" ", " _cmake_targets_not_defined_text "${_cmake_targets_not_defined}") 42 | message(FATAL_ERROR "Some (but not all) targets in this export set were already defined.\nTargets Defined: ${_cmake_targets_defined_text}\nTargets not yet defined: ${_cmake_targets_not_defined_text}\n") 43 | endif() 44 | unset(_cmake_targets_defined) 45 | unset(_cmake_targets_not_defined) 46 | unset(_cmake_expected_targets) 47 | 48 | 49 | # Compute the installation prefix relative to this file. 50 | get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH) 51 | get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) 52 | get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) 53 | get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) 54 | if(_IMPORT_PREFIX STREQUAL "/") 55 | set(_IMPORT_PREFIX "") 56 | endif() 57 | 58 | # Create imported target OpenImageDenoise_weights 59 | add_library(OpenImageDenoise_weights INTERFACE IMPORTED) 60 | 61 | # Create imported target OpenImageDenoise_common 62 | add_library(OpenImageDenoise_common INTERFACE IMPORTED) 63 | 64 | # Create imported target OpenImageDenoise_core 65 | add_library(OpenImageDenoise_core SHARED IMPORTED) 66 | 67 | set_target_properties(OpenImageDenoise_core PROPERTIES 68 | INTERFACE_LINK_LIBRARIES "OpenImageDenoise_common" 69 | ) 70 | 71 | # Create imported target OpenImageDenoise 72 | add_library(OpenImageDenoise SHARED IMPORTED) 73 | 74 | set_target_properties(OpenImageDenoise PROPERTIES 75 | INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include" 76 | ) 77 | 78 | if(CMAKE_VERSION VERSION_LESS 3.0.0) 79 | message(FATAL_ERROR "This file relies on consumers using CMake 3.0.0 or greater.") 80 | endif() 81 | 82 | # Load information for each installed configuration. 83 | file(GLOB _cmake_config_files "${CMAKE_CURRENT_LIST_DIR}/OpenImageDenoiseTargets-*.cmake") 84 | foreach(_cmake_config_file IN LISTS _cmake_config_files) 85 | include("${_cmake_config_file}") 86 | endforeach() 87 | unset(_cmake_config_file) 88 | unset(_cmake_config_files) 89 | 90 | # Cleanup temporary variables. 91 | set(_IMPORT_PREFIX) 92 | 93 | # Loop over all imported files and verify that they actually exist 94 | foreach(_cmake_target IN LISTS _cmake_import_check_targets) 95 | foreach(_cmake_file IN LISTS "_cmake_import_check_files_for_${_cmake_target}") 96 | if(NOT EXISTS "${_cmake_file}") 97 | message(FATAL_ERROR "The imported target \"${_cmake_target}\" references the file 98 | \"${_cmake_file}\" 99 | but this file does not exist. Possible reasons include: 100 | * The file was deleted, renamed, or moved to another location. 101 | * An install or uninstall procedure did not complete successfully. 102 | * The installation package was faulty and contained 103 | \"${CMAKE_CURRENT_LIST_FILE}\" 104 | but not all the files it references. 105 | ") 106 | endif() 107 | endforeach() 108 | unset(_cmake_file) 109 | unset("_cmake_import_check_files_for_${_cmake_target}") 110 | endforeach() 111 | unset(_cmake_target) 112 | unset(_cmake_import_check_targets) 113 | 114 | # This file does not depend on other imported targets which have 115 | # been exported from the same project but in a separate export set. 116 | 117 | # Commands beyond this point should not need to know the version. 118 | set(CMAKE_IMPORT_FILE_VERSION) 119 | cmake_policy(POP) 120 | -------------------------------------------------------------------------------- /thirdparty/OpenImageDenoise/share/doc/OpenImageDenoise/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | Version History 2 | --------------- 3 | 4 | ### Changes in v2.1.0: 5 | 6 | - Added support for denoising 1-channel (e.g. alpha) and 2-channel images 7 | - Added support for arbitrary combinations of input image data types 8 | (e.g. `OIDN_FORMAT_FLOAT3` for `color` but `OIDN_FORMAT_HALF3` for `albedo`) 9 | - Improved performance for most dedicated GPU architectures 10 | - Re-added `OIDN_STATIC_LIB` CMake option which enables building as a static 11 | (CPU support only) or a hybrid static/shared (GPU support as well) library 12 | - Added `release()` method to C++ API objects (`DeviceRef`, `BufferRef`, 13 | `FilterRef`) 14 | - Fixed possible crash when releasing GPU devices, buffers or filters 15 | - Fixed possible crash at process exit for some SYCL runtime versions 16 | - Fixed image quality inconsistency on Intel integrated GPUs, but at the cost 17 | of some performance loss 18 | - Fixed future Windows driver compatibility for Intel integrated GPUs 19 | - Fixed rare output corruption on AMD RDNA2 GPUs 20 | - Fixed device detection on Windows when the path to the library has non-ANSI 21 | characters 22 | - Added support for Intel® oneAPI DPC++/C++ Compiler 2024.0 and compatible 23 | open source compiler versions 24 | - Upgraded to oneTBB 2021.10.0 in the official binaries 25 | - Improved detection of old oneTBB versions 26 | 27 | ### Changes in v2.0.1: 28 | 29 | - Fixed performance issue for Intel integrated GPUs using recent Linux drivers 30 | - Fixed crash on systems with both dedicated and integrated AMD GPUs 31 | - Fixed importing `D3D12_RESOURCE`, `D3D11_RESOURCE`, `D3D11_RESOURCE_KMT`, 32 | `D3D11_TEXTURE` and `D3D11_TEXTURE_KMT` external memory types on CUDA and 33 | HIP devices 34 | - Fixed the macOS deployment target of the official x86 binaries (lowered from 35 | 11.0 to 10.11) 36 | - Minor improvements to verbose output 37 | 38 | ### Changes in v2.0.0: 39 | 40 | - Added SYCL device for Intel Xe architecture GPUs (Xe-LP, Xe-HPG and Xe-HPC) 41 | - Added CUDA device for NVIDIA Volta, Turing, Ampere, Ada Lovelace and Hopper 42 | architecture GPUs 43 | - Added HIP device for AMD RDNA2 (Navi 21 only) and RDNA3 (Navi 3x) 44 | architecture GPUs 45 | - Added new buffer API functions for specifying the storage type (host, device 46 | or managed), copying data to/from the host, and importing external buffers from 47 | graphics APIs (e.g. Vulkan, Direct3D 12) 48 | - Removed the `oidnMapBuffer` and `oidnUnmapBuffer` functions 49 | - Added support for asynchronous execution (e.g. `oidnExecuteFilterAsync`, 50 | `oidnSyncDevice` functions) 51 | - Added physical device API for querying the supported devices in the system 52 | - Added functions for creating a device from a physical device ID, UUID, LUID 53 | or PCI address (e.g. `oidnNewDeviceByID`) 54 | - Added SYCL, CUDA and HIP interoperability API functions (e.g. `oidnNewSYCLDevice`, 55 | `oidnExecuteSYCLFilterAsync`) 56 | - Added `type` device parameter for querying the device type 57 | - Added `systemMemorySupported` and `managedMemorySupported` device parameters 58 | for querying memory allocations supported by the device 59 | - Added `externalMemoryTypes` device parameter for querying the supported 60 | external memory handle types 61 | - Added `quality` filter parameter for setting the filtering quality mode (high 62 | or balanced quality) 63 | - Minor API changes with backward compatibility: 64 | - Added `oidn(Get|Set)(Device|Filter)(Bool|Int|Float)` functions and 65 | deprecated `oidn(Get|Set)(Device|Filter)(1b|1i|1f)` functions 66 | - Added `oidnUnsetFilter(Image|Data)` functions and deprecated 67 | `oidnRemoveFilter(Image|Data)` functions 68 | - Renamed `alignment` and `overlap` filter parameters to `tileAlignment` 69 | and `tileOverlap` but the old names remain supported 70 | - Removed `OIDN_STATIC_LIB` and `OIDN_STATIC_RUNTIME` CMake options due to 71 | technical limitations 72 | - Fixed over-conservative buffer bounds checking for images with custom strides 73 | - Upgraded to oneTBB 2021.9.0 in the official binaries 74 | 75 | ### Changes in v1.4.3: 76 | 77 | - Fixed hardcoded library paths in installed macOS binaries 78 | - Disabled VTune profiling support of oneDNN kernels by default, can be 79 | enabled using CMake options if required (`DNNL_ENABLE_JIT_PROFILING` and 80 | `DNNL_ENABLE_ITT_TASKS`) 81 | - Upgraded to oneTBB 2021.5.0 in the official binaries 82 | 83 | ### Changes in v1.4.2: 84 | 85 | - Added support for 16-bit half-precision floating-point images 86 | - Added `oidnGetBufferData` and `oidnGetBufferSize` functions 87 | - Fixed performance issue on x86 hybrid architecture CPUs (e.g. Alder Lake) 88 | - Fixed build error when using OpenImageIO 2.3 or later 89 | - Upgraded to oneTBB 2021.4.0 in the official binaries 90 | 91 | ### Changes in v1.4.1: 92 | 93 | - Fixed crash when in-place denoising images with certain unusual resolutions 94 | - Fixed compile error when building for Apple Silicon using some unofficial 95 | builds of ISPC 96 | 97 | ### Changes in v1.4.0: 98 | 99 | - Improved fine detail preservation 100 | - Added the `cleanAux` filter parameter for further improving quality when the 101 | auxiliary feature (albedo, normal) images are noise-free 102 | - Added support for denoising auxiliary feature images, which can be used 103 | together with the new `cleanAux` parameter for improving quality when the 104 | auxiliary images are noisy (recommended for final frame denoising) 105 | - Normals are expected to be in the [-1, 1] range (but still do not have to 106 | be normalized) 107 | - Added the `oidnUpdateFilterData` function which must be called when the 108 | contents of an opaque data parameter bound to a filter (e.g. `weights`) has 109 | been changed after committing the filter 110 | - Added the `oidnRemoveFilterImage` and `oidnRemoveFilterData` functions for 111 | removing previously set image and opaque data parameters of filters 112 | - Reduced the overhead of `oidnCommitFilter` to zero in some cases (e.g. when 113 | changing already set image buffers/pointers or the `inputScale` parameter) 114 | - Reduced filter memory consumption by about 35% 115 | - Reduced total memory consumption significantly when using multiple filters 116 | that belong to the same device 117 | - Reduced the default maximum memory consumption to 3000 MB 118 | - Added the `OIDN_FILTER_RT` and `OIDN_FILTER_RTLIGHTMAP` CMake options for 119 | excluding the trained filter weights from the build to significantly 120 | decrease its size 121 | - Fixed detection of static TBB builds on Windows 122 | - Fixed compile error when using future glibc versions 123 | - Added `oidnBenchmark` option for setting custom resolutions 124 | - Upgraded to oneTBB 2021.2.0 in the official binaries 125 | 126 | ### Changes in v1.3.0: 127 | 128 | - Improved denoising quality 129 | - Improved sharpness of fine details / less blurriness 130 | - Fewer noisy artifacts 131 | - Slightly improved performance and lowered memory consumption 132 | - Added directional (e.g. spherical harmonics) lightmap denoising to the 133 | `RTLightmap` filter 134 | - Added `inputScale` filter parameter which generalizes the existing 135 | (and thus now deprecated) `hdrScale` parameter for non-HDR images 136 | - Added native support for Apple Silicon and the BNNS library on macOS 137 | (currently requires rebuilding from source) 138 | - Added `OIDN_NEURAL_RUNTIME` CMake option for setting the neural network 139 | runtime library 140 | - Reduced the size of the library binary 141 | - Fixed compile error on some older macOS versions 142 | - Upgraded release builds to use oneTBB 2021.1.1 143 | - Removed tbbmalloc dependency 144 | - Appended the library version to the name of the directory containing the 145 | installed CMake files 146 | - Training: 147 | - Faster training performance 148 | - Added mixed precision training (enabled by default) 149 | - Added efficient data-parallel training on multiple GPUs 150 | - Enabled preprocessing datasets multiple times with possibly different 151 | options 152 | - Minor bugfixes 153 | 154 | ### Changes in v1.2.4: 155 | 156 | - Added OIDN_API_NAMESPACE CMake option that allows to put all API functions 157 | inside a user-defined namespace 158 | - Fixed bug when TBB_USE_GLIBCXX_VERSION is defined 159 | - Fixed compile error when using an old compiler which does not support 160 | OpenMP SIMD 161 | - Added compatibility with oneTBB 2021 162 | - Export only necessary symbols on Linux and macOS 163 | 164 | ### Changes in v1.2.3: 165 | 166 | - Fixed incorrect detection of AVX-512 on macOS (sometimes causing a crash) 167 | - Fixed inconsistent performance and costly initialization for AVX-512 168 | - Fixed JIT'ed AVX-512 kernels not showing up correctly in VTune 169 | 170 | ### Changes in v1.2.2: 171 | 172 | - Fixed unhandled exception when canceling filter execution from the 173 | progress monitor callback function 174 | 175 | ### Changes in v1.2.1: 176 | 177 | - Fixed tiling artifacts when in-place denoising (using one of the input 178 | images as the output) high-resolution (> 1080p) images 179 | - Fixed ghosting/color bleeding artifacts in black regions when using 180 | albedo/normal buffers 181 | - Fixed error when building as a static library (`OIDN_STATIC_LIB` option) 182 | - Fixed compile error for ISPC 1.13 and later 183 | - Fixed minor TBB detection issues 184 | - Fixed crash on pre-SSE4 CPUs when using some recent compilers (e.g. GCC 10) 185 | - Link C/C++ runtime library dynamically on Windows too by default 186 | - Renamed example apps (`oidnDenoise`, `oidnTest`) 187 | - Added benchmark app (`oidnBenchmark`) 188 | - Fixed random data augmentation seeding in training 189 | - Fixed training warning with PyTorch 1.5 and later 190 | 191 | ### Changes in v1.2.0: 192 | 193 | - Added neural network training code 194 | - Added support for specifying user-trained models at runtime 195 | - Slightly improved denoising quality (e.g. less ringing artifacts, less 196 | blurriness in some cases) 197 | - Improved denoising speed by about 7-38% (mostly depending on the compiler) 198 | - Added `OIDN_STATIC_RUNTIME` CMake option (for Windows only) 199 | - Added support for OpenImageIO to the example apps (disabled by default) 200 | - Added check for minimum supported TBB version 201 | - Find debug versions of TBB 202 | - Added testing 203 | 204 | ### Changes in v1.1.0: 205 | 206 | - Added `RTLightmap` filter optimized for lightmaps 207 | - Added `hdrScale` filter parameter for manually specifying the mapping 208 | of HDR color values to luminance levels 209 | 210 | ### Changes in v1.0.0: 211 | 212 | - Improved denoising quality 213 | - More details preserved 214 | - Less artifacts (e.g. noisy spots, color bleeding with albedo/normal) 215 | - Added `maxMemoryMB` filter parameter for limiting the maximum memory 216 | consumption regardless of the image resolution, potentially at the cost 217 | of lower denoising speed. This is internally implemented by denoising the 218 | image in tiles 219 | - Significantly reduced memory consumption (but slightly lower performance) 220 | for high resolutions (> 2K) by default: limited to about 6 GB 221 | - Added `alignment` and `overlap` filter parameters that can be queried for 222 | manual tiled denoising 223 | - Added `verbose` device parameter for setting the verbosity of the console 224 | output, and disabled all console output by default 225 | - Fixed crash for zero-sized images 226 | 227 | ### Changes in v0.9.0: 228 | 229 | - Reduced memory consumption by about 38% 230 | - Added support for progress monitor callback functions 231 | - Enabled fully concurrent execution when using multiple devices 232 | - Clamp LDR input and output colors to 1 233 | - Fixed issue where some memory allocation errors were not reported 234 | 235 | ### Changes in v0.8.2: 236 | 237 | - Fixed wrong HDR output when the input contains infinities/NaNs 238 | - Fixed wrong output when multiple filters were executed concurrently on 239 | separate devices with AVX-512 support. Currently the filter executions are 240 | serialized as a temporary workaround, and a full fix will be included in a 241 | future release. 242 | - Added `OIDN_STATIC_LIB` CMake option for building as a static library 243 | (requires CMake 3.13.0 or later) 244 | - Fixed CMake error when adding the library with add_subdirectory() to a project 245 | 246 | ### Changes in v0.8.1: 247 | 248 | - Fixed wrong path to TBB in the generated CMake configs 249 | - Fixed wrong rpath in the binaries 250 | - Fixed compile error on some macOS systems 251 | - Fixed minor compile issues with Visual Studio 252 | - Lowered the CPU requirement to SSE4.1 253 | - Minor example update 254 | 255 | ### Changes in v0.8.0: 256 | 257 | - Initial beta release 258 | -------------------------------------------------------------------------------- /thirdparty/OpenImageDenoise/share/doc/OpenImageDenoise/readme.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergeneren/Volumetric-Path-Tracer/8708189867bebab06d75d1894746c4927e5800ec/thirdparty/OpenImageDenoise/share/doc/OpenImageDenoise/readme.pdf -------------------------------------------------------------------------------- /thirdparty/OpenImageDenoise/share/doc/OpenImageDenoise/third-party-programs-DPCPP.txt: -------------------------------------------------------------------------------- 1 | 2 | The oneAPI DPC++ Compiler can be found here: 3 | 4 | https://github.com/intel/llvm 5 | 6 | It uses various components with following licenses: 7 | 8 | https://github.com/intel/llvm/blob/master/flang/LICENSE.TXT 9 | https://github.com/intel/llvm/blob/master/compiler-rt/LICENSE.TXT 10 | https://github.com/intel/llvm/blob/master/mlir/LICENSE.TXT 11 | https://github.com/intel/llvm/blob/master/libclc/LICENSE.TXT 12 | https://github.com/intel/llvm/blob/master/libcxxabi/LICENSE.TXT 13 | https://github.com/intel/llvm/blob/master/lld/LICENSE.TXT 14 | https://github.com/intel/llvm/blob/master/cross-project-tests/debuginfo-tests/dexter/LICENSE.txt 15 | https://github.com/intel/llvm/blob/master/libc/LICENSE.TXT 16 | https://github.com/intel/llvm/blob/master/clang-tools-extra/LICENSE.TXT 17 | https://github.com/intel/llvm/blob/master/clang-tools-extra/clang-tidy/cert/LICENSE.TXT 18 | https://github.com/intel/llvm/blob/master/clang-tools-extra/clang-tidy/hicpp/LICENSE.TXT 19 | https://github.com/intel/llvm/blob/master/lldb/LICENSE.TXT 20 | https://github.com/intel/llvm/blob/master/lldb/third_party/Python/module/ptyprocess-0.6.0/LICENSE 21 | https://github.com/intel/llvm/blob/master/lldb/third_party/Python/module/six/LICENSE 22 | https://github.com/intel/llvm/blob/master/lldb/third_party/Python/module/pexpect-4.6/LICENSE 23 | https://github.com/intel/llvm/blob/master/polly/LICENSE.TXT 24 | https://github.com/intel/llvm/blob/master/polly/lib/External/isl/LICENSE 25 | https://github.com/intel/llvm/blob/master/polly/lib/External/isl/imath/LICENSE 26 | https://github.com/intel/llvm/blob/master/polly/tools/GPURuntime/LICENSE.TXT 27 | https://github.com/intel/llvm/blob/master/sycl/LICENSE.TXT 28 | https://github.com/intel/llvm/blob/master/llvm-spirv/LICENSE.TXT 29 | https://github.com/intel/llvm/blob/master/bolt/LICENSE.TXT 30 | https://github.com/intel/llvm/blob/master/pstl/LICENSE.TXT 31 | https://github.com/intel/llvm/blob/master/clang/LICENSE.TXT 32 | https://github.com/intel/llvm/blob/master/llvm/utils/lit/LICENSE.TXT 33 | https://github.com/intel/llvm/blob/master/llvm/utils/unittest/googletest/LICENSE.TXT 34 | https://github.com/intel/llvm/blob/master/llvm/utils/unittest/googlemock/LICENSE.txt 35 | https://github.com/intel/llvm/blob/master/llvm/LICENSE.TXT 36 | https://github.com/intel/llvm/blob/master/llvm/include/llvm/Support/LICENSE.TXT 37 | https://github.com/intel/llvm/blob/master/llvm/lib/Support/BLAKE3/LICENSE 38 | https://github.com/intel/llvm/blob/master/llvm/test/YAMLParser/LICENSE.txt 39 | https://github.com/intel/llvm/blob/master/libunwind/LICENSE.TXT 40 | https://github.com/intel/llvm/blob/master/openmp/LICENSE.TXT 41 | https://github.com/intel/llvm/blob/master/openmp/runtime/src/thirdparty/ittnotify/LICENSE.txt 42 | https://github.com/intel/llvm/blob/master/third-party/benchmark/LICENSE 43 | https://github.com/intel/llvm/blob/master/libcxx/LICENSE.TXT 44 | 45 | The following people and companies contributed to the LLVM project: 46 | 47 | https://github.com/intel/llvm/blob/master/compiler-rt/CREDITS.TXT 48 | https://github.com/intel/llvm/blob/master/libclc/CREDITS.TXT 49 | https://github.com/intel/llvm/blob/master/libcxxabi/CREDITS.TXT 50 | https://github.com/intel/llvm/blob/master/polly/CREDITS.txt 51 | https://github.com/intel/llvm/blob/master/pstl/CREDITS.txt 52 | https://github.com/intel/llvm/blob/master/llvm/CREDITS.TXT 53 | https://github.com/intel/llvm/blob/master/openmp/CREDITS.txt 54 | https://github.com/intel/llvm/blob/master/libcxx/CREDITS.TXT 55 | 56 | ============================================================================== 57 | Software from third parties included in the LLVM Project: 58 | ============================================================================== 59 | The LLVM Project contains third party software which is under different license 60 | terms. All such code will be identified clearly using at least one of two 61 | mechanisms: 62 | 1) It will be in a separate directory tree with its own `LICENSE.txt` or 63 | `LICENSE` file at the top containing the specific license and restrictions 64 | which apply to that software, or 65 | 2) It will contain specific license and restriction terms at the top of every 66 | file. 67 | 68 | ============================================================================== 69 | Legacy LLVM License (https://llvm.org/docs/DeveloperPolicy.html#legacy): 70 | ============================================================================== 71 | University of Illinois/NCSA 72 | Open Source License 73 | 74 | Copyright (c) 2003-2020 University of Illinois at Urbana-Champaign. 75 | All rights reserved. 76 | 77 | Developed by: 78 | 79 | LLVM Team 80 | 81 | University of Illinois at Urbana-Champaign 82 | 83 | http://llvm.org 84 | 85 | Permission is hereby granted, free of charge, to any person obtaining a copy of 86 | this software and associated documentation files (the "Software"), to deal with 87 | the Software without restriction, including without limitation the rights to 88 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 89 | of the Software, and to permit persons to whom the Software is furnished to do 90 | so, subject to the following conditions: 91 | 92 | * Redistributions of source code must retain the above copyright notice, 93 | this list of conditions and the following disclaimers. 94 | 95 | * Redistributions in binary form must reproduce the above copyright notice, 96 | this list of conditions and the following disclaimers in the 97 | documentation and/or other materials provided with the distribution. 98 | 99 | * Neither the names of the LLVM Team, University of Illinois at 100 | Urbana-Champaign, nor the names of its contributors may be used to 101 | endorse or promote products derived from this Software without specific 102 | prior written permission. 103 | 104 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 105 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 106 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 107 | CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 108 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 109 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE 110 | SOFTWARE. 111 | -------------------------------------------------------------------------------- /thirdparty/OpenImageDenoise/share/doc/OpenImageDenoise/third-party-programs-oneTBB.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergeneren/Volumetric-Path-Tracer/8708189867bebab06d75d1894746c4927e5800ec/thirdparty/OpenImageDenoise/share/doc/OpenImageDenoise/third-party-programs-oneTBB.txt -------------------------------------------------------------------------------- /vcpkg.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "main", 3 | "version-string": "latest", 4 | "dependencies": [ 5 | "openvdb", 6 | "glfw3", 7 | "glew", 8 | "openimageio", 9 | { 10 | "name": "imgui", 11 | "default-features": true, 12 | "features": [ "glfw-binding", "opengl3-binding" ] 13 | }, 14 | "tinyexr", 15 | "stb" 16 | ] 17 | } --------------------------------------------------------------------------------