Skip to content

Commit b5b654f

Browse files
havesscopybara-github
authored andcommitted
Correctly handle segmentation and ID_COLOR flag in filament.
PiperOrigin-RevId: 846319715 Change-Id: I244ae52c34079b79d3179fafdf6aa506cc89e1ff
1 parent 05e1c45 commit b5b654f

File tree

8 files changed

+6
-37
lines changed

8 files changed

+6
-37
lines changed

src/experimental/filament/filament/drawable.cc

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ void Drawable::Update(const mjModel* model, const mjvScene* scene,
161161
}
162162

163163
SetTransform(geom);
164-
UpdateMaterial(geom);
164+
UpdateMaterial(geom, scene->flags[mjRND_IDCOLOR]);
165165
}
166166

167167
void Drawable::AddMesh(int data_id) {
@@ -203,11 +203,6 @@ void Drawable::SetDrawMode(Material::DrawMode mode) {
203203
renderables_.SetMaterialInstance(material_.GetMaterialInstance(mode));
204204
}
205205

206-
void Drawable::SetUseDistinctSegmentationColors(
207-
bool use_distinct_segmentation_colors) {
208-
use_distinct_segmentation_colors_ = use_distinct_segmentation_colors;
209-
}
210-
211206
void Drawable::SetTransform(const mjvGeom& geom) {
212207
// Flex and skin geometries are in global space.
213208
if (geom.type == mjGEOM_FLEX || geom.type == mjGEOM_SKIN) {
@@ -321,7 +316,7 @@ void Drawable::SetTransform(const mjvGeom& geom) {
321316
}
322317
}
323318

324-
void Drawable::UpdateMaterial(const mjvGeom& geom) {
319+
void Drawable::UpdateMaterial(const mjvGeom& geom, bool use_segid_color) {
325320
ObjectManager* object_mgr = material_.GetObjectManager();
326321
const mjModel* model = object_mgr->GetModel();
327322

@@ -405,7 +400,6 @@ void Drawable::UpdateMaterial(const mjvGeom& geom) {
405400
params.emissive = geom.emission;
406401
params.specular = geom.specular;
407402
params.glossiness = geom.shininess;
408-
params.use_distinct_segmentation_colors = use_distinct_segmentation_colors_;
409403
if (geom.matid >= 0) {
410404
params.metallic = model->mat_metallic[geom.matid];
411405
params.roughness = model->mat_roughness[geom.matid];
@@ -414,8 +408,8 @@ void Drawable::UpdateMaterial(const mjvGeom& geom) {
414408
}
415409

416410
if (geom.segid >= 0) {
417-
uint32_t segmentation_color = geom.segid;
418-
if (use_distinct_segmentation_colors_) {
411+
uint32_t segmentation_color = geom.segid + 1;
412+
if (!use_segid_color) {
419413
constexpr double phi1 = 1.61803398874989484820; // Cached Phi(1).
420414
constexpr double coef1 = 1.0 / phi1;
421415
const double index = static_cast<double>(geom.segid);

src/experimental/filament/filament/drawable.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ class Drawable {
5353
// beginFrame/endFrame.
5454
void SetDrawMode(Material::DrawMode mode);
5555

56-
// Updates whether to remap segmentation IDs to distinct colors when rendering
57-
// segmentation. This is only really useful for visualization purposes.
58-
void SetUseDistinctSegmentationColors(bool use_distinct_segmentation_colors);
5956

6057
private:
6158
void AddMesh(int data_id);
@@ -66,11 +63,10 @@ class Drawable {
6663
void SetTransform(const mjvGeom& geom);
6764

6865
// Updates the material parameters of the drawable for rendering.
69-
void UpdateMaterial(const mjvGeom& geom);
66+
void UpdateMaterial(const mjvGeom& geom, bool use_segid_color);
7067

7168
Material material_;
7269
Renderables renderables_;
73-
bool use_distinct_segmentation_colors_ = false;
7470
};
7571

7672
} // namespace mujoco

src/experimental/filament/filament/filament_context.cc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,7 @@ FilamentContext::FilamentContext(const mjrFilamentConfig* config,
115115
}
116116
}
117117

118-
scene_view_ = std::make_unique<SceneView>(
119-
engine_, object_manager_.get());
120-
scene_view_->SetUseDistinctSegmentationColors(
121-
config_.use_distinct_segmentation_colors);
118+
scene_view_ = std::make_unique<SceneView>(engine_, object_manager_.get());
122119
if (config_.enable_gui) {
123120
gui_view_ = std::make_unique<GuiView>(engine_, object_manager_.get());
124121
}

src/experimental/filament/filament/material.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ class Material {
6060
float roughness = -1.0f;
6161
float emissive = -1.0f;
6262
bool tex_uniform = false;
63-
bool use_distinct_segmentation_colors = false;
6463
};
6564

6665
Material(ObjectManager* object_mgr);

src/experimental/filament/filament/scene_view.cc

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,6 @@ void SceneView::SetColorGradingOptions(const ColorGradingOptions& opts) {
210210
color_grading_options_ = opts;
211211
}
212212

213-
void SceneView::SetUseDistinctSegmentationColors(
214-
bool use_distinct_segmentation_colors) {
215-
use_distinct_segmentation_colors_ = use_distinct_segmentation_colors;
216-
}
217-
218213
void SceneView::SetEnvironmentLight(std::string_view filename,
219214
float intensity) {
220215
auto* ibl = object_mgr_->LoadFallbackIndirectLight(filename, intensity);
@@ -359,8 +354,6 @@ void SceneView::UpdateScene(const mjrContext* context, const mjvScene* scene) {
359354

360355
auto drawable = std::make_unique<Drawable>(object_mgr_, *geom);
361356
drawable->AddToScene(scene_);
362-
drawable->SetUseDistinctSegmentationColors(
363-
use_distinct_segmentation_colors_);
364357
drawable->Update(object_mgr_->GetModel(), scene, *geom);
365358
drawables_.push_back(std::move(drawable));
366359
}

src/experimental/filament/filament/scene_view.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ class SceneView {
5555
// Updates the color grading options for the main render view.
5656
void SetColorGradingOptions(const ColorGradingOptions& opts);
5757

58-
// Updates whether to remap segmentation IDs to distinct colors when rendering
59-
// segmentation. This is only really useful for visualization purposes.
60-
void SetUseDistinctSegmentationColors(bool use_distinct_segmentation_colors);
61-
6258
// Updates the environment light using the KTX image at the given path.
6359
void SetEnvironmentLight(std::string_view filename, float intensity);
6460

@@ -104,7 +100,6 @@ class SceneView {
104100
ColorGradingOptions color_grading_options_;
105101
DrawMode active_mode_ = DrawMode::kNumDrawModes;
106102
float aspect_ratio_ = 1.0f;
107-
bool use_distinct_segmentation_colors_ = false;
108103
};
109104

110105
} // namespace mujoco

src/experimental/filament/render_context_filament.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ struct mjrFilamentConfig {
5151

5252
// Whether or not to enable GUI rendering.
5353
bool enable_gui;
54-
55-
// Whether to remap segmentation IDs to distinct colors for visual display.
56-
// This is only really useful for visualization purposes in studio.
57-
bool use_distinct_segmentation_colors;
5854
};
5955

6056
void mjr_defaultFilamentConfig(mjrFilamentConfig* config);

src/experimental/studio/app.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ App::App(int width, int height, std::string ini_path,
142142
render_config.load_asset = &App::LoadAssetCallback;
143143
render_config.load_asset_user_data = this;
144144
render_config.enable_gui = true;
145-
render_config.use_distinct_segmentation_colors = true;
146145
#if defined(USE_FILAMENT_OPENGL)
147146
render_config.graphics_api = mjGFX_OPENGL;
148147
#elif defined(USE_FILAMENT_VULKAN)

0 commit comments

Comments
 (0)