Properly handle PBR materials where no color texture is provided.
In this case, we'll use the mujoco material color which is then multiplied with a white fallback texture. PiperOrigin-RevId: 840244521 Change-Id: I2134f45dcbaed7db268e5278ca8ac5429488943d
This commit is contained in:
committed by
Copybara-Service
parent
680e9a6b79
commit
5f59104877
@@ -342,7 +342,9 @@ void Drawable::UpdateMaterial(const mjvGeom& geom) {
|
|||||||
if (geom.type == mjGEOM_LINE || geom.type == mjGEOM_LINEBOX) {
|
if (geom.type == mjGEOM_LINE || geom.type == mjGEOM_LINEBOX) {
|
||||||
material_.SetNormalMaterialType(ObjectManager::kUnlitLine);
|
material_.SetNormalMaterialType(ObjectManager::kUnlitLine);
|
||||||
} else {
|
} else {
|
||||||
|
bool material_assigned = false;
|
||||||
if (geom.matid >= 0) {
|
if (geom.matid >= 0) {
|
||||||
|
material_assigned = true;
|
||||||
if (textures.orm) {
|
if (textures.orm) {
|
||||||
material_.SetNormalMaterialType(ObjectManager::kPbrPacked);
|
material_.SetNormalMaterialType(ObjectManager::kPbrPacked);
|
||||||
} else if (textures.metallic) {
|
} else if (textures.metallic) {
|
||||||
@@ -353,43 +355,47 @@ void Drawable::UpdateMaterial(const mjvGeom& geom) {
|
|||||||
material_.SetNormalMaterialType(ObjectManager::kPbr);
|
material_.SetNormalMaterialType(ObjectManager::kPbr);
|
||||||
} else if (model->mat_roughness[geom.matid] >= 0) {
|
} else if (model->mat_roughness[geom.matid] >= 0) {
|
||||||
material_.SetNormalMaterialType(ObjectManager::kPbr);
|
material_.SetNormalMaterialType(ObjectManager::kPbr);
|
||||||
|
} else {
|
||||||
|
material_assigned = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check to see if we're dealing with a mesh with texture coordinates.
|
if (!material_assigned) {
|
||||||
// `data_id` is the id of the mesh in model (i.e. the geom has mesh
|
// Check to see if we're dealing with a mesh with texture coordinates.
|
||||||
// geometry) and `mesh_texcoordadr` stores the address of the mesh uvs if it
|
// `data_id` is the id of the mesh in model (i.e. the geom has mesh
|
||||||
// has them.
|
// geometry) and `mesh_texcoordadr` stores the address of the mesh uvs if
|
||||||
bool has_texcoords = false;
|
// it has them.
|
||||||
if ((geom.type == mjGEOM_MESH || geom.type == mjGEOM_SDF) &&
|
bool has_texcoords = false;
|
||||||
geom.dataid >= 0 && model->mesh_texcoordadr[geom.dataid / 2] >= 0) {
|
if ((geom.type == mjGEOM_MESH || geom.type == mjGEOM_SDF) &&
|
||||||
has_texcoords = true;
|
geom.dataid >= 0 && model->mesh_texcoordadr[geom.dataid / 2] >= 0) {
|
||||||
}
|
has_texcoords = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (textures.color == nullptr) {
|
if (textures.color == nullptr) {
|
||||||
if (geom.rgba[3] < 1.0f) {
|
if (geom.rgba[3] < 1.0f) {
|
||||||
material_.SetNormalMaterialType(ObjectManager::kPhongColorFade);
|
material_.SetNormalMaterialType(ObjectManager::kPhongColorFade);
|
||||||
|
} else {
|
||||||
|
material_.SetNormalMaterialType(ObjectManager::kPhongColor);
|
||||||
|
}
|
||||||
|
} else if (textures.color->getTarget() ==
|
||||||
|
filament::Texture::Sampler::SAMPLER_CUBEMAP) {
|
||||||
|
if (geom.rgba[3] < 1.0f) {
|
||||||
|
material_.SetNormalMaterialType(ObjectManager::kPhongCubeFade);
|
||||||
|
} else {
|
||||||
|
material_.SetNormalMaterialType(ObjectManager::kPhongCube);
|
||||||
|
}
|
||||||
|
} else if (has_texcoords) {
|
||||||
|
if (geom.rgba[3] < 1.0f) {
|
||||||
|
material_.SetNormalMaterialType(ObjectManager::kPhong2dUvFade);
|
||||||
|
} else {
|
||||||
|
material_.SetNormalMaterialType(ObjectManager::kPhong2dUv);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
material_.SetNormalMaterialType(ObjectManager::kPhongColor);
|
if (geom.rgba[3] < 1.0f) {
|
||||||
}
|
material_.SetNormalMaterialType(ObjectManager::kPhong2dFade);
|
||||||
} else if (textures.color->getTarget() ==
|
} else {
|
||||||
filament::Texture::Sampler::SAMPLER_CUBEMAP) {
|
material_.SetNormalMaterialType(ObjectManager::kPhong2d);
|
||||||
if (geom.rgba[3] < 1.0f) {
|
}
|
||||||
material_.SetNormalMaterialType(ObjectManager::kPhongCubeFade);
|
|
||||||
} else {
|
|
||||||
material_.SetNormalMaterialType(ObjectManager::kPhongCube);
|
|
||||||
}
|
|
||||||
} else if (has_texcoords) {
|
|
||||||
if (geom.rgba[3] < 1.0f) {
|
|
||||||
material_.SetNormalMaterialType(ObjectManager::kPhong2dUvFade);
|
|
||||||
} else {
|
|
||||||
material_.SetNormalMaterialType(ObjectManager::kPhong2dUv);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (geom.rgba[3] < 1.0f) {
|
|
||||||
material_.SetNormalMaterialType(ObjectManager::kPhong2dFade);
|
|
||||||
} else {
|
|
||||||
material_.SetNormalMaterialType(ObjectManager::kPhong2d);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -121,8 +121,8 @@ ObjectManager::ObjectManager(const mjModel* model, filament::Engine* engine,
|
|||||||
fallback_orm_ = Create2dTexture(engine_, 1, 1, 3, orm_data, false);
|
fallback_orm_ = Create2dTexture(engine_, 1, 1, 3, orm_data, false);
|
||||||
|
|
||||||
fallback_textures_[mjTEXROLE_USER] = fallback_black_;
|
fallback_textures_[mjTEXROLE_USER] = fallback_black_;
|
||||||
fallback_textures_[mjTEXROLE_RGB] = fallback_black_;
|
fallback_textures_[mjTEXROLE_RGB] = fallback_white_;
|
||||||
fallback_textures_[mjTEXROLE_OCCLUSION] = fallback_black_;
|
fallback_textures_[mjTEXROLE_OCCLUSION] = fallback_white_;
|
||||||
fallback_textures_[mjTEXROLE_ROUGHNESS] = fallback_white_;
|
fallback_textures_[mjTEXROLE_ROUGHNESS] = fallback_white_;
|
||||||
fallback_textures_[mjTEXROLE_METALLIC] = fallback_black_;
|
fallback_textures_[mjTEXROLE_METALLIC] = fallback_black_;
|
||||||
fallback_textures_[mjTEXROLE_NORMAL] = fallback_normal_;
|
fallback_textures_[mjTEXROLE_NORMAL] = fallback_normal_;
|
||||||
|
|||||||
Reference in New Issue
Block a user