mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-04 06:24:41 +02:00
Merge pull request #14222 from SamGondelman/material
Fix material entity opacity maps
This commit is contained in:
commit
e6ec32e515
4 changed files with 46 additions and 23 deletions
|
@ -24,12 +24,18 @@ bool MaterialEntityRenderer::needsRenderUpdateFromTypedEntity(const TypedEntityP
|
||||||
if (entity->getMaterialMappingPos() != _materialMappingPos || entity->getMaterialMappingScale() != _materialMappingScale || entity->getMaterialMappingRot() != _materialMappingRot) {
|
if (entity->getMaterialMappingPos() != _materialMappingPos || entity->getMaterialMappingScale() != _materialMappingScale || entity->getMaterialMappingRot() != _materialMappingRot) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (!_texturesLoaded) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MaterialEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& scene, Transaction& transaction, const TypedEntityPointer& entity) {
|
void MaterialEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& scene, Transaction& transaction, const TypedEntityPointer& entity) {
|
||||||
withWriteLock([&] {
|
withWriteLock([&] {
|
||||||
|
if (_drawMaterial != entity->getMaterial()) {
|
||||||
|
_texturesLoaded = false;
|
||||||
_drawMaterial = entity->getMaterial();
|
_drawMaterial = entity->getMaterial();
|
||||||
|
}
|
||||||
_parentID = entity->getParentID();
|
_parentID = entity->getParentID();
|
||||||
_materialMappingPos = entity->getMaterialMappingPos();
|
_materialMappingPos = entity->getMaterialMappingPos();
|
||||||
_materialMappingScale = entity->getMaterialMappingScale();
|
_materialMappingScale = entity->getMaterialMappingScale();
|
||||||
|
@ -38,6 +44,12 @@ void MaterialEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer&
|
||||||
const float MATERIAL_ENTITY_SCALE = 0.5f;
|
const float MATERIAL_ENTITY_SCALE = 0.5f;
|
||||||
_renderTransform.postScale(MATERIAL_ENTITY_SCALE);
|
_renderTransform.postScale(MATERIAL_ENTITY_SCALE);
|
||||||
_renderTransform.postScale(ENTITY_ITEM_DEFAULT_DIMENSIONS);
|
_renderTransform.postScale(ENTITY_ITEM_DEFAULT_DIMENSIONS);
|
||||||
|
|
||||||
|
bool newTexturesLoaded = _drawMaterial ? !_drawMaterial->isMissingTexture() : false;
|
||||||
|
if (!_texturesLoaded && newTexturesLoaded) {
|
||||||
|
_drawMaterial->checkResetOpacityMap();
|
||||||
|
}
|
||||||
|
_texturesLoaded = newTexturesLoaded;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,7 @@ private:
|
||||||
glm::vec2 _materialMappingPos;
|
glm::vec2 _materialMappingPos;
|
||||||
glm::vec2 _materialMappingScale;
|
glm::vec2 _materialMappingScale;
|
||||||
float _materialMappingRot;
|
float _materialMappingRot;
|
||||||
|
bool _texturesLoaded { false };
|
||||||
|
|
||||||
std::shared_ptr<NetworkMaterial> _drawMaterial;
|
std::shared_ptr<NetworkMaterial> _drawMaterial;
|
||||||
};
|
};
|
||||||
|
|
|
@ -414,33 +414,13 @@ bool Geometry::areTexturesLoaded() const {
|
||||||
if (!_areTexturesLoaded) {
|
if (!_areTexturesLoaded) {
|
||||||
for (auto& material : _materials) {
|
for (auto& material : _materials) {
|
||||||
// Check if material textures are loaded
|
// Check if material textures are loaded
|
||||||
bool materialMissingTexture = std::any_of(material->_textures.cbegin(), material->_textures.cend(),
|
bool materialMissingTexture = material->isMissingTexture();
|
||||||
[](const NetworkMaterial::Textures::value_type& it) {
|
|
||||||
auto texture = it.texture;
|
|
||||||
if (!texture) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// Failed texture downloads need to be considered as 'loaded'
|
|
||||||
// or the object will never fade in
|
|
||||||
bool finished = texture->isFailed() || (texture->isLoaded() && texture->getGPUTexture() && texture->getGPUTexture()->isDefined());
|
|
||||||
if (!finished) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (materialMissingTexture) {
|
if (materialMissingTexture) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If material textures are loaded, check the material translucency
|
material->checkResetOpacityMap();
|
||||||
// FIXME: This should not be done here. The opacity map should already be reset in Material::setTextureMap.
|
|
||||||
// However, currently that code can be called before the albedo map is defined, so resetOpacityMap will fail.
|
|
||||||
// Geometry::areTexturesLoaded() is called repeatedly until it returns true, so we do the check here for now
|
|
||||||
const auto albedoTexture = material->_textures[NetworkMaterial::MapChannel::ALBEDO_MAP];
|
|
||||||
if (albedoTexture.texture) {
|
|
||||||
material->resetOpacityMap();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_areTexturesLoaded = true;
|
_areTexturesLoaded = true;
|
||||||
|
@ -783,4 +763,31 @@ void NetworkMaterial::setTextures(const QVariantMap& textureMap) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool NetworkMaterial::isMissingTexture() {
|
||||||
|
for (auto& networkTexture : _textures) {
|
||||||
|
auto& texture = networkTexture.texture;
|
||||||
|
if (!texture) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// Failed texture downloads need to be considered as 'loaded'
|
||||||
|
// or the object will never fade in
|
||||||
|
bool finished = texture->isFailed() || (texture->isLoaded() && texture->getGPUTexture() && texture->getGPUTexture()->isDefined());
|
||||||
|
if (!finished) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NetworkMaterial::checkResetOpacityMap() {
|
||||||
|
// If material textures are loaded, check the material translucency
|
||||||
|
// FIXME: This should not be done here. The opacity map should already be reset in Material::setTextureMap.
|
||||||
|
// However, currently that code can be called before the albedo map is defined, so resetOpacityMap will fail.
|
||||||
|
// Geometry::areTexturesLoaded() is called repeatedly until it returns true, so we do the check here for now
|
||||||
|
const auto& albedoTexture = _textures[NetworkMaterial::MapChannel::ALBEDO_MAP];
|
||||||
|
if (albedoTexture.texture) {
|
||||||
|
resetOpacityMap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#include "ModelCache.moc"
|
#include "ModelCache.moc"
|
||||||
|
|
|
@ -177,6 +177,9 @@ public:
|
||||||
void setScatteringMap(const QUrl& url);
|
void setScatteringMap(const QUrl& url);
|
||||||
void setLightmapMap(const QUrl& url);
|
void setLightmapMap(const QUrl& url);
|
||||||
|
|
||||||
|
bool isMissingTexture();
|
||||||
|
void checkResetOpacityMap();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
friend class Geometry;
|
friend class Geometry;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue