19 #pragma warning(disable : 4068 4146 4293)
22 #include <filament/Camera.h>
23 #include <filament/ColorGrading.h>
24 #include <filament/Engine.h>
25 #include <filament/RenderableManager.h>
26 #include <filament/Scene.h>
27 #include <filament/View.h>
28 #include <filament/Viewport.h>
41 namespace visualization {
46 #define AUTO_CLEAR_COLOR 0
49 const filament::LinearColorA kDepthClearColor = {0.f, 0.f, 0.f, 0.f};
50 const filament::LinearColorA kNormalsClearColor = {0.5f, 0.5f, 0.5f, 1.f};
57 : engine_(engine), resource_mgr_(resource_mgr) {
58 view_ = engine_.createView();
59 view_->setSampleCount(4);
69 camera_ = std::make_unique<FilamentCamera>(engine_);
70 view_->setCamera(camera_->GetNativeCamera());
72 camera_->SetProjection(90, 4.f / 3.f, 0.01, 1000,
88 view_->setCamera(
nullptr);
89 view_->setScene(
nullptr);
92 engine_.destroy(view_);
93 engine_.destroy(color_grading_);
105 view_->setClearColor(
106 {clearColor_.x(), clearColor_.y(), clearColor_.z(), 1.f});
110 view_->setClearColor(kDepthClearColor);
114 view_->setClearColor(kNormalsClearColor);
120 view_->setClearColor(kDepthClearColor);
129 discard_buffers_ = buffers;
130 view_->setRenderTarget(
nullptr);
150 view_->setViewport({x, y, w, h});
154 auto vp = view_->getViewport();
155 return {vp.left, vp.bottom, int(vp.width), int(vp.height)};
159 view_->setPostProcessingEnabled(enabled);
163 bool ssct_enabled ) {
164 filament::View::AmbientOcclusionOptions options;
165 options.enabled = enabled;
166 options.ssct.enabled = ssct_enabled;
167 view_->setAmbientOcclusionOptions(options);
173 filament::View::BloomOptions bloom_options;
174 bloom_options.enabled = enabled;
175 bloom_options.strength = strength;
176 bloom_options.threshold =
false;
177 bloom_options.levels = spread;
178 view_->setBloomOptions(bloom_options);
183 filament::View::TemporalAntiAliasingOptions options;
184 options.enabled = temporal;
185 view_->setAntiAliasing(filament::View::AntiAliasing::FXAA);
186 view_->setTemporalAntiAliasingOptions(options);
188 view_->setAntiAliasing(filament::View::AntiAliasing::NONE);
194 filament::View::ShadowType stype =
196 : filament::View::ShadowType::VSM;
197 view_->setShadowType(stype);
198 view_->setShadowingEnabled(
true);
200 view_->setShadowingEnabled(
false);
205 return filament::math::float3(v.x(), v.y(), v.z());
209 return filament::math::float4(v.x(), v.y(), v.z(), v.w());
213 filament::ColorGrading::QualityLevel q =
214 filament::ColorGrading::QualityLevel::LOW;
217 q = filament::ColorGrading::QualityLevel::MEDIUM;
220 q = filament::ColorGrading::QualityLevel::HIGH;
223 q = filament::ColorGrading::QualityLevel::ULTRA;
229 filament::ColorGrading::ToneMapping tm =
230 filament::ColorGrading::ToneMapping::LINEAR;
233 tm = filament::ColorGrading::ToneMapping::ACES_LEGACY;
236 tm = filament::ColorGrading::ToneMapping::ACES;
239 tm = filament::ColorGrading::ToneMapping::FILMIC;
242 tm = filament::ColorGrading::ToneMapping::UCHIMURA;
245 tm = filament::ColorGrading::ToneMapping::REINHARD;
248 tm = filament::ColorGrading::ToneMapping::DISPLAY_RANGE;
254 if (color_grading_) {
255 engine_.destroy(color_grading_);
258 filament::ColorGrading::Builder()
267 .shadowsMidtonesHighlights(
283 view_->setColorGrading(color_grading_);
287 view_->setSampleCount(1);
291 configured_for_picking_ =
true;
295 caching_enabled_ = enable;
297 if (caching_enabled_) {
298 if (render_target_) {
299 resource_mgr_.
Destroy(render_target_);
300 resource_mgr_.
Destroy(color_buffer_);
301 resource_mgr_.
Destroy(depth_buffer_);
308 auto vp = view_->getViewport();
315 SetRenderTarget(render_target_);
318 if (!caching_enabled_) {
319 view_->setRenderTarget(
nullptr);
328 if (!render_target) {
329 view_->setRenderTarget(
nullptr);
332 auto rt = rt_weak.lock();
335 "Invalid render target given to SetRenderTarget");
336 view_->setRenderTarget(
nullptr);
338 view_->setRenderTarget(rt.get());
347 view_->setRenderTarget(
nullptr);
348 auto vp = other.view_->getViewport();
350 camera_->CopyFrom(other.camera_.get());
351 if (other.configured_for_picking_) {
365 std::shared_ptr<filament::MaterialInstance> selected_material;
371 if (selected_material) {
372 const auto f = camera_->GetNativeCamera()->getCullingFar();
373 const auto n = camera_->GetNativeCamera()->getNear();
387 int coordinate_index = 0;
390 coordinate_index = 0;
393 coordinate_index = 1;
396 coordinate_index = 2;
405 if (selected_material) {
Eigen::Vector3f GetHighlightScale() const
Eigen::Vector4f GetRanges() const
Eigen::Vector4f GetMidtones() const
float GetTemperature() const
Eigen::Vector3f GetMixerBlue() const
Eigen::Vector3f GetMixerGreen() const
Eigen::Vector3f GetSlope() const
Eigen::Vector3f GetMidpoint() const
Eigen::Vector4f GetShadows() const
Eigen::Vector3f GetMixerRed() const
Eigen::Vector4f GetHighlights() const
Quality GetQuality() const
Eigen::Vector3f GetPower() const
ToneMapping GetToneMapping() const
float GetVibrance() const
float GetContrast() const
float GetSaturation() const
Eigen::Vector3f GetShadowGamma() const
Eigen::Vector3f GetOffset() const
MaterialModifier & SetParameter(const char *parameter, int value) override
void Destroy(const REHandle_abstract &id)
static const MaterialInstanceHandle kNormalsMaterial
std::weak_ptr< filament::RenderTarget > GetRenderTarget(const RenderTargetHandle &id)
TextureHandle CreateColorAttachmentTexture(int width, int height)
RenderTargetHandle CreateRenderTarget(TextureHandle color, TextureHandle depth)
static const MaterialInstanceHandle kColorMapMaterial
std::weak_ptr< filament::MaterialInstance > GetMaterialInstance(const MaterialInstanceHandle &id)
static const MaterialInstanceHandle kDepthMaterial
TextureHandle CreateDepthAttachmentTexture(int width, int height)
filament::Scene * GetNativeScene() const
void SetAmbientOcclusion(bool enabled, bool ssct_enabled=false) override
void SetWireframe(bool enable) override
void SetColorGrading(const ColorGradingParams &color_grading) override
void SetMode(Mode mode) override
void SetViewport(std::int32_t x, std::int32_t y, std::uint32_t w, std::uint32_t h) override
FilamentView(filament::Engine &engine, FilamentResourceManager &resource_mgr)
int GetSampleCount() const override
void CopySettingsFrom(const FilamentView &other)
bool IsCached() const override
void SetAntiAliasing(bool enabled, bool temporal=false) override
std::array< int, 4 > GetViewport() const override
void ConfigureForColorPicking() override
TextureHandle GetColorBuffer() override
void SetSampleCount(int n) override
Camera * GetCamera() const override
static constexpr std::uint8_t kAllLayersMask
void SetShadowing(bool enabled, ShadowType type) override
void SetPostProcessing(bool enabled) override
void SetScene(FilamentScene &scene)
void SetDiscardBuffers(const TargetBuffers &buffers) override
static constexpr std::uint8_t kMainLayer
void EnableViewCaching(bool enable) override
Mode GetMode() const override
void SetBloom(bool enabled, float strength=0.5f, int spread=6) override
virtual MaterialModifier & SetParameter(const char *parameter, int value)=0
virtual MaterialInstanceHandle Finish()=0
REHandle< EntityType::Texture > TextureHandle
REHandle< EntityType::RenderTarget > RenderTargetHandle
static filament::math::float4 eigen_to_float4(const Eigen::Vector4f &v)
static filament::math::float3 eigen_to_float3(const Eigen::Vector3f &v)
Generic file read and write utility for python interface.