Skip to content

Commit

Permalink
Rework material handling (#301)
Browse files Browse the repository at this point in the history
* Rework material handling

- Implement nodal data-driven material generation from the given HdMaterialNetwork.
- Prepare the ground for MaterialX support:
  * parse node definitions from the given .mtlx files
  * define all RPR native nodes (RPR_MATERIAL_NODE_*) as .mtlx files
- Implement convenient wrapper around arithmetic nodes to simplify its usage: previously we had to keep two distinct code-paths for scalar/vector inputs and texture inputs.
- Houdini: add VOP node for each RPR material node

* Update Houdini packaging

* Fix macOS compilation errors

* macOS fixes

* Fix linux compilation errors

* Add MaterialX dependency as submodule

* Update install instructions

* Allow displacement controled via non-texture input

* Fix color AOV HdFormat

* Handle normal input for UsdPreviewSurface

* Fix image caching in UsdUVTexture node

* Register materials from RprUsdMaterialRegistry in SdrRegistry

USD 20.05 Hydra forbids material nodes with unknown id.

* Resolve review remarks
  • Loading branch information
hshakula committed Jul 28, 2020
1 parent 876d7f7 commit 03a0568
Show file tree
Hide file tree
Showing 125 changed files with 6,283 additions and 2,353 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Expand Up @@ -4,3 +4,6 @@
[submodule "deps/RPR"]
path = deps/RPR
url = https://github.com/GPUOpen-LibrariesAndSDKs/RadeonProRenderSDK
[submodule "deps/MaterialX"]
path = deps/MaterialX
url = https://github.com/materialx/MaterialX
19 changes: 17 additions & 2 deletions CMakeLists.txt
Expand Up @@ -29,8 +29,23 @@ include(Public)

set(CMAKE_CXX_STANDARD 14)


add_subdirectory(pxr/imaging/plugin/hdRpr)
if(NOT MaterialX_FOUND)
# If MaterialX was not explicitly provided, use the one from a submodule
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
if(HoudiniUSD_FOUND AND CMAKE_SYSTEM_NAME STREQUAL "Linux")
# Houdini builds with the old ABI. We need to match.
set(EXTERNAL_COMPILE_FLAGS "-D_GLIBCXX_USE_CXX11_ABI=0")
endif()
set(MATERIALX_PYTHON_LTO OFF)
set(MATERIALX_INSTALL_PYTHON OFF)
set(MATERIALX_BUILD_RENDER OFF)
set(MATERIALX_BUILD_GEN_GLSL OFF)
set(MATERIALX_BUILD_GEN_OSL OFF)
set(MATERIALX_BUILD_TESTS OFF)
add_subdirectory(deps/MaterialX)
endif()

add_subdirectory(pxr/imaging)

install(FILES README.md DESTINATION .)
install(FILES INSTALL.md DESTINATION .)
Expand Down
6 changes: 3 additions & 3 deletions INSTALL.md
Expand Up @@ -15,7 +15,7 @@ Add a new Houdini package with such configuration json:
"HOUDINI_PATH":"$RPR/houdini"
},
{
"PATH":"$RPR/bin"
"PATH":"$RPR/lib"
}
]
}
Expand All @@ -32,11 +32,11 @@ More info here https://www.sidefx.com/docs/houdini/ref/plugins.html

* Add `HDRPR_PACKAGE_DIR/plugin` path entry to the `PXR_PLUGINPATH_NAME` environment variable
* Add `HDRPR_PACKAGE_DIR/lib/python` path entry to the `PYTHONPATH` environment variable
* Windows only: add the `HDRPR_PACKAGE_DIR/bin` path entry to the `PATH` environment variable
* Windows only: add the `HDRPR_PACKAGE_DIR/lib` path entry to the `PATH` environment variable

OR

You can copy hdRpr package directories (bin, lib and plugin) directly to the root of your USD package.
You can copy hdRpr package directories (lib and plugin) directly to the root of your USD package.

## Installation from sources

