├── .clang-format ├── .clang-tidy ├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── CODEOWNERS ├── LICENSE-THIRDPARTY.txt ├── LICENSE.txt ├── README.md ├── cmake ├── FindHoudiniUsd.cmake ├── FindPixarUsd.cmake └── FindUsd.cmake ├── package.py ├── plugin ├── CMakeLists.txt ├── hdCycles │ ├── CMakeLists.txt │ ├── Mikktspace │ │ ├── mikktspace.c │ │ └── mikktspace.h │ ├── api.h │ ├── attributeSource.cpp │ ├── attributeSource.h │ ├── basisCurves.cpp │ ├── basisCurves.h │ ├── camera.cpp │ ├── camera.h │ ├── config.cpp │ ├── config.h │ ├── debug_codes.cpp │ ├── debug_codes.h │ ├── hdcycles.h │ ├── instancer.cpp │ ├── instancer.h │ ├── light.cpp │ ├── light.h │ ├── material.cpp │ ├── material.h │ ├── mesh.cpp │ ├── mesh.h │ ├── meshRefiner.cpp │ ├── meshRefiner.h │ ├── meshSource.cpp │ ├── meshSource.h │ ├── objectSource.cpp │ ├── objectSource.h │ ├── openvdb_asset.cpp │ ├── openvdb_asset.h │ ├── plugInfo.json │ ├── points.cpp │ ├── points.h │ ├── renderBuffer.cpp │ ├── renderBuffer.h │ ├── renderDelegate.cpp │ ├── renderDelegate.h │ ├── renderParam.cpp │ ├── renderParam.h │ ├── renderPass.cpp │ ├── renderPass.h │ ├── renderPassState.cpp │ ├── renderPassState.h │ ├── rendererPlugin.cpp │ ├── rendererPlugin.h │ ├── resourceRegistry.cpp │ ├── resourceRegistry.h │ ├── rprim.h │ ├── transformSource.cpp │ ├── transformSource.h │ ├── utils.cpp │ ├── utils.h │ ├── volume.cpp │ └── volume.h ├── ndrCycles │ ├── CMakeLists.txt │ ├── api.h │ ├── discovery.cpp │ ├── discovery.h │ ├── parser.cpp │ ├── parser.h │ └── plugInfo.json ├── usdCycles │ ├── CMakeLists.txt │ ├── __init__.py │ ├── module.cpp │ ├── moduleDeps.cpp │ ├── plugInfo.cmake │ └── schema.usda └── usdImagingCycles │ ├── CMakeLists.txt │ ├── engine.cpp │ └── engine.h └── tests ├── CMakeLists.txt ├── README.md ├── lsan.supp ├── test_attributeSource.cpp ├── test_transformSource.cpp └── tests.cpp /.clang-format: -------------------------------------------------------------------------------- 1 | Language: Cpp 2 | BasedOnStyle: WebKit 3 | SpaceBeforeParens: ControlStatements 4 | 5 | AccessModifierOffset: -4 6 | AlignAfterOpenBracket: Align 7 | AlignConsecutiveAssignments: false 8 | AlignConsecutiveDeclarations: false 9 | AlignEscapedNewlines: Right 10 | AlignOperands: true 11 | AlignTrailingComments: true 12 | AllowAllArgumentsOnNextLine: true 13 | AllowAllConstructorInitializersOnNextLine: true 14 | AllowAllParametersOfDeclarationOnNextLine: false 15 | AllowShortBlocksOnASingleLine: true 16 | AllowShortCaseLabelsOnASingleLine: true 17 | AllowShortFunctionsOnASingleLine: All 18 | AllowShortLambdasOnASingleLine: All 19 | AllowShortIfStatementsOnASingleLine: Never 20 | AllowShortLoopsOnASingleLine: false 21 | AlwaysBreakAfterDefinitionReturnType: None 22 | AlwaysBreakAfterReturnType: TopLevel 23 | AlwaysBreakBeforeMultilineStrings: false 24 | AlwaysBreakTemplateDeclarations: MultiLine 25 | BinPackArguments: true 26 | BinPackParameters: true 27 | BraceWrapping: 28 | AfterCaseLabel: false 29 | AfterClass: false 30 | AfterControlStatement: false 31 | AfterEnum: false 32 | AfterFunction: true 33 | AfterNamespace: false 34 | AfterObjCDeclaration: false 35 | AfterStruct: false 36 | AfterUnion: false 37 | AfterExternBlock: false 38 | BeforeCatch: false 39 | BeforeElse: false 40 | IndentBraces: false 41 | SplitEmptyFunction: false 42 | SplitEmptyRecord: false 43 | SplitEmptyNamespace: false 44 | BreakBeforeBinaryOperators: All 45 | BreakBeforeBraces: WebKit 46 | BreakBeforeInheritanceComma: false 47 | BreakInheritanceList: BeforeColon 48 | BreakBeforeTernaryOperators: true 49 | BreakConstructorInitializersBeforeComma: false 50 | BreakConstructorInitializers: BeforeComma 51 | BreakAfterJavaFieldAnnotations: false 52 | BreakStringLiterals: false 53 | ColumnLimit: 120 54 | CommentPragmas: '^ IWYU pragma:' 55 | CompactNamespaces: false 56 | ConstructorInitializerAllOnOneLineOrOnePerLine: false 57 | ConstructorInitializerIndentWidth: 4 58 | ContinuationIndentWidth: 4 59 | Cpp11BracedListStyle: false 60 | DerivePointerAlignment: false 61 | DisableFormat: false 62 | ExperimentalAutoDetectBinPacking: false 63 | FixNamespaceComments: true 64 | ForEachMacros: 65 | - foreach 66 | - Q_FOREACH 67 | - BOOST_FOREACH 68 | IncludeBlocks: Preserve 69 | IncludeCategories: 70 | - Regex: '^"(llvm|llvm-c|clang|clang-c)/' 71 | Priority: 2 72 | - Regex: '^(<|"(gtest|gmock|isl|json)/)' 73 | Priority: 3 74 | - Regex: '.*' 75 | Priority: 1 76 | IncludeIsMainRegex: '(Test)?$' 77 | IndentCaseLabels: false 78 | IndentPPDirectives: AfterHash 79 | IndentWidth: 4 80 | IndentWrappedFunctionNames: false 81 | JavaScriptQuotes: Leave 82 | JavaScriptWrapImports: true 83 | KeepEmptyLinesAtTheStartOfBlocks: false 84 | MacroBlockBegin: '' 85 | MacroBlockEnd: '' 86 | MaxEmptyLinesToKeep: 3 87 | NamespaceIndentation: Inner 88 | ObjCBinPackProtocolList: Auto 89 | ObjCBlockIndentWidth: 4 90 | ObjCSpaceAfterProperty: true 91 | ObjCSpaceBeforeProtocolList: true 92 | PenaltyBreakAssignment: 40 93 | PenaltyBreakBeforeFirstCallParameter: 100 94 | PenaltyBreakComment: 300 95 | PenaltyBreakFirstLessLess: 120 96 | PenaltyBreakString: 1000 97 | PenaltyBreakTemplateDeclaration: 10 98 | PenaltyExcessCharacter: 75 99 | PenaltyReturnTypeOnItsOwnLine: 50 100 | PointerAlignment: Left 101 | ReflowComments: false 102 | SortIncludes: true 103 | SortUsingDeclarations: true 104 | SpaceAfterCStyleCast: false 105 | SpaceAfterLogicalNot: false 106 | SpaceAfterTemplateKeyword: false 107 | SpaceBeforeAssignmentOperators: true 108 | SpaceBeforeCpp11BracedList: true 109 | SpaceBeforeCtorInitializerColon: true 110 | SpaceBeforeInheritanceColon: true 111 | SpaceBeforeParens: ControlStatements 112 | SpaceBeforeRangeBasedForLoopColon: true 113 | SpaceInEmptyBlock: false 114 | SpaceInEmptyParentheses: false 115 | SpacesBeforeTrailingComments: 2 116 | SpacesInAngles: false 117 | SpacesInContainerLiterals: true 118 | SpacesInCStyleCastParentheses: false 119 | SpacesInParentheses: false 120 | SpacesInSquareBrackets: false 121 | Standard: Cpp11 122 | StatementMacros: 123 | - Q_UNUSED 124 | - QT_REQUIRE_VERSION 125 | TabWidth: 8 126 | UseTab: Never 127 | #... 128 | -------------------------------------------------------------------------------- /.clang-tidy: -------------------------------------------------------------------------------- 1 | Checks: '-*,clang-analyzer-security*' 2 | WarningsAsErrors: '' 3 | HeaderFilterRegex: '(OpenImageIO/[a-zA-Z0-9_]+\.h)|(imageio)|(oiio)|(iv/)|(_pvt\.h)' 4 | AnalyzeTemporaryDtors: false 5 | User: lg 6 | CheckOptions: 7 | - key: modernize-use-nullptr.NullMacros 8 | value: 'NULL' 9 | - key: modernize-use-emplace.SmartPointers 10 | value: 'OIIO::intrusive_ptr' 11 | ... -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | [Bb]uild/ 2 | _rez_build/ 3 | cmake-build-*/ 4 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "tests/doctest"] 2 | path = tests/doctest 3 | url = https://github.com/onqtam/doctest.git 4 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Tangent Animation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | # including without limitation, as related to merchantability and fitness 13 | # for a particular purpose. 14 | # 15 | # In no event shall any copyright holder be liable for any damages of any kind 16 | # arising from the use of this software, whether in contract, tort or otherwise. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | 20 | cmake_minimum_required(VERSION 3.18) 21 | project(HdBlackbird CXX C) 22 | 23 | # Options debug 24 | option(USE_TESTS "" OFF) 25 | option(USE_ASAN "" OFF) 26 | option(USE_IMAGING_ENGINE "" OFF) 27 | 28 | # Global Settings 29 | set(CMAKE_CXX_STANDARD 14) 30 | set(CMAKE_CXX_STANDARD_REQUIRED TRUE) 31 | set(CMAKE_POSITION_INDEPENDENT_CODE ON) 32 | 33 | # Find Cycles, Blackbird project uses it as submodule 34 | if(NOT TARGET Cycles::Cycles) 35 | find_package(Cycles REQUIRED) 36 | endif() 37 | 38 | # Find Usd 39 | include(cmake/FindUsd.cmake) 40 | 41 | if (MSVC) 42 | set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /NODEFAULTLIB:libmmd.lib /NODEFAULTLIB:libirc.lib /NODEFAULTLIB:svml_dispmd.lib /NODEFAULTLIB:libdecimal.lib" ) 43 | set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF") 44 | endif() 45 | 46 | # Linux only 47 | if(${USE_TESTS} AND ${USE_ASAN}) 48 | add_compile_definitions(USE_ASAN) 49 | add_compile_options(-fno-omit-frame-pointer -fsanitize=address) 50 | add_link_options(-fno-omit-frame-pointer -fsanitize=address) 51 | endif() 52 | 53 | add_subdirectory(plugin) 54 | 55 | if(${USE_TESTS}) 56 | message(STATUS "Building with tests") 57 | add_subdirectory(tests) 58 | endif() 59 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @boberfly @dedoardo @sergeneren @skwerner @bareya 2 | -------------------------------------------------------------------------------- /LICENSE-THIRDPARTY.txt: -------------------------------------------------------------------------------- 1 | For main licese check LICENSE.txt 2 | 3 | ======================================================================================================================== 4 | 5 | OTHER LICENSES 6 | 7 | ------------------------------------------------------------------------------------------------------------------------ 8 | 9 | BSD-3-Clause 10 | 11 | Copyright (c) . All rights reserved. 12 | 13 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 14 | 15 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 16 | 17 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 18 | 19 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 22 | 23 | ------------------------------------------------------------------------------------------------------------------------ 24 | 25 | MIT 26 | 27 | MIT License Copyright (c) 28 | 29 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 30 | 31 | The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software. 32 | 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 34 | 35 | ------------------------------------------------------------------------------------------------------------------------ 36 | 37 | Zlib 38 | 39 | zlib License Copyright (c) 40 | 41 | This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. 42 | 43 | Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 44 | 45 | 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 46 | 47 | 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 48 | 49 | 3. This notice may not be removed or altered from any source distribution. 50 | 51 | ------------------------------------------------------------------------------------------------------------------------ 52 | 53 | ======================================================================================================================== 54 | 55 | ACKNOWLEDGEMENTS 56 | 57 | ------------------------------------------------------------------------------------------------------------------------ 58 | 59 | BSD-3-Clause 60 | 61 | Blender Foundation 62 | 63 | ------------------------------------------------------------------------------------------------------------------------ 64 | 65 | BSD-3-Clause 66 | 67 | Alex Fuller 68 | 69 | ------------------------------------------------------------------------------------------------------------------------ 70 | 71 | MIT 72 | 73 | Justus Calvin 74 | 75 | ------------------------------------------------------------------------------------------------------------------------ 76 | 77 | Zlib 78 | 79 | Morten S. Mikkelsen 80 | 81 | ------------------------------------------------------------------------------------------------------------------------ 82 | 83 | Apache-2.0 84 | 85 | Tangent Animation 86 | 87 | ------------------------------------------------------------------------------------------------------------------------ 88 | 89 | Apache-2.0 90 | 91 | Pixar 92 | 93 | ------------------------------------------------------------------------------------------------------------------------ 94 | 95 | Apache-2.0 96 | 97 | Luma Pictures 98 | 99 | ------------------------------------------------------------------------------------------------------------------------ 100 | 101 | Apache-2.0 102 | 103 | Advanced Micro Devices, Inc 104 | 105 | ------------------------------------------------------------------------------------------------------------------------ 106 | 107 | Copyright notices 108 | 109 | Copyright 2020 Tangent Animation 110 | Copyright 2020 Autodesk 111 | Copyright 2020 Advanced Micro Devices, Inc 112 | Copyright 2019 Pixar 113 | Copyright 2019 Luma Pictures 114 | Copyright 2018 Pixar 115 | Copyright 2018 Alex Fuller 116 | Copyright 2017 Pixar 117 | Copyright 2016 Pixar 118 | Copyright 2015 Justus Calvin 119 | Copyright 2013 Blender Foundation. 120 | Copyright 2011 Morten S. Mikkelsen 121 | Copyright 2011 Blender Foundation. 122 | -------------------------------------------------------------------------------- /cmake/FindHoudiniUsd.cmake: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Tangent Animation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | # including without limitation, as related to merchantability and fitness 13 | # for a particular purpose. 14 | # 15 | # In no event shall any copyright holder be liable for any damages of any kind 16 | # arising from the use of this software, whether in contract, tort or otherwise. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | 20 | if(NOT DEFINED HOUDINI_ROOT) 21 | message(FATAL_ERROR "HOUDINI_ROOT not defined") 22 | endif() 23 | 24 | find_package(Houdini REQUIRED PATHS ${HOUDINI_ROOT}/toolkit/cmake) 25 | target_link_libraries(UsdInterface INTERFACE Houdini) 26 | 27 | # DSO 28 | target_compile_definitions(UsdInterface 29 | INTERFACE 30 | USE_HBOOST 31 | BOOST_NS=hboost 32 | Houdini_FOUND=TRUE 33 | ) 34 | 35 | set(_houdini_libs 36 | OpenImageIO_sidefx; 37 | hboost_filesystem-mt-x64; 38 | hboost_iostreams-mt-x64; 39 | hboost_system-mt-x64; 40 | hboost_regex-mt-x64; 41 | ) 42 | 43 | # optional boost_program_options 44 | if(${USE_IMAGING_ENGINE}) 45 | list(APPEND _houdini_libs hboost_program_options-mt-x64) 46 | endif() 47 | 48 | foreach(_houdini_lib ${_houdini_libs}) 49 | find_library(${_houdini_lib}_path 50 | NAMES 51 | ${_houdini_lib} 52 | PATHS 53 | ${HOUDINI_ROOT}/dsolib 54 | ${HOUDINI_ROOT}/custom/houdini/dsolib/ 55 | REQUIRED 56 | ) 57 | 58 | message(STATUS "Found ${_houdini_lib}: ${${_houdini_lib}_path}") 59 | 60 | target_link_libraries(UsdInterface 61 | INTERFACE 62 | ${${_houdini_lib}_path} 63 | ) 64 | 65 | endforeach() 66 | 67 | # Python 68 | find_library(_houdini_python_lib 69 | NAMES 70 | python27 71 | python2.7 72 | python 73 | PATHS 74 | ${HOUDINI_ROOT}/python27/libs 75 | ${HOUDINI_ROOT}/python/libs 76 | ${HOUDINI_ROOT}/python/lib 77 | REQUIRED 78 | ) 79 | 80 | find_library(_houdini_hboost_python 81 | NAMES 82 | hboost_python27-mt-x64 83 | hboost_python-mt-x64 84 | PATHS 85 | ${HOUDINI_ROOT}/dsolib 86 | ${HOUDINI_ROOT}/custom/houdini/dsolib/ 87 | REQUIRED 88 | ) 89 | 90 | target_link_libraries(Houdini INTERFACE ${_houdini_python_lib} ${_houdini_hboost_python}) 91 | 92 | # Usd 93 | list(APPEND CMAKE_FIND_LIBRARY_PREFIXES lib) # append lib prefix to have same behaviour on win and lin 94 | set(_houdini_pxr_libs pxr_ar;pxr_arch;pxr_cameraUtil;pxr_garch;pxr_gf;pxr_glf;pxr_hd;pxr_hdSt;pxr_hdx;pxr_hf;pxr_hgi;pxr_hgiGL;pxr_hio;pxr_js;pxr_kind;pxr_ndr;pxr_pcp;pxr_plug;pxr_pxOsd;pxr_sdf;pxr_sdr;pxr_tf;pxr_trace;pxr_usd;pxr_usdHydra;pxr_usdImaging;pxr_usdImagingGL;pxr_usdLux;pxr_usdRender;pxr_usdShade;pxr_usdSkel;pxr_usdUtils;pxr_usdVol;pxr_vt;pxr_work;pxr_usdGeom) 95 | foreach(_pxr_lib ${_houdini_pxr_libs}) 96 | find_library(${_pxr_lib}_path 97 | NAMES 98 | ${_pxr_lib} 99 | PATHS 100 | ${HOUDINI_ROOT}/dsolib 101 | ${HOUDINI_ROOT}/custom/houdini/dsolib/ 102 | REQUIRED 103 | ) 104 | 105 | target_link_libraries(UsdInterface 106 | INTERFACE 107 | ${${_pxr_lib}_path} 108 | ) 109 | 110 | endforeach() 111 | 112 | # Find Usd Schema Generator 113 | if (NOT USD_SCHEMA_GENERATOR) 114 | find_program(USD_SCHEMA_GENERATOR 115 | NAMES 116 | usdGenSchema 117 | usdGenSchema.py 118 | PATHS 119 | ${HOUDINI_ROOT}/bin 120 | ${HOUDINI_ROOT}/Resources/bin 121 | REQUIRED 122 | NO_DEFAULT_PATH 123 | ) 124 | 125 | get_filename_component(USD_SCHEMA_GENERATOR_EXT 126 | ${USD_SCHEMA_GENERATOR} 127 | EXT 128 | ) 129 | 130 | if("${USD_SCHEMA_GENERATOR_EXT}" STREQUAL ".py") 131 | find_program(HYTHON_EXECUTABLE 132 | NAMES 133 | hython 134 | PATHS 135 | ${HOUDINI_ROOT}/bin 136 | ${HOUDINI_ROOT}/Resources/bin 137 | REQUIRED 138 | NO_DEFAULT_PATH 139 | ) 140 | list(PREPEND USD_SCHEMA_GENERATOR ${HYTHON_EXECUTABLE}) 141 | set(USD_SCHEMA_GENERATOR ${USD_SCHEMA_GENERATOR} CACHE STRING "" FORCE) 142 | endif() 143 | endif() 144 | -------------------------------------------------------------------------------- /cmake/FindPixarUsd.cmake: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Tangent Animation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | # including without limitation, as related to merchantability and fitness 13 | # for a particular purpose. 14 | # 15 | # In no event shall any copyright holder be liable for any damages of any kind 16 | # arising from the use of this software, whether in contract, tort or otherwise. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | 20 | if(NOT DEFINED USD_ROOT) 21 | message(FATAL_ERROR "USD_ROOT not defined") 22 | endif() 23 | 24 | find_package(pxr CONFIG REQUIRED PATHS ${USD_ROOT}) 25 | 26 | target_compile_definitions(UsdInterface 27 | INTERFACE 28 | BOOST_NS=boost 29 | $<$:HAVE_SNPRINTF> 30 | $<$:TBB_USE_DEBUG=0> 31 | ) 32 | 33 | target_link_libraries(UsdInterface 34 | INTERFACE 35 | hd usdHydra usdImaging usdRender usdSkel 36 | ) 37 | 38 | # optional boost_program_options 39 | if(${USE_IMAGING_ENGINE}) 40 | find_library(BOOST_PROGRAM_OPTIONS_LIBRARY 41 | NAMES 42 | boost_program_options 43 | REQUIRED 44 | ) 45 | 46 | target_link_libraries(UsdInterface 47 | INTERFACE 48 | hdx 49 | ${BOOST_PROGRAM_OPTIONS_LIBRARY} 50 | ) 51 | endif() 52 | 53 | # Find Usd Schema Generator 54 | 55 | find_program(USD_SCHEMA_GENERATOR 56 | NAMES 57 | usdGenSchema 58 | PATHS 59 | ${USD_ROOT}/bin 60 | NO_DEFAULT_PATH 61 | ) 62 | 63 | # Fallback to py script, remove after 18.5.519 release and add REQUIORED to usdGenSchema find_program 64 | 65 | if(NOT USD_SCHEMA_GENERATOR) 66 | find_program(USD_SCHEMA_GENERATOR 67 | NAMES 68 | usdGenSchema.py 69 | PATHS 70 | ${USD_ROOT}/bin 71 | REQUIRED 72 | NO_DEFAULT_PATH 73 | ) 74 | list(PREPEND USD_SCHEMA_GENERATOR python) 75 | set(USD_SCHEMA_GENERATOR ${USD_SCHEMA_GENERATOR} CACHE STRING "" FORCE) 76 | endif() 77 | -------------------------------------------------------------------------------- /cmake/FindUsd.cmake: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Tangent Animation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | # including without limitation, as related to merchantability and fitness 13 | # for a particular purpose. 14 | # 15 | # In no event shall any copyright holder be liable for any damages of any kind 16 | # arising from the use of this software, whether in contract, tort or otherwise. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | 20 | # Tangent specific build variables 21 | if(DEFINED ENV{REZ_HOUDINI_ROOT}) 22 | message(STATUS "Rez Houdini USD override") 23 | set(HOUDINI_ROOT $ENV{HFS}) 24 | elseif(DEFINED ENV{REZ_USD_ROOT}) 25 | message(STATUS "Rez Pixar USD override") 26 | set(USD_ROOT $ENV{REZ_USD_ROOT}) 27 | endif() 28 | 29 | # Usd interface 30 | add_library(UsdInterface INTERFACE) 31 | add_library(Usd::Usd ALIAS UsdInterface) 32 | 33 | if(DEFINED USD_ROOT) 34 | message(STATUS "Using Pixar USD: ${USD_ROOT}") 35 | include(cmake/FindPixarUsd.cmake) 36 | elseif(DEFINED HOUDINI_ROOT) 37 | message(STATUS "Using Houdini USD: ${HOUDINI_ROOT}") 38 | include(cmake/FindHoudiniUsd.cmake) 39 | else() 40 | message(FATAL_ERROR "No Houdini USD or Pixar USD ROOT was set, can not continue!") 41 | endif() 42 | 43 | message(STATUS "Using Usd Schema Generator: ${USD_SCHEMA_GENERATOR}") -------------------------------------------------------------------------------- /package.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | name = 'hdcycles' 4 | 5 | version = '0.15.0' 6 | 7 | authors = [ 8 | 'benjamin.skinner', 9 | ] 10 | 11 | requires = [ 12 | 'cycles-1.13.0-ta.1.14.7', 13 | ] 14 | 15 | variants = [ 16 | ['platform-windows', 'arch-x64', 'os-windows-10', 'usd-20.05-ta.1.2'], 17 | ['platform-windows', 'arch-x64', 'os-windows-10', 'usd-20.11'], 18 | ['platform-windows', 'arch-x64', 'os-windows-10', 'houdini-18.5'], 19 | ['platform-linux', 'arch-x86_64', 'os-centos-7', 'houdini-18.5'], 20 | ] 21 | 22 | build_system = "cmake" 23 | 24 | # At Tangent rez-release is external by default, 25 | # this forces a rez-release as an internal package 26 | with scope("config") as c: 27 | import sys 28 | if 'win' in str(sys.platform): 29 | c.release_packages_path = "R:/int" 30 | else: 31 | c.release_packages_path = "/r/int" 32 | 33 | # At Tangent we have a visual studio package which 34 | # exposes the visual studio compiler for rez. 35 | @early() 36 | def private_build_requires(): 37 | import sys 38 | if 'win' in str(sys.platform): 39 | return ['cmake-3.18<3.20', 'visual_studio', 'Jinja2'] 40 | else: 41 | return ['cmake-3.18<3.20', 'gcc-6'] 42 | 43 | # Pass along rez version to cmake build 44 | def pre_build_commands(): 45 | env.HDCYCLES_BUILD_VERSION_MAJOR.set(this.version.major) 46 | env.HDCYCLES_BUILD_VERSION_MINOR.set(this.version.minor) 47 | env.HDCYCLES_BUILD_VERSION_PATCH.set(this.version.patch) 48 | 49 | env.HDCYCLES_BUILD_VERSION.set(str(this.version)) 50 | 51 | # Main commands for rez build and environment 52 | def commands(): 53 | env.HDCYCLES_ROOT.set('{root}') 54 | env.HDCYCLES_PLUGIN_ROOT.set('{root}/plugin') 55 | env.HDCYCLES_TOOLS_ROOT.set('{root}/tools') 56 | 57 | env.PXR_PLUGINPATH_NAME.append('{root}/plugin/usd/ndrCycles/resources') 58 | env.PXR_PLUGINPATH_NAME.append('{root}/plugin/usd/usdCycles/resources') 59 | env.PXR_PLUGINPATH_NAME.append('{root}/plugin/usd/hdCycles/resources') 60 | 61 | env.PYTHONPATH.prepend('{root}/plugin/python') 62 | 63 | # required on windows 64 | env.PATH.append('{root}/plugin/usd') 65 | 66 | # For houdini_cycles to locate the schema 67 | env.USD_CYCLES_GENERATED_SCHEMA.set('{root}/plugin/usd/usdCycles/resources/generatedSchema.usda') 68 | -------------------------------------------------------------------------------- /plugin/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Tangent Animation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | # including without limitation, as related to merchantability and fitness 13 | # for a particular purpose. 14 | # 15 | # In no event shall any copyright holder be liable for any damages of any kind 16 | # arising from the use of this software, whether in contract, tort or otherwise. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | 20 | add_subdirectory(usdCycles) 21 | add_subdirectory(ndrCycles) 22 | add_subdirectory(hdCycles) 23 | 24 | if(${USE_IMAGING_ENGINE}) 25 | add_subdirectory(usdImagingCycles) 26 | endif() -------------------------------------------------------------------------------- /plugin/hdCycles/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Tangent Animation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | # including without limitation, as related to merchantability and fitness 13 | # for a particular purpose. 14 | # 15 | # In no event shall any copyright holder be liable for any damages of any kind 16 | # arising from the use of this software, whether in contract, tort or otherwise. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | 20 | if(NOT DEFINED HD_CYCLES_VERSION) 21 | add_compile_definitions(HD_CYCLES_VERSION="0.0.0") 22 | else() 23 | add_compile_definitions(HD_CYCLES_VERSION="${HD_CYCLES_VERSION}") 24 | endif() 25 | 26 | add_library(MikktSpace STATIC 27 | Mikktspace/mikktspace.c 28 | Mikktspace/mikktspace.h 29 | ) 30 | add_library(MikktSpace::MikktSpace ALIAS MikktSpace) 31 | 32 | add_library(hdCycles SHARED 33 | api.h 34 | rprim.h 35 | basisCurves.cpp 36 | basisCurves.h 37 | camera.cpp 38 | camera.h 39 | config.cpp 40 | config.h 41 | debug_codes.cpp 42 | debug_codes.h 43 | hdcycles.h 44 | instancer.cpp 45 | instancer.h 46 | light.cpp 47 | light.h 48 | material.cpp 49 | material.h 50 | mesh.cpp 51 | mesh.h 52 | meshRefiner.cpp 53 | meshRefiner.h 54 | openvdb_asset.cpp 55 | openvdb_asset.h 56 | points.cpp 57 | points.h 58 | renderBuffer.cpp 59 | renderBuffer.h 60 | renderDelegate.cpp 61 | renderDelegate.h 62 | rendererPlugin.cpp 63 | rendererPlugin.h 64 | renderParam.cpp 65 | renderParam.h 66 | renderPass.cpp 67 | renderPass.h 68 | utils.cpp 69 | utils.h 70 | volume.cpp 71 | volume.h 72 | resourceRegistry.cpp 73 | resourceRegistry.h 74 | objectSource.cpp 75 | objectSource.h 76 | attributeSource.cpp 77 | attributeSource.h 78 | renderPassState.cpp 79 | renderPassState.h 80 | transformSource.cpp 81 | transformSource.h 82 | meshSource.cpp 83 | meshSource.h 84 | ) 85 | 86 | target_include_directories(hdCycles 87 | PUBLIC 88 | ${CMAKE_CURRENT_SOURCE_DIR}/../ 89 | ) 90 | 91 | target_link_libraries(hdCycles 92 | PRIVATE 93 | MikktSpace::MikktSpace 94 | PUBLIC 95 | Cycles::Cycles 96 | Usd::Usd 97 | usdCycles 98 | ) 99 | 100 | target_compile_options(hdCycles 101 | PRIVATE 102 | $<$:/W4 /wd4273 /Zi /experimental:external /external:W0> 103 | $<$,$>:/Ob0 /Od> 104 | $<$:-Wall -Wextra -pedantic -Wno-deprecated -Wshadow -Wdouble-promotion -Wconversion -Wnull-dereference -Wold-style-cast -Wuseless-cast> 105 | $<$,$>:-g3> 106 | ) 107 | 108 | target_link_options(hdCycles 109 | PRIVATE 110 | $<$:/ignore:4217 /ignore:4049> 111 | ) 112 | 113 | target_compile_definitions(hdCycles 114 | PRIVATE 115 | MFB_PACKAGE_NAME=hdCycles 116 | MFB_ALT_PACKAGE_NAME=hdCycles 117 | ) 118 | 119 | set_target_properties(hdCycles PROPERTIES 120 | PREFIX "" 121 | INSTALL_RPATH "$ORIGIN" 122 | ) 123 | install(TARGETS hdCycles DESTINATION plugin/usd) 124 | 125 | if (MSVC) 126 | install(FILES $ DESTINATION plugin/usd OPTIONAL) 127 | endif () 128 | 129 | # plugInfo.json 130 | set(PLUG_INFO_LIBRARY_PATH "../hdCycles${CMAKE_SHARED_LIBRARY_SUFFIX}") 131 | set(PLUG_INFO_RESOURCE_PATH "resources") 132 | set(PLUG_INFO_ROOT "..") 133 | configure_file(plugInfo.json plugInfo.json @ONLY) 134 | install(FILES "${CMAKE_CURRENT_BINARY_DIR}/plugInfo.json" DESTINATION plugin/usd/hdCycles/resources) 135 | -------------------------------------------------------------------------------- /plugin/hdCycles/Mikktspace/mikktspace.h: -------------------------------------------------------------------------------- 1 | /** \file mikktspace/mikktspace.h 2 | * \ingroup mikktspace 3 | */ 4 | /** 5 | * Copyright (C) 2011 by Morten S. Mikkelsen 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * 11 | * Permission is granted to anyone to use this software for any purpose, 12 | * including commercial applications, and to alter it and redistribute it 13 | * freely, subject to the following restrictions: 14 | * 15 | * 1. The origin of this software must not be misrepresented; you must not 16 | * claim that you wrote the original software. If you use this software 17 | * in a product, an acknowledgment in the product documentation would be 18 | * appreciated but is not required. 19 | * 2. Altered source versions must be plainly marked as such, and must not be 20 | * misrepresented as being the original software. 21 | * 3. This notice may not be removed or altered from any source distribution. 22 | */ 23 | 24 | #ifndef __MIKKTSPACE_H__ 25 | #define __MIKKTSPACE_H__ 26 | 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | /* Author: Morten S. Mikkelsen 33 | * Version: 1.0 34 | * 35 | * The files mikktspace.h and mikktspace.c are designed to be 36 | * stand-alone files and it is important that they are kept this way. 37 | * Not having dependencies on structures/classes/libraries specific 38 | * to the program, in which they are used, allows them to be copied 39 | * and used as is into any tool, program or plugin. 40 | * The code is designed to consistently generate the same 41 | * tangent spaces, for a given mesh, in any tool in which it is used. 42 | * This is done by performing an internal welding step and subsequently an order-independent evaluation 43 | * of tangent space for meshes consisting of triangles and quads. 44 | * This means faces can be received in any order and the same is true for 45 | * the order of vertices of each face. The generated result will not be affected 46 | * by such reordering. Additionally, whether degenerate (vertices or texture coordinates) 47 | * primitives are present or not will not affect the generated results either. 48 | * Once tangent space calculation is done the vertices of degenerate primitives will simply 49 | * inherit tangent space from neighboring non degenerate primitives. 50 | * The analysis behind this implementation can be found in my master's thesis 51 | * which is available for download --> http://image.diku.dk/projects/media/morten.mikkelsen.08.pdf 52 | * Note that though the tangent spaces at the vertices are generated in an order-independent way, 53 | * by this implementation, the interpolated tangent space is still affected by which diagonal is 54 | * chosen to split each quad. A sensible solution is to have your tools pipeline always 55 | * split quads by the shortest diagonal. This choice is order-independent and works with mirroring. 56 | * If these have the same length then compare the diagonals defined by the texture coordinates. 57 | * XNormal which is a tool for baking normal maps allows you to write your own tangent space plugin 58 | * and also quad triangulator plugin. 59 | */ 60 | 61 | 62 | typedef int tbool; 63 | typedef struct SMikkTSpaceContext SMikkTSpaceContext; 64 | 65 | typedef struct { 66 | // Returns the number of faces (triangles/quads) on the mesh to be processed. 67 | int (*m_getNumFaces)(const SMikkTSpaceContext* pContext); 68 | 69 | // Returns the number of vertices on face number iFace 70 | // iFace is a number in the range {0, 1, ..., getNumFaces()-1} 71 | int (*m_getNumVerticesOfFace)(const SMikkTSpaceContext* pContext, const int iFace); 72 | 73 | // returns the position/normal/texcoord of the referenced face of vertex number iVert. 74 | // iVert is in the range {0,1,2} for triangles and {0,1,2,3} for quads. 75 | void (*m_getPosition)(const SMikkTSpaceContext* pContext, float fvPosOut[], const int iFace, const int iVert); 76 | void (*m_getNormal)(const SMikkTSpaceContext* pContext, float fvNormOut[], const int iFace, const int iVert); 77 | void (*m_getTexCoord)(const SMikkTSpaceContext* pContext, float fvTexcOut[], const int iFace, const int iVert); 78 | 79 | // either (or both) of the two setTSpace callbacks can be set. 80 | // The call-back m_setTSpaceBasic() is sufficient for basic normal mapping. 81 | 82 | // This function is used to return the tangent and fSign to the application. 83 | // fvTangent is a unit length vector. 84 | // For normal maps it is sufficient to use the following simplified version of the bitangent which is generated at pixel/vertex level. 85 | // bitangent = fSign * cross(vN, tangent); 86 | // Note that the results are returned unindexed. It is possible to generate a new index list 87 | // But averaging/overwriting tangent spaces by using an already existing index list WILL produce INCRORRECT results. 88 | // DO NOT! use an already existing index list. 89 | void (*m_setTSpaceBasic)(const SMikkTSpaceContext* pContext, const float fvTangent[], const float fSign, 90 | const int iFace, const int iVert); 91 | 92 | // This function is used to return tangent space results to the application. 93 | // fvTangent and fvBiTangent are unit length vectors and fMagS and fMagT are their 94 | // true magnitudes which can be used for relief mapping effects. 95 | // fvBiTangent is the "real" bitangent and thus may not be perpendicular to fvTangent. 96 | // However, both are perpendicular to the vertex normal. 97 | // For normal maps it is sufficient to use the following simplified version of the bitangent which is generated at pixel/vertex level. 98 | // fSign = bIsOrientationPreserving ? 1.0f : (-1.0f); 99 | // bitangent = fSign * cross(vN, tangent); 100 | // Note that the results are returned unindexed. It is possible to generate a new index list 101 | // But averaging/overwriting tangent spaces by using an already existing index list WILL produce INCRORRECT results. 102 | // DO NOT! use an already existing index list. 103 | void (*m_setTSpace)(const SMikkTSpaceContext* pContext, const float fvTangent[], const float fvBiTangent[], 104 | const float fMagS, const float fMagT, const tbool bIsOrientationPreserving, const int iFace, 105 | const int iVert); 106 | } SMikkTSpaceInterface; 107 | 108 | struct SMikkTSpaceContext { 109 | SMikkTSpaceInterface* m_pInterface; // initialized with callback functions 110 | void* m_pUserData; // pointer to client side mesh data etc. (passed as the first parameter with every interface call) 111 | }; 112 | 113 | // these are both thread safe! 114 | tbool 115 | genTangSpaceDefault( 116 | const SMikkTSpaceContext* 117 | pContext); // Default (recommended) fAngularThreshold is 180 degrees (which means threshold disabled) 118 | tbool 119 | genTangSpace(const SMikkTSpaceContext* pContext, const float fAngularThreshold); 120 | 121 | 122 | // To avoid visual errors (distortions/unwanted hard edges in lighting), when using sampled normal maps, the 123 | // normal map sampler must use the exact inverse of the pixel shader transformation. 124 | // The most efficient transformation we can possibly do in the pixel shader is 125 | // achieved by using, directly, the "unnormalized" interpolated tangent, bitangent and vertex normal: vT, vB and vN. 126 | // pixel shader (fast transform out) 127 | // vNout = normalize( vNt.x * vT + vNt.y * vB + vNt.z * vN ); 128 | // where vNt is the tangent space normal. The normal map sampler must likewise use the 129 | // interpolated and "unnormalized" tangent, bitangent and vertex normal to be compliant with the pixel shader. 130 | // sampler does (exact inverse of pixel shader): 131 | // float3 row0 = cross(vB, vN); 132 | // float3 row1 = cross(vN, vT); 133 | // float3 row2 = cross(vT, vB); 134 | // float fSign = dot(vT, row0)<0 ? -1 : 1; 135 | // vNt = normalize( fSign * float3(dot(vNout,row0), dot(vNout,row1), dot(vNout,row2)) ); 136 | // where vNout is the sampled normal in some chosen 3D space. 137 | // 138 | // Should you choose to reconstruct the bitangent in the pixel shader instead 139 | // of the vertex shader, as explained earlier, then be sure to do this in the normal map sampler also. 140 | // Finally, beware of quad triangulations. If the normal map sampler doesn't use the same triangulation of 141 | // quads as your renderer then problems will occur since the interpolated tangent spaces will differ 142 | // eventhough the vertex level tangent spaces match. This can be solved either by triangulating before 143 | // sampling/exporting or by using the order-independent choice of diagonal for splitting quads suggested earlier. 144 | // However, this must be used both by the sampler and your tools/rendering pipeline. 145 | 146 | #ifdef __cplusplus 147 | } 148 | #endif 149 | 150 | #endif -------------------------------------------------------------------------------- /plugin/hdCycles/api.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Tangent Animation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | // including without limitation, as related to merchantability and fitness 13 | // for a particular purpose. 14 | // 15 | // In no event shall any copyright holder be liable for any damages of any kind 16 | // arising from the use of this software, whether in contract, tort or otherwise. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | #ifndef HD_CYCLES_API_H 21 | #define HD_CYCLES_API_H 22 | 23 | #include 24 | 25 | #endif // HD_CYCLES_API_H 26 | -------------------------------------------------------------------------------- /plugin/hdCycles/attributeSource.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Tangent Animation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | // including without limitation, as related to merchantability and fitness 13 | // for a particular purpose. 14 | // 15 | // In no event shall any copyright holder be liable for any damages of any kind 16 | // arising from the use of this software, whether in contract, tort or otherwise. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | 21 | #ifndef HDBB_ATTRIBUTESOURCE_H 22 | #define HDBB_ATTRIBUTESOURCE_H 23 | 24 | #include 25 | #include 26 | 27 | #include 28 | 29 | namespace ccl { 30 | class PointCloud; 31 | } 32 | 33 | PXR_NAMESPACE_OPEN_SCOPE 34 | 35 | /// 36 | /// Blackbird Attribute to be resolved 37 | /// 38 | class HdBbAttributeSource : public HdBufferSource { 39 | public: 40 | // unfortunately AttributeSet has to be passed to support Geometry::attributes and Mesh::subd_attributes 41 | HdBbAttributeSource(TfToken name, const TfToken& role, const VtValue& value, ccl::AttributeSet* attributes, 42 | ccl::AttributeElement element, const ccl::TypeDesc& type_desc); 43 | 44 | HdBbAttributeSource(const VtValue& value, ccl::AttributeSet* attribs, ccl::AttributeStandard std); 45 | 46 | // immutable data accessors 47 | const TfToken& GetName() const override { return m_name; } 48 | const ccl::AttributeElement& GetAttributeElement() const { return m_element; } 49 | const ccl::TypeDesc& GetSourceTypeDesc() const { return m_type_desc; } 50 | const ccl::Attribute* GetAttribute() const { return m_attribute; } 51 | const ccl::Geometry* GetGeometry() const { return m_attributes->geometry; } 52 | 53 | // creates attribute for geometry 54 | bool Resolve() override; 55 | 56 | // accessors for underlying type 57 | HdTupleType GetTupleType() const override; 58 | void GetBufferSpecs(HdBufferSpecVector* specs) const override; 59 | const void* GetData() const override; 60 | size_t GetNumElements() const override; 61 | 62 | // Conversion from HdType and Hd Role to TypeDesc 63 | static ccl::TypeDesc GetTypeDesc(const HdType& type); 64 | static ccl::TypeDesc GetTypeDesc(const TfToken& role); 65 | static ccl::TypeDesc GetTypeDesc(const HdType& type, const TfToken& role); 66 | 67 | // Conversion from TypeDesc to Hd Role 68 | static const TfToken& GetRole(const ccl::TypeDesc& type_desc); 69 | 70 | // Conversion from TypeDesc to HdType 71 | static HdType GetType(const ccl::TypeDesc& type_desc); 72 | static HdTupleType GetTupleType(const ccl::TypeDesc& type_desc); 73 | 74 | // Conversion from any type to float with respecting HdTupleType 75 | static bool IsHoldingFloat(const VtValue& value); 76 | static bool CanCastToFloat(const VtValue& value); 77 | static VtValue UncheckedCastToFloat(const VtValue& value); 78 | 79 | protected: 80 | TfToken m_name; // attribute name 81 | VtValue m_value; // source data to be committed 82 | 83 | ccl::AttributeSet* m_attributes; // required for element size lookup 84 | ccl::AttributeElement m_element; // element 85 | ccl::TypeDesc m_type_desc; // type desc 86 | ccl::Attribute* m_attribute; // attribute to be created 87 | 88 | // broken down checks 89 | bool _CheckBuffersValid() const; 90 | bool _CheckBuffersSize() const; 91 | bool _CheckBuffersType() const; 92 | 93 | // 94 | bool _CheckValid() const override; 95 | 96 | // 97 | bool ResolveUnlocked(); 98 | 99 | virtual bool ResolveAsValue(); 100 | virtual bool ResolveAsArray(); 101 | }; 102 | 103 | using HdBbAttributeSourceSharedPtr = std::shared_ptr; 104 | 105 | /// 106 | /// Cycles PointCloud 107 | /// 108 | class HdCyclesPointCloudAttributeSource : public HdBbAttributeSource { 109 | public: 110 | HdCyclesPointCloudAttributeSource(TfToken name, const TfToken& role, const VtValue& value, ccl::PointCloud* pc, 111 | const HdInterpolation& interpolation); 112 | }; 113 | 114 | 115 | PXR_NAMESPACE_CLOSE_SCOPE 116 | 117 | #endif //HDBB_ATTRIBUTESOURCE_H 118 | -------------------------------------------------------------------------------- /plugin/hdCycles/basisCurves.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Tangent Animation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | // including without limitation, as related to merchantability and fitness 13 | // for a particular purpose. 14 | // 15 | // In no event shall any copyright holder be liable for any damages of any kind 16 | // arising from the use of this software, whether in contract, tort or otherwise. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | #ifndef HD_CYCLES_BASIS_CURVES_H 21 | #define HD_CYCLES_BASIS_CURVES_H 22 | 23 | #include "api.h" 24 | 25 | #include "attributeSource.h" 26 | #include "hdcycles.h" 27 | #include "objectSource.h" 28 | #include "renderDelegate.h" 29 | #include "utils.h" 30 | #include "rprim.h" 31 | 32 | #include 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | 39 | namespace ccl { 40 | class Mesh; 41 | class Scene; 42 | class Object; 43 | class Camera; 44 | class Hair; 45 | class Geometry; 46 | } // namespace ccl 47 | 48 | PXR_NAMESPACE_OPEN_SCOPE 49 | 50 | class HdSceneDelegate; 51 | class HdCyclesRenderDelegate; 52 | 53 | /** 54 | * @brief Cycles Basis Curve Rprim mapped to Cycles Basis Curve 55 | * 56 | */ 57 | class HdCyclesBasisCurves final : public HdBbRPrim { 58 | public: 59 | /** 60 | * @brief Construct a new HdCycles Basis Curve object 61 | * 62 | * @param id Path to the Basis Curve Primitive 63 | * @param instancerId If specified the HdInstancer at this id uses this curve 64 | * as a prototype 65 | */ 66 | HdCyclesBasisCurves(SdfPath const& id, SdfPath const& instancerId, HdCyclesRenderDelegate* a_renderDelegate); 67 | /** 68 | * @brief Destroy the HdCycles Basis Curves object 69 | * 70 | */ 71 | virtual ~HdCyclesBasisCurves(); 72 | 73 | /** 74 | * @brief Pull invalidated material data and prepare/update the core Cycles 75 | * representation. 76 | * 77 | * This must be thread safe. 78 | * 79 | * @param sceneDelegate The data source for the basis curve 80 | * @param renderParam State 81 | * @param dirtyBits Which bits of scene data has changed 82 | */ 83 | void Sync(HdSceneDelegate* sceneDelegate, HdRenderParam* renderParam, HdDirtyBits* dirtyBits, 84 | TfToken const& reprSelector) override; 85 | 86 | /** 87 | * @brief Inform the scene graph which state needs to be downloaded in 88 | * the first Sync() call 89 | * 90 | * @return The initial dirty state this basis curve wants to query 91 | */ 92 | HdDirtyBits GetInitialDirtyBitsMask() const override; 93 | 94 | /** 95 | * @return Return true if this light is valid. 96 | */ 97 | bool IsValid() const; 98 | 99 | /** 100 | * @brief Not Implemented 101 | */ 102 | void Finalize(HdRenderParam* renderParam) override; 103 | 104 | protected: 105 | /** 106 | * @brief Initialize the given representation of this Rprim. 107 | * This is called prior to syncing the prim. 108 | * 109 | * @param reprToken The name of the repr to initialize 110 | * @param dirtyBits In/Out dirty values 111 | */ 112 | void _InitRepr(TfToken const& reprToken, HdDirtyBits* dirtyBits) override; 113 | 114 | /** 115 | * @brief Set additional dirty bits 116 | * 117 | * @param bits 118 | * @return New value of dirty bits 119 | */ 120 | HdDirtyBits _PropagateDirtyBits(HdDirtyBits bits) const override; 121 | 122 | /** 123 | * @brief Add Color and arbitrary primvar attributes to curves 124 | * Specifically only uniform varying are supported with the Cycles API 125 | * This means vertex varying primvars are lossy and grabbed from the root. 126 | * 127 | * @param name Name of the color primvar 128 | * @param value VtValue holding data (floats-float4) 129 | * @param interpolation Interpolation of colors 130 | */ 131 | void _AddColors(TfToken name, VtValue value, HdInterpolation interpolation); 132 | 133 | /** 134 | * @brief Add UV specific attributes to curves. 135 | * Specifically only uniform varying are supported with the Cycles API 136 | * This means vertex varying uvs are lossy and grabbed from the root. 137 | * 138 | * @param name Name of the UV Set 139 | * @param uvs VtValue holding uvs 140 | * @param interpolation Interpolation of uvs 141 | */ 142 | void _AddUVS(TfToken name, VtValue uvs, HdInterpolation interpolation); 143 | 144 | void _PopulateMotion(HdSceneDelegate* sceneDelegate, const SdfPath& id); 145 | 146 | /** 147 | * @brief Populate generated coordinates for basisCurves 148 | * 149 | */ 150 | void _PopulateGenerated(); 151 | 152 | protected: 153 | VtVec3fArray m_points; 154 | VtVec3fArray m_normals; 155 | VtFloatArray m_widths; 156 | HdBasisCurvesTopology m_topology; 157 | HdInterpolation m_widthsInterpolation; 158 | VtIntArray m_indices; 159 | GfMatrix4f m_transform; 160 | 161 | unsigned int m_visibilityFlags; 162 | 163 | ccl::CurveShapeType m_curveShape; 164 | int m_curveResolution; 165 | 166 | ccl::vector m_usedShaders; 167 | 168 | private: 169 | /** 170 | * @brief Populate the Cycles mesh representation from delegate's data 171 | */ 172 | void _PopulateCurveMesh(HdRenderParam* renderParam); 173 | 174 | /** 175 | * @brief Manually create ribbon geometry for curves 176 | * 177 | * @param a_camera Optional camera to orient towards 178 | */ 179 | void _CreateRibbons(ccl::Camera* a_camera = nullptr); 180 | 181 | /** 182 | * @brief Manually create tube/bevelled geometry for curves 183 | * 184 | */ 185 | void _CreateTubeMesh(); 186 | 187 | /** 188 | * @brief Properly populate native cycles curves with curve data 189 | * 190 | * @param a_scene Scene to add to 191 | */ 192 | void _CreateCurves(ccl::Scene* a_scene); 193 | 194 | ccl::Mesh* m_cyclesMesh; 195 | ccl::Hair* m_cyclesHair; 196 | ccl::Geometry* m_cyclesGeometry; 197 | 198 | HdCyclesObjectSourceSharedPtr m_object_source; 199 | HdCyclesRenderDelegate* m_renderDelegate; 200 | }; 201 | 202 | class HdBbHairAttributeSource : public HdBbAttributeSource { 203 | public: 204 | HdBbHairAttributeSource(TfToken name, const TfToken& role, const VtValue& value, ccl::Hair* hair, 205 | const HdInterpolation& interpolation); 206 | }; 207 | 208 | PXR_NAMESPACE_CLOSE_SCOPE 209 | 210 | #endif // HD_CYCLES_BASIS_CURVES_H 211 | -------------------------------------------------------------------------------- /plugin/hdCycles/camera.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Tangent Animation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | // including without limitation, as related to merchantability and fitness 13 | // for a particular purpose. 14 | // 15 | // In no event shall any copyright holder be liable for any damages of any kind 16 | // arising from the use of this software, whether in contract, tort or otherwise. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | #ifndef HD_CYCLES_CAMERA_H 21 | #define HD_CYCLES_CAMERA_H 22 | 23 | #include "api.h" 24 | 25 | #include "hdcycles.h" 26 | 27 | #include 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | namespace ccl { 38 | class Camera; 39 | } 40 | 41 | PXR_NAMESPACE_OPEN_SCOPE 42 | 43 | class HdSceneDelegate; 44 | class HdCyclesRenderDelegate; 45 | 46 | /** 47 | * @brief Cycles Camera Sprim mapped to Cycles Camera 48 | * 49 | */ 50 | class HdCyclesCamera final : public HdCamera { 51 | public: 52 | /** 53 | * @brief Construct a new HdCycles Camera object 54 | * 55 | * @param id Path to the Camera Primitive 56 | */ 57 | HdCyclesCamera(SdfPath const& id, HdCyclesRenderDelegate* a_renderDelegate); 58 | virtual ~HdCyclesCamera(); 59 | 60 | /** 61 | * @brief Pull invalidated camera data and prepare/update the core Cycles 62 | * representation. 63 | * 64 | * This must be thread safe. 65 | * 66 | * @param sceneDelegate The data source for the mesh 67 | * @param renderParam State 68 | * @param dirtyBits Which bits of scene data has changed 69 | */ 70 | virtual void Sync(HdSceneDelegate* sceneDelegate, HdRenderParam* renderParam, HdDirtyBits* dirtyBits) override; 71 | 72 | /** 73 | * @brief Inform the scene graph which state needs to be downloaded in 74 | * the first Sync() call 75 | * 76 | * @return The initial dirty state this camera wants to query 77 | */ 78 | virtual HdDirtyBits GetInitialDirtyBitsMask() const override; 79 | 80 | /** 81 | * @return Return time sampled xforms that were quereied during Sync 82 | */ 83 | HdTimeSampleArray const& GetTimeSampleXforms() const 84 | { 85 | return m_transformSamples; 86 | } 87 | 88 | /** 89 | * @brief Get the HdCyclesCamera Aperture Size 90 | * 91 | * @param value Value of Aperture Size 92 | * @return Return true if found 93 | */ 94 | bool GetApertureSize(GfVec2f* value) const; 95 | 96 | /** 97 | * @brief Get the HdCyclesCamera Aperture Offset 98 | * 99 | * @param value Value of Aperture Offset 100 | * @return Return true if found 101 | */ 102 | bool GetApertureOffset(GfVec2f* value) const; 103 | 104 | /** 105 | * @brief Get the HdCyclesCamera Focal Lenth 106 | * 107 | * @param value Value of Focal Lenth 108 | * @return Return true if found 109 | */ 110 | bool GetFocalLength(float* value) const; 111 | 112 | /** 113 | * @brief Get the HdCyclesCamera FStop 114 | * 115 | * @param value Value of FStop 116 | * @return Return true if found 117 | */ 118 | bool GetFStop(float* value) const; 119 | 120 | /** 121 | * @brief Get the HdCyclesCamera Focus Distance 122 | * 123 | * @param value Value of Focus Distance 124 | * @return Return true if found 125 | */ 126 | bool GetFocusDistance(float* value) const; 127 | 128 | /** 129 | * @brief Get the HdCyclesCamera Shutter Open 130 | * 131 | * @param value Value of Shutter Open 132 | * @return Return true if found 133 | */ 134 | bool GetShutterOpen(double* value) const; 135 | 136 | /** 137 | * @brief Get the HdCyclesCamera Shutter Close 138 | * 139 | * @param value Value of Shutter Close 140 | * @return Return true if found 141 | */ 142 | bool GetShutterClose(double* value) const; 143 | 144 | /** 145 | * @brief Get the HdCyclesCamera Clipping Range 146 | * 147 | * @param value Value of Clipping Range 148 | * @return Return true if found 149 | */ 150 | bool GetClippingRange(GfRange1f* value) const; 151 | 152 | /** 153 | * @brief Get the HdCyclesCamera Projection Type 154 | * 155 | * @param value Value of Projection Type 156 | * @return Return true if found 157 | */ 158 | bool GetProjectionType(TfToken* value) const; 159 | 160 | /** 161 | * @brief Get the Cycles Camera object 162 | * 163 | * @return ccl::Camera* Camera 164 | */ 165 | ccl::Camera* GetCamera() { return m_cyclesCamera; } 166 | 167 | /** 168 | * @brief Set value of cycles field of view 169 | * 170 | * @param a_value FOV 171 | */ 172 | void SetFOV(const float& a_value); 173 | 174 | /** 175 | * @brief Set the transform based on projection matrix 176 | * 177 | * @param a_projectionMatrix 178 | */ 179 | void SetTransform(const GfMatrix4d a_projectionMatrix); 180 | 181 | /** 182 | * @brief Apply this cameras stored/synced settings 183 | * to the given cycles camera 184 | * 185 | * @param a_camera 186 | * @return Return true if sync has incurred an update 187 | */ 188 | bool ApplyCameraSettings(ccl::Camera* a_camera); 189 | 190 | const bool& IsDirty() { return m_needsUpdate; } 191 | 192 | private: 193 | float m_horizontalAperture; 194 | float m_verticalAperture; 195 | float m_horizontalApertureOffset; 196 | float m_verticalApertureOffset; 197 | float m_focalLength; 198 | float m_fStop; 199 | float m_focusDistance; 200 | double m_shutterOpen; 201 | double m_shutterClose; 202 | GfRange1f m_clippingRange; 203 | TfToken m_projectionType; 204 | 205 | GfMatrix4d m_projMtx; 206 | 207 | // Cycles camera specifics 208 | float m_fov; 209 | GfMatrix4d m_transform; 210 | float m_shutterTime; 211 | float m_rollingShutterTime; 212 | float m_apertureRatio; 213 | int m_blades; 214 | float m_bladesRotation; 215 | float m_apertureSize; 216 | 217 | int m_motionPosition; 218 | int m_rollingShutterType; 219 | int m_panoramaType; 220 | int m_stereoEye; 221 | float m_offscreenDicingScale; 222 | 223 | ccl::array m_shutterCurve; 224 | 225 | float m_fisheyeFov; 226 | float m_fisheyeLens; 227 | float m_latMin, m_latMax, m_longMin, m_longMax; 228 | bool m_useSphericalStereo; 229 | 230 | float m_interocularDistance; 231 | float m_convergenceDistance; 232 | bool m_usePoleMerge; 233 | float m_poleMergeAngleFrom, m_poleMergeAngleTo; 234 | 235 | bool m_useDof; 236 | 237 | bool m_useMotionBlur; 238 | float m_fps; 239 | 240 | HdTimeSampleArray m_transformSamples; 241 | 242 | ccl::Camera* m_cyclesCamera; 243 | 244 | HdCyclesRenderDelegate* m_renderDelegate; 245 | 246 | bool m_needsUpdate; 247 | }; 248 | 249 | PXR_NAMESPACE_CLOSE_SCOPE 250 | 251 | #endif // HD_CYCLES_CAMERA_H 252 | -------------------------------------------------------------------------------- /plugin/hdCycles/config.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Tangent Animation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | // including without limitation, as related to merchantability and fitness 13 | // for a particular purpose. 14 | // 15 | // In no event shall any copyright holder be liable for any damages of any kind 16 | // arising from the use of this software, whether in contract, tort or otherwise. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | #include "config.h" 21 | 22 | #include "points.h" 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | 30 | PXR_NAMESPACE_OPEN_SCOPE 31 | 32 | template<> HdCyclesEnvValue::HdCyclesEnvValue(const char* a_envName, bool a_default) 33 | { 34 | envName = std::string(a_envName); 35 | value = TfGetenvBool(envName, a_default); 36 | hasOverride = TfGetenv(envName) != ""; 37 | } 38 | 39 | template<> HdCyclesEnvValue::HdCyclesEnvValue(const char* a_envName, int a_default) 40 | { 41 | envName = std::string(a_envName); 42 | value = TfGetenvInt(envName, a_default); 43 | hasOverride = TfGetenv(envName) != ""; 44 | } 45 | 46 | template<> HdCyclesEnvValue::HdCyclesEnvValue(const char* a_envName, double a_default) 47 | { 48 | envName = std::string(a_envName); 49 | value = TfGetenvDouble(envName, a_default); 50 | hasOverride = TfGetenv(envName) != ""; 51 | } 52 | 53 | template<> HdCyclesEnvValue::HdCyclesEnvValue(const char* a_envName, float a_default) 54 | { 55 | envName = std::string(a_envName); 56 | value = static_cast(TfGetenvDouble(envName, static_cast(a_default))); 57 | hasOverride = TfGetenv(envName) != ""; 58 | } 59 | 60 | template<> HdCyclesEnvValue::HdCyclesEnvValue(const char* a_envName, std::string a_default) 61 | { 62 | envName = std::string(a_envName); 63 | value = TfGetenv(envName, a_default); 64 | hasOverride = TfGetenv(envName) != ""; 65 | } 66 | 67 | TF_INSTANTIATE_SINGLETON(HdCyclesConfig); 68 | 69 | /* ====== HdCycles Settings ====== */ 70 | 71 | // For distinct generic delegate settings we still use the pixar TF_DEFINE_ENV_SETTING 72 | 73 | TF_DEFINE_ENV_SETTING(CYCLES_ENABLE_LOGGING, false, "Enable HdCycles Logging") 74 | 75 | TF_DEFINE_ENV_SETTING(CYCLES_LOGGING_SEVERITY, 1, "Enable HdCycles progress reporting") 76 | 77 | TF_DEFINE_ENV_SETTING(CYCLES_DUMP_SHADER_GRAPH_DIR, "", "Valid, existing directory to dump shader graphs for render") 78 | 79 | TF_DEFINE_ENV_SETTING(HD_CYCLES_ENABLE_LOGGING, false, "Enable HdCycles Logging") 80 | 81 | TF_DEFINE_ENV_SETTING(HD_CYCLES_ENABLE_PROGRESS, false, "Enable HdCycles progress reporting") 82 | 83 | TF_DEFINE_ENV_SETTING(HD_CYCLES_USE_TILED_RENDERING, false, "Use Tiled Rendering (Experimental)") 84 | 85 | TF_DEFINE_ENV_SETTING(HD_CYCLES_UP_AXIS, "Z", "Set custom up axis (Z or Y currently supported)") 86 | 87 | // HdCycles Constructor 88 | HdCyclesConfig::HdCyclesConfig() 89 | { 90 | // -- Cycles Settings 91 | use_tiled_rendering = TfGetEnvSetting(HD_CYCLES_USE_TILED_RENDERING); 92 | 93 | cycles_enable_logging = TfGetEnvSetting(CYCLES_ENABLE_LOGGING); 94 | cycles_logging_severity = TfGetEnvSetting(CYCLES_LOGGING_SEVERITY); 95 | 96 | cycles_shader_graph_dump_dir = TfGetEnvSetting(CYCLES_DUMP_SHADER_GRAPH_DIR); 97 | 98 | // -- HdCycles Settings 99 | enable_logging = TfGetEnvSetting(HD_CYCLES_ENABLE_LOGGING); 100 | enable_progress = TfGetEnvSetting(HD_CYCLES_ENABLE_PROGRESS); 101 | 102 | up_axis = TfGetEnvSetting(HD_CYCLES_UP_AXIS); 103 | 104 | motion_blur = HdCyclesEnvValue("HD_CYCLES_MOTION_BLUR", true); 105 | enable_subdivision = HdCyclesEnvValue("HD_CYCLES_ENABLE_SUBDIVISION", false); 106 | subdivision_dicing_rate = HdCyclesEnvValue("HD_CYCLES_SUBDIVISION_DICING_RATE", 1.0); 107 | max_subdivision = HdCyclesEnvValue("HD_CYCLES_MAX_SUBDIVISION", 12); 108 | enable_dof = HdCyclesEnvValue("HD_CYCLES_ENABLE_DOF", true); 109 | 110 | render_width = HdCyclesEnvValue("HD_CYCLES_RENDER_WIDTH", 1280); 111 | render_height = HdCyclesEnvValue("HD_CYCLES_RENDER_HEIGHT", 720); 112 | use_old_curves = HdCyclesEnvValue("HD_CYCLES_USE_OLD_CURVES", false); 113 | 114 | enable_transparent_background = HdCyclesEnvValue("HD_CYCLES_USE_TRANSPARENT_BACKGROUND", false); 115 | use_square_samples = HdCyclesEnvValue("HD_CYCLES_USE_SQUARE_SAMPLES", false); 116 | 117 | // -- Cycles Settings 118 | enable_experimental = HdCyclesEnvValue("HD_CYCLES_ENABLE_EXPERIMENTAL", false); 119 | bvh_type = HdCyclesEnvValue("HD_CYCLES_BVH_TYPE", "DYNAMIC"); 120 | device_name = HdCyclesEnvValue("HD_CYCLES_DEVICE_NAME", "CPU"); 121 | shading_system = HdCyclesEnvValue("HD_CYCLES_SHADING_SYSTEM", "SVM"); 122 | display_buffer_linear = HdCyclesEnvValue("HD_CYCLES_DISPLAY_BUFFER_LINEAR", true); 123 | 124 | max_samples = HdCyclesEnvValue("HD_CYCLES_MAX_SAMPLES", 512); 125 | 126 | pixel_size = HdCyclesEnvValue("HD_CYCLES_PIXEL_SIZE", 1); 127 | tile_size_x = HdCyclesEnvValue("HD_CYCLES_TILE_SIZE_X", 64); 128 | tile_size_y = HdCyclesEnvValue("HD_CYCLES_TILE_SIZE_Y", 64); 129 | start_resolution = HdCyclesEnvValue("HD_CYCLES_START_RESOLUTION", 8); 130 | shutter_motion_position = HdCyclesEnvValue("HD_CYCLES_SHUTTER_MOTION_POSITION", 1); 131 | 132 | default_point_style = HdCyclesEnvValue("HD_CYCLES_DEFAULT_POINT_STYLE", ccl::POINT_CLOUD_POINT_SPHERE); 133 | default_point_resolution = HdCyclesEnvValue("HD_CYCLES_DEFAULT_POINT_RESOLUTION", 16); 134 | 135 | texture_use_cache = HdCyclesEnvValue("HD_BLACKBIRD_TEXTURE_USE_CACHE", false); 136 | texture_cache_size = HdCyclesEnvValue("HD_BLACKBIRD_TEXTURE_CACHE_SIZE", 4096); 137 | texture_tile_size = HdCyclesEnvValue("HD_BLACKBIRD_TEXTURE_TILE_SIZE", 64); 138 | texture_diffuse_blur = HdCyclesEnvValue("HD_BLACKBIRD_TEXTURE_DIFFUSE_BLUR", 1.0f / 64.0f); 139 | texture_glossy_blur = HdCyclesEnvValue("HD_BLACKBIRD_TEXTURE_GLOSSY_BLUR", 0.0f); 140 | texture_auto_convert = HdCyclesEnvValue("HD_BLACKBIRD_TEXTURE_AUTO_CONVERT", false); 141 | texture_accept_unmipped = HdCyclesEnvValue("HD_BLACKBIRD_TEXTURE_ACCEPT_UNMIPPED", false); 142 | texture_accept_untiled = HdCyclesEnvValue("HD_BLACKBIRD_TEXTURE_ACCEPT_UNTILED", false); 143 | texture_auto_tile = HdCyclesEnvValue("HD_BLACKBIRD_TEXTURE_AUTO_TILE", false); 144 | texture_auto_mip = HdCyclesEnvValue("HD_BLACKBIRD_TEXTURE_AUTO_MIP", false); 145 | texture_use_custom_path = HdCyclesEnvValue("HD_BLACKBIRD_TEXTURE_USE_CUSTOM_PATH", false); 146 | texture_custom_path = HdCyclesEnvValue("HD_BLACKBIRD_TEXTURE_CUSTOM_PATH", ""); 147 | texture_max_size = HdCyclesEnvValue("HD_BLACKBIRD_TEXTURE_MAX_SIZE", 0); 148 | 149 | // -- Curve Settings 150 | 151 | curve_subdivisions = HdCyclesEnvValue("HD_CYCLES_CURVE_SUBDIVISIONS", 3); 152 | 153 | // -- Film 154 | exposure = HdCyclesEnvValue("HD_CYCLES_EXPOSURE", 1.0); 155 | 156 | // -- Integrator Settings 157 | integrator_method = HdCyclesEnvValue("HD_CYCLES_INTEGRATOR_METHOD", "PATH"); 158 | 159 | diffuse_samples = HdCyclesEnvValue("HD_CYCLES_DIFFUSE_SAMPLES", 1); 160 | glossy_samples = HdCyclesEnvValue("HD_CYCLES_GLOSSY_SAMPLES", 1); 161 | transmission_samples = HdCyclesEnvValue("HD_CYCLES_TRANSMISSION_SAMPLES", 1); 162 | ao_samples = HdCyclesEnvValue("HD_CYCLES_AO_SAMPLES", 1); 163 | mesh_light_samples = HdCyclesEnvValue("HD_CYCLES_MESH_LIGHT_SAMPLES", 1); 164 | subsurface_samples = HdCyclesEnvValue("HD_CYCLES_SUBSURFACE_SAMPLES", 1); 165 | volume_samples = HdCyclesEnvValue("HD_CYCLES_VOLUME_SAMPLES", 1); 166 | adaptive_min_samples = HdCyclesEnvValue("HD_CYCLES_VOLUME_SAMPLES", 1); 167 | } 168 | 169 | const HdCyclesConfig& 170 | HdCyclesConfig::GetInstance() 171 | { 172 | return TfSingleton::GetInstance(); 173 | } 174 | 175 | PXR_NAMESPACE_CLOSE_SCOPE -------------------------------------------------------------------------------- /plugin/hdCycles/debug_codes.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Tangent Animation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | // including without limitation, as related to merchantability and fitness 13 | // for a particular purpose. 14 | // 15 | // In no event shall any copyright holder be liable for any damages of any kind 16 | // arising from the use of this software, whether in contract, tort or otherwise. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | // Usage of the debug codes follows Arnold's render delegate 21 | // https://github.com/Autodesk/arnold-usd/blob/11eb3ced2b6a148bb5737fddeb25e4e21273607f/render_delegate/ 22 | 23 | #include "debug_codes.h" 24 | 25 | #include 26 | 27 | PXR_NAMESPACE_OPEN_SCOPE 28 | 29 | TF_REGISTRY_FUNCTION(TfDebug) 30 | { 31 | TF_DEBUG_ENVIRONMENT_SYMBOL( 32 | HDCYCLES_MESH, "Print warnings when syncing cycles meshes"); 33 | } 34 | 35 | PXR_NAMESPACE_CLOSE_SCOPE -------------------------------------------------------------------------------- /plugin/hdCycles/debug_codes.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Tangent Animation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | // including without limitation, as related to merchantability and fitness 13 | // for a particular purpose. 14 | // 15 | // In no event shall any copyright holder be liable for any damages of any kind 16 | // arising from the use of this software, whether in contract, tort or otherwise. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | // Usage of the debug codes follows Arnold's render delegate 21 | // https://github.com/Autodesk/arnold-usd/blob/11eb3ced2b6a148bb5737fddeb25e4e21273607f/render_delegate/ 22 | 23 | #ifndef HD_CYCLES_DEBUG_CODES_H 24 | #define HD_CYCLES_DEBUG_CODES_H 25 | 26 | #include 27 | 28 | #include 29 | 30 | PXR_NAMESPACE_OPEN_SCOPE 31 | 32 | // clang-format off 33 | TF_DEBUG_CODES( 34 | HDCYCLES_MESH 35 | ) 36 | // clang-format on 37 | 38 | PXR_NAMESPACE_CLOSE_SCOPE 39 | 40 | #endif // HD_CYCLES_DEBUG_CODES_H -------------------------------------------------------------------------------- /plugin/hdCycles/hdcycles.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Tangent Animation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | // including without limitation, as related to merchantability and fitness 13 | // for a particular purpose. 14 | // 15 | // In no event shall any copyright holder be liable for any damages of any kind 16 | // arising from the use of this software, whether in contract, tort or otherwise. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | #ifndef HD_CYCLES_H 21 | #define HD_CYCLES_H 22 | 23 | static constexpr int HD_CYCLES_MOTION_STEPS = 3; 24 | static constexpr int HD_CYCLES_MAX_PRIMVAR_SAMPLES = 3; 25 | 26 | #endif // HD_CYCLES_H -------------------------------------------------------------------------------- /plugin/hdCycles/instancer.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Tangent Animation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | // including without limitation, as related to merchantability and fitness 13 | // for a particular purpose. 14 | // 15 | // In no event shall any copyright holder be liable for any damages of any kind 16 | // arising from the use of this software, whether in contract, tort or otherwise. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | #ifndef HD_CYCLES_INSTANCER_H 21 | #define HD_CYCLES_INSTANCER_H 22 | 23 | #include "hdcycles.h" 24 | 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | PXR_NAMESPACE_OPEN_SCOPE 35 | 36 | class HdSceneDelegate; 37 | 38 | /** 39 | * @brief Properly computes instance transforms for time varying data 40 | * Heavily inspired by ReadeonProRenderUSD's Instancer.cpp 41 | * 42 | */ 43 | class HdCyclesInstancer : public HdInstancer { 44 | public: 45 | HdCyclesInstancer(HdSceneDelegate* delegate, SdfPath const& id, SdfPath const& parentInstancerId) 46 | : HdInstancer(delegate, id, parentInstancerId) 47 | { 48 | } 49 | 50 | VtMatrix4dArray ComputeTransforms(SdfPath const& prototypeId); 51 | 52 | HdTimeSampleArray SampleInstanceTransforms(SdfPath const& prototypeId); 53 | 54 | private: 55 | void Sync(); 56 | 57 | VtMatrix4dArray m_transform; 58 | VtVec3fArray m_translate; 59 | VtVec4fArray m_rotate; 60 | VtVec3fArray m_scale; 61 | 62 | std::mutex m_syncMutex; 63 | }; 64 | 65 | PXR_NAMESPACE_CLOSE_SCOPE 66 | 67 | #endif // HD_CYCLES_INSTANCER_H 68 | -------------------------------------------------------------------------------- /plugin/hdCycles/light.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Tangent Animation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | // including without limitation, as related to merchantability and fitness 13 | // for a particular purpose. 14 | // 15 | // In no event shall any copyright holder be liable for any damages of any kind 16 | // arising from the use of this software, whether in contract, tort or otherwise. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | #ifndef HD_CYCLES_LIGHT_H 21 | #define HD_CYCLES_LIGHT_H 22 | 23 | #include "api.h" 24 | 25 | #include "renderDelegate.h" 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | #include 32 | 33 | namespace ccl { 34 | class Light; 35 | class Shader; 36 | class Scene; 37 | class BackgroundNode; 38 | class TextureCoordinateNode; 39 | class EnvironmentTextureNode; 40 | class EmissionNode; 41 | class BlackbodyNode; 42 | } // namespace ccl 43 | 44 | PXR_NAMESPACE_OPEN_SCOPE 45 | 46 | class HdSceneDelegate; 47 | class HdCyclesRenderParam; 48 | class HdCyclesRenderDelegate; 49 | 50 | /** 51 | * @brief Cycles Light Sprim mapped to Cycles Light 52 | * More work will be done here when the new light node network schema is released. 53 | * DomeLights/WorldMaterial is currently pretty hard coded, this will also be 54 | * unecessary with the new changes. 55 | * 56 | */ 57 | class HdCyclesLight final : public HdLight { 58 | public: 59 | /** 60 | * @brief Construct a new HdCycles Light object 61 | * 62 | * @param id Path to the Light Primitive 63 | * @param lightType Type of light to create 64 | * @param a_renderDelegate Associated Render Delegate 65 | * as a prototype 66 | */ 67 | HdCyclesLight(SdfPath const& id, TfToken const& lightType, HdCyclesRenderDelegate* a_renderDelegate); 68 | 69 | /** 70 | * @brief Destroy the HdCycles Light object 71 | * 72 | */ 73 | virtual ~HdCyclesLight(); 74 | 75 | /** 76 | * @brief Pull invalidated light data and prepare/update the core Cycles 77 | * representation. 78 | * 79 | * This must be thread safe. 80 | * 81 | * @param sceneDelegate The data source for the light 82 | * @param renderParam State 83 | * @param dirtyBits Which bits of scene data has changed 84 | */ 85 | void Sync(HdSceneDelegate* sceneDelegate, HdRenderParam* renderParam, HdDirtyBits* dirtyBits) override; 86 | 87 | /** 88 | * @brief Inform the scene graph which state needs to be downloaded in 89 | * the first Sync() call 90 | * 91 | * @return The initial dirty state this light wants to query 92 | */ 93 | HdDirtyBits GetInitialDirtyBitsMask() const override; 94 | 95 | /** 96 | * @return Return true if this light is valid. 97 | */ 98 | bool IsValid() const; 99 | 100 | /** 101 | * @brief TODO: Implement 102 | */ 103 | void Finalize(HdRenderParam* renderParam) override; 104 | 105 | private: 106 | // Tracking for Cycles light shader graphs, saves on potentially 107 | // expensive new/delete re-creation of graphs for interactive sessions. 108 | enum ShaderGraphBits : uint8_t { 109 | Default = 0, 110 | Temperature = 1 << 0, 111 | IES = 1 << 1, 112 | Texture = 1 << 2, 113 | All = (Temperature | IES | Texture) 114 | }; 115 | 116 | /** 117 | * @brief Create the cycles light representation 118 | * 119 | * @param id SceneDelegate id of light 120 | * @param renderParam HdCycles renderParam 121 | * @return New allocated pointer to ccl::Light 122 | */ 123 | void _CreateCyclesLight(SdfPath const& id, HdCyclesRenderParam* renderParam); 124 | 125 | /** 126 | * @brief Set transform of light and associate light types 127 | * 128 | * @param a_transform Transform to use 129 | */ 130 | void _SetTransform(const ccl::Transform& a_transform); 131 | 132 | /** 133 | * @brief Get default shader graph for lights 134 | * 135 | * @param isBackground Is the shader graph for the background shader 136 | * @return Newly allocated default shader graph 137 | */ 138 | ccl::ShaderGraph* _GetDefaultShaderGraph(const bool isBackground = false); 139 | 140 | /** 141 | * @brief Find first shader node based on type. 142 | * 143 | * @param graph ShaderGraph to search in 144 | * @param type The type of ShaderNode to search for 145 | * @return The first ShaderNode found based on type in graph 146 | */ 147 | ccl::ShaderNode* _FindShaderNode(const ccl::ShaderGraph* graph, const ccl::NodeType* type, 148 | const ccl::ustring name = ccl::ustring()); 149 | 150 | const TfToken m_hdLightType; 151 | ccl::Light* m_cyclesLight; 152 | ShaderGraphBits m_shaderGraphBits; 153 | 154 | HdCyclesRenderDelegate* m_renderDelegate; 155 | }; 156 | 157 | PXR_NAMESPACE_CLOSE_SCOPE 158 | 159 | #endif // HD_CYCLES_LIGHT_H 160 | -------------------------------------------------------------------------------- /plugin/hdCycles/material.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Tangent Animation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | // including without limitation, as related to merchantability and fitness 13 | // for a particular purpose. 14 | // 15 | // In no event shall any copyright holder be liable for any damages of any kind 16 | // arising from the use of this software, whether in contract, tort or otherwise. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | #ifndef HD_CYCLES_MATERIAL_H 21 | #define HD_CYCLES_MATERIAL_H 22 | 23 | #include "api.h" 24 | 25 | #include 26 | #include 27 | 28 | namespace ccl { 29 | class Object; 30 | class Shader; 31 | class ShaderNode; 32 | class ShaderGraph; 33 | } // namespace ccl 34 | 35 | PXR_NAMESPACE_OPEN_SCOPE 36 | 37 | // Terminal keys used in material networks. 38 | 39 | // clang-format off 40 | #define HD_CYCLES_MATERIAL_TERMINAL_TOKENS \ 41 | ((surface, "surface")) \ 42 | ((cyclesSurface, "cycles:surface")) \ 43 | ((displacement, "displacement")) \ 44 | ((cyclesDisplacement, "cycles:displacement")) \ 45 | ((volume, "volume")) \ 46 | ((cyclesVolume, "cycles:volume")) 47 | 48 | TF_DECLARE_PUBLIC_TOKENS(HdCyclesMaterialTerminalTokens, 49 | HD_CYCLES_MATERIAL_TERMINAL_TOKENS 50 | ); 51 | // clang-format on 52 | 53 | class HdSceneDelegate; 54 | class HdCyclesRenderDelegate; 55 | 56 | /** 57 | * @brief HdCycles Material Sprim mapped to Cycles Material 58 | * 59 | */ 60 | class HdCyclesMaterial final : public HdMaterial { 61 | public: 62 | /** 63 | * @brief Construct a new HdCycles Material 64 | * 65 | * @param id Path to the Material 66 | */ 67 | HdCyclesMaterial(SdfPath const& id, HdCyclesRenderDelegate* a_renderDelegate); 68 | 69 | /** 70 | * @brief Destroy the HdCycles Material 71 | * 72 | */ 73 | virtual ~HdCyclesMaterial(); 74 | 75 | /** 76 | * @brief Pull invalidated material data and prepare/update the core Cycles 77 | * representation. 78 | * 79 | * This must be thread safe. 80 | * 81 | * @param sceneDelegate The data source for the material 82 | * @param renderParam State 83 | * @param dirtyBits Which bits of scene data has changed 84 | */ 85 | void Sync(HdSceneDelegate* sceneDelegate, HdRenderParam* renderParam, HdDirtyBits* dirtyBits) override; 86 | 87 | /** 88 | * @brief Inform the scene graph which state needs to be downloaded in 89 | * the first Sync() call 90 | * 91 | * @return The initial dirty state this material wants to query 92 | */ 93 | HdDirtyBits GetInitialDirtyBitsMask() const override; 94 | 95 | /** 96 | * @brief Causes the shader to be reloaded 97 | * 98 | */ 99 | void Reload() 100 | #if PXR_MAJOR_VERSION > 19 101 | override 102 | #endif 103 | ; 104 | 105 | /** 106 | * @return Return true if this material is valid 107 | */ 108 | bool IsValid() const; 109 | 110 | /** 111 | * @brief Return the static list of tokens supported. 112 | * 113 | */ 114 | static TfTokenVector const& GetShaderSourceTypes(); 115 | 116 | /** 117 | * @brief Accessor for material's associated cycles shader 118 | * 119 | * @return ccl::Shader* cycles shader 120 | */ 121 | ccl::Shader* GetCyclesShader() const; 122 | 123 | protected: 124 | ccl::Shader* m_shader; 125 | ccl::ShaderGraph* m_shaderGraph; 126 | 127 | HdCyclesRenderDelegate* m_renderDelegate; 128 | 129 | void _FixPreviewShadersOutput(const std::vector& preview_shaders); 130 | }; 131 | 132 | PXR_NAMESPACE_CLOSE_SCOPE 133 | 134 | #endif // HD_CYCLES_MATERIAL_H 135 | -------------------------------------------------------------------------------- /plugin/hdCycles/mesh.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Tangent Animation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | // including without limitation, as related to merchantability and fitness 13 | // for a particular purpose. 14 | // 15 | // In no event shall any copyright holder be liable for any damages of any kind 16 | // arising from the use of this software, whether in contract, tort or otherwise. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | #ifndef HD_CYCLES_MESH_H 21 | #define HD_CYCLES_MESH_H 22 | 23 | #include "utils.h" 24 | 25 | #include "hdcycles.h" 26 | #include "meshRefiner.h" 27 | #include "objectSource.h" 28 | #include "rprim.h" 29 | 30 | #include 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | namespace ccl { 44 | class Scene; 45 | class Mesh; 46 | class Object; 47 | } // namespace ccl 48 | 49 | PXR_NAMESPACE_OPEN_SCOPE 50 | 51 | class HdCyclesRenderDelegate; 52 | class HdCyclesMeshRefiner; 53 | class HdCyclesRenderParam; 54 | 55 | /** 56 | * @brief HdCycles Mesh Rprim mapped to Cycles mesh 57 | * 58 | */ 59 | class HdCyclesMesh final : public HdBbRPrim { 60 | public: 61 | HF_MALLOC_TAG_NEW("new HdCyclesMesh") 62 | 63 | /** 64 | * @brief Construct a new HdCycles Mesh object 65 | * 66 | * @param id Path to the Mesh Primitive 67 | * @param instancerId If specified the HdInstancer at this id uses this mesh 68 | * as a prototype 69 | */ 70 | HdCyclesMesh(SdfPath const& id, SdfPath const& instancerId, HdCyclesRenderDelegate* a_renderDelegate); 71 | 72 | /** 73 | * @brief Destroy the HdCycles Mesh object 74 | * 75 | */ 76 | virtual ~HdCyclesMesh(); 77 | 78 | /** 79 | * @brief Inform the scene graph which state needs to be downloaded in 80 | * the first Sync() call 81 | * 82 | * @return The initial dirty state this mesh wants to query 83 | */ 84 | HdDirtyBits GetInitialDirtyBitsMask() const override; 85 | 86 | /** 87 | * @brief Pull invalidated mesh data and prepare/update the core Cycles 88 | * representation. 89 | * 90 | * This must be thread safe. 91 | * 92 | * @param sceneDelegate The data source for the mesh 93 | * @param renderParam State 94 | * @param dirtyBits Which bits of scene data has changed 95 | * @param reprToken Which representation to draw with 96 | */ 97 | void Sync(HdSceneDelegate* sceneDelegate, HdRenderParam* renderParam, HdDirtyBits* dirtyBits, 98 | TfToken const& reprToken) override; 99 | 100 | protected: 101 | void _InitializeNewCyclesMesh(); 102 | 103 | /** 104 | * @brief Create the cycles mesh representation 105 | * 106 | * @return New allocated pointer to ccl::Mesh 107 | */ 108 | ccl::Mesh* _CreateCyclesMesh(); 109 | 110 | /** 111 | * @brief Create the cycles object representation 112 | * 113 | * @return ccl::Object* 114 | */ 115 | ccl::Object* _CreateCyclesObject(); 116 | 117 | /** 118 | * @brief Perform final mesh computations (bounds, tangents, etc) 119 | * 120 | * @param scene 121 | */ 122 | void _FinishMesh(ccl::Scene* scene); 123 | 124 | /** 125 | * @brief Add abitrary uv set 126 | * 127 | * @param name 128 | * @param uvs 129 | * @param interpolation 130 | */ 131 | void _AddUVSet(const TfToken& name, const VtValue& uvs, ccl::Scene* scene, HdInterpolation interpolation); 132 | 133 | /** 134 | * @brief Add vertex/face normals (Not implemented) 135 | * 136 | * @param normals 137 | * @param interpolation 138 | */ 139 | 140 | /** 141 | * @brief Add vertex velocities 142 | * 143 | * @param velocities 144 | * @param interpolation 145 | */ 146 | void _AddVelocities(const SdfPath& id, const VtValue& value, HdInterpolation interpolation); 147 | 148 | 149 | /** 150 | * @brief Add vertex accelerations 151 | * 152 | * @param accelerations 153 | * @param interpolation 154 | */ 155 | void _AddAccelerations(const SdfPath& id, const VtValue& value, HdInterpolation interpolation); 156 | 157 | /** 158 | * @brief Add vertex/primitive colors 159 | * TODO: This handles more than just colors, we should probably refactor 160 | * 161 | * @param name 162 | * @param colors 163 | * @param scene 164 | * @param interpolation 165 | */ 166 | void _PopulateColors(const TfToken& name, const TfToken& role, const VtValue& data, ccl::Scene* scene, 167 | HdInterpolation interpolation, const SdfPath& id); 168 | 169 | private: 170 | struct PrimvarSource { 171 | VtValue data; 172 | HdInterpolation interpolation; 173 | }; 174 | TfHashMap _primvarSourceMap; 175 | 176 | /** 177 | * @brief Initialize the given representation of this Rprim. 178 | * This is called prior to syncing the prim. 179 | * 180 | * @param reprToken The name of the repr to initialize 181 | * @param dirtyBits In/Out dirty values 182 | */ 183 | void _InitRepr(TfToken const& reprToken, HdDirtyBits* dirtyBits) override; 184 | 185 | /** 186 | * @brief Set additional dirty bits 187 | * 188 | * @param bits 189 | * @return New value of dirty bits 190 | */ 191 | HdDirtyBits _PropagateDirtyBits(HdDirtyBits bits) const override; 192 | 193 | /** 194 | * @brief Do not allow this class to be copied 195 | * 196 | */ 197 | HdCyclesMesh(const HdCyclesMesh&) = delete; 198 | /** 199 | * @brief Do not allow this class to be assigned 200 | * 201 | */ 202 | HdCyclesMesh& operator=(const HdCyclesMesh&) = delete; 203 | 204 | /** 205 | * @brief Populate vertices of cycles mesh 206 | * 207 | */ 208 | 209 | void _PopulateMotion(HdSceneDelegate* sceneDelegate, const SdfPath& id); 210 | void _PopulateMotionAttributeVec3f(HdSceneDelegate* sceneDelegate, const SdfPath& id, const TfToken& token, 211 | const TfToken& role, const HdInterpolation& interpolation_refine, 212 | const HdInterpolation& interpolation, int cycles_motion_attribute, 213 | size_t n_expected_samples); 214 | 215 | void _PopulateTopology(HdSceneDelegate* sceneDelegate, const SdfPath& id); 216 | void _PopulateVertices(HdSceneDelegate* sceneDelegate, const SdfPath& id, HdDirtyBits* dirtyBits); 217 | void _PopulateNormals(HdSceneDelegate* sceneDelegate, const SdfPath& id); 218 | void _PopulateTangents(HdSceneDelegate* sceneDelegate, const SdfPath& id, ccl::Scene* scene); 219 | 220 | void _PopulateMaterials(HdSceneDelegate* sceneDelegate, HdCyclesRenderParam* renderParam, 221 | ccl::Shader* default_surface, const SdfPath& id); 222 | void _PopulateObjectMaterial(HdSceneDelegate* sceneDelegate, const SdfPath& id); 223 | void _PopulateSubSetsMaterials(HdSceneDelegate* sceneDelegate, const SdfPath& id); 224 | 225 | void _PopulatePrimvars(HdSceneDelegate* sceneDelegate, ccl::Scene* scene, const SdfPath& id, 226 | HdDirtyBits* dirtyBits); 227 | 228 | 229 | void _UpdateObject(ccl::Scene* scene, HdCyclesRenderParam* param, HdDirtyBits* dirtyBits, bool rebuildBvh); 230 | 231 | /** 232 | * @brief Populate generated coordinates attribute 233 | * 234 | */ 235 | void _PopulateGenerated(ccl::Scene* scene); 236 | 237 | enum DirtyBits : HdDirtyBits { 238 | DirtyTangents = HdChangeTracker::CustomBitsBegin, 239 | }; 240 | 241 | HdCyclesObjectSourceSharedPtr m_object_source; 242 | 243 | ccl::Mesh* m_cyclesMesh; 244 | std::vector m_cyclesInstances; 245 | 246 | ccl::Shader* m_object_display_color_shader; 247 | ccl::Shader* m_attrib_display_color_shader; 248 | 249 | HdTimeSampleArray m_transformSamples; 250 | 251 | int m_refineLevel; 252 | std::shared_ptr m_topology; 253 | bool m_useLimitSurfaceTangents; 254 | 255 | float m_velocityScale; 256 | 257 | std::vector m_texture_names; 258 | VtFloat3Array m_limit_us; 259 | VtFloat3Array m_limit_vs; 260 | 261 | HdCyclesRenderDelegate* m_renderDelegate; 262 | }; 263 | 264 | PXR_NAMESPACE_CLOSE_SCOPE 265 | 266 | #endif // HD_CYCLES_MESH_H 267 | -------------------------------------------------------------------------------- /plugin/hdCycles/meshRefiner.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Tangent Animation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | // including without limitation, as related to merchantability and fitness 13 | // for a particular purpose. 14 | // 15 | // In no event shall any copyright holder be liable for any damages of any kind 16 | // arising from the use of this software, whether in contract, tort or otherwise. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | #ifndef HDCYCLES_MESHREFINER_H 21 | #define HDCYCLES_MESHREFINER_H 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | 29 | #include 30 | 31 | namespace ccl { 32 | class Mesh; 33 | } 34 | 35 | PXR_NAMESPACE_OPEN_SCOPE 36 | 37 | using VtFloat3Array = VtArray; 38 | 39 | class HdDisplayStyle; 40 | class HdMeshTopology; 41 | class VtValue; 42 | class TfToken; 43 | class SdfPath; 44 | 45 | /// 46 | /// \brief Refines mesh to triangles 47 | /// 48 | /// Refiner's job is to prepare geometry for Cycles. That includes following requirements 49 | /// * topology refinement - triangulation 50 | //// * primvar refinement - data conversion to float and refinement 51 | /// 52 | class HdCyclesMeshRefiner { 53 | public: 54 | virtual ~HdCyclesMeshRefiner(); 55 | 56 | VtValue Refine(const TfToken& name, const TfToken& role, const VtValue& value, 57 | const HdInterpolation& interpolation) const; 58 | 59 | /// @{ \brief Refine/approximate primvar data. 60 | virtual VtValue RefineConstantData(const TfToken& name, const TfToken& role, const VtValue& data) const = 0; 61 | virtual VtValue RefineUniformData(const TfToken& name, const TfToken& role, const VtValue& data) const = 0; 62 | virtual VtValue RefineVaryingData(const TfToken& name, const TfToken& role, const VtValue& data) const = 0; 63 | virtual VtValue RefineVertexData(const TfToken& name, const TfToken& role, const VtValue& data) const = 0; 64 | virtual VtValue RefineFaceVaryingData(const TfToken& name, const TfToken& role, const VtValue& data) const = 0; 65 | /// @} 66 | 67 | const HdMeshTopology& GetTriangulatedTopology() const { return m_triangulated_topology; } 68 | 69 | virtual bool IsSubdivided() const = 0; 70 | 71 | virtual void EvaluateLimit(const VtFloat3Array& refined_vertices, VtFloat3Array& limit_ps, VtFloat3Array& limit_du, 72 | VtFloat3Array& limit_dv) const = 0; 73 | 74 | HdCyclesMeshRefiner(const HdCyclesMeshRefiner&) = delete; 75 | HdCyclesMeshRefiner(HdCyclesMeshRefiner&&) noexcept = delete; 76 | 77 | HdCyclesMeshRefiner& operator=(const HdCyclesMeshRefiner&) = delete; 78 | HdCyclesMeshRefiner& operator=(HdCyclesMeshRefiner&&) noexcept = delete; 79 | 80 | protected: 81 | HdCyclesMeshRefiner(); 82 | 83 | HdMeshTopology m_triangulated_topology; 84 | }; 85 | 86 | /// 87 | /// Hd Blackbird topology 88 | /// 89 | class HdBbMeshTopology : public HdMeshTopology { 90 | public: 91 | HdBbMeshTopology(const SdfPath& id, const HdMeshTopology& src, int refine_level); 92 | 93 | const SdfPath& GetId() const { return m_id; } 94 | const HdCyclesMeshRefiner* GetRefiner() const { return m_refiner.get(); } 95 | 96 | private: 97 | const SdfPath m_id; 98 | std::unique_ptr m_refiner; 99 | }; 100 | 101 | inline VtValue 102 | HdCyclesMeshRefiner::Refine(const TfToken& name, const TfToken& role, const VtValue& value, 103 | const HdInterpolation& interpolation) const 104 | { 105 | switch (interpolation) { 106 | case HdInterpolationConstant: return RefineConstantData(name, role, value); 107 | case HdInterpolationUniform: return RefineUniformData(name, role, value); 108 | case HdInterpolationVarying: return RefineVaryingData(name, role, value); 109 | case HdInterpolationVertex: return RefineVertexData(name, role, value); 110 | case HdInterpolationFaceVarying: return RefineFaceVaryingData(name, role, value); 111 | default: assert(0); return value; 112 | } 113 | } 114 | 115 | PXR_NAMESPACE_CLOSE_SCOPE 116 | 117 | #endif //HDCYCLES_MESHREFINER_H 118 | -------------------------------------------------------------------------------- /plugin/hdCycles/meshSource.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Tangent Animation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | // including without limitation, as related to merchantability and fitness 13 | // for a particular purpose. 14 | // 15 | // In no event shall any copyright holder be liable for any damages of any kind 16 | // arising from the use of this software, whether in contract, tort or otherwise. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | #include "meshSource.h" 21 | #include "meshRefiner.h" 22 | 23 | #include 24 | 25 | PXR_NAMESPACE_USING_DIRECTIVE 26 | 27 | namespace { 28 | 29 | ccl::AttributeElement 30 | interpolation_to_mesh_element(const HdInterpolation& interpolation) 31 | { 32 | switch (interpolation) { 33 | case HdInterpolationConstant: return ccl::AttributeElement::ATTR_ELEMENT_OBJECT; 34 | case HdInterpolationUniform: return ccl::AttributeElement::ATTR_ELEMENT_FACE; 35 | case HdInterpolationVarying: return ccl::AttributeElement::ATTR_ELEMENT_VERTEX; 36 | case HdInterpolationVertex: return ccl::AttributeElement::ATTR_ELEMENT_VERTEX; 37 | case HdInterpolationFaceVarying: return ccl::AttributeElement::ATTR_ELEMENT_CORNER; 38 | case HdInterpolationInstance: return ccl::AttributeElement::ATTR_ELEMENT_NONE; // not supported 39 | default: return ccl::AttributeElement::ATTR_ELEMENT_NONE; 40 | } 41 | } 42 | 43 | } // namespace 44 | 45 | HdBbMeshAttributeSource::HdBbMeshAttributeSource(TfToken name, const TfToken& role, const VtValue& value, 46 | ccl::Mesh* mesh, const HdInterpolation& interpolation, 47 | std::shared_ptr topology) 48 | : HdBbAttributeSource(std::move(name), role, value, &mesh->attributes, interpolation_to_mesh_element(interpolation), 49 | GetTypeDesc(HdGetValueTupleType(value).type, role)) 50 | , m_interpolation { interpolation } 51 | , m_topology { std::move(topology) } 52 | { 53 | } 54 | 55 | bool 56 | HdBbMeshAttributeSource::Resolve() 57 | { 58 | if (!_TryLock()) { 59 | return false; 60 | } 61 | 62 | // refine attribute 63 | const ccl::TypeDesc& source_type_desc = GetSourceTypeDesc(); 64 | const VtValue source_value = m_value; 65 | m_value = m_topology->GetRefiner()->Refine(GetName(), GetRole(source_type_desc), source_value, 66 | GetInterpolation()); 67 | 68 | // late size check, since it is only known after refining 69 | if (!_CheckBuffersSize()) { 70 | _SetResolveError(); 71 | return true; 72 | } 73 | 74 | bool resolved = HdBbAttributeSource::ResolveUnlocked(); 75 | 76 | // marked as finished 77 | _SetResolved(); 78 | return resolved; 79 | } 80 | 81 | bool 82 | HdBbMeshAttributeSource::_CheckValid() const 83 | { 84 | // size might be different because attribute could be refined 85 | 86 | if (!_CheckBuffersValid()) { 87 | return false; 88 | } 89 | 90 | // early exit on correct types 91 | if (_CheckBuffersType()) { 92 | return true; 93 | } 94 | 95 | TF_CODING_ERROR( 96 | "Attribute:%s is not going to be committed. Attribute has unknown type or can not be converted to known type!", 97 | m_name.data()); 98 | return false; // unsupported type 99 | } 100 | -------------------------------------------------------------------------------- /plugin/hdCycles/meshSource.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Tangent Animation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | // including without limitation, as related to merchantability and fitness 13 | // for a particular purpose. 14 | // 15 | // In no event shall any copyright holder be liable for any damages of any kind 16 | // arising from the use of this software, whether in contract, tort or otherwise. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | #ifndef HDBB_MESHSOURCE_H 21 | #define HDBB_MESHSOURCE_H 22 | 23 | #include "attributeSource.h" 24 | 25 | PXR_NAMESPACE_OPEN_SCOPE 26 | 27 | class HdBbMeshTopology; 28 | 29 | /// 30 | /// Blackbird Mesh attribute source 31 | /// 32 | class HdBbMeshAttributeSource : public HdBbAttributeSource { 33 | public: 34 | HdBbMeshAttributeSource(TfToken name, const TfToken& role, const VtValue& value, ccl::Mesh* mesh, 35 | const HdInterpolation& interpolation, std::shared_ptr topology); 36 | 37 | // Underlying VtValue has different size than ccl::Geometry, we have to accommodate for that. 38 | bool Resolve() override; 39 | const HdInterpolation& GetInterpolation() const { return m_interpolation; } 40 | 41 | private: 42 | bool _CheckValid() const override; 43 | 44 | HdInterpolation m_interpolation; 45 | std::shared_ptr m_topology; 46 | }; 47 | 48 | PXR_NAMESPACE_CLOSE_SCOPE 49 | 50 | #endif //HDCYCLES_MESHSOURCE_H 51 | -------------------------------------------------------------------------------- /plugin/hdCycles/objectSource.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Tangent Animation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | // including without limitation, as related to merchantability and fitness 13 | // for a particular purpose. 14 | // 15 | // In no event shall any copyright holder be liable for any damages of any kind 16 | // arising from the use of this software, whether in contract, tort or otherwise. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | #include "objectSource.h" 21 | 22 | #include 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | PXR_NAMESPACE_USING_DIRECTIVE 29 | 30 | HdCyclesObjectSource::HdCyclesObjectSource(ccl::Object* object, const SdfPath& id, bool isReference) 31 | : m_object { object } 32 | , m_id { id } 33 | , m_isReference { isReference } 34 | { 35 | m_object->name = ccl::ustring { m_id.GetToken().GetText(), m_id.GetToken().size() }; 36 | } 37 | 38 | HdCyclesObjectSource::~HdCyclesObjectSource() 39 | { 40 | if (!m_isReference) { 41 | assert(m_object != nullptr); 42 | delete m_object->geometry; 43 | delete m_object; 44 | } 45 | } 46 | 47 | bool 48 | HdCyclesObjectSource::Resolve() 49 | { 50 | if (!_TryLock()) { 51 | return false; 52 | } 53 | 54 | // TODO bind ot the scene? 55 | 56 | // marked as finished 57 | _SetResolved(); 58 | return true; 59 | } 60 | 61 | HdBbbObjectPropertiesSource* 62 | HdCyclesObjectSource::AddObjectPropertiesSource(HdBbbObjectPropertiesSourceSharedPtr source) 63 | { 64 | const TfToken& name = source->GetName(); 65 | m_pending_properties[name] = std::move(source); 66 | return m_pending_properties[name].get(); 67 | } 68 | 69 | HdBbAttributeSource* 70 | HdCyclesObjectSource::AddAttributeSource(HdBbAttributeSourceSharedPtr source) 71 | { 72 | const TfToken& name = source->GetName(); 73 | m_pending_attributes[name] = std::move(source); 74 | return m_pending_attributes[name].get(); 75 | } 76 | 77 | const TfToken& 78 | HdCyclesObjectSource::GetName() const 79 | { 80 | return m_id.GetToken(); 81 | } 82 | 83 | size_t 84 | HdCyclesObjectSource::ResolvePendingSources() 85 | { 86 | size_t num_resolved_sources = 0; 87 | 88 | for (auto& source : m_pending_properties) { 89 | if (!source.second->IsValid()) { 90 | continue; 91 | } 92 | if(source.second->IsResolved()) { 93 | continue; 94 | } 95 | source.second->Resolve(); 96 | ++num_resolved_sources; 97 | } 98 | 99 | // resolve pending sources 100 | for (auto& source : m_pending_attributes) { 101 | if (!source.second->IsValid()) { 102 | continue; 103 | } 104 | if(source.second->IsResolved()) { 105 | continue; 106 | } 107 | source.second->Resolve(); 108 | ++num_resolved_sources; 109 | } 110 | 111 | // cleanup sources right after the resolve 112 | m_pending_properties.clear(); 113 | m_pending_attributes.clear(); 114 | 115 | return num_resolved_sources; 116 | } 117 | -------------------------------------------------------------------------------- /plugin/hdCycles/objectSource.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Tangent Animation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | // including without limitation, as related to merchantability and fitness 13 | // for a particular purpose. 14 | // 15 | // In no event shall any copyright holder be liable for any damages of any kind 16 | // arising from the use of this software, whether in contract, tort or otherwise. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | #ifndef HDCYCLES_OBJECTSOURCE_H 21 | #define HDCYCLES_OBJECTSOURCE_H 22 | 23 | #include "attributeSource.h" 24 | #include "transformSource.h" 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | namespace ccl { 32 | class Object; 33 | class Scene; 34 | } // namespace ccl 35 | 36 | PXR_NAMESPACE_OPEN_SCOPE 37 | 38 | class SdfPath; 39 | 40 | /// 41 | /// 42 | /// 43 | class HdCyclesObjectSource : public HdBufferSource { 44 | public: 45 | explicit HdCyclesObjectSource(ccl::Object* object, const SdfPath& id, bool isReference = true); 46 | ~HdCyclesObjectSource() override; 47 | 48 | HdBbbObjectPropertiesSource* AddObjectPropertiesSource(HdBbbObjectPropertiesSourceSharedPtr source); 49 | 50 | /// Add new source to the pending sources list 51 | HdBbAttributeSource* AddAttributeSource(HdBbAttributeSourceSharedPtr source); 52 | 53 | /// Create new source, private attributes are going to be ignored and nullptr is returned 54 | template 55 | HdBbAttributeSource* CreateAttributeSource(const TfToken& name, Args&&... args) { 56 | const std::string& name_str = name.GetString(); 57 | if(name_str.find("__", 0) == 0){ 58 | return nullptr; 59 | } 60 | 61 | return AddAttributeSource(std::make_shared(name, std::forward(args)...)); 62 | } 63 | 64 | const ccl::Object* GetObject() const { return m_object; } 65 | ccl::Object* GetObject() { return m_object; } 66 | 67 | // TODO: Resolve binds object to the scene 68 | bool Resolve() override; 69 | size_t ResolvePendingSources(); 70 | 71 | const TfToken& GetName() const override; 72 | void GetBufferSpecs(HdBufferSpecVector* specs) const override {} 73 | const void* GetData() const override { return nullptr; } 74 | HdTupleType GetTupleType() const override { return HdTupleType {}; } 75 | size_t GetNumElements() const override { return 0; } 76 | 77 | protected: 78 | bool _CheckValid() const override { return m_object != nullptr; } 79 | 80 | ccl::Object* m_object; 81 | SdfPath m_id; 82 | bool m_isReference; 83 | 84 | TfHashMap m_pending_properties; 85 | TfHashMap m_pending_attributes; 86 | }; 87 | 88 | using HdCyclesObjectSourceSharedPtr = std::shared_ptr; 89 | 90 | PXR_NAMESPACE_CLOSE_SCOPE 91 | 92 | #endif //HDCYCLES_OBJECTSOURCE_H 93 | -------------------------------------------------------------------------------- /plugin/hdCycles/openvdb_asset.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Tangent Animation & Advanced Micro Devices 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | // including without limitation, as related to merchantability and fitness 13 | // for a particular purpose. 14 | // 15 | // In no event shall any copyright holder be liable for any damages of any kind 16 | // arising from the use of this software, whether in contract, tort or otherwise. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | 21 | #ifdef Houdini_FOUND 22 | # include 23 | #endif 24 | 25 | #include "openvdb_asset.h" 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | PXR_NAMESPACE_OPEN_SCOPE 32 | 33 | #ifdef Houdini_FOUND 34 | namespace { 35 | // This struct loads a vdb grid from Houdini memory by loading the USD_SopVol 36 | // This code uses a modified version AMD Radeon ProRender USD Hydra delegate HoudiniOpenvdbLoader. 37 | // Modified by using the USD native "ArchLibraryGetSymbolAddress" and returning a ConstPtr 38 | // to the grid instead of a raw pointer to GridBase. Nested in an anonymous namespace and 39 | // uses a struct instead of a singleton class. 40 | struct HoudiniVdbLoader { 41 | HoudiniVdbLoader() 42 | { 43 | auto hfs = std::getenv("HFS"); 44 | if (hfs) { 45 | auto lib_path = hfs + std::string("/houdini/dso/USD_SopVol") + ARCH_LIBRARY_SUFFIX; 46 | m_handle = ArchLibraryOpen(lib_path, ARCH_LIBRARY_LAZY); 47 | 48 | if (m_handle) { 49 | m_houdiniVdbLoadFunc = (houdiniVdbLoadFunc)ArchLibraryGetSymbolAddress(m_handle, 50 | "SOPgetVDBVolumePrimitive"); 51 | if (!m_houdiniVdbLoadFunc) { 52 | TF_RUNTIME_ERROR("USD_SopVol missing required symbol: SOPgetVDBVolumePrimitive"); 53 | } 54 | } else { 55 | auto err = ArchLibraryError(); 56 | if (err.empty()) { 57 | err = "Unable to open USD_SopVol library! Unkown Error!"; 58 | } 59 | TF_RUNTIME_ERROR("Failed to load USD_SopVol library: %s", err.c_str()); 60 | } 61 | } 62 | } 63 | 64 | openvdb::GridBase::ConstPtr getGrid(const char* file_path, const char* name) const 65 | { 66 | if (!m_houdiniVdbLoadFunc) { 67 | return nullptr; 68 | } 69 | auto vdbPrim = reinterpret_cast((*m_houdiniVdbLoadFunc)(file_path, name)); 70 | if (!vdbPrim) { 71 | return nullptr; 72 | } 73 | 74 | const auto* grid_base = vdbPrim->getGrid(); 75 | return grid_base ? grid_base->copyGrid() : nullptr; 76 | } 77 | 78 | ~HoudiniVdbLoader() 79 | { 80 | if (m_handle) { 81 | ArchLibraryClose(m_handle); 82 | } 83 | } 84 | 85 | private: 86 | void* m_handle = nullptr; 87 | typedef void* (*houdiniVdbLoadFunc)(const char* filepath, const char* name); 88 | houdiniVdbLoadFunc m_houdiniVdbLoadFunc = nullptr; 89 | }; 90 | 91 | static HoudiniVdbLoader houdiniVdbLoader; 92 | } // namespace 93 | #endif 94 | 95 | void 96 | HdCyclesVolumeLoader::UpdateGrid() 97 | { 98 | if (TF_VERIFY(!m_file_path.empty())) { 99 | try { 100 | #ifdef Houdini_FOUND 101 | if (grid) { 102 | grid.reset(); 103 | } 104 | 105 | // Load vdb grid from memory if the filepath is pointing to a houdini sop 106 | static std::string opPrefix("op:"); 107 | if (m_file_path.compare(0, opPrefix.size(), opPrefix) == 0) { 108 | this->grid = houdiniVdbLoader.getGrid(m_file_path.c_str(), grid_name.c_str()); 109 | } else { 110 | openvdb::io::File file(m_file_path); 111 | file.setCopyMaxBytes(0); 112 | file.open(); 113 | 114 | this->grid = file.readGrid(grid_name); 115 | } 116 | 117 | if (!grid) { 118 | TF_WARN("Vdb grid is empty!"); 119 | } 120 | #else 121 | openvdb::io::File file(m_file_path); 122 | file.setCopyMaxBytes(0); 123 | file.open(); 124 | 125 | if (grid) { 126 | grid.reset(); 127 | } 128 | 129 | this->grid = file.readGrid(grid_name); 130 | #endif 131 | } catch (const openvdb::IoError& e) { 132 | TF_RUNTIME_ERROR("Unable to load grid %s from file %s", grid_name.c_str(), m_file_path.c_str()); 133 | } catch (const std::exception& e) { 134 | TF_RUNTIME_ERROR("Error updating grid: %s", e.what()); 135 | } 136 | } else { 137 | TF_WARN("Volume file path is empty!"); 138 | } 139 | } 140 | 141 | HdCyclesOpenvdbAsset::HdCyclesOpenvdbAsset(HdCyclesRenderDelegate* a_delegate, const SdfPath& id) 142 | : HdField(id) 143 | { 144 | TF_UNUSED(a_delegate); 145 | } 146 | 147 | void 148 | HdCyclesOpenvdbAsset::Sync(HdSceneDelegate* a_sceneDelegate, HdRenderParam* a_renderParam, HdDirtyBits* a_dirtyBits) 149 | { 150 | TF_UNUSED(a_renderParam); 151 | if (*a_dirtyBits & HdField::DirtyParams) { 152 | auto& changeTracker = a_sceneDelegate->GetRenderIndex().GetChangeTracker(); 153 | // But accessing this list happens on a single thread, 154 | // as bprims are synced before rprims. 155 | for (const auto& volume : _volumeList) { 156 | changeTracker.MarkRprimDirty(volume, HdChangeTracker::DirtyTopology); 157 | } 158 | } 159 | *a_dirtyBits = HdField::Clean; 160 | } 161 | 162 | HdDirtyBits 163 | HdCyclesOpenvdbAsset::GetInitialDirtyBitsMask() const 164 | { 165 | return HdField::AllDirty; 166 | } 167 | 168 | // This will be called from multiple threads. 169 | void 170 | HdCyclesOpenvdbAsset::TrackVolumePrimitive(const SdfPath& id) 171 | { 172 | std::lock_guard lock(_volumeListMutex); 173 | _volumeList.insert(id); 174 | } 175 | 176 | PXR_NAMESPACE_CLOSE_SCOPE -------------------------------------------------------------------------------- /plugin/hdCycles/openvdb_asset.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Tangent Animation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | // including without limitation, as related to merchantability and fitness 13 | // for a particular purpose. 14 | // 15 | // In no event shall any copyright holder be liable for any damages of any kind 16 | // arising from the use of this software, whether in contract, tort or otherwise. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | #ifndef HD_CYCLES_OPENVDB_ASSET_H 21 | #define HD_CYCLES_OPENVDB_ASSET_H 22 | 23 | #include "api.h" 24 | #include 25 | 26 | #include "renderDelegate.h" 27 | #include 28 | 29 | #include 30 | #include 31 | 32 | #ifdef WITH_OPENVDB 33 | # include 34 | # include 35 | #endif 36 | 37 | PXR_NAMESPACE_OPEN_SCOPE 38 | 39 | #ifdef WITH_OPENVDB 40 | // Very temporary. Apparently Cycles has code to do this but it isnt in the head cycles standalone repo 41 | class HdCyclesVolumeLoader : public ccl::VDBImageLoader { 42 | public: 43 | HdCyclesVolumeLoader(const char* filepath, const char* grid_name_in) 44 | : ccl::VDBImageLoader(grid_name_in) 45 | , m_file_path(filepath) 46 | { 47 | UpdateGrid(); 48 | } 49 | 50 | void UpdateGrid(); 51 | 52 | void cleanup() override 53 | { 54 | # ifdef WITH_NANOVDB 55 | nanogrid.reset(); 56 | # endif 57 | } 58 | 59 | private: 60 | std::string m_file_path; 61 | }; 62 | #endif 63 | 64 | 65 | /// Utility class for translating Hydra Openvdb Asset to Cycles Volume. 66 | class HdCyclesOpenvdbAsset : public HdField { 67 | public: 68 | /// Constructor for HdCyclesOpenvdbAsset 69 | /// 70 | /// @param delegate Pointer to the Render Delegate. 71 | /// @param id Path to the OpenVDB Asset. 72 | HdCyclesOpenvdbAsset(HdCyclesRenderDelegate* delegate, const SdfPath& id); 73 | 74 | /// Syncing the Hydra Openvdb Asset to the Cycles Volume. 75 | /// 76 | /// The functions main purpose is to dirty every Volume primitive's 77 | /// topology, so the grid definitions on the volume can be rebuilt, since 78 | /// changing the the grid name on the openvdb asset doesn't dirty the 79 | /// volume primitive, which holds the cycles volume shape. 80 | /// 81 | /// @param sceneDelegate Pointer to the Hydra Scene Delegate. 82 | /// @param renderParam Pointer to a HdCyclesRenderParam instance. 83 | /// @param dirtyBits Dirty Bits to sync. 84 | void Sync(HdSceneDelegate* sceneDelegate, HdRenderParam* renderParam, HdDirtyBits* dirtyBits) override; 85 | 86 | /// Returns the initial Dirty Bits for the Primitive. 87 | /// 88 | /// @return Initial Dirty Bits. 89 | HdDirtyBits GetInitialDirtyBitsMask() const override; 90 | 91 | /// Tracks a HdCyclesVolume primitive. 92 | /// 93 | /// Hydra separates the volume definitions from the grids each volume 94 | /// requires, so we need to make sure each grid definition, which can be 95 | /// shared between multiple volumes, knows which volume it belongs to. 96 | /// 97 | /// @param id Path to the Hydra Volume. 98 | void TrackVolumePrimitive(const SdfPath& id); 99 | 100 | private: 101 | std::mutex _volumeListMutex; ///< Lock for the _volumeList. 102 | /// Storing all the Hydra Volumes using this asset. 103 | std::unordered_set _volumeList; 104 | }; 105 | 106 | PXR_NAMESPACE_CLOSE_SCOPE 107 | 108 | #endif // HD_CYCLES_OPENVDB_ASSET_H 109 | -------------------------------------------------------------------------------- /plugin/hdCycles/plugInfo.json: -------------------------------------------------------------------------------- 1 | { 2 | "Plugins": [ 3 | { 4 | "Info": { 5 | "Types": { 6 | "HdCyclesRendererPlugin": { 7 | "bases": [ 8 | "HdRendererPlugin" 9 | ], 10 | "displayName": "Cycles", 11 | "priority": 99 12 | } 13 | } 14 | }, 15 | "LibraryPath": "@PLUG_INFO_LIBRARY_PATH@", 16 | "Name": "hdCycles", 17 | "ResourcePath": "@PLUG_INFO_RESOURCE_PATH@", 18 | "Root": "@PLUG_INFO_ROOT@", 19 | "Type": "library" 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /plugin/hdCycles/points.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Tangent Animation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | // including without limitation, as related to merchantability and fitness 13 | // for a particular purpose. 14 | // 15 | // In no event shall any copyright holder be liable for any damages of any kind 16 | // arising from the use of this software, whether in contract, tort or otherwise. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | #ifndef HD_CYCLES_POINTS_H 21 | #define HD_CYCLES_POINTS_H 22 | 23 | #include "api.h" 24 | 25 | #include "hdcycles.h" 26 | #include "renderDelegate.h" 27 | #include "rprim.h" 28 | 29 | #include 30 | 31 | #include 32 | #include 33 | 34 | namespace ccl { 35 | class Object; 36 | class Mesh; 37 | class Scene; 38 | class PointCloud; 39 | class Shader; 40 | } // namespace ccl 41 | 42 | PXR_NAMESPACE_OPEN_SCOPE 43 | 44 | class HdSceneDelegate; 45 | class HdCyclesRenderDelegate; 46 | 47 | /** 48 | * @brief HdCycles Points Rprim mapped to Cycles point cloud or mesh instances 49 | * 50 | */ 51 | class HdCyclesPoints final : public HdBbRPrim { 52 | public: 53 | /** 54 | * @brief Construct a new HdCycles Point object 55 | * 56 | * @param id Path to the Point Primitive 57 | * @param instancerId If specified the HdInstancer at this id uses this curve 58 | * as a prototype 59 | */ 60 | HdCyclesPoints(SdfPath const& id, SdfPath const& instancerId, HdCyclesRenderDelegate* a_renderDelegate); 61 | /** 62 | * @brief Destroy the HdCycles Points object 63 | * 64 | */ 65 | virtual ~HdCyclesPoints(); 66 | 67 | /** 68 | * @brief Pull invalidated material data and prepare/update the core Cycles 69 | * representation. 70 | * 71 | * This must be thread safe. 72 | * 73 | * @param sceneDelegate The data source for the Point 74 | * @param renderParam State 75 | * @param dirtyBits Which bits of scene data has changed 76 | */ 77 | void Sync(HdSceneDelegate* sceneDelegate, HdRenderParam* renderParam, HdDirtyBits* dirtyBits, 78 | TfToken const& reprSelector) override; 79 | 80 | /** 81 | * @brief Inform the scene graph which state needs to be downloaded in 82 | * the first Sync() call 83 | * 84 | * @return The initial dirty state this Point wants to query 85 | */ 86 | HdDirtyBits GetInitialDirtyBitsMask() const override; 87 | 88 | /** 89 | * @return Return true if this light is valid. 90 | */ 91 | bool IsValid() const; 92 | 93 | /** 94 | * @brief Not Implemented 95 | */ 96 | void Finalize(HdRenderParam* renderParam) override; 97 | 98 | protected: 99 | /** 100 | * @brief Initialize the cycles objects and adds them to the scene 101 | */ 102 | void _InitializeNewCyclesPointCloud(); 103 | 104 | /** 105 | * @brief Reads various object flags before setting other geometric data 106 | */ 107 | void _ReadObjectFlags(HdSceneDelegate* sceneDelegate, const SdfPath& id, HdDirtyBits* dirtyBits); 108 | 109 | /** 110 | * @brief Fills in the point positions 111 | */ 112 | void _PopulatePoints(HdSceneDelegate* sceneDelegate, const SdfPath& id, bool styleHasChanged, bool& sizeHasChanged); 113 | 114 | /** 115 | * @brief Fill in the point widths 116 | */ 117 | void _PopulateWidths(HdSceneDelegate* sceneDelegate, const SdfPath& id, const HdInterpolation& interpolation, 118 | VtValue value); 119 | 120 | /** 121 | * @brief Fill in the point colors 122 | */ 123 | void _PopulateColors(HdSceneDelegate* sceneDelegate, const SdfPath& id, const HdInterpolation& interpolation, 124 | VtValue value); 125 | 126 | /** 127 | * @brief Fill in the point alpha 128 | */ 129 | void _PopulateOpacities(HdSceneDelegate* sceneDelegate, const SdfPath& id, const HdInterpolation& interpolation, 130 | VtValue value); 131 | 132 | /** 133 | * @brief Fill in the point normals 134 | */ 135 | void _PopulateNormals(HdSceneDelegate* sceneDelegate, const SdfPath& id, const HdInterpolation& interpolation, 136 | VtValue value); 137 | 138 | /** 139 | * @brief Fill in the point normals 140 | */ 141 | void _PopulateVelocities(HdSceneDelegate* sceneDelegate, const SdfPath& id, const HdInterpolation& interpolation, 142 | VtValue value); 143 | 144 | /** 145 | * @brief Fill in the point accelerations if velocities 146 | */ 147 | void _PopulateAccelerations(HdSceneDelegate* sceneDelegate, const SdfPath& id, const HdInterpolation& interpolation, 148 | VtValue value); 149 | 150 | 151 | /** 152 | * @brief Fills in the point positions 153 | */ 154 | void _PopulateGenerated(ccl::Scene* scene, const SdfPath& id); 155 | void _PopulateMaterial(HdSceneDelegate* sceneDelegate, HdCyclesRenderParam* renderParam, 156 | ccl::Shader* default_surface, const SdfPath& id); 157 | void _PopulateObjectMaterial(HdSceneDelegate* sceneDelegate, const SdfPath& id); 158 | 159 | /** 160 | * @brief Flag the object for update in the scene 161 | */ 162 | void _UpdateObject(ccl::Scene* scene, HdCyclesRenderParam* param, HdDirtyBits* dirtyBits, bool rebuildBVH = false); 163 | 164 | /** 165 | * @brief Initialize the given representation of this Rprim. 166 | * This is called prior to syncing the prim. 167 | * 168 | * @param reprToken The name of the repr to initialize 169 | * @param dirtyBits In/Out dirty values 170 | */ 171 | void _InitRepr(TfToken const& reprToken, HdDirtyBits* dirtyBits) override; 172 | 173 | /** 174 | * @brief Set additional dirty bits 175 | * 176 | * @param bits 177 | * @return New value of dirty bits 178 | */ 179 | HdDirtyBits _PropagateDirtyBits(HdDirtyBits bits) const override; 180 | 181 | private: 182 | /** 183 | * @brief Check that the combination of object attributes matches 184 | * the Cycles specification. If it doesn't, it notifies the user 185 | * and reverts the object to a state where it doesn't crash 186 | * the renderer internally. 187 | */ 188 | void _CheckIntegrity(HdCyclesRenderParam* param); 189 | 190 | ccl::PointCloud* m_cyclesPointCloud; 191 | 192 | ccl::Shader* m_point_display_color_shader; 193 | 194 | int m_pointResolution; // ? 195 | 196 | HdCyclesObjectSourceSharedPtr m_objectSource; 197 | HdCyclesRenderDelegate* m_renderDelegate; 198 | }; 199 | 200 | PXR_NAMESPACE_CLOSE_SCOPE 201 | 202 | #endif // HD_CYCLES_POINTS_H 203 | -------------------------------------------------------------------------------- /plugin/hdCycles/renderBuffer.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Tangent Animation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | // including without limitation, as related to merchantability and fitness 13 | // for a particular purpose. 14 | // 15 | // In no event shall any copyright holder be liable for any damages of any kind 16 | // arising from the use of this software, whether in contract, tort or otherwise. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | #ifndef HD_CYCLES_RENDER_BUFFER_H 21 | #define HD_CYCLES_RENDER_BUFFER_H 22 | 23 | #include "api.h" 24 | 25 | #include 26 | #include 27 | 28 | #include 29 | 30 | PXR_NAMESPACE_OPEN_SCOPE 31 | 32 | class HdCyclesRenderDelegate; 33 | 34 | /** 35 | * @brief Utility class for handling HdCycles Render Buffers 36 | * This handles 2d images for render output. 37 | * 38 | */ 39 | class HdCyclesRenderBuffer : public HdRenderBuffer { 40 | public: 41 | /** 42 | * @brief Construct a new HdCycles Render Buffer object 43 | * 44 | * @param id Path to the Render Buffer Primitive 45 | */ 46 | HdCyclesRenderBuffer(HdCyclesRenderDelegate* renderDelegate, const SdfPath& id); 47 | 48 | /** 49 | * @brief Destroy the HdCycles Render Buffer object 50 | * 51 | */ 52 | ~HdCyclesRenderBuffer() override; 53 | 54 | /** 55 | * @brief Allocates the memory used by the render buffer 56 | * 57 | * @param dimensions 3 Dimension Vector describing the dimensions of the 58 | * render buffer 59 | * @param format HdFormat specifying the format of the Render Buffer 60 | * @param multiSampled Bool to indicate if the Render Buffer is multisampled 61 | * @return Returns true if allocation was successful 62 | */ 63 | bool Allocate(const GfVec3i& dimensions, HdFormat format, bool multiSampled) override; 64 | 65 | /** 66 | * @return Returns the width of the render buffer 67 | */ 68 | unsigned int GetWidth() const override; 69 | 70 | /** 71 | * @return Returns the height of the render buffer 72 | */ 73 | unsigned int GetHeight() const override; 74 | 75 | /** 76 | * @return Returns the depth of the render buffer 77 | */ 78 | unsigned int GetDepth() const override; 79 | 80 | /** 81 | * @return Returns the format of the render buffer 82 | */ 83 | HdFormat GetFormat() const override; 84 | 85 | /** 86 | * @return Returns if the render buffer is multi-sampled 87 | */ 88 | bool IsMultiSampled() const override; 89 | 90 | /** 91 | * @brief Maps the render buffer to the system memory. 92 | * This returns the Cycles representation of data stored in _buffer 93 | * 94 | * @return Pointer to the render buffer mapped to system memory 95 | */ 96 | void* Map() override; 97 | 98 | /** 99 | * @brief Unmaps the render buffer by decrementing ref count. 100 | * TODO: Should this free memory? 101 | * 102 | * @return Unmap 103 | */ 104 | void Unmap() override; 105 | 106 | /** 107 | * @return Returns true if the render buffer is mapped to system memory 108 | */ 109 | bool IsMapped() const override; 110 | 111 | /** 112 | * @brief Resolve the buffer so that reads reflect the latest writes 113 | * This does nothing. 114 | */ 115 | void Resolve() override; 116 | 117 | /** 118 | * @return Returns true if the buffer is converged. 119 | */ 120 | bool IsConverged() const override; 121 | /** 122 | * @brief Set whether or not the buffer is Converged 123 | * 124 | * @param cv Is Converged 125 | */ 126 | void SetConverged(bool cv); 127 | 128 | void Clear(); 129 | 130 | void Finalize(HdRenderParam* renderParam) override; 131 | 132 | /** 133 | * @brief Helper to blit the render buffer data 134 | * 135 | * @param format Input format 136 | * @param width Width of buffer 137 | * @param height Height of buffer 138 | * @param offset Offset between pixels 139 | * @param stride Stride of pixel 140 | * @param data Pointer to data 141 | */ 142 | void BlitTile(HdFormat format, unsigned int x, unsigned int y, unsigned int width, unsigned int height, 143 | float width_data, float height_data, int offset, int stride, uint8_t const* data); 144 | 145 | protected: 146 | /** 147 | * @brief Deallocate memory allocated by the render buffer 148 | * TODO: Implement this 149 | */ 150 | void _Deallocate() override; 151 | 152 | private: 153 | unsigned int m_width; 154 | unsigned int m_height; 155 | HdFormat m_format; 156 | unsigned int m_pixelSize; 157 | 158 | std::vector m_buffer; 159 | std::atomic m_mappers; 160 | std::atomic m_converged; 161 | 162 | // Synchronizes resize with writes from cycles and 163 | // reads from hydra. Maybe it could be made more lightweight 164 | // with some assumptions on execution? 165 | std::mutex m_mutex; 166 | 167 | HdCyclesRenderDelegate* m_renderDelegate; 168 | }; 169 | 170 | PXR_NAMESPACE_CLOSE_SCOPE 171 | 172 | #endif // HD_CYCLES_RENDER_BUFFER_H 173 | -------------------------------------------------------------------------------- /plugin/hdCycles/renderPass.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Tangent Animation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | // including without limitation, as related to merchantability and fitness 13 | // for a particular purpose. 14 | // 15 | // In no event shall any copyright holder be liable for any damages of any kind 16 | // arising from the use of this software, whether in contract, tort or otherwise. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | #include "renderPass.h" 21 | 22 | #include "camera.h" 23 | #include "renderBuffer.h" 24 | #include "renderParam.h" 25 | #include "utils.h" 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | PXR_NAMESPACE_OPEN_SCOPE 37 | 38 | // clang-format off 39 | #ifdef __GNUC__ 40 | #pragma GCC diagnostic push 41 | #pragma GCC diagnostic ignored "-Wunused-variable" 42 | #endif 43 | TF_DEFINE_PRIVATE_TOKENS(_tokens, 44 | (color) 45 | (depth) 46 | ); 47 | #ifdef __GNUC__ 48 | #pragma GCC diagnostic pop 49 | #endif 50 | // clang-format on 51 | 52 | HdCyclesRenderPass::HdCyclesRenderPass(HdCyclesRenderDelegate* delegate, HdRenderIndex* index, 53 | HdRprimCollection const& collection) 54 | : HdRenderPass(index, collection) 55 | , m_delegate(delegate) 56 | { 57 | } 58 | 59 | HdCyclesRenderPass::~HdCyclesRenderPass() {} 60 | 61 | void 62 | HdCyclesRenderPass::_Execute(HdRenderPassStateSharedPtr const& renderPassState, TfTokenVector const& renderTags) 63 | { 64 | auto* renderParam = reinterpret_cast(m_delegate->GetRenderParam()); 65 | 66 | // Update convergence status. Cycles will stop blitting once rendering has finished, 67 | // but this is needed to let Hydra and the viewport know. 68 | m_isConverged = renderParam->IsConverged(); 69 | 70 | // Update the Cycles render passes with the new aov bindings if they have changed 71 | // Do not reset the session yet 72 | HdRenderPassAovBindingVector aovBindings = renderPassState->GetAovBindings(); 73 | const bool aovBindingsHaveChanged = renderParam->GetAovBindings() != aovBindings; 74 | if (aovBindingsHaveChanged) { 75 | renderParam->SetAovBindings(aovBindings); 76 | } 77 | 78 | // TODO: Revisit this code and move it to HdCyclesRenderPassState 79 | bool shouldUpdate = false; 80 | auto hdCam = const_cast(dynamic_cast(renderPassState->GetCamera())); 81 | if (hdCam) { 82 | GfMatrix4d projMtx = renderPassState->GetProjectionMatrix(); 83 | GfMatrix4d viewMtx = renderPassState->GetWorldToViewMatrix(); 84 | 85 | ccl::Camera* active_camera = renderParam->GetCyclesSession()->scene->camera; 86 | 87 | if (projMtx != m_projMtx || viewMtx != m_viewMtx) { 88 | m_projMtx = projMtx; 89 | m_viewMtx = viewMtx; 90 | 91 | const float fov_rad = atanf(1.0f / static_cast(m_projMtx[1][1])) * 2.0f; 92 | hdCam->SetFOV(fov_rad); 93 | 94 | shouldUpdate = true; 95 | } 96 | 97 | if (!shouldUpdate) { 98 | shouldUpdate = hdCam->IsDirty(); 99 | } 100 | 101 | if (shouldUpdate) { 102 | hdCam->ApplyCameraSettings(active_camera); 103 | 104 | // Needed for now, as houdini looks through a generated camera 105 | // and doesn't copy the projection type (as of 18.0.532) 106 | bool is_ortho = round(m_projMtx[3][3]) == 1.0; 107 | 108 | if (is_ortho) { 109 | active_camera->type = ccl::CameraType::CAMERA_ORTHOGRAPHIC; 110 | } else 111 | active_camera->type = ccl::CameraType::CAMERA_PERSPECTIVE; 112 | 113 | active_camera->tag_update(); 114 | 115 | // DirectReset here instead of Interrupt for faster IPR camera orbits 116 | renderParam->DirectReset(); 117 | } 118 | } 119 | 120 | // Resetting the Cycles session if the viewport size or AOV bindings changed 121 | const GfVec4f& viewport = renderPassState->GetViewport(); 122 | const auto width = static_cast(viewport[2]); 123 | const auto height = static_cast(viewport[3]); 124 | 125 | if (width != m_width || height != m_height) { 126 | m_width = width; 127 | m_height = height; 128 | 129 | // TODO: Due to the startup flow of Cycles, this gets called after a tiled render 130 | // has already started. Sometimes causing the original tiled render to complete 131 | // before actually rendering at the appropriate size. This seems to be a Cycles 132 | // issue, however the startup flow of HdCycles has LOTS of room for improvement... 133 | renderParam->SetViewport(m_width, m_height); 134 | 135 | // TODO: This is very hacky... But stops the tiled render double render issue... 136 | if (renderParam->IsTiledRender()) { 137 | renderParam->StartRender(); 138 | } 139 | 140 | renderParam->Interrupt(); 141 | } else if (aovBindingsHaveChanged) { 142 | renderParam->DirectReset(); 143 | renderParam->Interrupt(); 144 | } 145 | } 146 | 147 | PXR_NAMESPACE_CLOSE_SCOPE 148 | -------------------------------------------------------------------------------- /plugin/hdCycles/renderPass.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Tangent Animation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | // including without limitation, as related to merchantability and fitness 13 | // for a particular purpose. 14 | // 15 | // In no event shall any copyright holder be liable for any damages of any kind 16 | // arising from the use of this software, whether in contract, tort or otherwise. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | #ifndef HD_CYCLES_RENDER_PASS_H 21 | #define HD_CYCLES_RENDER_PASS_H 22 | 23 | #include "api.h" 24 | 25 | #include "renderDelegate.h" 26 | 27 | #include 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | PXR_NAMESPACE_OPEN_SCOPE 34 | 35 | class HdCyclesRenderDelegate; 36 | 37 | /** 38 | * @brief Represents a single render iteration. rendering a view of the scene 39 | * (HdRprimCollection) for a specific viewer (camera/viewport params in 40 | * HdRenderPassState) to the current draw target. 41 | * 42 | */ 43 | class HdCyclesRenderPass final : public HdRenderPass { 44 | public: 45 | /** 46 | * @brief Construct a new HdCycles Render Pass object 47 | * 48 | * @param delegate 49 | * @param index The render index containing scene data to render 50 | * @param collection Initial rprim collection for this render pass 51 | */ 52 | HdCyclesRenderPass(HdCyclesRenderDelegate* delegate, HdRenderIndex* index, HdRprimCollection const& collection); 53 | 54 | /** 55 | * @brief Destroy the HdCycles Render Pass object 56 | * 57 | */ 58 | virtual ~HdCyclesRenderPass(); 59 | 60 | protected: 61 | /** 62 | * @brief Draw the scene with the bound renderpass state 63 | * 64 | * @param renderPassState Input parameters 65 | * @param renderTags Which render tags should be drawn this pass 66 | */ 67 | void _Execute(HdRenderPassStateSharedPtr const& renderPassState, TfTokenVector const& renderTags) override; 68 | 69 | bool IsConverged() const override { return m_isConverged; } 70 | 71 | protected: 72 | HdCyclesRenderDelegate* m_delegate; 73 | 74 | GfMatrix4d m_projMtx; 75 | GfMatrix4d m_viewMtx; 76 | 77 | public: 78 | int m_width = 0; 79 | int m_height = 0; 80 | 81 | bool m_isConverged = false; 82 | }; 83 | 84 | PXR_NAMESPACE_CLOSE_SCOPE 85 | 86 | #endif // HD_CYCLES_RENDER_PASS_H 87 | -------------------------------------------------------------------------------- /plugin/hdCycles/renderPassState.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Tangent Animation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | // including without limitation, as related to merchantability and fitness 13 | // for a particular purpose. 14 | // 15 | // In no event shall any copyright holder be liable for any damages of any kind 16 | // arising from the use of this software, whether in contract, tort or otherwise. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | #include "renderPassState.h" 21 | #include "camera.h" 22 | #include "resourceRegistry.h" 23 | 24 | PXR_NAMESPACE_USING_DIRECTIVE 25 | 26 | HdCyclesRenderPassState::HdCyclesRenderPassState(const HdCyclesRenderDelegate* renderDelegate) 27 | : m_renderDelegate { renderDelegate } 28 | { 29 | } 30 | 31 | void 32 | HdCyclesRenderPassState::Prepare(const HdResourceRegistrySharedPtr& resourceRegistry) 33 | { 34 | HdCyclesResourceRegistry* registry = dynamic_cast(resourceRegistry.get()); 35 | if (!registry) { 36 | return; 37 | } 38 | 39 | // TODO: Resource registry is a shared pointer that is const, but the pointer held is not const! 40 | // We can continue committing camera changes from here. That means no need to cast away const correctness 41 | // for the camera. The camera render parameters are set through HdxRenderSetupTask::PrepareCamera. 42 | // All code related to camera update should be moved here, and committed to resource registry as pending 43 | // source. 44 | } 45 | -------------------------------------------------------------------------------- /plugin/hdCycles/renderPassState.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Tangent Animation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | // including without limitation, as related to merchantability and fitness 13 | // for a particular purpose. 14 | // 15 | // In no event shall any copyright holder be liable for any damages of any kind 16 | // arising from the use of this software, whether in contract, tort or otherwise. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | #ifndef HDCYCLES_RENDERPASSSTATE_H 21 | #define HDCYCLES_RENDERPASSSTATE_H 22 | 23 | #include 24 | 25 | PXR_NAMESPACE_OPEN_SCOPE 26 | 27 | class HdCyclesRenderDelegate; 28 | 29 | class HdCyclesRenderPassState : public HdRenderPassState { 30 | public: 31 | explicit HdCyclesRenderPassState(const HdCyclesRenderDelegate* renderDelegate); 32 | 33 | void Prepare(const HdResourceRegistrySharedPtr& resourceRegistry) override; 34 | 35 | private: 36 | const HdCyclesRenderDelegate* m_renderDelegate; 37 | }; 38 | 39 | using HdCyclesRenderPassStateSharedPtr = std::shared_ptr; 40 | 41 | PXR_NAMESPACE_CLOSE_SCOPE 42 | 43 | #endif //HDCYCLES_RENDERPASSSTATE_H 44 | -------------------------------------------------------------------------------- /plugin/hdCycles/rendererPlugin.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Tangent Animation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | // including without limitation, as related to merchantability and fitness 13 | // for a particular purpose. 14 | // 15 | // In no event shall any copyright holder be liable for any damages of any kind 16 | // arising from the use of this software, whether in contract, tort or otherwise. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | #include "rendererPlugin.h" 21 | #include "renderDelegate.h" 22 | 23 | #include 24 | 25 | PXR_NAMESPACE_OPEN_SCOPE 26 | 27 | // Register the plugin with the renderer plugin system. 28 | TF_REGISTRY_FUNCTION(TfType) { HdRendererPluginRegistry::Define(); } 29 | 30 | HdCyclesRendererPlugin::HdCyclesRendererPlugin() {} 31 | 32 | HdCyclesRendererPlugin::~HdCyclesRendererPlugin() {} 33 | 34 | HdRenderDelegate* 35 | HdCyclesRendererPlugin::CreateRenderDelegate() 36 | { 37 | return new HdCyclesRenderDelegate(); 38 | } 39 | 40 | HdRenderDelegate* 41 | HdCyclesRendererPlugin::CreateRenderDelegate(HdRenderSettingsMap const& settingsMap) 42 | { 43 | return new HdCyclesRenderDelegate(settingsMap); 44 | } 45 | 46 | void 47 | HdCyclesRendererPlugin::DeleteRenderDelegate(HdRenderDelegate* renderDelegate) 48 | { 49 | delete renderDelegate; 50 | } 51 | 52 | bool 53 | HdCyclesRendererPlugin::IsSupported() const 54 | { 55 | return true; 56 | } 57 | 58 | PXR_NAMESPACE_CLOSE_SCOPE 59 | -------------------------------------------------------------------------------- /plugin/hdCycles/rendererPlugin.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Tangent Animation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | // including without limitation, as related to merchantability and fitness 13 | // for a particular purpose. 14 | // 15 | // In no event shall any copyright holder be liable for any damages of any kind 16 | // arising from the use of this software, whether in contract, tort or otherwise. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | #ifndef HD_CYCLES_RENDERER_PLUGIN_H 21 | #define HD_CYCLES_RENDERER_PLUGIN_H 22 | 23 | #include "api.h" 24 | 25 | #include 26 | #include 27 | 28 | PXR_NAMESPACE_OPEN_SCOPE 29 | 30 | /** 31 | * @brief First entry point into HdCycles. 32 | * Allows for the creation and deletion of the core 33 | * render delegate classes. 34 | * 35 | */ 36 | class HdCyclesRendererPlugin final : public HdRendererPlugin { 37 | public: 38 | /** 39 | * @brief Use default constructor 40 | * 41 | */ 42 | HdCyclesRendererPlugin(); 43 | 44 | /** 45 | * @brief Use default destructor 46 | * 47 | */ 48 | ~HdCyclesRendererPlugin() override; 49 | 50 | /** 51 | * @brief Construct a new render delegate of type HdCyclesRenderDelegate 52 | * 53 | * @return Created Render Delegate 54 | */ 55 | HdRenderDelegate* CreateRenderDelegate() override; 56 | 57 | HdRenderDelegate* CreateRenderDelegate(HdRenderSettingsMap const& settingsMap) override; 58 | 59 | /** 60 | * @brief Destroy a render delegate created by this class 61 | * 62 | * @param renderDelegate The render delegate to delete 63 | * @return 64 | */ 65 | void DeleteRenderDelegate(HdRenderDelegate* renderDelegate) override; 66 | 67 | /** 68 | * @brief Checks to see if the plugin is supported on the running system 69 | * 70 | */ 71 | bool IsSupported() const override; 72 | 73 | private: 74 | /** 75 | * @brief This class does not support copying 76 | * 77 | */ 78 | HdCyclesRendererPlugin(const HdCyclesRendererPlugin&) = delete; 79 | HdCyclesRendererPlugin& operator=(const HdCyclesRendererPlugin&) = delete; 80 | }; 81 | 82 | PXR_NAMESPACE_CLOSE_SCOPE 83 | 84 | #endif // HD_CYCLES_RENDERER_PLUGIN_H 85 | -------------------------------------------------------------------------------- /plugin/hdCycles/resourceRegistry.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Tangent Animation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | // including without limitation, as related to merchantability and fitness 13 | // for a particular purpose. 14 | // 15 | // In no event shall any copyright holder be liable for any damages of any kind 16 | // arising from the use of this software, whether in contract, tort or otherwise. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | #include "resourceRegistry.h" 21 | #include "renderDelegate.h" 22 | #include "renderParam.h" 23 | 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | 30 | PXR_NAMESPACE_USING_DIRECTIVE 31 | 32 | HdCyclesResourceRegistry::HdCyclesResourceRegistry(HdCyclesRenderDelegate* renderDelegate) 33 | : m_renderDelegate { renderDelegate } 34 | { 35 | } 36 | 37 | void 38 | HdCyclesResourceRegistry::_Commit() 39 | { 40 | // This function is under heavy wip. In ideal situation committing all resources to cycles should happen in one 41 | // place only. 42 | 43 | auto scene = m_renderDelegate->GetCyclesRenderParam()->GetCyclesScene(); 44 | ccl::thread_scoped_lock scene_lock { scene->mutex }; 45 | // TODO: acquire display lock 46 | 47 | // State used to control session/scene update reset 48 | std::atomic_bool requires_reset { false }; 49 | 50 | // * bind objects to the scene 51 | for (auto& object_source : m_objects) { 52 | if (!object_source.second.value->IsValid()) { 53 | continue; 54 | } 55 | 56 | if (object_source.second.value->IsResolved()) { 57 | continue; 58 | } 59 | 60 | object_source.second.value->Resolve(); 61 | } 62 | 63 | // * commit all pending object resources 64 | using ValueType = HdInstanceRegistry::const_iterator::value_type; 65 | WorkParallelForEach(m_objects.begin(), m_objects.end(), [&requires_reset, scene](const ValueType& object_source) { 66 | // resolve per object 67 | size_t num_resolved_sources = object_source.second.value->ResolvePendingSources(); 68 | if (num_resolved_sources > 0) { 69 | requires_reset = true; 70 | } 71 | }); 72 | 73 | // * notify session that new resources have been committed and reset is required 74 | if (requires_reset) { 75 | // TODO: After we are done removing scene and session mutations from *::Sync. We can request update and reset 76 | } 77 | } 78 | 79 | void 80 | HdCyclesResourceRegistry::_GarbageCollect() 81 | { 82 | auto scene = m_renderDelegate->GetCyclesRenderParam()->GetCyclesScene(); 83 | ccl::thread_scoped_lock scene_lock { scene->mutex }; 84 | 85 | // delete unique objects 86 | m_objects.GarbageCollect(); 87 | } 88 | 89 | HdInstance 90 | HdCyclesResourceRegistry::GetObjectInstance(const SdfPath& id) 91 | { 92 | return m_objects.GetInstance(id.GetHash()); 93 | } 94 | -------------------------------------------------------------------------------- /plugin/hdCycles/resourceRegistry.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Tangent Animation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | // including without limitation, as related to merchantability and fitness 13 | // for a particular purpose. 14 | // 15 | // In no event shall any copyright holder be liable for any damages of any kind 16 | // arising from the use of this software, whether in contract, tort or otherwise. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | #ifndef HDCYCLES_RESOURCEREGISTRY_H 21 | #define HDCYCLES_RESOURCEREGISTRY_H 22 | 23 | #include "objectSource.h" 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | namespace ccl { 32 | class Scene; 33 | } 34 | 35 | PXR_NAMESPACE_OPEN_SCOPE 36 | 37 | class HdCyclesRenderDelegate; 38 | 39 | class HdCyclesResourceRegistry final : public HdResourceRegistry { 40 | public: 41 | explicit HdCyclesResourceRegistry(HdCyclesRenderDelegate* renderDelegate); 42 | 43 | HdInstance GetObjectInstance(const SdfPath& id); 44 | 45 | private: 46 | void _Commit() override; 47 | void _GarbageCollect() override; 48 | 49 | HdCyclesRenderDelegate* m_renderDelegate; 50 | HdInstanceRegistry m_objects; 51 | }; 52 | 53 | using HdCyclesResourceRegistrySharedPtr = std::shared_ptr; 54 | 55 | PXR_NAMESPACE_CLOSE_SCOPE 56 | 57 | #endif //HDCYCLES_RESOURCEREGISTRY_H 58 | -------------------------------------------------------------------------------- /plugin/hdCycles/rprim.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Tangent Animation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | // including without limitation, as related to merchantability and fitness 13 | // for a particular purpose. 14 | // 15 | // In no event shall any copyright holder be liable for any damages of any kind 16 | // arising from the use of this software, whether in contract, tort or otherwise. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | 21 | #ifndef HDBLACKBIRD_RPRIM_H 22 | #define HDBLACKBIRD_RPRIM_H 23 | 24 | #include 25 | 26 | #include 27 | 28 | #include 29 | 30 | #include 31 | 32 | PXR_NAMESPACE_OPEN_SCOPE 33 | 34 | template class HdBbRPrim : public T { 35 | public: 36 | static_assert(!std::is_base_of::value, "HdBbRPrim must wrap HdRPrim class"); 37 | 38 | using HdPrimvarDescriptorMap = std::map; 39 | 40 | protected: 41 | HdBbRPrim(SdfPath const& id, SdfPath const& instancerId) 42 | : T { id, instancerId } 43 | , m_cyclesObject { nullptr } 44 | , m_visibilityFlags { ccl::PATH_RAY_ALL_VISIBILITY } 45 | , m_motionBlur { true } 46 | , m_motionTransformSteps { 3 } 47 | , m_motionDeformSteps { 3 } 48 | { 49 | } 50 | 51 | HdPrimvarDescriptorMap GetPrimvarDescriptorMap(HdSceneDelegate* sceneDelegate) const 52 | { 53 | SdfPath const& id = T::GetId(); 54 | return { 55 | { HdInterpolationFaceVarying, sceneDelegate->GetPrimvarDescriptors(id, HdInterpolationFaceVarying) }, 56 | { HdInterpolationVertex, sceneDelegate->GetPrimvarDescriptors(id, HdInterpolationVertex) }, 57 | { HdInterpolationConstant, sceneDelegate->GetPrimvarDescriptors(id, HdInterpolationConstant) }, 58 | { HdInterpolationUniform, sceneDelegate->GetPrimvarDescriptors(id, HdInterpolationUniform) }, 59 | }; 60 | } 61 | 62 | void GetObjectPrimvars(HdPrimvarDescriptorMap const& descriptor_map, HdSceneDelegate* sceneDelegate, 63 | const HdDirtyBits* dirtyBits) 64 | { 65 | assert(m_cyclesObject != nullptr); 66 | 67 | const SdfPath& id = T::GetId(); 68 | 69 | // visibility 70 | m_visibilityFlags = 0; 71 | bool visCamera = true; 72 | bool visDiffuse = true; 73 | bool visGlossy = true; 74 | bool visScatter = true; 75 | bool visShadow = true; 76 | bool visTransmission = true; 77 | 78 | // motion blur 79 | m_motionBlur = true; 80 | m_motionTransformSteps = 3; 81 | m_motionDeformSteps = 3; 82 | 83 | // pass and names 84 | m_cyclesObject->is_shadow_catcher = false; 85 | m_cyclesObject->pass_id = 0; 86 | m_cyclesObject->use_holdout = false; 87 | m_cyclesObject->asset_name = ""; 88 | m_cyclesObject->lightgroup = ""; 89 | 90 | for (auto& descriptor_interpolation : descriptor_map) { 91 | for (auto& pv : descriptor_interpolation.second) { 92 | if (!HdChangeTracker::IsPrimvarDirty(*dirtyBits, id, pv.name)) { 93 | continue; 94 | } 95 | 96 | const std::string primvar_name = std::string { "primvars:" } + pv.name.GetString(); 97 | 98 | // visibility 99 | if (primvar_name == usdCyclesTokens->primvarsCyclesObjectVisibilityCamera) { 100 | VtValue value = T::GetPrimvar(sceneDelegate, pv.name); 101 | visCamera = value.Get(); 102 | continue; 103 | } 104 | 105 | if (primvar_name == usdCyclesTokens->primvarsCyclesObjectVisibilityDiffuse) { 106 | VtValue value = T::GetPrimvar(sceneDelegate, pv.name); 107 | visDiffuse = value.Get(); 108 | continue; 109 | } 110 | 111 | if (primvar_name == usdCyclesTokens->primvarsCyclesObjectVisibilityGlossy) { 112 | VtValue value = T::GetPrimvar(sceneDelegate, pv.name); 113 | visGlossy = value.Get(); 114 | continue; 115 | } 116 | 117 | if (primvar_name == usdCyclesTokens->primvarsCyclesObjectVisibilityScatter) { 118 | VtValue value = T::GetPrimvar(sceneDelegate, pv.name); 119 | visScatter = value.Get(); 120 | continue; 121 | } 122 | 123 | if (primvar_name == usdCyclesTokens->primvarsCyclesObjectVisibilityShadow) { 124 | VtValue value = T::GetPrimvar(sceneDelegate, pv.name); 125 | visShadow = value.Get(); 126 | continue; 127 | } 128 | 129 | if (primvar_name == usdCyclesTokens->primvarsCyclesObjectVisibilityTransmission) { 130 | VtValue value = T::GetPrimvar(sceneDelegate, pv.name); 131 | visTransmission = value.Get(); 132 | continue; 133 | } 134 | 135 | // motion blur 136 | if (primvar_name == usdCyclesTokens->primvarsCyclesObjectMblur) { 137 | VtValue value = T::GetPrimvar(sceneDelegate, pv.name); 138 | m_motionBlur = value.Get(); 139 | continue; 140 | } 141 | 142 | if (primvar_name == usdCyclesTokens->primvarsCyclesObjectTransformSamples) { 143 | VtValue value = T::GetPrimvar(sceneDelegate, pv.name); 144 | m_motionTransformSteps = value.Get(); 145 | continue; 146 | } 147 | 148 | if (primvar_name == usdCyclesTokens->primvarsCyclesObjectDeformSamples) { 149 | VtValue value = T::GetPrimvar(sceneDelegate, pv.name); 150 | m_motionDeformSteps = value.Get(); 151 | continue; 152 | } 153 | 154 | // names 155 | if (primvar_name == usdCyclesTokens->primvarsCyclesObjectAsset_name) { 156 | VtValue value = T::GetPrimvar(sceneDelegate, pv.name); 157 | auto& assetName = value.Get(); 158 | m_cyclesObject->asset_name = ccl::ustring(assetName); 159 | continue; 160 | } 161 | 162 | if (primvar_name == usdCyclesTokens->primvarsCyclesObjectLightgroup) { 163 | VtValue value = T::GetPrimvar(sceneDelegate, pv.name); 164 | auto& lightGroup = value.Get(); 165 | m_cyclesObject->lightgroup = ccl::ustring(lightGroup); 166 | continue; 167 | } 168 | 169 | // pass 170 | if (primvar_name == usdCyclesTokens->primvarsCyclesObjectPass_id) { 171 | VtValue value = T::GetPrimvar(sceneDelegate, pv.name); 172 | m_cyclesObject->pass_id = value.Get(); 173 | continue; 174 | } 175 | 176 | // shadows 177 | if (primvar_name == usdCyclesTokens->primvarsCyclesObjectIs_shadow_catcher) { 178 | VtValue value = T::GetPrimvar(sceneDelegate, pv.name); 179 | m_cyclesObject->is_shadow_catcher = value.Get(); 180 | continue; 181 | } 182 | 183 | if (primvar_name == usdCyclesTokens->primvarsCyclesObjectUse_holdout) { 184 | VtValue value = T::GetPrimvar(sceneDelegate, pv.name); 185 | m_cyclesObject->use_holdout = value.Get(); 186 | continue; 187 | } 188 | } 189 | } 190 | 191 | // build visibility flags 192 | m_visibilityFlags |= visCamera ? ccl::PATH_RAY_CAMERA : 0; 193 | m_visibilityFlags |= visDiffuse ? ccl::PATH_RAY_DIFFUSE : 0; 194 | m_visibilityFlags |= visGlossy ? ccl::PATH_RAY_GLOSSY : 0; 195 | m_visibilityFlags |= visScatter ? ccl::PATH_RAY_VOLUME_SCATTER : 0; 196 | m_visibilityFlags |= visShadow ? ccl::PATH_RAY_SHADOW : 0; 197 | m_visibilityFlags |= visTransmission ? ccl::PATH_RAY_TRANSMIT : 0; 198 | } 199 | 200 | void UpdateObject(ccl::Scene* scene, HdDirtyBits* dirtyBits, bool rebuildBvh) 201 | { 202 | assert(m_cyclesObject != nullptr); 203 | 204 | if (m_cyclesObject->geometry) { 205 | m_cyclesObject->geometry->tag_update(scene, rebuildBvh); 206 | } 207 | m_cyclesObject->visibility = T::IsVisible() ? m_visibilityFlags : 0; 208 | m_cyclesObject->tag_update(scene); 209 | 210 | // Mark visibility clean. When sync method is called object might be invisible. At that point we do not 211 | // need to trigger the topology and data generation. It can be postponed until visibility becomes on. 212 | // We need to manually mark visibility clean, but other flags remain dirty. 213 | if (!T::IsVisible()) { 214 | *dirtyBits &= ~HdChangeTracker::DirtyVisibility; 215 | } 216 | } 217 | 218 | ccl::Object* m_cyclesObject; 219 | 220 | unsigned int m_visibilityFlags; 221 | 222 | bool m_motionBlur; 223 | int m_motionTransformSteps; 224 | int m_motionDeformSteps; 225 | }; 226 | 227 | PXR_NAMESPACE_CLOSE_SCOPE 228 | 229 | #endif //HDBLACKBIRD_RPRIM_H 230 | -------------------------------------------------------------------------------- /plugin/hdCycles/transformSource.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Tangent Animation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | // including without limitation, as related to merchantability and fitness 13 | // for a particular purpose. 14 | // 15 | // In no event shall any copyright holder be liable for any damages of any kind 16 | // arising from the use of this software, whether in contract, tort or otherwise. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | #ifndef HDCYCLES_TRANSFORMSOURCE_H 21 | #define HDCYCLES_TRANSFORMSOURCE_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | 31 | #include 32 | #include 33 | 34 | PXR_NAMESPACE_OPEN_SCOPE 35 | 36 | /// 37 | /// Max motion samples dictated by Cycles(Embree) 38 | /// 39 | static constexpr ccl::uint HD_CYCLES_MAX_TRANSFORM_STEPS = ccl::Object::MAX_MOTION_STEPS; 40 | static constexpr ccl::uint HD_CYCLES_MAX_GEOMETRY_STEPS = ccl::Geometry::MAX_MOTION_STEPS; 41 | 42 | /// 43 | /// Common aliases used in motion sampling 44 | /// 45 | using HdCyclesValueTimeSampleArray = HdTimeSampleArray; 46 | using HdCyclesVec3fArrayTimeSampleArray = HdTimeSampleArray; 47 | using HdCyclesMatrix4dTimeSampleArray = HdTimeSampleArray; 48 | using HdCyclesMatrix4dArrayTimeSampleArray = HdTimeSampleArray; 49 | using HdCyclesTransformTimeSampleArray = HdTimeSampleArray; 50 | 51 | using HdCyclesTransformSmallVector = TfSmallVector; 52 | 53 | /// 54 | /// Common abstract base for all properties to be committed to the object 55 | /// 56 | class HdBbbObjectPropertiesSource : public HdBufferSource { 57 | protected: 58 | using HdBufferSource::HdBufferSource; 59 | }; 60 | 61 | using HdBbbObjectPropertiesSourceSharedPtr = std::shared_ptr; 62 | 63 | /// 64 | /// Transformation motion sample source 65 | /// 66 | class HdCyclesTransformSource : public HdBbbObjectPropertiesSource { 67 | public: 68 | HdCyclesTransformSource(ccl::Object* object, const HdCyclesMatrix4dTimeSampleArray& samples, 69 | const GfMatrix4d& fallback, unsigned int new_num_samples = 0); 70 | 71 | bool Resolve() override; 72 | const TfToken& GetName() const override { return HdTokens->transform; } 73 | void GetBufferSpecs(HdBufferSpecVector* specs) const override {} 74 | const void* GetData() const override { return nullptr; } 75 | HdTupleType GetTupleType() const override { return {}; } 76 | size_t GetNumElements() const override { return 0; } 77 | 78 | const ccl::Object* GetObject() const { return m_object; } 79 | 80 | static HdCyclesTransformTimeSampleArray ResampleUniform(const HdCyclesMatrix4dTimeSampleArray& samples, 81 | unsigned int new_num_samples); 82 | 83 | private: 84 | bool _CheckValid() const override; 85 | 86 | ccl::Object* m_object; 87 | HdCyclesMatrix4dTimeSampleArray m_samples; 88 | GfMatrix4d m_fallback; 89 | unsigned int m_new_num_samples; 90 | }; 91 | 92 | PXR_NAMESPACE_CLOSE_SCOPE 93 | 94 | #endif //HDCYCLES_TRANSFORMSOURCE_H 95 | -------------------------------------------------------------------------------- /plugin/hdCycles/volume.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Tangent Animation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | // including without limitation, as related to merchantability and fitness 13 | // for a particular purpose. 14 | // 15 | // In no event shall any copyright holder be liable for any damages of any kind 16 | // arising from the use of this software, whether in contract, tort or otherwise. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | #ifndef HD_CYCLES_VOLUME_H 21 | #define HD_CYCLES_VOLUME_H 22 | 23 | #include "api.h" 24 | 25 | #include "hdcycles.h" 26 | #include "renderDelegate.h" 27 | #include "rprim.h" 28 | #include "utils.h" 29 | 30 | #include 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | #ifdef WITH_OPENVDB 37 | # include 38 | #endif 39 | 40 | namespace ccl { 41 | class Mesh; 42 | class Scene; 43 | class Object; 44 | class Geometry; 45 | } // namespace ccl 46 | 47 | PXR_NAMESPACE_OPEN_SCOPE 48 | 49 | class HdSceneDelegate; 50 | class HdCyclesRenderDelegate; 51 | 52 | /** 53 | * @brief USD Volume mapped to Cycles Volume 54 | * 55 | */ 56 | class HdCyclesVolume final : public HdBbRPrim { 57 | public: 58 | /** 59 | * @brief Construct a new HdCycles Volume object 60 | * 61 | * @param id Path to the Volume Primitive 62 | * @param instancerId If specified the HdInstancer at this id uses this volume 63 | * as a prototype 64 | */ 65 | HdCyclesVolume(SdfPath const& id, SdfPath const& instancerId, HdCyclesRenderDelegate* a_renderDelegate); 66 | /** 67 | * @brief Destroy the HdCycles Volume object 68 | * 69 | */ 70 | virtual ~HdCyclesVolume(); 71 | 72 | /** 73 | * @brief Pull invalidated material data and prepare/update the core Cycles 74 | * representation. 75 | * 76 | * This must be thread safe. 77 | * 78 | * @param sceneDelegate The data source for the volume 79 | * @param renderParam State 80 | * @param dirtyBits Which bits of scene data has changed 81 | */ 82 | void Sync(HdSceneDelegate* sceneDelegate, HdRenderParam* renderParam, HdDirtyBits* dirtyBits, 83 | TfToken const& reprSelector) override; 84 | 85 | /** 86 | * @brief Inform the scene graph which state needs to be downloaded in 87 | * the first Sync() call 88 | * 89 | * @return The initial dirty state this volume wants to query 90 | */ 91 | HdDirtyBits GetInitialDirtyBitsMask() const override; 92 | 93 | /** 94 | * @return Return true if this volume is valid. 95 | */ 96 | bool IsValid() const; 97 | 98 | /** 99 | * @brief Not Implemented 100 | */ 101 | void Finalize(HdRenderParam* renderParam) override; 102 | 103 | protected: 104 | /** 105 | * @brief Initialize the given representation of this Rprim. 106 | * This is called prior to syncing the prim. 107 | * 108 | * @param reprToken The name of the repr to initialize 109 | * @param dirtyBits In/Out dirty values 110 | */ 111 | void _InitRepr(TfToken const& reprToken, HdDirtyBits* dirtyBits) override; 112 | 113 | /** 114 | * @brief Set additional dirty bits 115 | * 116 | * @param bits 117 | * @return New value of dirty bits 118 | */ 119 | HdDirtyBits _PropagateDirtyBits(HdDirtyBits bits) const override; 120 | 121 | protected: 122 | GfMatrix4f m_transform; 123 | 124 | bool m_useMotionBlur; 125 | 126 | private: 127 | /** 128 | * @brief Create the cycles object representation 129 | * 130 | * @return New allocated pointer to ccl::Object 131 | */ 132 | ccl::Object* _CreateObject(); 133 | 134 | /** 135 | * @brief Create the cycles volume mesh representation 136 | * 137 | * @return New allocated pointer to ccl::Mesh 138 | */ 139 | ccl::Mesh* _CreateVolume(); 140 | 141 | /** 142 | * @brief Populate the Cycles mesh representation from delegate's data 143 | */ 144 | void _PopulateVolume(const SdfPath& id, HdSceneDelegate* delegate, ccl::Scene* scene); 145 | void _PopulateConstantPrimvars(const SdfPath& id, HdSceneDelegate* delegate, ccl::Scene* scene, 146 | HdPrimvarDescriptorMap const& descriptor_map, HdDirtyBits* dirtyBits); 147 | 148 | /** 149 | * @brief Update the OpenVDB loader grid for mesh builder 150 | */ 151 | void _UpdateGrids(); 152 | 153 | /** 154 | * @brief Update the Cycles Object 155 | */ 156 | void _UpdateObject(ccl::Scene* scene, HdCyclesRenderParam* param, HdDirtyBits* dirtyBits, bool rebuildBvh); 157 | 158 | ccl::Mesh* m_cyclesVolume; 159 | 160 | HdCyclesObjectSourceSharedPtr m_object_source; 161 | 162 | std::vector m_cyclesInstances; 163 | 164 | HdCyclesRenderDelegate* m_renderDelegate; 165 | 166 | HdTimeSampleArray m_transformSamples; 167 | 168 | ccl::vector m_usedShaders; 169 | }; 170 | 171 | PXR_NAMESPACE_CLOSE_SCOPE 172 | 173 | #endif // HD_CYCLES_VOLUME_H 174 | -------------------------------------------------------------------------------- /plugin/ndrCycles/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Tangent Animation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | # including without limitation, as related to merchantability and fitness 13 | # for a particular purpose. 14 | # 15 | # In no event shall any copyright holder be liable for any damages of any kind 16 | # arising from the use of this software, whether in contract, tort or otherwise. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | 20 | add_library(ndrCycles SHARED 21 | discovery.cpp 22 | discovery.h 23 | parser.cpp 24 | parser.h 25 | api.h 26 | ) 27 | 28 | target_include_directories(ndrCycles 29 | PUBLIC 30 | ${CMAKE_CURRENT_SOURCE_DIR}/../ 31 | ) 32 | 33 | target_link_libraries(ndrCycles 34 | PUBLIC 35 | Cycles::Cycles 36 | Usd::Usd 37 | ) 38 | 39 | target_compile_options(ndrCycles 40 | PRIVATE 41 | $<$:/W4 /wd4273 /Zi /experimental:external /external:W0> 42 | $<$,$>:/Ob0 /Od> 43 | $<$:-Wall -Wextra -pedantic -Wno-deprecated -Wshadow -Wdouble-promotion -Wconversion -Wnull-dereference -Wold-style-cast -Wuseless-cast> 44 | ) 45 | 46 | target_compile_definitions(ndrCycles 47 | PRIVATE 48 | MFB_PACKAGE_NAME=ndrCycles 49 | MFB_ALT_PACKAGE_NAME=ndrCycles 50 | ) 51 | 52 | set_target_properties(ndrCycles PROPERTIES 53 | PREFIX "" 54 | ) 55 | install(TARGETS ndrCycles DESTINATION plugin/usd) 56 | if (MSVC) 57 | install(FILES $ DESTINATION plugin/usd OPTIONAL) 58 | endif () 59 | 60 | # plugInfo.json 61 | set(PLUG_INFO_LIBRARY_PATH "../ndrCycles${CMAKE_SHARED_LIBRARY_SUFFIX}") 62 | set(PLUG_INFO_RESOURCE_PATH "resources") 63 | set(PLUG_INFO_ROOT "..") 64 | configure_file(plugInfo.json plugInfo.json @ONLY) 65 | install(FILES "${CMAKE_CURRENT_BINARY_DIR}/plugInfo.json" DESTINATION plugin/usd/ndrCycles/resources) 66 | -------------------------------------------------------------------------------- /plugin/ndrCycles/api.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Tangent Animation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | // including without limitation, as related to merchantability and fitness 13 | // for a particular purpose. 14 | // 15 | // In no event shall any copyright holder be liable for any damages of any kind 16 | // arising from the use of this software, whether in contract, tort or otherwise. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | #ifndef NDR_CYCLES_API_H 21 | #define NDR_CYCLES_API_H 22 | 23 | #include 24 | 25 | #endif // NDR_CYCLES_API_H 26 | -------------------------------------------------------------------------------- /plugin/ndrCycles/discovery.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Tangent Animation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | // including without limitation, as related to merchantability and fitness 13 | // for a particular purpose. 14 | // 15 | // In no event shall any copyright holder be liable for any damages of any kind 16 | // arising from the use of this software, whether in contract, tort or otherwise. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | #include "discovery.h" 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | PXR_NAMESPACE_OPEN_SCOPE 31 | 32 | // clang-format off 33 | TF_DEFINE_PRIVATE_TOKENS(_tokens, 34 | (shader) 35 | (cycles) 36 | (filename) 37 | ); 38 | // clang-format on 39 | 40 | NDR_REGISTER_DISCOVERY_PLUGIN(NdrCyclesDiscoveryPlugin) 41 | 42 | NdrCyclesDiscoveryPlugin::NdrCyclesDiscoveryPlugin() {} 43 | 44 | NdrCyclesDiscoveryPlugin::~NdrCyclesDiscoveryPlugin() {} 45 | 46 | NdrNodeDiscoveryResultVec 47 | NdrCyclesDiscoveryPlugin::DiscoverNodes(const Context& context) 48 | { 49 | TfToken filename(""); 50 | NdrNodeDiscoveryResultVec ret; 51 | 52 | // TODO: Store these in proper USD Schema and read at runtime... 53 | std::vector temp_nodes; 54 | temp_nodes.push_back("output"); 55 | temp_nodes.push_back("diffuse_bsdf"); 56 | temp_nodes.push_back("principled_bsdf"); 57 | temp_nodes.push_back("glossy_bsdf"); 58 | temp_nodes.push_back("principled_hair_bsdf"); 59 | temp_nodes.push_back("anisotropic_bsdf"); 60 | temp_nodes.push_back("glass_bsdf"); 61 | temp_nodes.push_back("refraction_bsdf"); 62 | temp_nodes.push_back("toon_bsdf"); 63 | temp_nodes.push_back("velvet_bsdf"); 64 | temp_nodes.push_back("translucent_bsdf"); 65 | temp_nodes.push_back("transparent_bsdf"); 66 | temp_nodes.push_back("subsurface_scattering"); 67 | temp_nodes.push_back("mix_closure"); 68 | temp_nodes.push_back("add_closure"); 69 | temp_nodes.push_back("hair_bsdf"); 70 | temp_nodes.push_back("principled_volume"); 71 | temp_nodes.push_back("scatter_volume"); 72 | temp_nodes.push_back("absorption_volume"); 73 | temp_nodes.push_back("emission"); 74 | temp_nodes.push_back("displacement"); 75 | 76 | for (const std::string& n : temp_nodes) { 77 | std::string cycles_id = "cycles_" + n; 78 | ret.emplace_back(NdrIdentifier(TfStringPrintf("%s", cycles_id.c_str())), // identifier 79 | NdrVersion(1, 0), // version 80 | n.c_str(), // name 81 | _tokens->shader, // family 82 | _tokens->cycles, // discoveryType 83 | _tokens->cycles, // sourceType 84 | filename, // uri 85 | filename // resolvedUri 86 | ); 87 | 88 | // DEPRECATED: 89 | // Added for backwards support whilst we transition to new identifier 90 | cycles_id = "cycles:" + n; 91 | ret.emplace_back(NdrIdentifier(TfStringPrintf("%s", cycles_id.c_str())), // identifier 92 | NdrVersion(1, 0), // version 93 | n.c_str(), // name 94 | _tokens->shader, // family 95 | _tokens->cycles, // discoveryType 96 | _tokens->cycles, // sourceType 97 | filename, // uri 98 | filename // resolvedUri 99 | ); 100 | } 101 | 102 | return ret; 103 | } 104 | 105 | const NdrStringVec& 106 | NdrCyclesDiscoveryPlugin::GetSearchURIs() const 107 | { 108 | static const auto result = []() -> NdrStringVec { 109 | NdrStringVec ret = TfStringSplit(TfGetenv("CYCLES_PLUGIN_PATH"), ARCH_PATH_LIST_SEP); 110 | ret.push_back(""); 111 | return ret; 112 | }(); 113 | return result; 114 | } 115 | 116 | PXR_NAMESPACE_CLOSE_SCOPE -------------------------------------------------------------------------------- /plugin/ndrCycles/discovery.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Tangent Animation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | // including without limitation, as related to merchantability and fitness 13 | // for a particular purpose. 14 | // 15 | // In no event shall any copyright holder be liable for any damages of any kind 16 | // arising from the use of this software, whether in contract, tort or otherwise. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | #ifndef NDR_CYCLES_DISCOVERY_H 21 | #define NDR_CYCLES_DISCOVERY_H 22 | 23 | #include "api.h" 24 | 25 | #include 26 | #include 27 | 28 | PXR_NAMESPACE_OPEN_SCOPE 29 | 30 | /** 31 | * @brief Ndr Discovery for cycles shader nodes 32 | * 33 | */ 34 | class NdrCyclesDiscoveryPlugin : public NdrDiscoveryPlugin { 35 | public: 36 | using Context = NdrDiscoveryPluginContext; 37 | 38 | /** 39 | * @brief Creates an instance of NdrCyclesDiscoveryPlugin 40 | * 41 | */ 42 | NdrCyclesDiscoveryPlugin(); 43 | 44 | /** 45 | * @brief Destructor of NdrCyclesDiscoveryPlugin 46 | * 47 | */ 48 | ~NdrCyclesDiscoveryPlugin() override; 49 | 50 | /** 51 | * @brief Discovers the cycles shaders 52 | * 53 | * @param context NdrDiscoveryPluginContext of the discovery process 54 | * @return List of the discovered cycles nodes 55 | */ 56 | NdrNodeDiscoveryResultVec DiscoverNodes(const Context& context) override; 57 | 58 | /** 59 | * @brief Returns the URIs used to search for cycles shader nodes. 60 | * 61 | * @return All the paths from CYCLES_PLUGIN_PATH 62 | */ 63 | const NdrStringVec& GetSearchURIs() const override; 64 | }; 65 | 66 | PXR_NAMESPACE_CLOSE_SCOPE 67 | 68 | #endif // NDR_CYCLES_DISCOVERY_H 69 | -------------------------------------------------------------------------------- /plugin/ndrCycles/parser.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Tangent Animation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | // including without limitation, as related to merchantability and fitness 13 | // for a particular purpose. 14 | // 15 | // In no event shall any copyright holder be liable for any damages of any kind 16 | // arising from the use of this software, whether in contract, tort or otherwise. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | #include "parser.h" 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | PXR_NAMESPACE_OPEN_SCOPE 31 | 32 | NDR_REGISTER_PARSER_PLUGIN(NdrCyclesParserPlugin) 33 | 34 | // clang-format off 35 | TF_DEFINE_PRIVATE_TOKENS(_tokens, 36 | (cycles) 37 | (binary) 38 | ); 39 | // clang-format on 40 | 41 | namespace { 42 | // We have to subclass SdrShaderProperty, because it tries to read the SdfType 43 | // from a token, and it doesn't support all the parameter types cycles does, 44 | // like the 4 component color. Besides this, we also guarantee that the default 45 | // value will match the SdfType, as the SdfType comes from the default value. 46 | class CyclesShaderProperty : public SdrShaderProperty { 47 | public: 48 | CyclesShaderProperty(const TfToken& name, const SdfValueTypeName& typeName, const VtValue& defaultValue, 49 | bool isOutput, size_t arraySize, const NdrTokenMap& metadata, const NdrTokenMap& hints, 50 | const NdrOptionVec& options) 51 | : SdrShaderProperty(name, typeName.GetAsToken(), defaultValue, isOutput, arraySize, metadata, hints, options) 52 | , _typeName(typeName) 53 | { 54 | } 55 | 56 | const SdfTypeIndicator GetTypeAsSdfType() const override { return { _typeName, _typeName.GetAsToken() }; } 57 | 58 | private: 59 | SdfValueTypeName _typeName; 60 | }; 61 | 62 | } // namespace 63 | 64 | NdrCyclesParserPlugin::NdrCyclesParserPlugin() {} 65 | 66 | NdrCyclesParserPlugin::~NdrCyclesParserPlugin() {} 67 | 68 | NdrNodeUniquePtr 69 | NdrCyclesParserPlugin::Parse(const NdrNodeDiscoveryResult& discoveryResult) 70 | { 71 | NdrPropertyUniquePtrVec properties; 72 | #if PXR_MINOR_VERSION >= 20 && PXR_PATCH_VERSION >= 5 73 | return NdrNodeUniquePtr(new SdrShaderNode(discoveryResult.identifier, // identifier 74 | discoveryResult.version, // version 75 | discoveryResult.name, // name 76 | discoveryResult.family, // family 77 | discoveryResult.discoveryType, // context 78 | discoveryResult.sourceType, // sourceType 79 | discoveryResult.uri, // uri 80 | discoveryResult.uri, // resolvedUri 81 | std::move(properties))); 82 | #else 83 | return NdrNodeUniquePtr(new SdrShaderNode(discoveryResult.identifier, // identifier 84 | discoveryResult.version, // version 85 | discoveryResult.name, // name 86 | discoveryResult.family, // family 87 | discoveryResult.discoveryType, // context 88 | discoveryResult.sourceType, // sourceType 89 | discoveryResult.uri, // uri 90 | std::move(properties))); 91 | #endif 92 | } 93 | 94 | const NdrTokenVec& 95 | NdrCyclesParserPlugin::GetDiscoveryTypes() const 96 | { 97 | static const NdrTokenVec ret = { _tokens->cycles }; 98 | return ret; 99 | } 100 | 101 | const TfToken& 102 | NdrCyclesParserPlugin::GetSourceType() const 103 | { 104 | return _tokens->cycles; 105 | } 106 | 107 | PXR_NAMESPACE_CLOSE_SCOPE -------------------------------------------------------------------------------- /plugin/ndrCycles/parser.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Tangent Animation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | // including without limitation, as related to merchantability and fitness 13 | // for a particular purpose. 14 | // 15 | // In no event shall any copyright holder be liable for any damages of any kind 16 | // arising from the use of this software, whether in contract, tort or otherwise. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | #ifndef NDR_CYCLES_PARSER_H 21 | #define NDR_CYCLES_PARSER_H 22 | 23 | #include "api.h" 24 | 25 | #include 26 | #include 27 | 28 | PXR_NAMESPACE_OPEN_SCOPE 29 | 30 | /// Ndr Parser for cycles shader nodes. 31 | class NdrCyclesParserPlugin : public NdrParserPlugin { 32 | public: 33 | /** 34 | * @brief Creates an instance of NdrCyclesParserPlugin. 35 | * 36 | */ 37 | NdrCyclesParserPlugin(); 38 | 39 | /** 40 | * @brief Destructor for NdrCyclesParserPlugin. 41 | * 42 | */ 43 | ~NdrCyclesParserPlugin() override; 44 | 45 | /** 46 | * @brief Parses a node discovery result to a NdrNode. 47 | * 48 | * @param discoveryResult NdrNodeDiscoveryResult returned by the discovery plugin. 49 | * @return The parsed Ndr Node. 50 | */ 51 | NdrNodeUniquePtr Parse(const NdrNodeDiscoveryResult& discoveryResult) override; 52 | 53 | /** 54 | * @brief Returns all the supported discovery types. 55 | * 56 | * @return Returns "cycles" as the only supported discovery type. 57 | */ 58 | const NdrTokenVec& GetDiscoveryTypes() const override; 59 | 60 | /** 61 | * @brief Returns all the supported source types. 62 | * 63 | * @return Returns "cycles" as the only supported source type. 64 | */ 65 | const TfToken& GetSourceType() const override; 66 | }; 67 | 68 | PXR_NAMESPACE_CLOSE_SCOPE 69 | 70 | #endif // NDR_CYCLES_PARSER_H 71 | -------------------------------------------------------------------------------- /plugin/ndrCycles/plugInfo.json: -------------------------------------------------------------------------------- 1 | { 2 | "Plugins": [ 3 | { 4 | "Info": { 5 | "SdfMetadata": { 6 | "filename": { 7 | "appliesTo": [ 8 | "prims" 9 | ], 10 | "default": "", 11 | "displayGroup": "Cycles", 12 | "documentation": "Cycles plugin location for a node.", 13 | "type": "token" 14 | } 15 | }, 16 | "Types": { 17 | "NdrCyclesParserPlugin": { 18 | "bases": [ 19 | "NdrParserPlugin" 20 | ], 21 | "displayName": "Cycles Node Parser" 22 | }, 23 | "NdrCyclesDiscoveryPlugin": { 24 | "bases": [ 25 | "NdrDiscoveryPlugin" 26 | ], 27 | "displayName": "Cycles Node Discovery" 28 | } 29 | } 30 | }, 31 | "LibraryPath": "@PLUG_INFO_LIBRARY_PATH@", 32 | "Name": "ndrCycles", 33 | "ResourcePath": "@PLUG_INFO_RESOURCE_PATH@", 34 | "Root": "@PLUG_INFO_ROOT@", 35 | "Type": "library" 36 | } 37 | ] 38 | } -------------------------------------------------------------------------------- /plugin/usdCycles/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Tangent Animation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | # including without limitation, as related to merchantability and fitness 13 | # for a particular purpose. 14 | # 15 | # In no event shall any copyright holder be liable for any damages of any kind 16 | # arising from the use of this software, whether in contract, tort or otherwise. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | 20 | set(USD_CYCLES_SCHEMA_SOURCE_OUTPUT 21 | # api 22 | api.h 23 | 24 | # tokens 25 | tokens.h 26 | tokens.cpp 27 | 28 | # render 29 | rendererSettingsAPI.h 30 | rendererSettingsAPI.cpp 31 | 32 | # denoise 33 | denoiseSettingsAPI.h 34 | denoiseSettingsAPI.cpp 35 | 36 | # integrator 37 | integratorSettingsAPI.h 38 | integratorSettingsAPI.cpp 39 | 40 | # film 41 | filmSettingsAPI.h 42 | filmSettingsAPI.cpp 43 | 44 | # light 45 | lightSettingsAPI.h 46 | lightSettingsAPI.cpp 47 | 48 | # camera 49 | cameraSettingsAPI.h 50 | cameraSettingsAPI.cpp 51 | 52 | # object 53 | objectSettingsAPI.h 54 | objectSettingsAPI.cpp 55 | 56 | # mesh 57 | meshSettingsAPI.h 58 | meshSettingsAPI.cpp 59 | 60 | # material 61 | materialSettingsAPI.h 62 | materialSettingsAPI.cpp 63 | 64 | # background 65 | backgroundAPI.h 66 | backgroundAPI.cpp 67 | 68 | # curve 69 | curveSettingsAPI.h 70 | curveSettingsAPI.cpp 71 | 72 | # points 73 | pointsSettingsAPI.h 74 | pointsSettingsAPI.cpp 75 | 76 | # bake 77 | bakeSettingsAPI.h 78 | bakeSettingsAPI.cpp 79 | ) 80 | 81 | 82 | set(USD_CYCLES_SCHEMA_WRAP_OUTPUT 83 | wrapTokens.cpp 84 | wrapRendererSettingsAPI.cpp 85 | wrapDenoiseSettingsAPI.cpp 86 | wrapIntegratorSettingsAPI.cpp 87 | wrapFilmSettingsAPI.cpp 88 | wrapLightSettingsAPI.cpp 89 | wrapCameraSettingsAPI.cpp 90 | wrapObjectSettingsAPI.cpp 91 | wrapMeshSettingsAPI.cpp 92 | wrapMaterialSettingsAPI.cpp 93 | wrapBackgroundAPI.cpp 94 | wrapCurveSettingsAPI.cpp 95 | wrapPointsSettingsAPI.cpp 96 | wrapBakeSettingsAPI.cpp 97 | ) 98 | 99 | add_custom_command(OUTPUT 100 | ${USD_CYCLES_SCHEMA_SOURCE_OUTPUT} 101 | ${USD_CYCLES_SCHEMA_WRAP_OUTPUT} 102 | plugInfo.json generatedSchema.usda 103 | COMMAND ${USD_SCHEMA_GENERATOR} ${CMAKE_CURRENT_SOURCE_DIR}/schema.usda 104 | COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/plugInfo.cmake 105 | DEPENDS 106 | ${CMAKE_CURRENT_SOURCE_DIR}/schema.usda 107 | ${CMAKE_CURRENT_SOURCE_DIR}/plugInfo.cmake 108 | VERBATIM 109 | ) 110 | 111 | # usdCycles 112 | 113 | add_library(usdCycles SHARED ${USD_CYCLES_SCHEMA_SOURCE_OUTPUT}) 114 | 115 | target_include_directories(usdCycles 116 | PUBLIC 117 | ${CMAKE_CURRENT_BINARY_DIR}/../ 118 | ) 119 | 120 | target_link_libraries(usdCycles 121 | PUBLIC 122 | Cycles::Cycles 123 | Usd::Usd 124 | ) 125 | 126 | target_compile_options(usdCycles 127 | PRIVATE 128 | $<$:/wd4273 /Zi> 129 | $<$,$>:/Ob0 /Od> 130 | $<$:-Wno-unused-variable> 131 | ) 132 | 133 | target_link_options(usdCycles 134 | PRIVATE 135 | $<$:/ignore:4217 /ignore:4049> 136 | ) 137 | 138 | target_compile_definitions(usdCycles 139 | PRIVATE 140 | MFB_PACKAGE_NAME=usdCycles 141 | MFB_ALT_PACKAGE_NAME=usdCycles 142 | ) 143 | 144 | set_target_properties(usdCycles PROPERTIES 145 | PREFIX "" 146 | ) 147 | install(TARGETS usdCycles DESTINATION plugin/usd) 148 | if (MSVC) 149 | install(FILES $ DESTINATION plugin/usd OPTIONAL) 150 | endif () 151 | 152 | install(FILES 153 | ${CMAKE_CURRENT_BINARY_DIR}/plugInfo.json 154 | ${CMAKE_CURRENT_BINARY_DIR}/generatedSchema.usda 155 | DESTINATION plugin/usd/usdCycles/resources 156 | ) 157 | 158 | install(FILES schema.usda DESTINATION plugin/usd/usdCycles/resources/usdCycles) 159 | 160 | # _usdCycles - python 161 | 162 | add_library(_usdCycles SHARED 163 | ${USD_CYCLES_SCHEMA_WRAP_OUTPUT} 164 | module.cpp 165 | moduleDeps.cpp 166 | ) 167 | 168 | target_include_directories(_usdCycles 169 | PUBLIC 170 | ${CMAKE_CURRENT_BINARY_DIR}/../ 171 | ) 172 | 173 | target_link_libraries(_usdCycles 174 | PUBLIC 175 | usdCycles 176 | ) 177 | 178 | target_compile_options(_usdCycles 179 | PRIVATE 180 | $<$:/wd4273 /Zi> 181 | $<$,$>:/Ob0 /Od> 182 | ) 183 | 184 | target_link_options(_usdCycles 185 | PRIVATE 186 | $<$:/ignore:4217 /ignore:4049> 187 | ) 188 | 189 | target_compile_definitions(_usdCycles 190 | PRIVATE 191 | MFB_PACKAGE_NAME=usdCycles 192 | MFB_ALT_PACKAGE_NAME=usdCycles 193 | ) 194 | 195 | set_target_properties(_usdCycles PROPERTIES 196 | PREFIX "" 197 | INSTALL_RPATH "$ORIGIN/../../usd" 198 | ) 199 | 200 | if (WIN32) 201 | set_target_properties(_usdCycles PROPERTIES SUFFIX ".pyd") 202 | endif () 203 | 204 | install(TARGETS _usdCycles DESTINATION plugin/python/UsdCycles) 205 | install(FILES __init__.py DESTINATION plugin/python/UsdCycles) 206 | if (MSVC) 207 | install(FILES $ DESTINATION plugin/python/UsdCycles OPTIONAL) 208 | endif () 209 | -------------------------------------------------------------------------------- /plugin/usdCycles/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Tangent Animation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | # including without limitation, as related to merchantability and fitness 13 | # for a particular purpose. 14 | # 15 | # In no event shall any copyright holder be liable for any damages of any kind 16 | # arising from the use of this software, whether in contract, tort or otherwise. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | 20 | from . import _usdCycles 21 | from pxr import Tf 22 | Tf.PrepareModule(_usdCycles, locals()) 23 | del Tf 24 | 25 | try: 26 | import __DOC 27 | __DOC.Execute(locals()) 28 | del __DOC 29 | except Exception: 30 | try: 31 | import __tmpDoc 32 | __tmpDoc.Execute(locals()) 33 | del __tmpDoc 34 | except: 35 | pass -------------------------------------------------------------------------------- /plugin/usdCycles/module.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Tangent Animation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | // including without limitation, as related to merchantability and fitness 13 | // for a particular purpose. 14 | // 15 | // In no event shall any copyright holder be liable for any damages of any kind 16 | // arising from the use of this software, whether in contract, tort or otherwise. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | #include 21 | 22 | PXR_NAMESPACE_USING_DIRECTIVE 23 | 24 | TF_WRAP_MODULE 25 | { 26 | TF_WRAP(usdCyclesCameraSettingsAPI); 27 | TF_WRAP(usdCyclesCurveSettingsAPI); 28 | TF_WRAP(usdCyclesFilmSettingsAPI); 29 | //TF_WRAP(usdCyclesIntegratorSettingsAPI); 30 | //TF_WRAP(usdCyclesLightSettingsAPI); 31 | //TF_WRAP(usdCyclesMaterialSettingsAPI); 32 | TF_WRAP(usdCyclesObjectSettingsAPI); 33 | TF_WRAP(usdCyclesPointsSettingsAPI); 34 | TF_WRAP(usdCyclesRendererSettingsAPI); 35 | } -------------------------------------------------------------------------------- /plugin/usdCycles/moduleDeps.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Tangent Animation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | // including without limitation, as related to merchantability and fitness 13 | // for a particular purpose. 14 | // 15 | // In no event shall any copyright holder be liable for any damages of any kind 16 | // arising from the use of this software, whether in contract, tort or otherwise. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | 27 | PXR_NAMESPACE_OPEN_SCOPE 28 | 29 | TF_REGISTRY_FUNCTION(TfScriptModuleLoader) 30 | { 31 | // List of direct deps for this library 32 | const std::vector reqs = { TfToken("sdf"), TfToken("tf"), TfToken("usd"), TfToken("vt") }; 33 | TfScriptModuleLoader::GetInstance().RegisterLibrary(TfToken("usdCycles"), TfToken("UsdCycles"), reqs); 34 | } 35 | 36 | PXR_NAMESPACE_CLOSE_SCOPE -------------------------------------------------------------------------------- /plugin/usdCycles/plugInfo.cmake: -------------------------------------------------------------------------------- 1 | set(PLUG_INFO_LIBRARY_PATH "../usdCycles${CMAKE_SHARED_LIBRARY_SUFFIX}") 2 | set(PLUG_INFO_RESOURCE_PATH "resources") 3 | set(PLUG_INFO_ROOT "..") 4 | 5 | configure_file(${CMAKE_CURRENT_BINARY_DIR}/plugInfo.json ${CMAKE_CURRENT_BINARY_DIR}/plugInfo.json @ONLY) -------------------------------------------------------------------------------- /plugin/usdImagingCycles/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Tangent Animation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | # including without limitation, as related to merchantability and fitness 13 | # for a particular purpose. 14 | # 15 | # In no event shall any copyright holder be liable for any damages of any kind 16 | # arising from the use of this software, whether in contract, tort or otherwise. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | 20 | add_executable(blackbirdengine 21 | engine.cpp 22 | engine.h 23 | ) 24 | 25 | target_include_directories(blackbirdengine 26 | PUBLIC 27 | .. 28 | ) 29 | 30 | target_link_libraries(blackbirdengine 31 | PUBLIC 32 | Cycles::Cycles 33 | Usd::Usd 34 | hdCycles 35 | usdCycles 36 | ) 37 | 38 | target_compile_options(blackbirdengine 39 | PRIVATE 40 | $<$:/W4 /wd4273 /Zi /experimental:external /external:W0> 41 | $<$,$>:/Ob0 /Od> 42 | $<$:-Wall -Wextra -pedantic -Wno-deprecated -Wshadow -Wdouble-promotion -Wconversion -Wnull-dereference -Wold-style-cast -Wuseless-cast> 43 | $<$,$>:-g3> 44 | ) 45 | 46 | target_link_options(blackbirdengine 47 | PRIVATE 48 | $<$:/ignore:4217 /ignore:4049> 49 | ) 50 | 51 | install(TARGETS blackbirdengine DESTINATION bin) -------------------------------------------------------------------------------- /plugin/usdImagingCycles/engine.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Tangent Animation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | // including without limitation, as related to merchantability and fitness 13 | // for a particular purpose. 14 | // 15 | // In no event shall any copyright holder be liable for any damages of any kind 16 | // arising from the use of this software, whether in contract, tort or otherwise. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | #ifndef BLACKBIRD_ENGINE_H 21 | #define BLACKBIRD_ENGINE_H 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | PXR_NAMESPACE_OPEN_SCOPE 32 | 33 | class HdEngine; 34 | class ParamsDelegate; 35 | class UsdImagingDelegate; 36 | class HdRprimCollection; 37 | class HdRenderIndex; 38 | class HdRenderDelegate; 39 | class HdxTask; 40 | class HdRenderBuffer; 41 | class HdRendererPlugin; 42 | 43 | class UsdImagingBbEngine final { 44 | public: 45 | UsdImagingBbEngine() = default; 46 | ~UsdImagingBbEngine(); 47 | 48 | HdRendererPlugin* FindPlugin(std::string const& pluginName); 49 | bool OpenUsdScene(std::string const& filename); 50 | bool ReadRenderSettings(const std::string& path, HdRenderSettingsMap& render_settings_map); 51 | 52 | bool CreateDelegates(HdRendererPlugin* plugin, const HdRenderSettingsMap& render_settings); 53 | 54 | void SetCamera(std::string const& camera); 55 | void SetResolution(int x, int y); 56 | 57 | void Render(); 58 | bool WriteToFile(std::string const& filename) const; 59 | 60 | private: 61 | TfToken renderDelegateId; 62 | HdRenderDelegate* _renderDelegate; 63 | 64 | std::unique_ptr _renderIndex; 65 | std::unique_ptr _sceneDelegate; 66 | std::unique_ptr _paramsDelegate; 67 | std::unique_ptr _engine; 68 | 69 | UsdStageRefPtr _stage; 70 | 71 | std::vector _taskIds; 72 | std::vector _bufferIds; 73 | 74 | HdRenderBuffer* _renderBuffer; 75 | SdfPath _renderBufferId; 76 | SdfPath _renderTaskId; 77 | }; 78 | 79 | PXR_NAMESPACE_CLOSE_SCOPE 80 | 81 | #endif //BLACKBIRD_ENGINE_H -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Tangent Animation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | # including without limitation, as related to merchantability and fitness 13 | # for a particular purpose. 14 | # 15 | # In no event shall any copyright holder be liable for any damages of any kind 16 | # arising from the use of this software, whether in contract, tort or otherwise. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | 20 | add_executable(tests 21 | tests.cpp 22 | test_attributeSource.cpp 23 | test_transformSource.cpp 24 | ) 25 | 26 | target_include_directories(tests 27 | PRIVATE 28 | ${CMAKE_CURRENT_SOURCE_DIR}/doctest/ 29 | ) 30 | 31 | target_link_libraries(tests 32 | PRIVATE 33 | hdCycles 34 | ) 35 | -------------------------------------------------------------------------------- /tests/README.md: -------------------------------------------------------------------------------- 1 | # Tests 2 | 3 | ## Leak sanitizer 4 | 5 | ### Suppression file 6 | 7 | ``` 8 | > ./tests 9 | [doctest] doctest version is "2.4.6" 10 | [doctest] run with "--help" for options 11 | =============================================================================== 12 | [doctest] test cases: 9 | 9 passed | 0 failed | 0 skipped 13 | [doctest] assertions: 409 | 409 passed | 0 failed | 14 | [doctest] Status: SUCCESS! 15 | 16 | ================================================================= 17 | ==742373==ERROR: LeakSanitizer: detected memory leaks 18 | 19 | Direct leak of 1544 byte(s) in 1 object(s) allocated from: 20 | #0 0x7ff52344eec0 in operator new(unsigned long) (/lib/x86_64-linux-gnu/libasan.so.3+0xc7ec0) 21 | #1 0x7ff51d42397c in tbb::interface6::internal::ets_base<(tbb::ets_key_usage_type)1>::table_lookup(bool&) [clone .constprop.338] (/opt/hfs18.5/dsolib/libpxr_tf.so+0xab97c) 22 | 23 | Direct leak of 35 byte(s) in 1 object(s) allocated from: 24 | #0 0x7ff52344eec0 in operator new(unsigned long) (/lib/x86_64-linux-gnu/libasan.so.3+0xc7ec0) 25 | #1 0x7ff51cf05308 in std::string::_Rep::_S_create(unsigned long, unsigned long, std::allocator const&) (/lib/x86_64-linux-gnu/libstdc++.so.6+0xee308) 26 | 27 | Direct leak of 16 byte(s) in 2 object(s) allocated from: 28 | #0 0x7ff52344eec0 in operator new(unsigned long) (/lib/x86_64-linux-gnu/libasan.so.3+0xc7ec0) 29 | #1 0x7ff51f29f78d in void std::vector >::_M_emplace_back_aux(std::string&&) (/opt/hfs18.5/dsolib/libIlmImf_sidefx.so.24+0xbd78d) 30 | 31 | SUMMARY: AddressSanitizer: 1595 byte(s) leaked in 4 allocation(s). 32 | ``` 33 | 34 | ``` 35 | > LSAN_OPTIONS=suppressions=/home/bareya/tangent/dev/hdcycles/tests/lsan.supp ./tests 36 | [doctest] doctest version is "2.4.6" 37 | [doctest] run with "--help" for options 38 | =============================================================================== 39 | [doctest] test cases: 9 | 9 passed | 0 failed | 0 skipped 40 | [doctest] assertions: 409 | 409 passed | 0 failed | 41 | [doctest] Status: SUCCESS! 42 | ----------------------------------------------------- 43 | Suppressions used: 44 | count bytes template 45 | 3 51 std::string 46 | 1 1544 tbb:*table_lookup* 47 | ----------------------------------------------------- 48 | 49 | ``` -------------------------------------------------------------------------------- /tests/lsan.supp: -------------------------------------------------------------------------------- 1 | leak:std::string 2 | leak:tbb:*table_lookup* -------------------------------------------------------------------------------- /tests/test_transformSource.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Tangent Animation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | // including without limitation, as related to merchantability and fitness 13 | // for a particular purpose. 14 | // 15 | // In no event shall any copyright holder be liable for any damages of any kind 16 | // arising from the use of this software, whether in contract, tort or otherwise. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | 21 | #include 22 | 23 | #include 24 | #include 25 | 26 | PXR_NAMESPACE_USING_DIRECTIVE 27 | 28 | TEST_SUITE("Testing HdCyclesTransformSource") 29 | { 30 | // TODO: HdCyclesObjectSource should own object in the future 31 | // Include those tests directly into library 32 | auto _object_ptr = std::make_unique(); 33 | auto _object = _object_ptr.get(); 34 | 35 | HdCyclesMatrix4dTimeSampleArray samples; 36 | GfMatrix4d _fallback; 37 | 38 | TEST_CASE("Empty samples no motion blur - fallback matrix") 39 | { 40 | HdCyclesTransformSource src { _object, samples, _fallback }; 41 | CHECK(src.IsValid() == true); 42 | CHECK(src.Resolve() == true); 43 | CHECK(src.GetObject()->motion.size() == 0); 44 | } 45 | 46 | TEST_CASE("Single sample - no motion blur") 47 | { 48 | samples.Resize(1); 49 | 50 | HdCyclesTransformSource src { _object, samples, _fallback }; 51 | CHECK(src.IsValid() == true); 52 | CHECK(src.Resolve() == true); 53 | CHECK(src.GetObject()->motion.size() == 0); 54 | } 55 | 56 | TEST_CASE("Multi overlapping samples - no motion blur") 57 | { 58 | samples.Resize(10); 59 | 60 | HdCyclesTransformSource src { _object, samples, _fallback }; 61 | CHECK(src.IsValid() == true); 62 | CHECK(src.Resolve() == true); 63 | CHECK(src.GetObject()->motion.size() == 0); 64 | }; 65 | 66 | TEST_CASE("Three non overlapping samples") 67 | { 68 | samples.Resize(3); 69 | samples.times[0] = -1.0; 70 | samples.times[1] = -0.0; 71 | samples.times[2] = 1.0; 72 | 73 | HdCyclesTransformSource src { _object, samples, _fallback }; 74 | CHECK(src.IsValid() == true); 75 | CHECK(src.Resolve() == true); 76 | CHECK(src.GetObject()->motion.size() == 3); 77 | } 78 | 79 | TEST_CASE("Resample0") 80 | { 81 | samples.Resize(2); 82 | samples.times[0] = -0.5; 83 | samples.times[1] = 0.5; 84 | auto result = HdCyclesTransformSource::ResampleUniform(samples, 5); 85 | CHECK(result.count == 5); 86 | CHECK(result.times[0] == doctest::Approx { -0.50 }); 87 | CHECK(result.times[1] == doctest::Approx { -0.25 }); 88 | CHECK(result.times[2] == doctest::Approx { -0.00 }); 89 | CHECK(result.times[3] == doctest::Approx { +0.25 }); 90 | CHECK(result.times[4] == doctest::Approx { +0.50 }); 91 | } 92 | 93 | TEST_CASE("Resample1") 94 | { 95 | samples.Resize(2); 96 | samples.times[0] = -0.5; 97 | samples.times[1] = 0.5; 98 | auto result = HdCyclesTransformSource::ResampleUniform(samples, 3); 99 | CHECK(result.count == 3); 100 | } 101 | 102 | 103 | TEST_CASE("Resample2") 104 | { 105 | samples.Resize(5); 106 | samples.times[0] = -0.250; 107 | samples.times[1] = -0.125; 108 | samples.times[2] = -0.000; 109 | samples.times[3] = +0.125; 110 | samples.times[4] = +0.250; 111 | auto result = HdCyclesTransformSource::ResampleUniform(samples, 10); 112 | CHECK(result.count == 11); 113 | } 114 | 115 | 116 | TEST_CASE("Resample3") 117 | { 118 | samples.Resize(5); 119 | samples.times[0] = -0.250; 120 | samples.times[1] = -0.125; 121 | samples.times[2] = -0.000; 122 | samples.times[3] = +0.125; 123 | samples.times[4] = +0.250; 124 | auto result = HdCyclesTransformSource::ResampleUniform(samples, 3); 125 | CHECK(result.count == 3); 126 | CHECK(result.times[0] == doctest::Approx { -0.25 }); 127 | CHECK(result.times[1] == doctest::Approx { -0.00 }); 128 | CHECK(result.times[2] == doctest::Approx { +0.25 }); 129 | } 130 | 131 | TEST_CASE("Test request more samples than input data") 132 | { 133 | samples.Resize(3); 134 | samples.times[0] = -1.0; 135 | samples.times[1] = -0.0; 136 | samples.times[2] = 1.0; 137 | 138 | HdCyclesTransformSource src { _object, samples, _fallback, 11 }; 139 | CHECK(src.IsValid() == true); 140 | CHECK(src.Resolve() == true); 141 | CHECK(src.GetObject()->motion.size() == 11); 142 | } 143 | 144 | TEST_CASE("Test request less samples than input data") 145 | { 146 | samples.Resize(5); 147 | samples.times[0] = -0.250; 148 | samples.times[1] = -0.125; 149 | samples.times[2] = -0.000; 150 | samples.times[3] = +0.125; 151 | samples.times[4] = +0.250; 152 | 153 | HdCyclesTransformSource src { _object, samples, _fallback, 3 }; 154 | CHECK(src.IsValid() == true); 155 | CHECK(src.Resolve() == true); 156 | CHECK(src.GetObject()->motion.size() == 3); 157 | } 158 | 159 | TEST_CASE("Test request one sample") 160 | { 161 | samples.Resize(5); 162 | samples.times[0] = -0.250; 163 | samples.times[1] = -0.125; 164 | samples.times[2] = -0.000; 165 | samples.times[3] = +0.125; 166 | samples.times[4] = +0.250; 167 | 168 | HdCyclesTransformSource src { _object, samples, _fallback, 1 }; 169 | CHECK(src.IsValid() == true); 170 | CHECK(src.Resolve() == true); 171 | CHECK(src.GetObject()->motion.size() == 1); 172 | } 173 | 174 | TEST_CASE("Test request two get three samples") 175 | { 176 | samples.Resize(5); 177 | samples.times[0] = -0.250; 178 | samples.times[1] = -0.125; 179 | samples.times[2] = -0.000; 180 | samples.times[3] = +0.125; 181 | samples.times[4] = +0.250; 182 | 183 | HdCyclesTransformSource src { _object, samples, _fallback, 2 }; 184 | CHECK(src.IsValid() == true); 185 | CHECK(src.Resolve() == true); 186 | CHECK(src.GetObject()->motion.size() == 3); 187 | } 188 | } -------------------------------------------------------------------------------- /tests/tests.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Tangent Animation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 12 | // including without limitation, as related to merchantability and fitness 13 | // for a particular purpose. 14 | // 15 | // In no event shall any copyright holder be liable for any damages of any kind 16 | // arising from the use of this software, whether in contract, tort or otherwise. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | #define DOCTEST_CONFIG_IMPLEMENT 21 | #include 22 | --------------------------------------------------------------------------------