From de90c5088c7bb3fe9bb6a51c423ebca078fa4463 Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Thu, 16 May 2019 18:50:04 -0700 Subject: [PATCH] =?UTF-8?q?(=E2=9C=BF=E2=97=A0=E2=80=BF=E2=97=A0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/RenderableModelEntityItem.cpp | 2 +- .../src/graphics-scripting/Forward.h | 3 + .../GraphicsScriptingInterface.cpp | 201 +++++++++--------- .../graphics-scripting/ScriptableModel.cpp | 154 +++++++------- libraries/graphics/src/graphics/Material.cpp | 3 + libraries/graphics/src/graphics/Material.h | 6 +- .../procedural/src/procedural/Procedural.h | 8 +- .../procedural/ProceduralMaterialCache.cpp | 8 +- .../src/CauterizedMeshPartPayload.cpp | 5 +- .../src/CauterizedMeshPartPayload.h | 2 +- .../render-utils/src/CauterizedModel.cpp | 2 +- .../render-utils/src/MeshPartPayload.cpp | 12 +- libraries/render-utils/src/MeshPartPayload.h | 5 +- libraries/render-utils/src/Model.cpp | 7 +- libraries/render-utils/src/Model.h | 4 +- 15 files changed, 230 insertions(+), 192 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index bf0abe92dd..13c93fb2fa 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -1325,7 +1325,7 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce // Check for addition if (_hasModel && !model) { - model = std::make_shared(nullptr, entity.get()); + model = std::make_shared(nullptr, entity.get(), _created); connect(model.get(), &Model::requestRenderUpdate, this, &ModelEntityRenderer::requestRenderUpdate); connect(model.get(), &Model::setURLFinished, this, [&](bool didVisualGeometryRequestSucceed) { setKey(didVisualGeometryRequestSucceed); diff --git a/libraries/graphics-scripting/src/graphics-scripting/Forward.h b/libraries/graphics-scripting/src/graphics-scripting/Forward.h index 6d1b9d83d2..e365bcc8b8 100644 --- a/libraries/graphics-scripting/src/graphics-scripting/Forward.h +++ b/libraries/graphics-scripting/src/graphics-scripting/Forward.h @@ -64,6 +64,7 @@ namespace scriptable { * @property {string} lightmapParams * @property {string} materialParams * @property {boolean} defaultFallthrough + * @property {string} procedural */ class ScriptableMaterial { public: @@ -98,6 +99,8 @@ namespace scriptable { bool defaultFallthrough; std::unordered_map propertyFallthroughs; // not actually exposed to script + QString procedural; + graphics::MaterialKey key { 0 }; }; diff --git a/libraries/graphics-scripting/src/graphics-scripting/GraphicsScriptingInterface.cpp b/libraries/graphics-scripting/src/graphics-scripting/GraphicsScriptingInterface.cpp index eb4bfa197c..9c9175d97e 100644 --- a/libraries/graphics-scripting/src/graphics-scripting/GraphicsScriptingInterface.cpp +++ b/libraries/graphics-scripting/src/graphics-scripting/GraphicsScriptingInterface.cpp @@ -372,120 +372,125 @@ namespace scriptable { obj.setProperty("opacity", material.opacity); } - if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::MaterialKey::GLOSSY_VAL_BIT)) { - obj.setProperty("roughness", FALLTHROUGH); - } else if (material.key.isGlossy()) { - obj.setProperty("roughness", material.roughness); - } - - if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::MaterialKey::METALLIC_VAL_BIT)) { - obj.setProperty("metallic", FALLTHROUGH); - } else if (material.key.isMetallic()) { - obj.setProperty("metallic", material.metallic); - } - - if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::MaterialKey::SCATTERING_VAL_BIT)) { - obj.setProperty("scattering", FALLTHROUGH); - } else if (material.key.isScattering()) { - obj.setProperty("scattering", material.scattering); - } - - if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::MaterialKey::UNLIT_VAL_BIT)) { - obj.setProperty("unlit", FALLTHROUGH); - } else if (material.key.isUnlit()) { - obj.setProperty("unlit", material.unlit); - } - - if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::MaterialKey::EMISSIVE_VAL_BIT)) { - obj.setProperty("emissive", FALLTHROUGH); - } else if (material.key.isEmissive()) { - obj.setProperty("emissive", vec3ColorToScriptValue(engine, material.emissive)); - } - if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::MaterialKey::ALBEDO_VAL_BIT)) { obj.setProperty("albedo", FALLTHROUGH); } else if (material.key.isAlbedo()) { obj.setProperty("albedo", vec3ColorToScriptValue(engine, material.albedo)); } - if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::MaterialKey::EMISSIVE_MAP_BIT)) { - obj.setProperty("emissiveMap", FALLTHROUGH); - } else if (!material.emissiveMap.isEmpty()) { - obj.setProperty("emissiveMap", material.emissiveMap); - } + if (material.model.toStdString() == graphics::Material::HIFI_PBR) { + if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::MaterialKey::GLOSSY_VAL_BIT)) { + obj.setProperty("roughness", FALLTHROUGH); + } else if (material.key.isGlossy()) { + obj.setProperty("roughness", material.roughness); + } - if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::MaterialKey::ALBEDO_MAP_BIT)) { - obj.setProperty("albedoMap", FALLTHROUGH); - } else if (!material.albedoMap.isEmpty()) { - obj.setProperty("albedoMap", material.albedoMap); - } + if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::MaterialKey::METALLIC_VAL_BIT)) { + obj.setProperty("metallic", FALLTHROUGH); + } else if (material.key.isMetallic()) { + obj.setProperty("metallic", material.metallic); + } - if (!material.opacityMap.isEmpty()) { - obj.setProperty("opacityMap", material.opacityMap); - } + if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::MaterialKey::SCATTERING_VAL_BIT)) { + obj.setProperty("scattering", FALLTHROUGH); + } else if (material.key.isScattering()) { + obj.setProperty("scattering", material.scattering); + } - if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::MaterialKey::OCCLUSION_MAP_BIT)) { - obj.setProperty("occlusionMap", FALLTHROUGH); - } else if (!material.occlusionMap.isEmpty()) { - obj.setProperty("occlusionMap", material.occlusionMap); - } + if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::MaterialKey::UNLIT_VAL_BIT)) { + obj.setProperty("unlit", FALLTHROUGH); + } else if (material.key.isUnlit()) { + obj.setProperty("unlit", material.unlit); + } - if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::MaterialKey::LIGHTMAP_MAP_BIT)) { - obj.setProperty("lightmapMap", FALLTHROUGH); - } else if (!material.lightmapMap.isEmpty()) { - obj.setProperty("lightmapMap", material.lightmapMap); - } + if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::MaterialKey::EMISSIVE_VAL_BIT)) { + obj.setProperty("emissive", FALLTHROUGH); + } else if (material.key.isEmissive()) { + obj.setProperty("emissive", vec3ColorToScriptValue(engine, material.emissive)); + } - if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::MaterialKey::SCATTERING_MAP_BIT)) { - obj.setProperty("scatteringMap", FALLTHROUGH); - } else if (!material.scatteringMap.isEmpty()) { - obj.setProperty("scatteringMap", material.scatteringMap); - } + if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::MaterialKey::EMISSIVE_MAP_BIT)) { + obj.setProperty("emissiveMap", FALLTHROUGH); + } else if (!material.emissiveMap.isEmpty()) { + obj.setProperty("emissiveMap", material.emissiveMap); + } - // Only set one of each of these - if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::MaterialKey::METALLIC_MAP_BIT)) { - obj.setProperty("metallicMap", FALLTHROUGH); - } else if (!material.metallicMap.isEmpty()) { - obj.setProperty("metallicMap", material.metallicMap); - } else if (!material.specularMap.isEmpty()) { - obj.setProperty("specularMap", material.specularMap); - } + if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::MaterialKey::ALBEDO_MAP_BIT)) { + obj.setProperty("albedoMap", FALLTHROUGH); + } else if (!material.albedoMap.isEmpty()) { + obj.setProperty("albedoMap", material.albedoMap); + } - if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::MaterialKey::ROUGHNESS_MAP_BIT)) { - obj.setProperty("roughnessMap", FALLTHROUGH); - } else if (!material.roughnessMap.isEmpty()) { - obj.setProperty("roughnessMap", material.roughnessMap); - } else if (!material.glossMap.isEmpty()) { - obj.setProperty("glossMap", material.glossMap); - } + if (!material.opacityMap.isEmpty()) { + obj.setProperty("opacityMap", material.opacityMap); + } - if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::MaterialKey::NORMAL_MAP_BIT)) { - obj.setProperty("normalMap", FALLTHROUGH); - } else if (!material.normalMap.isEmpty()) { - obj.setProperty("normalMap", material.normalMap); - } else if (!material.bumpMap.isEmpty()) { - obj.setProperty("bumpMap", material.bumpMap); - } + if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::MaterialKey::OCCLUSION_MAP_BIT)) { + obj.setProperty("occlusionMap", FALLTHROUGH); + } else if (!material.occlusionMap.isEmpty()) { + obj.setProperty("occlusionMap", material.occlusionMap); + } - // These need to be implemented, but set the fallthrough for now - if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::Material::TEXCOORDTRANSFORM0)) { - obj.setProperty("texCoordTransform0", FALLTHROUGH); - } else if (material.texCoordTransforms[0] != mat4()) { - obj.setProperty("texCoordTransform0", mat4toScriptValue(engine, material.texCoordTransforms[0])); - } - if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::Material::TEXCOORDTRANSFORM1)) { - obj.setProperty("texCoordTransform1", FALLTHROUGH); - } else if (material.texCoordTransforms[1] != mat4()) { - obj.setProperty("texCoordTransform1", mat4toScriptValue(engine, material.texCoordTransforms[1])); - } - if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::Material::LIGHTMAP_PARAMS)) { - obj.setProperty("lightmapParams", FALLTHROUGH); - } - if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::Material::MATERIAL_PARAMS)) { - obj.setProperty("materialParams", FALLTHROUGH); - } + if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::MaterialKey::LIGHTMAP_MAP_BIT)) { + obj.setProperty("lightmapMap", FALLTHROUGH); + } else if (!material.lightmapMap.isEmpty()) { + obj.setProperty("lightmapMap", material.lightmapMap); + } - obj.setProperty("defaultFallthrough", material.defaultFallthrough); + if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::MaterialKey::SCATTERING_MAP_BIT)) { + obj.setProperty("scatteringMap", FALLTHROUGH); + } else if (!material.scatteringMap.isEmpty()) { + obj.setProperty("scatteringMap", material.scatteringMap); + } + + // Only set one of each of these + if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::MaterialKey::METALLIC_MAP_BIT)) { + obj.setProperty("metallicMap", FALLTHROUGH); + } else if (!material.metallicMap.isEmpty()) { + obj.setProperty("metallicMap", material.metallicMap); + } else if (!material.specularMap.isEmpty()) { + obj.setProperty("specularMap", material.specularMap); + } + + if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::MaterialKey::ROUGHNESS_MAP_BIT)) { + obj.setProperty("roughnessMap", FALLTHROUGH); + } else if (!material.roughnessMap.isEmpty()) { + obj.setProperty("roughnessMap", material.roughnessMap); + } else if (!material.glossMap.isEmpty()) { + obj.setProperty("glossMap", material.glossMap); + } + + if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::MaterialKey::NORMAL_MAP_BIT)) { + obj.setProperty("normalMap", FALLTHROUGH); + } else if (!material.normalMap.isEmpty()) { + obj.setProperty("normalMap", material.normalMap); + } else if (!material.bumpMap.isEmpty()) { + obj.setProperty("bumpMap", material.bumpMap); + } + + if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::Material::TEXCOORDTRANSFORM0)) { + obj.setProperty("texCoordTransform0", FALLTHROUGH); + } else if (material.texCoordTransforms[0] != mat4()) { + obj.setProperty("texCoordTransform0", mat4toScriptValue(engine, material.texCoordTransforms[0])); + } + if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::Material::TEXCOORDTRANSFORM1)) { + obj.setProperty("texCoordTransform1", FALLTHROUGH); + } else if (material.texCoordTransforms[1] != mat4()) { + obj.setProperty("texCoordTransform1", mat4toScriptValue(engine, material.texCoordTransforms[1])); + } + + // These need to be implemented, but set the fallthrough for now + if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::Material::LIGHTMAP_PARAMS)) { + obj.setProperty("lightmapParams", FALLTHROUGH); + } + if (hasPropertyFallthroughs && material.propertyFallthroughs.at(graphics::Material::MATERIAL_PARAMS)) { + obj.setProperty("materialParams", FALLTHROUGH); + } + + obj.setProperty("defaultFallthrough", material.defaultFallthrough); + } else if (material.model.toStdString() == graphics::Material::HIFI_SHADER_SIMPLE) { + obj.setProperty("procedural", material.procedural); + } return obj; } diff --git a/libraries/graphics-scripting/src/graphics-scripting/ScriptableModel.cpp b/libraries/graphics-scripting/src/graphics-scripting/ScriptableModel.cpp index 8825a26bfe..c09754e108 100644 --- a/libraries/graphics-scripting/src/graphics-scripting/ScriptableModel.cpp +++ b/libraries/graphics-scripting/src/graphics-scripting/ScriptableModel.cpp @@ -23,27 +23,32 @@ scriptable::ScriptableMaterial& scriptable::ScriptableMaterial::operator=(const name = material.name; model = material.model; opacity = material.opacity; - roughness = material.roughness; - metallic = material.metallic; - scattering = material.scattering; - unlit = material.unlit; - emissive = material.emissive; albedo = material.albedo; - emissiveMap = material.emissiveMap; - albedoMap = material.albedoMap; - opacityMap = material.opacityMap; - metallicMap = material.metallicMap; - specularMap = material.specularMap; - roughnessMap = material.roughnessMap; - glossMap = material.glossMap; - normalMap = material.normalMap; - bumpMap = material.bumpMap; - occlusionMap = material.occlusionMap; - lightmapMap = material.lightmapMap; - scatteringMap = material.scatteringMap; - defaultFallthrough = material.defaultFallthrough; - propertyFallthroughs = material.propertyFallthroughs; + if (model.toStdString() == graphics::Material::HIFI_PBR) { + roughness = material.roughness; + metallic = material.metallic; + scattering = material.scattering; + unlit = material.unlit; + emissive = material.emissive; + emissiveMap = material.emissiveMap; + albedoMap = material.albedoMap; + opacityMap = material.opacityMap; + metallicMap = material.metallicMap; + specularMap = material.specularMap; + roughnessMap = material.roughnessMap; + glossMap = material.glossMap; + normalMap = material.normalMap; + bumpMap = material.bumpMap; + occlusionMap = material.occlusionMap; + lightmapMap = material.lightmapMap; + scatteringMap = material.scatteringMap; + + defaultFallthrough = material.defaultFallthrough; + propertyFallthroughs = material.propertyFallthroughs; + } else if (model.toStdString() == graphics::Material::HIFI_SHADER_SIMPLE) { + procedural = material.procedural; + } key = material.key; @@ -55,73 +60,78 @@ scriptable::ScriptableMaterial::ScriptableMaterial(const graphics::MaterialPoint name = material->getName().c_str(); model = material->getModel().c_str(); opacity = material->getOpacity(); - roughness = material->getRoughness(); - metallic = material->getMetallic(); - scattering = material->getScattering(); - unlit = material->isUnlit(); - emissive = material->getEmissive(); albedo = material->getAlbedo(); - defaultFallthrough = material->getDefaultFallthrough(); - propertyFallthroughs = material->getPropertyFallthroughs(); - key = material->getKey(); - auto map = material->getTextureMap(graphics::Material::MapChannel::EMISSIVE_MAP); - if (map && map->getTextureSource()) { - emissiveMap = map->getTextureSource()->getUrl().toString(); - } + if (model.toStdString() == graphics::Material::HIFI_PBR) { + roughness = material->getRoughness(); + metallic = material->getMetallic(); + scattering = material->getScattering(); + unlit = material->isUnlit(); + emissive = material->getEmissive(); + defaultFallthrough = material->getDefaultFallthrough(); + propertyFallthroughs = material->getPropertyFallthroughs(); + key = material->getKey(); - map = material->getTextureMap(graphics::Material::MapChannel::ALBEDO_MAP); - if (map && map->getTextureSource()) { - albedoMap = map->getTextureSource()->getUrl().toString(); - if (map->useAlphaChannel()) { - opacityMap = albedoMap; + auto map = material->getTextureMap(graphics::Material::MapChannel::EMISSIVE_MAP); + if (map && map->getTextureSource()) { + emissiveMap = map->getTextureSource()->getUrl().toString(); } - } - map = material->getTextureMap(graphics::Material::MapChannel::METALLIC_MAP); - if (map && map->getTextureSource()) { - if (map->getTextureSource()->getType() == image::TextureUsage::Type::METALLIC_TEXTURE) { - metallicMap = map->getTextureSource()->getUrl().toString(); - } else if (map->getTextureSource()->getType() == image::TextureUsage::Type::SPECULAR_TEXTURE) { - specularMap = map->getTextureSource()->getUrl().toString(); + map = material->getTextureMap(graphics::Material::MapChannel::ALBEDO_MAP); + if (map && map->getTextureSource()) { + albedoMap = map->getTextureSource()->getUrl().toString(); + if (map->useAlphaChannel()) { + opacityMap = albedoMap; + } } - } - map = material->getTextureMap(graphics::Material::MapChannel::ROUGHNESS_MAP); - if (map && map->getTextureSource()) { - if (map->getTextureSource()->getType() == image::TextureUsage::Type::ROUGHNESS_TEXTURE) { - roughnessMap = map->getTextureSource()->getUrl().toString(); - } else if (map->getTextureSource()->getType() == image::TextureUsage::Type::GLOSS_TEXTURE) { - glossMap = map->getTextureSource()->getUrl().toString(); + map = material->getTextureMap(graphics::Material::MapChannel::METALLIC_MAP); + if (map && map->getTextureSource()) { + if (map->getTextureSource()->getType() == image::TextureUsage::Type::METALLIC_TEXTURE) { + metallicMap = map->getTextureSource()->getUrl().toString(); + } else if (map->getTextureSource()->getType() == image::TextureUsage::Type::SPECULAR_TEXTURE) { + specularMap = map->getTextureSource()->getUrl().toString(); + } } - } - map = material->getTextureMap(graphics::Material::MapChannel::NORMAL_MAP); - if (map && map->getTextureSource()) { - if (map->getTextureSource()->getType() == image::TextureUsage::Type::NORMAL_TEXTURE) { - normalMap = map->getTextureSource()->getUrl().toString(); - } else if (map->getTextureSource()->getType() == image::TextureUsage::Type::BUMP_TEXTURE) { - bumpMap = map->getTextureSource()->getUrl().toString(); + map = material->getTextureMap(graphics::Material::MapChannel::ROUGHNESS_MAP); + if (map && map->getTextureSource()) { + if (map->getTextureSource()->getType() == image::TextureUsage::Type::ROUGHNESS_TEXTURE) { + roughnessMap = map->getTextureSource()->getUrl().toString(); + } else if (map->getTextureSource()->getType() == image::TextureUsage::Type::GLOSS_TEXTURE) { + glossMap = map->getTextureSource()->getUrl().toString(); + } } - } - map = material->getTextureMap(graphics::Material::MapChannel::OCCLUSION_MAP); - if (map && map->getTextureSource()) { - occlusionMap = map->getTextureSource()->getUrl().toString(); - } + map = material->getTextureMap(graphics::Material::MapChannel::NORMAL_MAP); + if (map && map->getTextureSource()) { + if (map->getTextureSource()->getType() == image::TextureUsage::Type::NORMAL_TEXTURE) { + normalMap = map->getTextureSource()->getUrl().toString(); + } else if (map->getTextureSource()->getType() == image::TextureUsage::Type::BUMP_TEXTURE) { + bumpMap = map->getTextureSource()->getUrl().toString(); + } + } - map = material->getTextureMap(graphics::Material::MapChannel::LIGHTMAP_MAP); - if (map && map->getTextureSource()) { - lightmapMap = map->getTextureSource()->getUrl().toString(); - } + map = material->getTextureMap(graphics::Material::MapChannel::OCCLUSION_MAP); + if (map && map->getTextureSource()) { + occlusionMap = map->getTextureSource()->getUrl().toString(); + } - map = material->getTextureMap(graphics::Material::MapChannel::SCATTERING_MAP); - if (map && map->getTextureSource()) { - scatteringMap = map->getTextureSource()->getUrl().toString(); - } + map = material->getTextureMap(graphics::Material::MapChannel::LIGHTMAP_MAP); + if (map && map->getTextureSource()) { + lightmapMap = map->getTextureSource()->getUrl().toString(); + } - for (int i = 0; i < graphics::Material::NUM_TEXCOORD_TRANSFORMS; i++) { - texCoordTransforms[i] = material->getTexCoordTransform(i); + map = material->getTextureMap(graphics::Material::MapChannel::SCATTERING_MAP); + if (map && map->getTextureSource()) { + scatteringMap = map->getTextureSource()->getUrl().toString(); + } + + for (int i = 0; i < graphics::Material::NUM_TEXCOORD_TRANSFORMS; i++) { + texCoordTransforms[i] = material->getTexCoordTransform(i); + } + } else if (model.toStdString() == graphics::Material::HIFI_SHADER_SIMPLE) { + procedural = material->getProceduralString(); } } } diff --git a/libraries/graphics/src/graphics/Material.cpp b/libraries/graphics/src/graphics/Material.cpp index 3ef407b7d9..c0a86ffc1b 100755 --- a/libraries/graphics/src/graphics/Material.cpp +++ b/libraries/graphics/src/graphics/Material.cpp @@ -24,6 +24,9 @@ const float Material::DEFAULT_METALLIC { 0.0f }; const float Material::DEFAULT_ROUGHNESS { 1.0f }; const float Material::DEFAULT_SCATTERING { 0.0f }; +const std::string Material::HIFI_PBR { "hifi_pbr" }; +const std::string Material::HIFI_SHADER_SIMPLE { "hifi_shader_simple" }; + Material::Material() { for (int i = 0; i < NUM_TOTAL_FLAGS; i++) { _propertyFallthroughs[i] = false; diff --git a/libraries/graphics/src/graphics/Material.h b/libraries/graphics/src/graphics/Material.h index 6bf72d9f24..415275c499 100755 --- a/libraries/graphics/src/graphics/Material.h +++ b/libraries/graphics/src/graphics/Material.h @@ -346,12 +346,16 @@ public: virtual bool isProcedural() const { return false; } virtual bool isEnabled() const { return true; } virtual bool isReady() const { return true; } + virtual QString getProceduralString() const { return QString(); } + + static const std::string HIFI_PBR; + static const std::string HIFI_SHADER_SIMPLE; protected: std::string _name { "" }; private: - std::string _model { "hifi_pbr" }; + std::string _model { HIFI_PBR }; mutable MaterialKey _key { 0 }; // Material properties diff --git a/libraries/procedural/src/procedural/Procedural.h b/libraries/procedural/src/procedural/Procedural.h index 2ae50e0ffe..1b190ec715 100644 --- a/libraries/procedural/src/procedural/Procedural.h +++ b/libraries/procedural/src/procedural/Procedural.h @@ -201,7 +201,12 @@ public: bool isProcedural() const override { return true; } bool isEnabled() const override { return _procedural.isEnabled(); } bool isReady() const override { return _procedural.isReady(); } - void setProceduralData(const QString& data) { _procedural.setProceduralData(ProceduralData::parse(data)); } + QString getProceduralString() const override { return _proceduralString; } + + void setProceduralData(const QString& data) { + _proceduralString = data; + _procedural.setProceduralData(ProceduralData::parse(data)); + } glm::vec4 getColor(const glm::vec4& color) const { return _procedural.getColor(color); } bool isFading() const { return _procedural.isFading(); } void setIsFading(bool isFading) { _procedural.setIsFading(isFading); } @@ -214,6 +219,7 @@ public: void initializeProcedural(); private: + QString _proceduralString; Procedural _procedural; }; typedef std::shared_ptr ProceduralMaterialPointer; diff --git a/libraries/procedural/src/procedural/ProceduralMaterialCache.cpp b/libraries/procedural/src/procedural/ProceduralMaterialCache.cpp index 78cb6c7daa..fee943141f 100644 --- a/libraries/procedural/src/procedural/ProceduralMaterialCache.cpp +++ b/libraries/procedural/src/procedural/ProceduralMaterialCache.cpp @@ -172,9 +172,7 @@ std::pair> NetworkMaterialResource std::string name = ""; std::shared_ptr networkMaterial; - static const std::string HIFI_PBR = "hifi_pbr"; - static const std::string HIFI_SHADER_SIMPLE = "hifi_shader_simple"; - std::string modelString = HIFI_PBR; + std::string modelString = graphics::Material::HIFI_PBR; auto modelJSONIter = materialJSON.find("model"); if (modelJSONIter != materialJSON.end() && modelJSONIter.value().isString()) { modelString = modelJSONIter.value().toString().toStdString(); @@ -182,7 +180,7 @@ std::pair> NetworkMaterialResource std::array texcoordTransforms; - if (modelString == HIFI_PBR) { + if (modelString == graphics::Material::HIFI_PBR) { auto material = std::make_shared(); const QString FALLTHROUGH("fallthrough"); for (auto& key : materialJSON.keys()) { @@ -424,7 +422,7 @@ std::pair> NetworkMaterialResource } } networkMaterial = material; - } else if (modelString == HIFI_SHADER_SIMPLE) { + } else if (modelString == graphics::Material::HIFI_SHADER_SIMPLE) { auto material = std::make_shared(); const QString FALLTHROUGH("fallthrough"); for (auto& key : materialJSON.keys()) { diff --git a/libraries/render-utils/src/CauterizedMeshPartPayload.cpp b/libraries/render-utils/src/CauterizedMeshPartPayload.cpp index a310c10136..9c7a2ee60b 100644 --- a/libraries/render-utils/src/CauterizedMeshPartPayload.cpp +++ b/libraries/render-utils/src/CauterizedMeshPartPayload.cpp @@ -18,8 +18,9 @@ using namespace render; -CauterizedMeshPartPayload::CauterizedMeshPartPayload(ModelPointer model, int meshIndex, int partIndex, int shapeIndex, const Transform& transform, const Transform& offsetTransform) - : ModelMeshPartPayload(model, meshIndex, partIndex, shapeIndex, transform, offsetTransform) {} +CauterizedMeshPartPayload::CauterizedMeshPartPayload(ModelPointer model, int meshIndex, int partIndex, int shapeIndex, + const Transform& transform, const Transform& offsetTransform, const uint64_t& created) + : ModelMeshPartPayload(model, meshIndex, partIndex, shapeIndex, transform, offsetTransform, created) {} void CauterizedMeshPartPayload::updateClusterBuffer(const std::vector& clusterMatrices, const std::vector& cauterizedClusterMatrices) { diff --git a/libraries/render-utils/src/CauterizedMeshPartPayload.h b/libraries/render-utils/src/CauterizedMeshPartPayload.h index 9a6cea8b9f..f1fe5faa35 100644 --- a/libraries/render-utils/src/CauterizedMeshPartPayload.h +++ b/libraries/render-utils/src/CauterizedMeshPartPayload.h @@ -13,7 +13,7 @@ class CauterizedMeshPartPayload : public ModelMeshPartPayload { public: - CauterizedMeshPartPayload(ModelPointer model, int meshIndex, int partIndex, int shapeIndex, const Transform& transform, const Transform& offsetTransform); + CauterizedMeshPartPayload(ModelPointer model, int meshIndex, int partIndex, int shapeIndex, const Transform& transform, const Transform& offsetTransform, const uint64_t& created); // matrix palette skinning void updateClusterBuffer(const std::vector& clusterMatrices, diff --git a/libraries/render-utils/src/CauterizedModel.cpp b/libraries/render-utils/src/CauterizedModel.cpp index c700f1ad3f..fac9082c74 100644 --- a/libraries/render-utils/src/CauterizedModel.cpp +++ b/libraries/render-utils/src/CauterizedModel.cpp @@ -88,7 +88,7 @@ void CauterizedModel::createRenderItemSet() { for (int partIndex = 0; partIndex < numParts; partIndex++) { initializeBlendshapes(hfmModel.meshes[i], i); - auto ptr = std::make_shared(shared_from_this(), i, partIndex, shapeID, transform, offset); + auto ptr = std::make_shared(shared_from_this(), i, partIndex, shapeID, transform, offset, _created); _modelMeshRenderItems << std::static_pointer_cast(ptr); auto material = getGeometry()->getShapeMaterial(shapeID); _modelMeshMaterialNames.push_back(material ? material->getName() : ""); diff --git a/libraries/render-utils/src/MeshPartPayload.cpp b/libraries/render-utils/src/MeshPartPayload.cpp index eaeac40e2c..b22f738bd1 100644 --- a/libraries/render-utils/src/MeshPartPayload.cpp +++ b/libraries/render-utils/src/MeshPartPayload.cpp @@ -52,7 +52,9 @@ template <> void payloadRender(const MeshPartPayload::Pointer& payload, RenderAr } } -MeshPartPayload::MeshPartPayload(const std::shared_ptr& mesh, int partIndex, graphics::MaterialPointer material) { +MeshPartPayload::MeshPartPayload(const std::shared_ptr& mesh, int partIndex, graphics::MaterialPointer material, const uint64_t& created) : + _created(created) +{ updateMeshPart(mesh, partIndex); addMaterial(graphics::MaterialLayer(material, 0)); } @@ -172,7 +174,7 @@ void MeshPartPayload::render(RenderArgs* args) { auto& schema = _drawMaterials.getSchemaBuffer().get(); glm::vec4 outColor = glm::vec4(ColorUtils::tosRGBVec3(schema._albedo), schema._opacity); outColor = procedural->getColor(outColor); - procedural->prepare(batch, _drawTransform.getTranslation(), _drawTransform.getScale(), _drawTransform.getRotation(), 0, // FIXME: pass in _created + procedural->prepare(batch, _drawTransform.getTranslation(), _drawTransform.getScale(), _drawTransform.getRotation(), _created, ProceduralProgramKey(outColor.a < 1.0f)); batch._glColor4f(outColor.r, outColor.g, outColor.b, outColor.a); } else { @@ -220,7 +222,8 @@ template <> void payloadRender(const ModelMeshPartPayload::Pointer& payload, Ren } -ModelMeshPartPayload::ModelMeshPartPayload(ModelPointer model, int meshIndex, int partIndex, int shapeIndex, const Transform& transform, const Transform& offsetTransform) : +ModelMeshPartPayload::ModelMeshPartPayload(ModelPointer model, int meshIndex, int partIndex, int shapeIndex, + const Transform& transform, const Transform& offsetTransform, const uint64_t& created) : _meshIndex(meshIndex), _shapeID(shapeIndex) { @@ -272,6 +275,7 @@ ModelMeshPartPayload::ModelMeshPartPayload(ModelPointer model, int meshIndex, in } #endif + _created = created; } void ModelMeshPartPayload::initCache(const ModelPointer& model) { @@ -468,7 +472,7 @@ void ModelMeshPartPayload::render(RenderArgs* args) { auto& schema = _drawMaterials.getSchemaBuffer().get(); glm::vec4 outColor = glm::vec4(ColorUtils::tosRGBVec3(schema._albedo), schema._opacity); outColor = procedural->getColor(outColor); - procedural->prepare(batch, _drawTransform.getTranslation(), _drawTransform.getScale(), _drawTransform.getRotation(), 0,// FIXME: pass in _created + procedural->prepare(batch, _drawTransform.getTranslation(), _drawTransform.getScale(), _drawTransform.getRotation(), _created, ProceduralProgramKey(outColor.a < 1.0f, _shapeKey.isDeformed(), _shapeKey.isDualQuatSkinned())); batch._glColor4f(outColor.r, outColor.g, outColor.b, outColor.a); } else { diff --git a/libraries/render-utils/src/MeshPartPayload.h b/libraries/render-utils/src/MeshPartPayload.h index e1103bb666..18ef513a87 100644 --- a/libraries/render-utils/src/MeshPartPayload.h +++ b/libraries/render-utils/src/MeshPartPayload.h @@ -27,7 +27,7 @@ class Model; class MeshPartPayload { public: MeshPartPayload() = default; - MeshPartPayload(const std::shared_ptr& mesh, int partIndex, graphics::MaterialPointer material); + MeshPartPayload(const std::shared_ptr& mesh, int partIndex, graphics::MaterialPointer material, const uint64_t& created); virtual ~MeshPartPayload() = default; typedef render::Payload Payload; @@ -77,6 +77,7 @@ public: protected: render::ItemKey _itemKey{ render::ItemKey::Builder::opaqueShape().build() }; + uint64_t _created; }; namespace render { @@ -88,7 +89,7 @@ namespace render { class ModelMeshPartPayload : public MeshPartPayload { public: - ModelMeshPartPayload(ModelPointer model, int meshIndex, int partIndex, int shapeIndex, const Transform& transform, const Transform& offsetTransform); + ModelMeshPartPayload(ModelPointer model, int meshIndex, int partIndex, int shapeIndex, const Transform& transform, const Transform& offsetTransform, const uint64_t& created); typedef render::Payload Payload; typedef Payload::DataPointer Pointer; diff --git a/libraries/render-utils/src/Model.cpp b/libraries/render-utils/src/Model.cpp index 96979a23a9..5ea03c1583 100644 --- a/libraries/render-utils/src/Model.cpp +++ b/libraries/render-utils/src/Model.cpp @@ -48,7 +48,7 @@ int normalTypeVecTypeId = qRegisterMetaType>("QVectorgetNumParts(); for (int partIndex = 0; partIndex < numParts; partIndex++) { initializeBlendshapes(hfmModel.meshes[i], i); - _modelMeshRenderItems << std::make_shared(shared_from_this(), i, partIndex, shapeID, transform, offset); + _modelMeshRenderItems << std::make_shared(shared_from_this(), i, partIndex, shapeID, transform, offset, _created); auto material = getGeometry()->getShapeMaterial(shapeID); _modelMeshMaterialNames.push_back(material ? material->getName() : ""); _modelMeshRenderItemShapes.emplace_back(ShapeInfo{ (int)i }); diff --git a/libraries/render-utils/src/Model.h b/libraries/render-utils/src/Model.h index 7c861a3bc1..da95fdef10 100644 --- a/libraries/render-utils/src/Model.h +++ b/libraries/render-utils/src/Model.h @@ -99,7 +99,7 @@ public: static void setAbstractViewStateInterface(AbstractViewStateInterface* viewState) { _viewState = viewState; } - Model(QObject* parent = nullptr, SpatiallyNestable* spatiallyNestableOverride = nullptr); + Model(QObject* parent = nullptr, SpatiallyNestable* spatiallyNestableOverride = nullptr, uint64_t created = 0); virtual ~Model(); inline ModelPointer getThisPointer() const { @@ -511,6 +511,8 @@ protected: void initializeBlendshapes(const HFMMesh& mesh, int index); + uint64_t _created; + private: float _loadingPriority { 0.0f };