Expand Down
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -49,6 +49,11 @@ Provide USD in one of two ways:
* An installation of USD. Define pxr_DIR to point to it when running cmake, if required. You can download USD to build yourself from [GitHub](https://www.github.com/PixarAnimationStudios/USD).
* The USD which is provided with Houdini. The HFS environment variable should point to the Houdini installation (the correct way is to run cmake from Houdini's `Command Line Tools` or by sourcing `houdini_setup`). You can download Houdini installer from [Downloads | SideFX](https://www.sidefx.com/download).

##### MaterialX Component

By default, MaterialX library will be compiled from the sources located under a MaterialX submodule `deps/MaterialX`.
You can override this behavior by providing a complete build of MaterialX to cmake. Please note, on Linux for Houdini plugin, MaterialX should be compiled with `-D_GLIBCXX_USE_CXX11_ABI=0` definition as it is required by Houdini.

##### Optional Components

##### OpenVDB
Expand Down
2 changes: 2 additions & 0 deletions cmake/defaults/Packages.cmake
Expand Up @@ -84,6 +84,8 @@ if (NOT PXR_MALLOC_LIBRARY)
endif()
endif()

find_package(MaterialX QUIET)

# Third Party Plugin Package Requirements
# ----------------------------------------------

Expand Down
5 changes: 5 additions & 0 deletions cmake/defaults/ProjectDefaults.cmake
Expand Up @@ -67,3 +67,8 @@ execute_process(
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_STRIP_TRAILING_WHITESPACE)
add_definitions(-DRPR_GIT_SHORT_HASH="${RPR_GIT_SHORT_HASH}")

if(MSVC)
# Allow running INSTALL target
set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1)
endif()
48 changes: 25 additions & 23 deletions cmake/macros/Private.cmake
Expand Up @@ -51,7 +51,7 @@ function(_copy_headers LIBRARY_NAME)
OUTPUT ${outfile}
COMMAND ${CMAKE_COMMAND} -E make_directory "${dir_to_create}"
COMMAND ${CMAKE_COMMAND} -Dinfile="${infile}" -Doutfile="${outfile}" -P "${PROJECT_SOURCE_DIR}/cmake/macros/copyHeaderForBuild.cmake"
MAIN_DEPENDENCY "${infile}"
DEPENDS "${infile}"
COMMENT "Copying ${f} ..."
VERBATIM
)
Expand Down Expand Up @@ -619,29 +619,32 @@ function(_pxr_add_rpath rpathRef target)
endfunction()

function(_pxr_install_rpath rpathRef NAME)
if(APPLE)
set(final "@loader_path/.")
else()
# Get and remove the origin.
list(GET ${rpathRef} 0 origin)
set(rpath ${${rpathRef}})
list(REMOVE_AT rpath 0)

set(final "")
# Canonicalize and uniquify paths.
foreach(path ${rpath})
# Strip trailing slashes.
string(REGEX REPLACE "/+$" "" path "${path}")

# Ignore paths we already have.
if (NOT ";${final};" MATCHES ";${path};")
list(APPEND final "${path}")
# Get and remove the origin.
list(GET ${rpathRef} 0 origin)
set(rpath ${${rpathRef}})
list(REMOVE_AT rpath 0)

# Canonicalize and uniquify paths.
set(final "")
foreach(path ${rpath})
if(APPLE)
if("${path}/" MATCHES "^[$]ORIGIN/")
# Replace with origin path.
string(REPLACE "$ORIGIN/" "@loader_path/" path "${path}/")
endif()
endforeach()
endif()
endif()

# Strip trailing slashes.
string(REGEX REPLACE "/+$" "" path "${path}")

# Ignore paths we already have.
if (NOT ";${final};" MATCHES ";${path};")
list(APPEND final "${path}")
endif()
endforeach()

set_target_properties(${NAME}
PROPERTIES
PROPERTIES
INSTALL_RPATH_USE_LINK_PATH FALSE
INSTALL_RPATH "${final}"
)
Expand Down Expand Up @@ -1256,10 +1259,9 @@ function(_pxr_library NAME)
${PXR_PREFIX}
)
target_include_directories(${NAME}
PRIVATE
PUBLIC
"${CMAKE_BINARY_DIR}/include"
"${CMAKE_BINARY_DIR}/${PXR_INSTALL_SUBDIR}/include"
PUBLIC
${args_INCLUDE_DIRS}
)

Expand Down
18 changes: 18 additions & 0 deletions cmake/macros/Public.cmake
Expand Up @@ -23,6 +23,24 @@
#
include(Private)

