Expose Drawable Material allowing users to manipulate it directly.
PiperOrigin-RevId: 897079632 Change-Id: Iec51ab30dc087562b8e6a464e122525f144e73a9
This commit is contained in:
committed by
Copybara-Service
parent
f6baacfa86
commit
26fb65c7a7
@@ -238,10 +238,8 @@ void Drawable::SetDrawMode(Material::DrawMode mode) {
|
|||||||
renderables_.SetMaterialInstance(material_.GetMaterialInstance(mode));
|
renderables_.SetMaterialInstance(material_.GetMaterialInstance(mode));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Drawable::UpdateReflectionTexture(const Texture* tex) {
|
Material& Drawable::GetMaterial() {
|
||||||
Material::Textures textures = material_.GetTextures();
|
return material_;
|
||||||
textures.reflection = tex;
|
|
||||||
material_.UpdateTextures(textures);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Drawable::SetLayerMask(std::uint8_t mask) {
|
void Drawable::SetLayerMask(std::uint8_t mask) {
|
||||||
@@ -374,16 +372,17 @@ void Drawable::UpdateMaterial(const mjvGeom& geom, bool use_segid_color,
|
|||||||
bool enable_reflection, const mjtNum* headpos) {
|
bool enable_reflection, const mjtNum* headpos) {
|
||||||
const mjModel* model = model_objs_->GetModel();
|
const mjModel* model = model_objs_->GetModel();
|
||||||
|
|
||||||
float4 color = ReadFloat4(geom.rgba);
|
Material::Params params;
|
||||||
|
params.color = ReadFloat4(geom.rgba);
|
||||||
if (geom.type == mjGEOM_PLANE) {
|
if (geom.type == mjGEOM_PLANE) {
|
||||||
if (IsBehind(headpos, geom.pos, geom.mat)) {
|
if (IsBehind(headpos, geom.pos, geom.mat)) {
|
||||||
color[3] *= 0.3;
|
params.color[3] *= 0.3;
|
||||||
renderables_.SetReceiveShadows(false);
|
renderables_.SetReceiveShadows(false);
|
||||||
reflective_ = false;
|
params.reflective = false;
|
||||||
} else {
|
} else {
|
||||||
renderables_.SetReceiveShadows(true);
|
renderables_.SetReceiveShadows(true);
|
||||||
reflective_ =
|
params.reflective =
|
||||||
enable_reflection && geom.reflectance > 0 && color.a == 1.0f;
|
enable_reflection && geom.reflectance > 0 && params.color.a == 1.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -434,34 +433,34 @@ void Drawable::UpdateMaterial(const mjvGeom& geom, bool use_segid_color,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (textures.color == nullptr) {
|
if (textures.color == nullptr) {
|
||||||
if (color.a < 1.0f) {
|
if (params.color.a < 1.0f) {
|
||||||
SetNormalMaterial(ObjectManager::kPhongColorFade);
|
SetNormalMaterial(ObjectManager::kPhongColorFade);
|
||||||
} else if (reflective_) {
|
} else if (params.reflective) {
|
||||||
SetNormalMaterial(ObjectManager::kPhongColorReflect);
|
SetNormalMaterial(ObjectManager::kPhongColorReflect);
|
||||||
} else {
|
} else {
|
||||||
SetNormalMaterial(ObjectManager::kPhongColor);
|
SetNormalMaterial(ObjectManager::kPhongColor);
|
||||||
}
|
}
|
||||||
} else if (textures.color->GetFilamentTexture()->getTarget() ==
|
} else if (textures.color->GetFilamentTexture()->getTarget() ==
|
||||||
filament::Texture::Sampler::SAMPLER_CUBEMAP) {
|
filament::Texture::Sampler::SAMPLER_CUBEMAP) {
|
||||||
if (color.a < 1.0f) {
|
if (params.color.a < 1.0f) {
|
||||||
SetNormalMaterial(ObjectManager::kPhongCubeFade);
|
SetNormalMaterial(ObjectManager::kPhongCubeFade);
|
||||||
} else if (reflective_) {
|
} else if (params.reflective) {
|
||||||
SetNormalMaterial(ObjectManager::kPhongCubeReflect);
|
SetNormalMaterial(ObjectManager::kPhongCubeReflect);
|
||||||
} else {
|
} else {
|
||||||
SetNormalMaterial(ObjectManager::kPhongCube);
|
SetNormalMaterial(ObjectManager::kPhongCube);
|
||||||
}
|
}
|
||||||
} else if (has_texcoords) {
|
} else if (has_texcoords) {
|
||||||
if (color.a < 1.0f) {
|
if (params.color.a < 1.0f) {
|
||||||
SetNormalMaterial(ObjectManager::kPhong2dUvFade);
|
SetNormalMaterial(ObjectManager::kPhong2dUvFade);
|
||||||
} else if (reflective_) {
|
} else if (params.reflective) {
|
||||||
SetNormalMaterial(ObjectManager::kPhong2dUvReflect);
|
SetNormalMaterial(ObjectManager::kPhong2dUvReflect);
|
||||||
} else {
|
} else {
|
||||||
SetNormalMaterial(ObjectManager::kPhong2dUv);
|
SetNormalMaterial(ObjectManager::kPhong2dUv);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (color.a < 1.0f) {
|
if (params.color.a < 1.0f) {
|
||||||
SetNormalMaterial(ObjectManager::kPhong2dFade);
|
SetNormalMaterial(ObjectManager::kPhong2dFade);
|
||||||
} else if (reflective_) {
|
} else if (params.reflective) {
|
||||||
SetNormalMaterial(ObjectManager::kPhong2dReflect);
|
SetNormalMaterial(ObjectManager::kPhong2dReflect);
|
||||||
} else {
|
} else {
|
||||||
SetNormalMaterial(ObjectManager::kPhong2d);
|
SetNormalMaterial(ObjectManager::kPhong2d);
|
||||||
@@ -470,8 +469,6 @@ void Drawable::UpdateMaterial(const mjvGeom& geom, bool use_segid_color,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Material::Params params;
|
|
||||||
params.color = color;
|
|
||||||
params.reflectance = geom.reflectance;
|
params.reflectance = geom.reflectance;
|
||||||
params.emissive = geom.emission;
|
params.emissive = geom.emission;
|
||||||
params.specular = geom.specular;
|
params.specular = geom.specular;
|
||||||
|
|||||||
@@ -26,7 +26,6 @@
|
|||||||
#include "experimental/filament/filament/model_objects.h"
|
#include "experimental/filament/filament/model_objects.h"
|
||||||
#include "experimental/filament/filament/object_manager.h"
|
#include "experimental/filament/filament/object_manager.h"
|
||||||
#include "experimental/filament/filament/renderables.h"
|
#include "experimental/filament/filament/renderables.h"
|
||||||
#include "experimental/filament/filament/texture.h"
|
|
||||||
|
|
||||||
namespace mujoco {
|
namespace mujoco {
|
||||||
|
|
||||||
@@ -63,13 +62,8 @@ class Drawable {
|
|||||||
// or hide the drawable from specific passes. The default layer mask is 0x01.
|
// or hide the drawable from specific passes. The default layer mask is 0x01.
|
||||||
void SetLayerMask(std::uint8_t mask);
|
void SetLayerMask(std::uint8_t mask);
|
||||||
|
|
||||||
// Returns true if the drawable is reflective.
|
// Returns the material for the drawable.
|
||||||
bool IsReflective() const { return reflective_; }
|
Material& GetMaterial();
|
||||||
|
|
||||||
// Sets the reflection texture for the drawable. We have a separate setter
|
|
||||||
// because we need to render the reflection texture before it can be applied
|
|
||||||
// to the material.
|
|
||||||
void UpdateReflectionTexture(const Texture* tex);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void AddMesh(int data_id);
|
void AddMesh(int data_id);
|
||||||
@@ -90,7 +84,6 @@ class Drawable {
|
|||||||
ModelObjects* model_objs_ = nullptr;
|
ModelObjects* model_objs_ = nullptr;
|
||||||
ObjectManager* object_mgr_ = nullptr;
|
ObjectManager* object_mgr_ = nullptr;
|
||||||
Renderables renderables_;
|
Renderables renderables_;
|
||||||
bool reflective_ = false;
|
|
||||||
filament::math::mat4 transform_;
|
filament::math::mat4 transform_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ class Material {
|
|||||||
float emissive = -1.0f;
|
float emissive = -1.0f;
|
||||||
float reflectance = 0.0f;
|
float reflectance = 0.0f;
|
||||||
bool tex_uniform = false;
|
bool tex_uniform = false;
|
||||||
|
bool reflective = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit Material(filament::Engine* engine);
|
explicit Material(filament::Engine* engine);
|
||||||
|
|||||||
@@ -194,7 +194,7 @@ void SceneView::RemoveFromScene(Light* light) {
|
|||||||
void SceneView::AddToScene(Drawable* drawable) {
|
void SceneView::AddToScene(Drawable* drawable) {
|
||||||
if (drawables_.insert(drawable).second) {
|
if (drawables_.insert(drawable).second) {
|
||||||
drawable->AddToScene(scene_);
|
drawable->AddToScene(scene_);
|
||||||
if (drawable->IsReflective()) {
|
if (drawable->GetMaterial().GetParams().reflective) {
|
||||||
AddReflectiveDrawable(drawable);
|
AddReflectiveDrawable(drawable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -305,7 +305,11 @@ void SceneView::AddReflectiveDrawable(Drawable* drawable) {
|
|||||||
auto viewport = reflect_view_->getViewport();
|
auto viewport = reflect_view_->getViewport();
|
||||||
auto& target = reflect_targets_[index];
|
auto& target = reflect_targets_[index];
|
||||||
target->Prepare(viewport.width, viewport.height);
|
target->Prepare(viewport.width, viewport.height);
|
||||||
drawable->UpdateReflectionTexture(target->GetColorTexture());
|
|
||||||
|
Material& material = drawable->GetMaterial();
|
||||||
|
Material::Textures textures = material.GetTextures();
|
||||||
|
textures.reflection = target->GetColorTexture();
|
||||||
|
material.UpdateTextures(textures);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SceneView::SetColorGradingOptions(const ColorGradingOptions& opts) {
|
void SceneView::SetColorGradingOptions(const ColorGradingOptions& opts) {
|
||||||
|
|||||||
Reference in New Issue
Block a user