Skip to content

Commit

Permalink
Draft : Prototype of named values proposal (AcademySoftwareFoundation…
Browse files Browse the repository at this point in the history
…#2149).

Add 'zero' and 'one' named values to some basic types, and use those named values in some of the basic arithmetic nodes as an example.  Add build time tool to process and write out resolved values, and add support for run-time evaluation - switchable by setting MATERIALX_BUILD_BAKE_NAMED_VALUES cmake flag
  • Loading branch information
ld-kerley committed Dec 17, 2024
1 parent 31ca71b commit a95b9d2
Show file tree
Hide file tree
Showing 12 changed files with 468 additions and 195 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ option(MATERIALX_BUILD_VIEWER "Build the MaterialX Viewer." OFF)
option(MATERIALX_BUILD_GRAPH_EDITOR "Build the MaterialX Graph Editor." OFF)
option(MATERIALX_BUILD_DOCS "Create HTML documentation using Doxygen. Requires that Doxygen be installed." OFF)

option(MATERIALX_BUILD_BAKE_NAMED_VALUES "Process the data library files at build time to bake out the named values." ON)

option(MATERIALX_BUILD_GEN_GLSL "Build the GLSL shader generator back-end." ON)
option(MATERIALX_BUILD_GEN_OSL "Build the OSL shader generator back-end." ON)
option(MATERIALX_BUILD_GEN_MDL "Build the MDL shader generator back-end." ON)
Expand Down Expand Up @@ -439,6 +441,7 @@ endif()
# Add core subdirectories
add_subdirectory(source/MaterialXCore)
add_subdirectory(source/MaterialXFormat)
add_subdirectory(source/MaterialXBuildTools/buildLibrary)

# Add shader generation subdirectories
add_subdirectory(source/MaterialXGenShader)
Expand Down
43 changes: 37 additions & 6 deletions libraries/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,39 @@

set(MATERIALX_DATA_LIBRARY_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/data_library)

function(build_data_library TARGET_NAME SOURCE_DIR DEST_DIR)

if (${MATERIALX_BUILD_BAKE_NAMED_VALUES})
add_custom_target(${TARGET_NAME} ALL
COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different
${SOURCE_DIR}/
${DEST_DIR}
COMMAND MaterialXBuildLibrary --sourceLibraryRoot ${SOURCE_DIR} --destLibraryRoot ${DEST_DIR}
COMMAND ${CMAKE_COMMAND} -E rm ${DEST_DIR}/CmakeLists.txt
)
else()
add_custom_target(${TARGET_NAME} ALL
COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different
${SOURCE_DIR}/
${DEST_DIR}
COMMAND ${CMAKE_COMMAND} -E rm ${DEST_DIR}/CmakeLists.txt
)
endif()

endfunction(build_data_library)

build_data_library(buildDataLibrary ${CMAKE_CURRENT_SOURCE_DIR} ${MATERIALX_DATA_LIBRARY_BUILD_DIR})

if(MATERIALX_BUILD_TESTS)
build_data_library(buildTestDataLibrary ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/libraries)
endif()



if(NOT SKBUILD)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/
DESTINATION "${MATERIALX_INSTALL_STDLIB_PATH}"
PATTERN "CMakeLists.txt" EXCLUDE)
install(DIRECTORY ${MATERIALX_DATA_LIBRARY_BUILD_DIR}/
DESTINATION "${MATERIALX_INSTALL_STDLIB_PATH}"
)
endif()

set(MATERIALX_PYTHON_LIBRARIES_PATH "${MATERIALX_PYTHON_FOLDER_NAME}/${MATERIALX_INSTALL_STDLIB_PATH}")
Expand All @@ -10,7 +42,6 @@ if(SKBUILD)
endif()