function(GroupSources target)
get_target_property(${target}_SOURCES ${target} SOURCES)
foreach(FILE ${${target}_SOURCES})
get_filename_component(ABS_FILE ${FILE} ABSOLUTE)
file(RELATIVE_PATH relPath ${CMAKE_CURRENT_SOURCE_DIR} ${ABS_FILE})

string(FIND "${relPath}" ".." out)
if("${out}" EQUAL 0)
source_group("external" FILES "${FILE}")
else()
get_filename_component(PARENT_DIR "${FILE}" DIRECTORY)
string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}" "" GROUP "${PARENT_DIR}")
string(REPLACE "/" "\\" GROUP "${GROUP}")
source_group("${GROUP}" FILES "${FILE}")
endif()
endforeach()
endfunction()

macro(GetAppDataPath retVal)
if(WIN32)
if(DEFINED ENV{PROGRAMDATA})
Expand Down
24 changes: 13 additions & 11 deletions cmake/modules/FindHoudiniUSD.cmake
@@ -1,17 +1,19 @@
# This finds Pixar USD which is part of a Houdini installation.

set(HOUDINI_ROOT $ENV{HFS} CACHE PATH "Houdini installation directory")

set(HUSD_REQ_VARS "")

find_path(Houdini_USD_INCLUDE_DIR
"pxr/pxr.h"
PATHS ENV HFS
PATHS ${HOUDINI_ROOT}
PATH_SUFFIXES "toolkit/include"
NO_DEFAULT_PATH)
list(APPEND HUSD_REQ_VARS "Houdini_USD_INCLUDE_DIR")

