From b6cb1fcfe723a5f84ca4854665c1d2eeb8231f6a Mon Sep 17 00:00:00 2001 From: HifiExperiments Date: Wed, 22 Apr 2020 16:36:51 -0700 Subject: [PATCH] fix procedural applying to other things --- .../src/RenderableModelEntityItem.cpp | 29 +++++++++++++++++++ .../src/RenderableModelEntityItem.h | 1 + .../src/RenderableShapeEntityItem.cpp | 6 ++-- .../render-utils/src/MeshPartPayload.cpp | 3 +- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 5fbbdfa0b8..c70220506e 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -1442,6 +1442,31 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce emit requestRenderUpdate(); } + if (!_allProceduralMaterialsLoaded) { + std::lock_guard lock(_materialsLock); + bool allProceduralMaterialsLoaded = true; + for (auto& shapeMaterialPair : _materials) { + auto material = shapeMaterialPair.second; + while (!material.empty()) { + auto mat = material.top(); + if (mat.material && mat.material->isProcedural() && !mat.material->isReady()) { + allProceduralMaterialsLoaded = false; + break; + } + material.pop(); + } + if (!allProceduralMaterialsLoaded) { + break; + } + } + if (!allProceduralMaterialsLoaded) { + emit requestRenderUpdate(); + } else { + _allProceduralMaterialsLoaded = true; + model->setRenderItemsNeedUpdate(); + } + } + // When the individual mesh parts of a model finish fading, they will mark their Model as needing updating // we will watch for that and ask the model to update it's render items if (model->getRenderItemsNeedUpdate()) { @@ -1559,6 +1584,10 @@ void ModelEntityRenderer::addMaterial(graphics::MaterialLayer material, const st if (_model && _model->fetchRenderItemIDs().size() > 0) { _model->addMaterial(material, parentMaterialName); } + if (material.material && material.material->isProcedural()) { + _allProceduralMaterialsLoaded = false; + emit requestRenderUpdate(); + } } void ModelEntityRenderer::removeMaterial(graphics::MaterialPointer material, const std::string& parentMaterialName) { diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.h b/libraries/entities-renderer/src/RenderableModelEntityItem.h index 0119c7bc26..7c219422a6 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.h +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.h @@ -198,6 +198,7 @@ private: bool _prevModelLoaded { false }; void processMaterials(); + bool _allProceduralMaterialsLoaded { false }; }; } } // namespace diff --git a/libraries/entities-renderer/src/RenderableShapeEntityItem.cpp b/libraries/entities-renderer/src/RenderableShapeEntityItem.cpp index 222b833be2..38dd3b2160 100644 --- a/libraries/entities-renderer/src/RenderableShapeEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableShapeEntityItem.cpp @@ -32,7 +32,7 @@ bool ShapeEntityRenderer::needsRenderUpdate() const { if (resultWithReadLock([&] { auto mat = _materials.find("0"); if (mat != _materials.end() && mat->second.top().material && mat->second.top().material->isProcedural() && - mat->second.top().material->isEnabled()) { + mat->second.top().material->isReady()) { auto procedural = std::static_pointer_cast(mat->second.top().material); if (procedural->isFading()) { return true; @@ -88,7 +88,7 @@ void ShapeEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce void ShapeEntityRenderer::doRenderUpdateAsynchronousTyped(const TypedEntityPointer& entity) { withReadLock([&] { auto mat = _materials.find("0"); - if (mat != _materials.end() && mat->second.top().material && mat->second.top().material->isProcedural() && mat->second.top().material->isEnabled()) { + if (mat != _materials.end() && mat->second.top().material && mat->second.top().material->isProcedural() && mat->second.top().material->isReady()) { auto procedural = std::static_pointer_cast(mat->second.top().material); if (procedural->isFading()) { procedural->setIsFading(Interpolate::calculateFadeRatio(procedural->getFadeStartTime()) < 1.0f); @@ -136,7 +136,7 @@ bool ShapeEntityRenderer::isTransparent() const { auto mat = _materials.find("0"); if (mat != _materials.end() && mat->second.top().material) { - if (mat->second.top().material->isProcedural() && mat->second.top().material->isEnabled()) { + if (mat->second.top().material->isProcedural() && mat->second.top().material->isReady()) { auto procedural = std::static_pointer_cast(mat->second.top().material); if (procedural->isFading()) { return true; diff --git a/libraries/render-utils/src/MeshPartPayload.cpp b/libraries/render-utils/src/MeshPartPayload.cpp index e82af5395f..544947ab59 100644 --- a/libraries/render-utils/src/MeshPartPayload.cpp +++ b/libraries/render-utils/src/MeshPartPayload.cpp @@ -493,8 +493,7 @@ void ModelMeshPartPayload::render(RenderArgs* args) { batch.setDrawcallUniform(drawcallInfo); } - if (!_drawMaterials.empty() && _drawMaterials.top().material && _drawMaterials.top().material->isProcedural() && - _drawMaterials.top().material->isReady()) { + if (_shapeKey.hasOwnPipeline()) { if (!(enableMaterialProceduralShaders)) { return; }