From bb6c8ef1c8aeb71ea3c02173d600ae6762520f4d Mon Sep 17 00:00:00 2001 From: Sungun Park Date: Tue, 12 Mar 2024 13:49:00 -0700 Subject: [PATCH] Add option FILAMENT_SAMPLES_STEREO_TYPE for samples/gltfio (#7658) This option can be either "instanced" or "multiview", indicating what stereoscopic rendering type shaders in samples/gltfio should be built for. --- CMakeLists.txt | 10 ++++++++++ libs/filamentapp/CMakeLists.txt | 12 +++++++++++- libs/filamentapp/src/FilamentApp.cpp | 5 +++++ libs/gltfio/CMakeLists.txt | 9 ++++++++- samples/CMakeLists.txt | 9 ++++++++- 5 files changed, 42 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 91ab2922d8..b18c4a5b4e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -531,6 +531,16 @@ else() option(FILAMENT_DISABLE_MATOPT "Disable material optimizations" ON) endif() +# This only affects the prebuilt shader files in gltfio and samples, not filament library. +# The value can be either "instanced" or "multiview". +set(FILAMENT_SAMPLES_STEREO_TYPE "instanced" CACHE STRING + "Stereoscopic type that shader files in gltfio and samples are built for." +) +string(TOLOWER "${FILAMENT_SAMPLES_STEREO_TYPE}" FILAMENT_SAMPLES_STEREO_TYPE) +if (NOT FILAMENT_SAMPLES_STEREO_TYPE STREQUAL "instanced" AND NOT FILAMENT_SAMPLES_STEREO_TYPE STREQUAL "multiview") + message(FATAL_ERROR "Invalid stereo type: \"${FILAMENT_SAMPLES_STEREO_TYPE}\" choose either \"instanced\" or \"multiview\" ") +endif () + # ================================================================================================== # Material compilation flags # ================================================================================================== diff --git a/libs/filamentapp/CMakeLists.txt b/libs/filamentapp/CMakeLists.txt index a2c1d0dedb..2e0e95b7da 100644 --- a/libs/filamentapp/CMakeLists.txt +++ b/libs/filamentapp/CMakeLists.txt @@ -88,13 +88,23 @@ file(MAKE_DIRECTORY ${MATERIAL_DIR}) file(MAKE_DIRECTORY ${RESOURCE_DIR}) set(RESOURCE_BINS) + +set (MATC_FLAGS ${MATC_BASE_FLAGS}) +if (FILAMENT_SAMPLES_STEREO_TYPE STREQUAL "instanced") + set (MATC_FLAGS ${MATC_FLAGS} -PstereoscopicType=instanced) + add_definitions(-DFILAMENT_SAMPLES_STEREO_TYPE_INSTANCED) +elseif (FILAMENT_SAMPLES_STEREO_TYPE STREQUAL "multiview") + set (MATC_FLAGS ${MATC_FLAGS} -PstereoscopicType=multiview) + add_definitions(-DFILAMENT_SAMPLES_STEREO_TYPE_MULTIVIEW) +endif () + foreach (mat_src ${MATERIAL_SRCS}) get_filename_component(localname "${mat_src}" NAME_WE) get_filename_component(fullname "${mat_src}" ABSOLUTE) set(output_path "${MATERIAL_DIR}/${localname}.filamat") add_custom_command( OUTPUT ${output_path} - COMMAND matc ${MATC_BASE_FLAGS} -o ${output_path} ${fullname} + COMMAND matc ${MATC_FLAGS} -o ${output_path} ${fullname} MAIN_DEPENDENCY ${mat_src} DEPENDS matc COMMENT "Compiling material ${mat_src} to ${output_path}" diff --git a/libs/filamentapp/src/FilamentApp.cpp b/libs/filamentapp/src/FilamentApp.cpp index 7e315b0da4..25f7126f83 100644 --- a/libs/filamentapp/src/FilamentApp.cpp +++ b/libs/filamentapp/src/FilamentApp.cpp @@ -605,6 +605,11 @@ FilamentApp::Window::Window(FilamentApp* filamentApp, Engine::Config engineConfig = {}; engineConfig.stereoscopicEyeCount = config.stereoscopicEyeCount; +#if defined(FILAMENT_SAMPLES_STEREO_TYPE_INSTANCED) + engineConfig.stereoscopicType = Engine::StereoscopicType::INSTANCED; +#elif defined (FILAMENT_SAMPLES_STEREO_TYPE_MULTIVIEW) + engineConfig.stereoscopicType = Engine::StereoscopicType::MULTIVIEW; +#endif if (backend == Engine::Backend::VULKAN) { #if defined(FILAMENT_DRIVER_SUPPORTS_VULKAN) diff --git a/libs/gltfio/CMakeLists.txt b/libs/gltfio/CMakeLists.txt index 3791525e29..2c1532cc16 100644 --- a/libs/gltfio/CMakeLists.txt +++ b/libs/gltfio/CMakeLists.txt @@ -69,6 +69,13 @@ set(TRANSPARENCY default) set(UBERZ_OUTPUT_PATH "${RESOURCE_DIR}/default.uberz") +set (MATC_FLAGS ${MATC_BASE_FLAGS}) +if (FILAMENT_SAMPLES_STEREO_TYPE STREQUAL "instanced") + set (MATC_FLAGS ${MATC_FLAGS} -PstereoscopicType=instanced) +elseif (FILAMENT_SAMPLES_STEREO_TYPE STREQUAL "multiview") + set (MATC_FLAGS ${MATC_FLAGS} -PstereoscopicType=multiview) +endif () + function(build_ubershader NAME SRC SHADINGMODEL BLENDING) set(DEST "${RESOURCE_DIR}/${NAME}") configure_file(materials/${SRC}.mat.in "${DEST}.mat" COPYONLY) @@ -85,7 +92,7 @@ function(build_ubershader NAME SRC SHADINGMODEL BLENDING) add_custom_command( OUTPUT "${NAME}.filamat" - COMMAND matc ${MATC_BASE_FLAGS} ${TEMPLATE_ARGS} -o "${NAME}.filamat" "${NAME}.mat" + COMMAND matc ${MATC_FLAGS} ${TEMPLATE_ARGS} -o "${NAME}.filamat" "${NAME}.mat" DEPENDS matc "${DEST}.mat" WORKING_DIRECTORY ${RESOURCE_DIR} COMMENT "Compiling material ${NAME}") diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 9b7804e94f..027f2f7d6b 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -47,13 +47,20 @@ endif() file(MAKE_DIRECTORY ${MATERIAL_DIR}) +set (MATC_FLAGS ${MATC_BASE_FLAGS}) +if (FILAMENT_SAMPLES_STEREO_TYPE STREQUAL "instanced") + set (MATC_FLAGS ${MATC_FLAGS} -PstereoscopicType=instanced) +elseif (FILAMENT_SAMPLES_STEREO_TYPE STREQUAL "multiview") + set (MATC_FLAGS ${MATC_FLAGS} -PstereoscopicType=multiview) +endif () + foreach (mat_src ${MATERIAL_SRCS}) get_filename_component(localname "${mat_src}" NAME_WE) get_filename_component(fullname "${mat_src}" ABSOLUTE) set(output_path "${MATERIAL_DIR}/${localname}.filamat") add_custom_command( OUTPUT ${output_path} - COMMAND matc ${MATC_BASE_FLAGS} -o ${output_path} ${fullname} + COMMAND matc ${MATC_FLAGS} -o ${output_path} ${fullname} MAIN_DEPENDENCY ${mat_src} DEPENDS matc COMMENT "Compiling material ${mat_src} to ${output_path}"