Skip to content

Commit

Permalink
Tweaks to deal with compilation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
errissa committed Nov 28, 2023
1 parent 2736006 commit 5e488a5
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 66 deletions.
11 changes: 6 additions & 5 deletions cpp/open3d/visualization/gui/ImguiFilamentBridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* limitations under the License.
*/

#include <cstring>
#include "open3d/visualization/gui/ImguiFilamentBridge.h"

// 4068: Filament has some clang-specific vectorizing pragma's that MSVC flags
Expand All @@ -31,6 +32,11 @@
#pragma warning(disable : 4068 4305)
#endif // _MSC_VER

#include <cerrno>
#include <iostream>
#include <map>
#include <vector>

#include <filament/Fence.h>
#include <filament/RenderableManager.h>
#include <filament/Scene.h>
Expand All @@ -45,11 +51,6 @@
#include <fcntl.h>
#include <imgui.h>

#include <cerrno>
#include <iostream>
#include <map>
#include <vector>

#include "open3d/utility/FileSystem.h"
#include "open3d/visualization/gui/Application.h"
#include "open3d/visualization/gui/Color.h"
Expand Down
1 change: 1 addition & 0 deletions cpp/open3d/visualization/gui/SceneWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <Eigen/Geometry>
#include <set>
#include <unordered_set>
#include <cstring>

#include "open3d/camera/PinholeCameraIntrinsic.h"
#include "open3d/geometry/BoundingVolume.h"
Expand Down
22 changes: 11 additions & 11 deletions cpp/open3d/visualization/rendering/filament/FilamentCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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<float>(cam_pos.x), static_cast<float>(cam_pos.y), static_cast<float>(cam_pos.z)};
}

Eigen::Vector3f FilamentCamera::GetForwardVector() const {
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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_);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
#include <filament/Skybox.h>
#include <filament/Texture.h>
#include <filament/TextureSampler.h>
#include <image/KtxBundle.h>
#include <image/KtxUtility.h>
#include <ktxreader/Ktx1Reader.h>

#ifdef _MSC_VER
#pragma warning(pop)
Expand Down Expand Up @@ -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<RenderTargetHandle>(engine_, rt, render_targets_);
return handle;
Expand All @@ -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<std::uint8_t*>(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)) {
Expand Down Expand Up @@ -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<std::uint8_t*>(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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <cstring>
#include <unordered_set>

#ifdef _MSC_VER
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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);
Expand Down
84 changes: 45 additions & 39 deletions cpp/open3d/visualization/rendering/filament/FilamentView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -227,38 +233,38 @@ 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_);
}
color_grading_ =
filament::ColorGrading::Builder()
.quality(q)
.toneMapping(tm)
// .toneMapping(tm)
.whiteBalance(color_grading.GetTemperature(),
color_grading.GetTint())
.channelMixer(
Expand All @@ -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);
Expand Down Expand Up @@ -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<float>(n))
.SetParameter("cameraFar", static_cast<float>(f))
.Finish();
}
} else if (mode_ == Mode::Normals) {
Expand Down

0 comments on commit 5e488a5

Please sign in to comment.