Make planes semi-transparent from behind.
PiperOrigin-RevId: 884896612 Change-Id: I00cc53e539fd1abccb43c7c6b89a7e063cb4848c
This commit is contained in:
committed by
Copybara-Service
parent
efae9157a7
commit
9a0dd7d32d
@@ -79,6 +79,12 @@ static float GetPlaneTileSize(const mjModel* model, int matid,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool IsBehind(const mjtNum* headpos, const float* pos, const float* mat) {
|
||||||
|
return ((headpos[0] - pos[0]) * mat[2] +
|
||||||
|
(headpos[1] - pos[1]) * mat[5] +
|
||||||
|
(headpos[2] - pos[2]) * mat[8] < 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
Drawable::Drawable(ObjectManager* object_mgr, const mjvGeom& geom)
|
Drawable::Drawable(ObjectManager* object_mgr, const mjvGeom& geom)
|
||||||
: material_(object_mgr), renderables_(object_mgr->GetEngine()) {
|
: material_(object_mgr), renderables_(object_mgr->GetEngine()) {
|
||||||
if (geom.category == mjCAT_DECOR) {
|
if (geom.category == mjCAT_DECOR) {
|
||||||
@@ -170,8 +176,11 @@ void Drawable::Update(const mjModel* model, const mjvScene* scene,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mjtNum head_pos[3];
|
||||||
|
mjv_cameraInModel(head_pos, nullptr, nullptr, scene);
|
||||||
|
|
||||||
SetTransform(geom);
|
SetTransform(geom);
|
||||||
UpdateMaterial(geom, scene->flags[mjRND_IDCOLOR]);
|
UpdateMaterial(geom, scene->flags[mjRND_IDCOLOR], head_pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Drawable::AddMesh(int data_id) {
|
void Drawable::AddMesh(int data_id) {
|
||||||
@@ -330,10 +339,16 @@ void Drawable::SetTransform(const mjvGeom& geom) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Drawable::UpdateMaterial(const mjvGeom& geom, bool use_segid_color) {
|
void Drawable::UpdateMaterial(const mjvGeom& geom, bool use_segid_color,
|
||||||
|
const mjtNum* headpos) {
|
||||||
ObjectManager* object_mgr = material_.GetObjectManager();
|
ObjectManager* object_mgr = material_.GetObjectManager();
|
||||||
const mjModel* model = object_mgr->GetModel();
|
const mjModel* model = object_mgr->GetModel();
|
||||||
|
|
||||||
|
float4 color = ReadFloat4(geom.rgba);
|
||||||
|
if (geom.type == mjGEOM_PLANE && IsBehind(headpos, geom.pos, geom.mat)) {
|
||||||
|
color[3] *= 0.3;
|
||||||
|
}
|
||||||
|
|
||||||
Material::Textures textures;
|
Material::Textures textures;
|
||||||
if (geom.matid >= 0) {
|
if (geom.matid >= 0) {
|
||||||
textures.color = object_mgr->GetTexture(geom.matid, mjTEXROLE_RGB);
|
textures.color = object_mgr->GetTexture(geom.matid, mjTEXROLE_RGB);
|
||||||
@@ -381,26 +396,26 @@ void Drawable::UpdateMaterial(const mjvGeom& geom, bool use_segid_color) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (textures.color == nullptr) {
|
if (textures.color == nullptr) {
|
||||||
if (geom.rgba[3] < 1.0f) {
|
if (color.a < 1.0f) {
|
||||||
material_.SetNormalMaterialType(ObjectManager::kPhongColorFade);
|
material_.SetNormalMaterialType(ObjectManager::kPhongColorFade);
|
||||||
} else {
|
} else {
|
||||||
material_.SetNormalMaterialType(ObjectManager::kPhongColor);
|
material_.SetNormalMaterialType(ObjectManager::kPhongColor);
|
||||||
}
|
}
|
||||||
} else if (textures.color->getTarget() ==
|
} else if (textures.color->getTarget() ==
|
||||||
filament::Texture::Sampler::SAMPLER_CUBEMAP) {
|
filament::Texture::Sampler::SAMPLER_CUBEMAP) {
|
||||||
if (geom.rgba[3] < 1.0f) {
|
if (color.a < 1.0f) {
|
||||||
material_.SetNormalMaterialType(ObjectManager::kPhongCubeFade);
|
material_.SetNormalMaterialType(ObjectManager::kPhongCubeFade);
|
||||||
} else {
|
} else {
|
||||||
material_.SetNormalMaterialType(ObjectManager::kPhongCube);
|
material_.SetNormalMaterialType(ObjectManager::kPhongCube);
|
||||||
}
|
}
|
||||||
} else if (has_texcoords) {
|
} else if (has_texcoords) {
|
||||||
if (geom.rgba[3] < 1.0f) {
|
if (color.a < 1.0f) {
|
||||||
material_.SetNormalMaterialType(ObjectManager::kPhong2dUvFade);
|
material_.SetNormalMaterialType(ObjectManager::kPhong2dUvFade);
|
||||||
} else {
|
} else {
|
||||||
material_.SetNormalMaterialType(ObjectManager::kPhong2dUv);
|
material_.SetNormalMaterialType(ObjectManager::kPhong2dUv);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (geom.rgba[3] < 1.0f) {
|
if (color.a < 1.0f) {
|
||||||
material_.SetNormalMaterialType(ObjectManager::kPhong2dFade);
|
material_.SetNormalMaterialType(ObjectManager::kPhong2dFade);
|
||||||
} else {
|
} else {
|
||||||
material_.SetNormalMaterialType(ObjectManager::kPhong2d);
|
material_.SetNormalMaterialType(ObjectManager::kPhong2d);
|
||||||
@@ -410,7 +425,7 @@ void Drawable::UpdateMaterial(const mjvGeom& geom, bool use_segid_color) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Material::Params params;
|
Material::Params params;
|
||||||
params.color = ReadFloat4(geom.rgba);
|
params.color = color;
|
||||||
params.emissive = geom.emission;
|
params.emissive = geom.emission;
|
||||||
params.specular = geom.specular;
|
params.specular = geom.specular;
|
||||||
params.glossiness = geom.shininess;
|
params.glossiness = geom.shininess;
|
||||||
|
|||||||
@@ -15,13 +15,11 @@
|
|||||||
#ifndef MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_DRAWABLE_H_
|
#ifndef MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_DRAWABLE_H_
|
||||||
#define MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_DRAWABLE_H_
|
#define MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_DRAWABLE_H_
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
|
|
||||||
#include <filament/Engine.h>
|
#include <filament/Engine.h>
|
||||||
#include <filament/Scene.h>
|
#include <filament/Scene.h>
|
||||||
#include <mujoco/mjmodel.h>
|
#include <mujoco/mjmodel.h>
|
||||||
|
#include <mujoco/mjtnum.h>
|
||||||
#include <mujoco/mjvisualize.h>
|
#include <mujoco/mjvisualize.h>
|
||||||
#include "experimental/filament/filament/buffer_util.h"
|
|
||||||
#include "experimental/filament/filament/material.h"
|
#include "experimental/filament/filament/material.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"
|
||||||
@@ -63,7 +61,8 @@ class Drawable {
|
|||||||
void SetTransform(const mjvGeom& geom);
|
void SetTransform(const mjvGeom& geom);
|
||||||
|
|
||||||
// Updates the material parameters of the drawable for rendering.
|
// Updates the material parameters of the drawable for rendering.
|
||||||
void UpdateMaterial(const mjvGeom& geom, bool use_segid_color);
|
void UpdateMaterial(const mjvGeom& geom, bool use_segid_color,
|
||||||
|
const mjtNum* headpos);
|
||||||
|
|
||||||
Material material_;
|
Material material_;
|
||||||
Renderables renderables_;
|
Renderables renderables_;
|
||||||
|
|||||||
Reference in New Issue
Block a user