From b794259b7dc59ba829771654c995b8703688f565 Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Fri, 5 Aug 2016 16:15:10 -0700 Subject: [PATCH] fixed procedural entity fade --- .../src/RenderableShapeEntityItem.cpp | 6 +++--- .../entities-renderer/src/RenderableShapeEntityItem.h | 10 +++++----- libraries/procedural/src/procedural/Procedural.cpp | 8 +++++++- libraries/procedural/src/procedural/Procedural.h | 1 + libraries/render-utils/src/simple.slf | 3 +-- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableShapeEntityItem.cpp b/libraries/entities-renderer/src/RenderableShapeEntityItem.cpp index 5bfd669a7c..42b63ee2c2 100644 --- a/libraries/entities-renderer/src/RenderableShapeEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableShapeEntityItem.cpp @@ -71,13 +71,13 @@ void RenderableShapeEntityItem::setUserData(const QString& value) { } } -/*bool RenderableShapeEntityItem::isTransparent() { +bool RenderableShapeEntityItem::isTransparent() { if (_procedural && _procedural->ready()) { return Interpolate::calculateFadeRatio(_procedural->getFadeStartTime()) < 1.0f; } else { return EntityItem::isTransparent(); } -}*/ +} void RenderableShapeEntityItem::render(RenderArgs* args) { PerformanceTimer perfTimer("RenderableShapeEntityItem::render"); @@ -91,7 +91,7 @@ void RenderableShapeEntityItem::render(RenderArgs* args) { _procedural->_fragmentSource = simple_frag; _procedural->_state->setCullMode(gpu::State::CULL_NONE); _procedural->_state->setDepthTest(true, true, gpu::LESS_EQUAL); - _procedural->_state->setBlendFunction(false, + _procedural->_state->setBlendFunction(true, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE); } diff --git a/libraries/entities-renderer/src/RenderableShapeEntityItem.h b/libraries/entities-renderer/src/RenderableShapeEntityItem.h index 68b36f7e45..7eefe0e7a4 100644 --- a/libraries/entities-renderer/src/RenderableShapeEntityItem.h +++ b/libraries/entities-renderer/src/RenderableShapeEntityItem.h @@ -21,17 +21,17 @@ public: static EntityItemPointer factory(const EntityItemID& entityID, const EntityItemProperties& properties); static EntityItemPointer boxFactory(const EntityItemID& entityID, const EntityItemProperties& properties); static EntityItemPointer sphereFactory(const EntityItemID& entityID, const EntityItemProperties& properties); - RenderableShapeEntityItem(const EntityItemID& entityItemID) : ShapeEntityItem(entityItemID) { _procedural.reset(nullptr); } + RenderableShapeEntityItem(const EntityItemID& entityItemID) : ShapeEntityItem(entityItemID) {} void render(RenderArgs* args) override; void setUserData(const QString& value) override; -// bool isTransparent() override; - - SIMPLE_RENDERABLE(); + bool isTransparent() override; private: - QSharedPointer _procedural; + std::unique_ptr _procedural { nullptr }; + + SIMPLE_RENDERABLE(); }; diff --git a/libraries/procedural/src/procedural/Procedural.cpp b/libraries/procedural/src/procedural/Procedural.cpp index 1c7fcade18..7f8ab2db41 100644 --- a/libraries/procedural/src/procedural/Procedural.cpp +++ b/libraries/procedural/src/procedural/Procedural.cpp @@ -175,6 +175,10 @@ void Procedural::parse(const QJsonObject& proceduralData) { } bool Procedural::ready() { + if (!_hasStartedFade) { + _fadeStartTime = usecTimestampNow(); + } + // Load any changes to the procedural // Check for changes atomically, in case they are currently being made if (_proceduralDataDirty) { @@ -184,7 +188,6 @@ bool Procedural::ready() { // Reset dirty flag after reading _proceduralData, but before releasing lock // to avoid resetting it after more data is set _proceduralDataDirty = false; - _fadeStartTime = usecTimestampNow(); } if (!_enabled) { @@ -203,6 +206,9 @@ bool Procedural::ready() { } } + if (!_hasStartedFade) { + _hasStartedFade = true; + } return true; } diff --git a/libraries/procedural/src/procedural/Procedural.h b/libraries/procedural/src/procedural/Procedural.h index f8d0c963f4..dea55f197b 100644 --- a/libraries/procedural/src/procedural/Procedural.h +++ b/libraries/procedural/src/procedural/Procedural.h @@ -109,6 +109,7 @@ private: void setupChannels(bool shouldCreate); quint64 _fadeStartTime; + bool _hasStartedFade { false }; }; #endif diff --git a/libraries/render-utils/src/simple.slf b/libraries/render-utils/src/simple.slf index 85d85b3db7..228560f394 100644 --- a/libraries/render-utils/src/simple.slf +++ b/libraries/render-utils/src/simple.slf @@ -52,11 +52,10 @@ void main(void) { const float ALPHA_THRESHOLD = 0.999; if (_color.a < ALPHA_THRESHOLD) { if (emissiveAmount > 0.0) { - // TODO: transparent emissive? packDeferredFragmentTranslucent( normal, _color.a, - diffuse, + specular, DEFAULT_FRESNEL, DEFAULT_ROUGHNESS); } else {