diff --git a/cpp/open3d/visualization/gui/ImguiFilamentBridge.cpp b/cpp/open3d/visualization/gui/ImguiFilamentBridge.cpp index 243e3868a77..49fa97ec041 100644 --- a/cpp/open3d/visualization/gui/ImguiFilamentBridge.cpp +++ b/cpp/open3d/visualization/gui/ImguiFilamentBridge.cpp @@ -22,6 +22,7 @@ * limitations under the License. */ +#include #include "open3d/visualization/gui/ImguiFilamentBridge.h" // 4068: Filament has some clang-specific vectorizing pragma's that MSVC flags @@ -31,6 +32,11 @@ #pragma warning(disable : 4068 4305) #endif // _MSC_VER +#include +#include +#include +#include + #include #include #include @@ -45,11 +51,6 @@ #include #include -#include -#include -#include -#include - #include "open3d/utility/FileSystem.h" #include "open3d/visualization/gui/Application.h" #include "open3d/visualization/gui/Color.h" diff --git a/cpp/open3d/visualization/gui/SceneWidget.cpp b/cpp/open3d/visualization/gui/SceneWidget.cpp index fe03ec73a7f..138c936c214 100644 --- a/cpp/open3d/visualization/gui/SceneWidget.cpp +++ b/cpp/open3d/visualization/gui/SceneWidget.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include "open3d/camera/PinholeCameraIntrinsic.h" #include "open3d/geometry/BoundingVolume.h" diff --git a/cpp/open3d/visualization/rendering/filament/FilamentCamera.cpp b/cpp/open3d/visualization/rendering/filament/FilamentCamera.cpp index 31f8572392e..eae8c7fd1a1 100644 --- a/cpp/open3d/visualization/rendering/filament/FilamentCamera.cpp +++ b/cpp/open3d/visualization/rendering/filament/FilamentCamera.cpp @@ -40,15 +40,15 @@ Camera::Transform FilamentToCameraTransform(const filament::math::mat4& ft) { return Camera::Transform(m); } -Camera::Transform FilamentToCameraTransform(const filament::math::mat4f& ft) { - Camera::Transform::MatrixType m; - - m << ft(0, 0), ft(0, 1), ft(0, 2), ft(0, 3), ft(1, 0), ft(1, 1), ft(1, 2), - ft(1, 3), ft(2, 0), ft(2, 1), ft(2, 2), ft(2, 3), ft(3, 0), - ft(3, 1), ft(3, 2), ft(3, 3); - - return Camera::Transform(m); -} +// Camera::Transform FilamentToCameraTransform(const filament::math::mat4f& ft) { +// Camera::Transform::MatrixType m; +// +// m << ft(0, 0), ft(0, 1), ft(0, 2), ft(0, 3), ft(1, 0), ft(1, 1), ft(1, 2), +// ft(1, 3), ft(2, 0), ft(2, 1), ft(2, 2), ft(2, 3), ft(3, 0), +// ft(3, 1), ft(3, 2), ft(3, 3); +// +// return Camera::Transform(m); +// } filament::math::mat4f CameraToFilamentTransformF(const Camera::Transform& t) { auto e_matrix = t.matrix(); @@ -240,7 +240,7 @@ void FilamentCamera::LookAt(const Eigen::Vector3f& center, Eigen::Vector3f FilamentCamera::GetPosition() const { auto cam_pos = camera_->getPosition(); - return {cam_pos.x, cam_pos.y, cam_pos.z}; + return {static_cast(cam_pos.x), static_cast(cam_pos.y), static_cast(cam_pos.z)}; } Eigen::Vector3f FilamentCamera::GetForwardVector() const { @@ -314,7 +314,7 @@ void FilamentCamera::SetModelMatrix(const Eigen::Vector3f& forward, const Eigen::Vector3f& up) { using namespace filament; - math::mat4f ftransform = camera_->getModelMatrix(); + math::mat4 ftransform = camera_->getModelMatrix(); ftransform[0].xyz = math::float3(left.x(), left.y(), left.z()); ftransform[1].xyz = math::float3(up.x(), up.y(), up.z()); ftransform[2].xyz = math::float3(forward.x(), forward.y(), forward.z()); diff --git a/cpp/open3d/visualization/rendering/filament/FilamentEngine.cpp b/cpp/open3d/visualization/rendering/filament/FilamentEngine.cpp index f3d03ebec40..2f0dfd43cc1 100644 --- a/cpp/open3d/visualization/rendering/filament/FilamentEngine.cpp +++ b/cpp/open3d/visualization/rendering/filament/FilamentEngine.cpp @@ -76,7 +76,7 @@ void EngineInstance::DestroyInstance() { g_instance.reset(); } /// external function defined in custom Filament EGL backend for headless /// rendering -extern "C" filament::backend::Platform* CreateEGLHeadlessPlatform(); +// extern "C" filament::backend::Platform* CreateEGLHeadlessPlatform(); EngineInstance::EngineInstance() { filament::backend::Backend backend = filament::backend::Backend::DEFAULT; @@ -99,13 +99,16 @@ EngineInstance::EngineInstance() { if (is_headless_) { #ifdef __linux__ utility::LogInfo("EGL headless mode enabled."); - custom_platform = CreateEGLHeadlessPlatform(); + // ******** NOTE ******** FIGURE OUT HEADLESS WITH LATEST FILAMENT!! + // custom_platform = CreateEGLHeadlessPlatform(); #else utility::LogError("EGL Headless is not supported on this platform."); #endif } engine_ = filament::Engine::create(backend, custom_platform); + utility::LogWarning("Feature level detected: {}", (int)engine_->getSupportedFeatureLevel()); + // engine_->setActiveFeatureLevel(filament::Engine::FeatureLevel::FEATURE_LEVEL_2); resource_manager_ = new FilamentResourceManager(*engine_); } diff --git a/cpp/open3d/visualization/rendering/filament/FilamentResourceManager.cpp b/cpp/open3d/visualization/rendering/filament/FilamentResourceManager.cpp index 0c831e9d2d0..d66ed45048a 100644 --- a/cpp/open3d/visualization/rendering/filament/FilamentResourceManager.cpp +++ b/cpp/open3d/visualization/rendering/filament/FilamentResourceManager.cpp @@ -33,8 +33,7 @@ #include #include #include -#include -#include +#include #ifdef _MSC_VER #pragma warning(pop) @@ -594,8 +593,8 @@ RenderTargetHandle FilamentResourceManager::CreateRenderTarget( } auto rt = RenderTarget::Builder() - .texture(RenderTarget::COLOR, color_tex.get()) - .texture(RenderTarget::DEPTH, depth_tex.get()) + .texture(RenderTarget::AttachmentPoint::COLOR, color_tex.get()) + .texture(RenderTarget::AttachmentPoint::DEPTH, depth_tex.get()) .build(engine_); handle = RegisterResource(engine_, rt, render_targets_); return handle; @@ -613,11 +612,11 @@ IndirectLightHandle FilamentResourceManager::CreateIndirectLight( &error_str)) { using namespace filament; // will be destroyed later by image::ktx::createTexture - auto* ibl_ktx = new image::KtxBundle( + auto* ibl_ktx = new image::Ktx1Bundle( reinterpret_cast(ibl_data.data()), std::uint32_t(ibl_data.size())); auto* ibl_texture = - image::ktx::createTexture(&engine_, ibl_ktx, false); + ktxreader::Ktx1Reader::createTexture(&engine_, ibl_ktx, false); filament::math::float3 bands[9] = {}; if (!ibl_ktx->getSphericalHarmonics(bands)) { @@ -682,11 +681,11 @@ SkyboxHandle FilamentResourceManager::CreateSkybox( &error_str)) { using namespace filament; // will be destroyed later by image::ktx::createTexture - auto* sky_ktx = new image::KtxBundle( + auto* sky_ktx = new image::Ktx1Bundle( reinterpret_cast(sky_data.data()), std::uint32_t(sky_data.size())); auto* sky_texture = - image::ktx::createTexture(&engine_, sky_ktx, false); + ktxreader::Ktx1Reader::createTexture(&engine_, sky_ktx, false); auto skybox = Skybox::Builder() .environment(sky_texture) diff --git a/cpp/open3d/visualization/rendering/filament/FilamentScene.cpp b/cpp/open3d/visualization/rendering/filament/FilamentScene.cpp index 64dffe9dc69..4c2caedfb82 100644 --- a/cpp/open3d/visualization/rendering/filament/FilamentScene.cpp +++ b/cpp/open3d/visualization/rendering/filament/FilamentScene.cpp @@ -13,6 +13,7 @@ // 32 so that x >> 32 gives a warning. (Or maybe the compiler can't // determine the if statement does not run.) // 4305: LightManager.h needs to specify some constants as floats +#include #include #ifdef _MSC_VER @@ -658,11 +659,13 @@ void FilamentScene::UpdateGeometry(const std::string& object_name, } // Update the geometry to reflect new geometry count + // ******** NOTE ******** setGeometryAt changed - this code path needs to be + // tested!!!! if (geometry_update_needed) { auto& renderable_mgr = engine_.getRenderableManager(); auto inst = renderable_mgr.getInstance(g->filament_entity); renderable_mgr.setGeometryAt( - inst, 0, filament::RenderableManager::PrimitiveType::POINTS, + inst, 0, filament::RenderableManager::PrimitiveType::POINTS, nullptr, nullptr, 0, n_vertices); } } @@ -1067,7 +1070,9 @@ void FilamentScene::UpdateMaterialProperties(RenderableGeometry& geom) { return map && map->HasData(); }; if (is_map_valid(props.albedo_img)) { + utility::LogWarning("Adding albedo texture with sRGB true!"); maps.albedo_map = renderer_.AddTexture(props.albedo_img, true); + // maps.albedo_map = renderer_.AddTexture(props.albedo_img); } if (is_map_valid(props.normal_img)) { maps.normal_map = renderer_.AddTexture(props.normal_img); diff --git a/cpp/open3d/visualization/rendering/filament/FilamentView.cpp b/cpp/open3d/visualization/rendering/filament/FilamentView.cpp index 2a11feff3f0..f0953a1a0ba 100644 --- a/cpp/open3d/visualization/rendering/filament/FilamentView.cpp +++ b/cpp/open3d/visualization/rendering/filament/FilamentView.cpp @@ -57,7 +57,8 @@ FilamentView::FilamentView(filament::Engine& engine, FilamentResourceManager& resource_mgr) : engine_(engine), resource_mgr_(resource_mgr) { view_ = engine_.createView(); - view_->setSampleCount(4); + filament::MultiSampleAntiAliasingOptions msaao({true, 4, false}); + view_->setMultiSampleAntiAliasingOptions(msaao); SetAntiAliasing(true, false); SetPostProcessing(true); SetAmbientOcclusion(true, false); @@ -140,9 +141,16 @@ void FilamentView::SetWireframe(bool enable) { } } -void FilamentView::SetSampleCount(int n) { view_->setSampleCount(n); } +void FilamentView::SetSampleCount(int n) { + auto msaao = view_->getMultiSampleAntiAliasingOptions(); + msaao.sampleCount = n; + view_->setMultiSampleAntiAliasingOptions(msaao); +} -int FilamentView::GetSampleCount() const { return view_->getSampleCount(); } +int FilamentView::GetSampleCount() const { + auto msaao = view_->getMultiSampleAntiAliasingOptions(); + return msaao.sampleCount; +} void FilamentView::SetViewport(std::int32_t x, std::int32_t y, @@ -180,14 +188,12 @@ void FilamentView::SetBloom(bool enabled, } void FilamentView::SetAntiAliasing(bool enabled, bool temporal /* = false */) { - if (enabled) { - filament::View::TemporalAntiAliasingOptions options; - options.enabled = temporal; - view_->setAntiAliasing(filament::View::AntiAliasing::FXAA); - view_->setTemporalAntiAliasingOptions(options); - } else { - view_->setAntiAliasing(filament::View::AntiAliasing::NONE); - } + auto options = view_->getTemporalAntiAliasingOptions(); + auto msaao = view_->getMultiSampleAntiAliasingOptions(); + options.enabled = temporal; + msaao.enabled = enabled; + view_->setMultiSampleAntiAliasingOptions(msaao); + view_->setTemporalAntiAliasingOptions(options); } void FilamentView::SetShadowing(bool enabled, ShadowType type) { @@ -227,30 +233,30 @@ void FilamentView::SetColorGrading(const ColorGradingParams& color_grading) { break; } - filament::ColorGrading::ToneMapping tm = - filament::ColorGrading::ToneMapping::LINEAR; - switch (color_grading.GetToneMapping()) { - case ColorGradingParams::ToneMapping::kAcesLegacy: - tm = filament::ColorGrading::ToneMapping::ACES_LEGACY; - break; - case ColorGradingParams::ToneMapping::kAces: - tm = filament::ColorGrading::ToneMapping::ACES; - break; - case ColorGradingParams::ToneMapping::kFilmic: - tm = filament::ColorGrading::ToneMapping::FILMIC; - break; - case ColorGradingParams::ToneMapping::kUchimura: - tm = filament::ColorGrading::ToneMapping::UCHIMURA; - break; - case ColorGradingParams::ToneMapping::kReinhard: - tm = filament::ColorGrading::ToneMapping::REINHARD; - break; - case ColorGradingParams::ToneMapping::kDisplayRange: - tm = filament::ColorGrading::ToneMapping::DISPLAY_RANGE; - break; - default: - break; - } + // filament::ColorGrading::ToneMapping tm = + // filament::ColorGrading::ToneMapping::LINEAR; + // switch (color_grading.GetToneMapping()) { + // case ColorGradingParams::ToneMapping::kAcesLegacy: + // tm = filament::ColorGrading::ToneMapping::ACES_LEGACY; + // break; + // case ColorGradingParams::ToneMapping::kAces: + // tm = filament::ColorGrading::ToneMapping::ACES; + // break; + // case ColorGradingParams::ToneMapping::kFilmic: + // tm = filament::ColorGrading::ToneMapping::FILMIC; + // break; + // case ColorGradingParams::ToneMapping::kUchimura: + // tm = filament::ColorGrading::ToneMapping::UCHIMURA; + // break; + // case ColorGradingParams::ToneMapping::kReinhard: + // tm = filament::ColorGrading::ToneMapping::REINHARD; + // break; + // case ColorGradingParams::ToneMapping::kDisplayRange: + // tm = filament::ColorGrading::ToneMapping::DISPLAY_RANGE; + // break; + // default: + // break; + // } if (color_grading_) { engine_.destroy(color_grading_); @@ -258,7 +264,7 @@ void FilamentView::SetColorGrading(const ColorGradingParams& color_grading) { color_grading_ = filament::ColorGrading::Builder() .quality(q) - .toneMapping(tm) + // .toneMapping(tm) .whiteBalance(color_grading.GetTemperature(), color_grading.GetTint()) .channelMixer( @@ -285,7 +291,7 @@ void FilamentView::SetColorGrading(const ColorGradingParams& color_grading) { } void FilamentView::ConfigureForColorPicking() { - view_->setSampleCount(1); + SetSampleCount(1); SetPostProcessing(false); SetAmbientOcclusion(false, false); SetShadowing(false, ShadowType::kPCF); @@ -385,8 +391,8 @@ void FilamentView::PreRender() { const auto n = camera_->GetNativeCamera()->getNear(); FilamentMaterialModifier(selected_material, material_handle) - .SetParameter("cameraNear", n) - .SetParameter("cameraFar", f) + .SetParameter("cameraNear", static_cast(n)) + .SetParameter("cameraFar", static_cast(f)) .Finish(); } } else if (mode_ == Mode::Normals) {