find_path(Houdini_USD_LIB_DIR
"libpxr_tf${CMAKE_SHARED_LIBRARY_SUFFIX}"
PATHS ENV HFS
PATHS ${HOUDINI_ROOT}
PATH_SUFFIXES
"dsolib" # Linux and Windows
"../Libraries" # macOS
Expand All @@ -22,15 +24,15 @@ list(APPEND HUSD_REQ_VARS "Houdini_USD_LIB_DIR")
if(WIN32)
find_path(Houdini_USD_IMPLIB_DIR
"libpxr_tf.lib"
PATHS ENV HFS
PATHS ${HOUDINI_ROOT}
PATH_SUFFIXES "custom/houdini/dsolib" # Windows (import lib)
NO_DEFAULT_PATH)
list(APPEND HUSD_REQ_VARS "Houdini_USD_IMPLIB_DIR")
endif()

find_path(Houdini_Python_INCLUDE_DIR
"pyconfig.h"
PATHS ENV HFS
PATHS ${HOUDINI_ROOT}
PATH_SUFFIXES
"toolkit/include/python2.7"
"toolkit/include/python3.7"
Expand All @@ -45,7 +47,7 @@ find_file(
"libpython3.7m${CMAKE_SHARED_LIBRARY_SUFFIX}" # Unix
#"python27.dll" "python37.dll" # Windows
"python27.lib" "python37.lib" # Windows (import lib)
PATHS ENV HFS
PATHS ${HOUDINI_ROOT}
PATH_SUFFIXES
"python/lib" # Linux
"../../../../Python.framework/Versions/Current/lib" # macOS
Expand All @@ -58,7 +60,7 @@ find_file(
Houdini_Boostpython_LIB
"libhboost_python-mt${CMAKE_SHARED_LIBRARY_SUFFIX}" # Unix
"hboost_python-mt.lib" # Windows (import lib)
PATHS ENV HFS
PATHS ${HOUDINI_ROOT}
PATH_SUFFIXES
"dsolib" # Linux
"../Libraries" # macOS
Expand All @@ -68,19 +70,19 @@ find_file(
list(APPEND HUSD_REQ_VARS "Houdini_Boostpython_LIB")

find_program(HYTHON_EXECUTABLE hython
PATHS ENV HFS
PATHS ${HOUDINI_ROOT}
PATH_SUFFIXES bin)
if(NOT HYTHON_EXECUTABLE)
message(FATAL "Could not find hython executable")
endif()
list(APPEND HUSD_REQ_VARS "HYTHON_EXECUTABLE")

if(WIN32)
set(Houdini_LIB_DIR $ENV{HFS}/custom/houdini/dsolib)
set(Houdini_LIB_DIR ${HOUDINI_ROOT}/custom/houdini/dsolib)
elseif(APPLE)
set(Houdini_LIB_DIR $ENV{HFS}/../Libraries)
set(Houdini_LIB_DIR ${HOUDINI_ROOT}/../Libraries)
else()
set(Houdini_LIB_DIR $ENV{HFS}/dsolib)
set(Houdini_LIB_DIR ${HOUDINI_ROOT}/dsolib)
endif()

include(FindPackageHandleStandardArgs)
Expand Down Expand Up @@ -128,7 +130,7 @@ if(HoudiniUSD_FOUND AND NOT TARGET hd)
"/wd4506" "/wd4244" "/wd4305" "/wd4267")
# For automatically linked libraries (python, tbb)
target_link_directories(${targetName}
INTERFACE "$ENV{HFS}/custom/houdini/dsolib")
INTERFACE "${HOUDINI_ROOT}/custom/houdini/dsolib")
endif()
endforeach()
# Add python to tf, usdImagingGL targets.
Expand Down
22 changes: 22 additions & 0 deletions cmake/modules/FindRpr.cmake
@@ -1,3 +1,7 @@
if(TARGET rpr)
return()
endif()

if(NOT RPR_LOCATION)
set(RPR_LOCATION ${PROJECT_SOURCE_DIR}/deps/RPR/RadeonProRender)
endif()
Expand Down Expand Up @@ -111,3 +115,21 @@ find_package_handle_standard_args(Rpr
RPR_LOADSTORE_LIBRARY
RPR_LIBRARY
)

add_library(rpr INTERFACE)
target_include_directories(rpr INTERFACE ${RPR_LOCATION_INCLUDE})
target_link_libraries(rpr INTERFACE ${RPR_LIBRARY} ${RPR_LOADSTORE_LIBRARY})

if(NOT DEFINED RPR_CPP_WRAPPER_LOCATION)
set(RPR_CPP_WRAPPER_LOCATION ${RPR_TOOLS_LOCATION})
endif()

add_library(cpprpr STATIC
${RPR_CPP_WRAPPER_LOCATION}/RadeonProRender.hpp
${RPR_CPP_WRAPPER_LOCATION}/RadeonProRenderCpp.cpp)
set_target_properties(cpprpr PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_include_directories(cpprpr PUBLIC ${RPR_CPP_WRAPPER_LOCATION})
target_link_libraries(cpprpr PUBLIC rpr)
target_compile_definitions(cpprpr PUBLIC
RPR_CPPWRAPER_DISABLE_MUTEXLOCK
RPR_API_USE_HEADER_V2)
10 changes: 10 additions & 0 deletions cmake/modules/FindUSDMonolithic.cmake
Expand Up @@ -91,4 +91,14 @@ if(USDMonolithic_FOUND)
IMPORTED_IMPLIB_RELEASE "${USD_MONOLITHIC_LIBRARY}"
IMPORTED_LOCATION_RELEASE "${USD_LIBRARY_DIR}/${PXR_LIB_PREFIX}usd_ms${CMAKE_SHARED_LIBRARY_SUFFIX}"
)

foreach(targetName
arch tf gf js trace work plug vt ar kind sdf ndr sdr pcp usd usdGeom
usdVol usdLux usdMedia usdShade usdRender usdHydra usdRi usdSkel usdUI
usdUtils garch hf hio cameraUtil pxOsd glf hgi hgiGL hd hdSt hdx
usdImaging usdImagingGL usdRiImaging usdSkelImaging usdVolImaging
usdAppUtils usdviewq)
add_library(${targetName} INTERFACE)
target_link_libraries(${targetName} INTERFACE usd_ms)
endforeach()
endif()
1 change: 1 addition & 0 deletions deps/MaterialX
Submodule MaterialX added at 8af392
2 changes: 2 additions & 0 deletions pxr/imaging/CMakeLists.txt
@@ -0,0 +1,2 @@
add_subdirectory(rprUsd)
add_subdirectory(plugin)
2 changes: 2 additions & 0 deletions pxr/imaging/plugin/CMakeLists.txt
@@ -0,0 +1,2 @@
add_subdirectory(hdRpr)
add_subdirectory(rprHoudini)

0 comments on commit 03a0568

Please sign in to comment.