if(MATERIALX_BUILD_PYTHON)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/
DESTINATION "${MATERIALX_PYTHON_LIBRARIES_PATH}"
PATTERN "CMakeLists.txt" EXCLUDE)
install(DIRECTORY ${MATERIALX_DATA_LIBRARY_BUILD_DIR}/
DESTINATION "${MATERIALX_PYTHON_LIBRARIES_PATH}")
endif()
250 changes: 125 additions & 125 deletions libraries/stdlib/stdlib_defs.mtlx

Large diffs are not rendered by default.

110 changes: 55 additions & 55 deletions libraries/stdlib/stdlib_ng.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -3795,11 +3795,11 @@
<input name="in" type="float" interfacename="in" />
<input name="inlow" type="float" interfacename="inlow" />
<input name="inhigh" type="float" interfacename="inhigh" />
<input name="outlow" type="float" value="0.0" />
<input name="outhigh" type="float" value="1.0" />
<input name="outlow" type="float" value="Value:zero" />
<input name="outhigh" type="float" value="Value:one" />
</remap>
<divide name="N_recip_float" type="float">
<input name="in1" type="float" value="1.0" />
<input name="in1" type="float" value="Value:one" />
<input name="in2" type="float" interfacename="gamma" />
</divide>
<absval name="N_abs_float" type="float">
Expand All @@ -3818,8 +3818,8 @@
</multiply>
<remap name="N_remap2_float" type="float">
<input name="in" type="float" nodename="N_gamma_float" />
<input name="inlow" type="float" value="0.0" />
<input name="inhigh" type="float" value="1.0" />
<input name="inlow" type="float" value="Value:zero" />
<input name="inhigh" type="float" value="Value:one" />
<input name="outlow" type="float" interfacename="outlow" />
<input name="outhigh" type="float" interfacename="outhigh" />
</remap>
Expand All @@ -3841,11 +3841,11 @@
<input name="in" type="color3" interfacename="in" />
<input name="inlow" type="color3" interfacename="inlow" />
<input name="inhigh" type="color3" interfacename="inhigh" />
<input name="outlow" type="color3" value="0.0, 0.0, 0.0" />
<input name="outhigh" type="color3" value="1.0, 1.0, 1.0" />
<input name="outlow" type="color3" value="Value:zero" />
<input name="outhigh" type="color3" value="Value:one" />
</remap>
<divide name="N_recip_color3" type="color3">
<input name="in1" type="color3" value="1.0, 1.0, 1.0" />
<input name="in1" type="color3" value="Value:one" />
<input name="in2" type="color3" interfacename="gamma" />
</divide>
<absval name="N_abs_color3" type="color3">
Expand All @@ -3864,8 +3864,8 @@
</multiply>
<remap name="N_remap2_color3" type="color3">
<input name="in" type="color3" nodename="N_gamma_color3" />
<input name="inlow" type="color3" value="0.0, 0.0, 0.0" />
<input name="inhigh" type="color3" value="1.0, 1.0, 1.0" />
<input name="inlow" type="color3" value="Value:zero" />
<input name="inhigh" type="color3" value="Value:one" />
<input name="outlow" type="color3" interfacename="outlow" />
<input name="outhigh" type="color3" interfacename="outhigh" />
</remap>
Expand All @@ -3887,11 +3887,11 @@
<input name="in" type="color4" interfacename="in" />
<input name="inlow" type="color4" interfacename="inlow" />
<input name="inhigh" type="color4" interfacename="inhigh" />
<input name="outlow" type="color4" value="0.0, 0.0, 0.0, 0.0" />
<input name="outhigh" type="color4" value="1.0, 1.0, 1.0, 1.0" />
<input name="outlow" type="color4" value="Value:zero" />
<input name="outhigh" type="color4" value="Value:one" />
</remap>
<divide name="N_recip_color4" type="color4">
<input name="in1" type="color4" value="1.0, 1.0, 1.0, 1.0" />
<input name="in1" type="color4" value="Value:one" />
<input name="in2" type="color4" interfacename="gamma" />
</divide>
<absval name="N_abs_color4" type="color4">
Expand All @@ -3910,8 +3910,8 @@
</multiply>
<remap name="N_remap2_color4" type="color4">
<input name="in" type="color4" nodename="N_gamma_color4" />
<input name="inlow" type="color4" value="0.0, 0.0, 0.0, 0.0" />
<input name="inhigh" type="color4" value="1.0, 1.0, 1.0, 1.0" />
<input name="inlow" type="color4" value="Value:zero" />
<input name="inhigh" type="color4" value="Value:one" />
<input name="outlow" type="color4" interfacename="outlow" />
<input name="outhigh" type="color4" interfacename="outhigh" />
</remap>
Expand All @@ -3933,11 +3933,11 @@
<input name="in" type="vector2" interfacename="in" />
<input name="inlow" type="vector2" interfacename="inlow" />
<input name="inhigh" type="vector2" interfacename="inhigh" />
<input name="outlow" type="vector2" value="0.0, 0.0" />
<input name="outhigh" type="vector2" value="1.0, 1.0" />
<input name="outlow" type="vector2" value="Value:zero" />
<input name="outhigh" type="vector2" value="Value:one" />
</remap>
<divide name="N_recip_vector2" type="vector2">
<input name="in1" type="vector2" value="1.0, 1.0" />
<input name="in1" type="vector2" value="Value:one" />
<input name="in2" type="vector2" interfacename="gamma" />
</divide>
<absval name="N_abs_vector2" type="vector2">
Expand All @@ -3956,8 +3956,8 @@
</multiply>
<remap name="N_remap2_vector2" type="vector2">
<input name="in" type="vector2" nodename="N_gamma_vector2" />
<input name="inlow" type="vector2" value="0.0, 0.0" />
<input name="inhigh" type="vector2" value="1.0, 1.0" />
<input name="inlow" type="vector2" value="Value:zero" />
<input name="inhigh" type="vector2" value="Value:one" />
<input name="outlow" type="vector2" interfacename="outlow" />
<input name="outhigh" type="vector2" interfacename="outhigh" />
</remap>
Expand All @@ -3979,11 +3979,11 @@
<input name="in" type="vector3" interfacename="in" />
<input name="inlow" type="vector3" interfacename="inlow" />
<input name="inhigh" type="vector3" interfacename="inhigh" />
<input name="outlow" type="vector3" value="0.0, 0.0, 0.0" />
<input name="outhigh" type="vector3" value="1.0, 1.0, 1.0" />
<input name="outlow" type="vector3" value="Value:zero" />
<input name="outhigh" type="vector3" value="Value:one" />
</remap>
<divide name="N_recip_vector3" type="vector3">
<input name="in1" type="vector3" value="1.0, 1.0, 1.0" />
<input name="in1" type="vector3" value="Value:one" />
<input name="in2" type="vector3" interfacename="gamma" />
</divide>
<absval name="N_abs_vector3" type="vector3">
Expand All @@ -4002,8 +4002,8 @@
</multiply>
<remap name="N_remap2_vector3" type="vector3">
<input name="in" type="vector3" nodename="N_gamma_vector3" />
<input name="inlow" type="vector3" value="0.0, 0.0, 0.0" />
<input name="inhigh" type="vector3" value="1.0, 1.0, 1.0" />
<input name="inlow" type="vector3" value="Value:zero" />
<input name="inhigh" type="vector3" value="Value:one" />
<input name="outlow" type="vector3" interfacename="outlow" />
<input name="outhigh" type="vector3" interfacename="outhigh" />
</remap>
Expand All @@ -4025,11 +4025,11 @@
<input name="in" type="vector4" interfacename="in" />
<input name="inlow" type="vector4" interfacename="inlow" />
<input name="inhigh" type="vector4" interfacename="inhigh" />
<input name="outlow" type="vector4" value="0.0, 0.0, 0.0, 0.0" />
<input name="outhigh" type="vector4" value="1.0, 1.0, 1.0, 1.0" />
<input name="outlow" type="vector4" value="Value:zero" />
<input name="outhigh" type="vector4" value="Value:one" />
</remap>
<divide name="N_recip_vector4" type="vector4">
<input name="in1" type="vector4" value="1.0, 1.0, 1.0, 1.0" />
<input name="in1" type="vector4" value="Value:one" />
<input name="in2" type="vector4" interfacename="gamma" />
</divide>
<absval name="N_abs_vector4" type="vector4">
Expand All @@ -4048,8 +4048,8 @@
</multiply>
<remap name="N_remap2_vector4" type="vector4">
<input name="in" type="vector4" nodename="N_gamma_vector4" />
<input name="inlow" type="vector4" value="0.0, 0.0, 0.0, 0.0" />
<input name="inhigh" type="vector4" value="1.0, 1.0, 1.0, 1.0" />
<input name="inlow" type="vector4" value="Value:zero" />
<input name="inhigh" type="vector4" value="Value:one" />
<input name="outlow" type="vector4" interfacename="outlow" />
<input name="outhigh" type="vector4" interfacename="outhigh" />
</remap>
Expand All @@ -4071,11 +4071,11 @@
<input name="in" type="color3" interfacename="in" />
<input name="inlow" type="float" interfacename="inlow" />
<input name="inhigh" type="float" interfacename="inhigh" />
<input name="outlow" type="float" value="0.0" />
<input name="outhigh" type="float" value="1.0" />
<input name="outlow" type="float" value="Value:zero" />
<input name="outhigh" type="float" value="Value:one" />
</remap>
<divide name="N_recip_color3FA" type="float">
<input name="in1" type="float" value="1.0" />
<input name="in1" type="float" value="Value:one" />
<input name="in2" type="float" interfacename="gamma" />
</divide>
<absval name="N_abs_color3FA" type="color3">
Expand All @@ -4094,8 +4094,8 @@
</multiply>
<remap name="N_remap2_color3FA" type="color3">
<input name="in" type="color3" nodename="N_gamma_color3FA" />
<input name="inlow" type="float" value="0.0" />
<input name="inhigh" type="float" value="1.0" />
<input name="inlow" type="float" value="Value:zero" />
<input name="inhigh" type="float" value="Value:one" />
<input name="outlow" type="float" interfacename="outlow" />
<input name="outhigh" type="float" interfacename="outhigh" />
</remap>
Expand All @@ -4117,11 +4117,11 @@
<input name="in" type="color4" interfacename="in" />
<input name="inlow" type="float" interfacename="inlow" />
<input name="inhigh" type="float" interfacename="inhigh" />
<input name="outlow" type="float" value="0.0" />
<input name="outhigh" type="float" value="1.0" />
<input name="outlow" type="float" value="Value:zero" />
<input name="outhigh" type="float" value="Value:one" />
</remap>
<divide name="N_recip_color4FA" type="float">
<input name="in1" type="float" value="1.0" />
<input name="in1" type="float" value="Value:one" />
<input name="in2" type="float" interfacename="gamma" />
</divide>
<absval name="N_abs_color4FA" type="color4">
Expand All @@ -4140,8 +4140,8 @@
</multiply>
<remap name="N_remap2_color4FA" type="color4">
<input name="in" type="color4" nodename="N_gamma_color4FA" />
<input name="inlow" type="float" value="0.0" />
<input name="inhigh" type="float" value="1.0" />
<input name="inlow" type="float" value="Value:zero" />
<input name="inhigh" type="float" value="Value:one" />
<input name="outlow" type="float" interfacename="outlow" />
<input name="outhigh" type="float" interfacename="outhigh" />
</remap>
Expand All @@ -4163,11 +4163,11 @@
<input name="in" type="vector2" interfacename="in" />
<input name="inlow" type="float" interfacename="inlow" />
<input name="inhigh" type="float" interfacename="inhigh" />
<input name="outlow" type="float" value="0.0" />
<input name="outhigh" type="float" value="1.0" />
<input name="outlow" type="float" value="Value:zero" />
<input name="outhigh" type="float" value="Value:one" />
</remap>
<divide name="N_recip_vector2FA" type="float">
<input name="in1" type="float" value="1.0" />
<input name="in1" type="float" value="Value:one" />
<input name="in2" type="float" interfacename="gamma" />
</divide>
<absval name="N_abs_vector2FA" type="vector2">
Expand All @@ -4186,8 +4186,8 @@
</multiply>
<remap name="N_remap2_vector2FA" type="vector2">
<input name="in" type="vector2" nodename="N_gamma_vector2FA" />
<input name="inlow" type="float" value="0.0" />
<input name="inhigh" type="float" value="1.0" />
<input name="inlow" type="float" value="Value:zero" />
<input name="inhigh" type="float" value="Value:one" />
<input name="outlow" type="float" interfacename="outlow" />
<input name="outhigh" type="float" interfacename="outhigh" />
</remap>
Expand All @@ -4209,11 +4209,11 @@
<input name="in" type="vector3" interfacename="in" />
<input name="inlow" type="float" interfacename="inlow" />
<input name="inhigh" type="float" interfacename="inhigh" />
<input name="outlow" type="float" value="0.0" />
<input name="outhigh" type="float" value="1.0" />
<input name="outlow" type="float" value="Value:zero" />
<input name="outhigh" type="float" value="Value:one" />
</remap>
<divide name="N_recip_vector3FA" type="float">
<input name="in1" type="float" value="1.0" />
<input name="in1" type="float" value="Value:one" />
<input name="in2" type="float" interfacename="gamma" />
</divide>
<absval name="N_abs_vector3FA" type="vector3">
Expand All @@ -4232,8 +4232,8 @@
</multiply>
<remap name="N_remap2_vector3FA" type="vector3">
<input name="in" type="vector3" nodename="N_gamma_vector3FA" />
<input name="inlow" type="float" value="0.0" />
<input name="inhigh" type="float" value="1.0" />
<input name="inlow" type="float" value="Value:zero" />
<input name="inhigh" type="float" value="Value:one" />
<input name="outlow" type="float" interfacename="outlow" />
<input name="outhigh" type="float" interfacename="outhigh" />
</remap>
Expand All @@ -4255,11 +4255,11 @@
<input name="in" type="vector4" interfacename="in" />
<input name="inlow" type="float" interfacename="inlow" />
<input name="inhigh" type="float" interfacename="inhigh" />
<input name="outlow" type="float" value="0.0" />
<input name="outhigh" type="float" value="1.0" />
<input name="outlow" type="float" value="Value:zero" />
<input name="outhigh" type="float" value="Value:one" />
</remap>
<divide name="N_recip_vector4FA" type="float">
<input name="in1" type="float" value="1.0" />
<input name="in1" type="float" value="Value:one" />
<input name="in2" type="float" interfacename="gamma" />
</divide>
<absval name="N_abs_vector4FA" type="vector4">
Expand All @@ -4278,8 +4278,8 @@
</multiply>
<remap name="N_remap2_vector4FA" type="vector4">
<input name="in" type="vector4" nodename="N_gamma_vector4FA" />
<input name="inlow" type="float" value="0.0" />
<input name="inhigh" type="float" value="1.0" />
<input name="inlow" type="float" value="Value:zero" />
<input name="inhigh" type="float" value="Value:one" />
<input name="outlow" type="float" interfacename="outlow" />
<input name="outhigh" type="float" interfacename="outhigh" />
</remap>
Expand Down
15 changes: 15 additions & 0 deletions source/MaterialXBuildTools/buildLibrary/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

file(GLOB materialx_source "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
file(GLOB materialx_headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h*")

set(TARGET_NAME MaterialXBuildLibrary)

set(MATERIALX_LIBRARIES
MaterialXFormat
MaterialXCore)

add_executable(${TARGET_NAME} ${materialx_source} ${materialx_headers})

target_link_libraries(
${TARGET_NAME}
${MATERIALX_LIBRARIES})
Loading

0 comments on commit a95b9d2

Please sign in to comment.