From abb0cbc98ea4821396c442ea2c4e655f2d687785 Mon Sep 17 00:00:00 2001 From: Sungun Park Date: Mon, 25 Mar 2024 14:43:04 -0700 Subject: [PATCH] Add FILAMENT_ENABLE_MULTIVIEW option (#7707) This allows the engine to include multiview shader code for default materials. --- CMakeLists.txt | 7 +++++++ filament/CMakeLists.txt | 7 ++++++- filament/src/details/Engine.cpp | 4 ++++ filament/src/details/Skybox.cpp | 4 ++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b18c4a5b4e..ed32949873 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,6 +45,8 @@ option(FILAMENT_ENABLE_TSAN "Enable Thread Sanitizer" OFF) option(FILAMENT_ENABLE_FEATURE_LEVEL_0 "Enable Feature Level 0" ON) +option(FILAMENT_ENABLE_MULTIVIEW "Enable multiview for Filament" OFF) + set(FILAMENT_NDK_VERSION "" CACHE STRING "Android NDK version or version prefix to be used when building for Android." ) @@ -541,6 +543,11 @@ if (NOT FILAMENT_SAMPLES_STEREO_TYPE STREQUAL "instanced" AND NOT FILAMENT_SAMPL message(FATAL_ERROR "Invalid stereo type: \"${FILAMENT_SAMPLES_STEREO_TYPE}\" choose either \"instanced\" or \"multiview\" ") endif () +# Compiling samples for multiview implies enabling multiview feature as well. +if (FILAMENT_SAMPLES_STEREO_TYPE STREQUAL "multiview") + set(FILAMENT_ENABLE_MULTIVIEW ON) +endif () + # ================================================================================================== # Material compilation flags # ================================================================================================== diff --git a/filament/CMakeLists.txt b/filament/CMakeLists.txt index 66b78307cc..b978d2da1b 100644 --- a/filament/CMakeLists.txt +++ b/filament/CMakeLists.txt @@ -290,6 +290,11 @@ if (FILAMENT_ENABLE_FEATURE_LEVEL_0) add_definitions(-DFILAMENT_ENABLE_FEATURE_LEVEL_0) endif() +# Whether to include MULTIVIEW materials. +if (FILAMENT_ENABLE_MULTIVIEW) + add_definitions(-DFILAMENT_ENABLE_MULTIVIEW) +endif() + # ================================================================================================== # Definitions # ================================================================================================== @@ -343,7 +348,7 @@ foreach (mat_src ${MATERIAL_SRCS}) endif () list(FIND MATERIAL_MULTIVIEW_SRCS ${mat_src} index) - if (${index} GREATER -1) + if (${index} GREATER -1 AND FILAMENT_ENABLE_MULTIVIEW) string(REGEX REPLACE "[.]filamat$" "_multiview.filamat" output_path_multiview ${output_path}) add_custom_command( OUTPUT ${output_path_multiview} diff --git a/filament/src/details/Engine.cpp b/filament/src/details/Engine.cpp index dbd49a8b71..5f7396fb3d 100644 --- a/filament/src/details/Engine.cpp +++ b/filament/src/details/Engine.cpp @@ -356,8 +356,12 @@ void FEngine::init() { MATERIALS_DEFAULTMATERIAL_DATA, MATERIALS_DEFAULTMATERIAL_SIZE); break; case StereoscopicType::MULTIVIEW: +#ifdef FILAMENT_ENABLE_MULTIVIEW defaultMaterialBuilder.package( MATERIALS_DEFAULTMATERIAL_MULTIVIEW_DATA, MATERIALS_DEFAULTMATERIAL_MULTIVIEW_SIZE); +#else + assert_invariant(false); +#endif break; } mDefaultMaterial = downcast(defaultMaterialBuilder.build(*const_cast(this))); diff --git a/filament/src/details/Skybox.cpp b/filament/src/details/Skybox.cpp index 7fe6291bc8..39aca8ef8c 100644 --- a/filament/src/details/Skybox.cpp +++ b/filament/src/details/Skybox.cpp @@ -129,7 +129,11 @@ FMaterial const* FSkybox::createMaterial(FEngine& engine) { builder.package(MATERIALS_SKYBOX_DATA, MATERIALS_SKYBOX_SIZE); break; case Engine::StereoscopicType::MULTIVIEW: +#ifdef FILAMENT_ENABLE_MULTIVIEW builder.package(MATERIALS_SKYBOX_MULTIVIEW_DATA, MATERIALS_SKYBOX_MULTIVIEW_SIZE); +#else + assert_invariant(false); +#endif break; } }