Small fixes to decor rendering.

Use an unlit material for decorative elements and do not render them
in the reflection pass.

PiperOrigin-RevId: 899560291
Change-Id: I3b035d556432c850ce8240e0c4c4c2d6645d7bf2
This commit is contained in:
Haroon Qureshi
2026-04-14 06:50:16 -07:00
committed by Copybara-Service
parent 72cb2b210d
commit 08bb6e66f1
8 changed files with 48 additions and 6 deletions
+1
View File
@@ -114,6 +114,7 @@ set(MATERIAL_FILES
phong_cube_fade.mat
phong_cube.mat
phong_cube_reflect.mat
unlit_decor.mat
unlit_depth.mat
unlit_line.mat
unlit_segmentation.mat
@@ -0,0 +1,29 @@
// Copyright 2025 DeepMind Technologies Limited
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
material {
name : unlit_decor,
shadingModel : unlit,
culling: none,
parameters : [
{ type : float4, name : BaseColorFactor }
]
}
fragment {
void material(inout MaterialInputs material) {
prepareMaterial(material);
material.baseColor = materialParams.BaseColorFactor;
}
}
@@ -84,6 +84,7 @@ ObjectManager::ObjectManager(filament::Engine* engine)
materials_[kPhongCubeReflect] = LoadMaterial("phong_cube_reflect.filamat");
materials_[kUnlitSegmentation] = LoadMaterial("unlit_segmentation.filamat");
materials_[kUnlitLine] = LoadMaterial("unlit_line.filamat");
materials_[kUnlitDecor] = LoadMaterial("unlit_decor.filamat");
materials_[kUnlitDepth] = LoadMaterial("unlit_depth.filamat");
materials_[kUnlitUi] = LoadMaterial("unlit_ui.filamat");
@@ -49,6 +49,7 @@ class ObjectManager {
kPhongCubeFade,
kPhongCubeReflect,
kUnlitSegmentation,
kUnlitDecor,
kUnlitDepth,
kUnlitLine,
kUnlitUi,
@@ -183,7 +183,8 @@ void Renderable::SetMaterialInstance(filament::MaterialInstance* instance) {
}
}
void Renderable::SetLayerMask(std::uint8_t mask) {
std::uint8_t Renderable::SetLayerMask(std::uint8_t mask) {
std::uint8_t prev = layer_mask_;
if (mask != layer_mask_) {
layer_mask_ = mask;
@@ -192,9 +193,11 @@ void Renderable::SetLayerMask(std::uint8_t mask) {
rm.setLayerMask(rm.getInstance(entity), 0xff, layer_mask_);
}
}
return prev;
}
void Renderable::SetPriority(std::uint8_t priority) {
std::uint8_t Renderable::SetPriority(std::uint8_t priority) {
std::uint8_t prev = priority_;
if (priority != priority_) {
priority_ = priority;
@@ -203,6 +206,7 @@ void Renderable::SetPriority(std::uint8_t priority) {
rm.setPriority(rm.getInstance(entity), priority_);
}
}
return prev;
}
void Renderable::SetCastShadows(bool cast_shadows) {
@@ -57,10 +57,10 @@ class Renderable {
int GetNumEntities() const { return entities_.size(); }
// Hides all managed entities.
void SetLayerMask(std::uint8_t mask);
std::uint8_t SetLayerMask(std::uint8_t mask);
// Sets the priority of all managed entities.
void SetPriority(std::uint8_t priority);
std::uint8_t SetPriority(std::uint8_t priority);
// Disables the renderables from casting shadows.
void SetCastShadows(bool cast_shadows);
@@ -206,6 +206,7 @@ static void SetGeomTransform(Renderable& renderable, const mjvGeom& geom) {
}
mat4 transform = mat4(ReadMat3(geom.mat), ReadFloat3(geom.pos));
renderable.SetLayerMask(geom.category);
float3 size = ReadFloat3(geom.size);
filament::TransformManager& tm =
@@ -362,6 +363,8 @@ static void UpdateGeomMaterial(Renderable& renderable, const mjvGeom& geom,
ObjectManager::MaterialType material_type = ObjectManager::kNumMaterials;
if (geom.type == mjGEOM_LINE || geom.type == mjGEOM_LINEBOX) {
material_type = ObjectManager::kUnlitLine;
} else if (geom.category == mjCAT_DECOR) {
material_type = ObjectManager::kUnlitSegmentation;
} else {
bool material_assigned = false;
if (geom.matid >= 0) {
@@ -17,6 +17,7 @@
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <memory>
#include <filament/ColorGrading.h>
@@ -135,6 +136,7 @@ SceneView::SceneView(filament::Engine* engine) : engine_(engine) {
view = engine->createView();
view->setScene(scene_);
view->setCamera(camera_);
view->setVisibleLayers(0xff, mjCAT_ALL);
}
reflect_view_ = engine->createView();
@@ -142,6 +144,7 @@ SceneView::SceneView(filament::Engine* engine) : engine_(engine) {
reflect_view_->setCamera(reflect_camera_);
reflect_view_->setShadowingEnabled(false);
reflect_view_->setPostProcessingEnabled(false);
reflect_view_->setVisibleLayers(0xff, mjCAT_DYNAMIC | mjCAT_STATIC);
// Disable post processing for the depth and segmentation views to preserve
// the values.
@@ -260,7 +263,7 @@ void SceneView::Render(filament::Renderer* renderer,
SetupReflectionCamera(transform, camera_, reflect_camera_);
// Hide reflective surface from its own reflection pass.
renderable->SetLayerMask(0x00);
std::uint8_t previous_layer_mask = renderable->SetLayerMask(0x00);
// Render the reflection to its render target.
reflect_view_->setRenderTarget(
@@ -268,7 +271,7 @@ void SceneView::Render(filament::Renderer* renderer,
renderer->render(reflect_view_);
// Unhide the reflective surface.
renderable->SetLayerMask(0x01);
renderable->SetLayerMask(previous_layer_mask);
}
}