From 131a57248b694d1cfedd9ef744207c1aba09aee3 Mon Sep 17 00:00:00 2001 From: Simon Walton Date: Fri, 8 Jun 2018 10:27:03 -0700 Subject: [PATCH 01/16] NLPacket local ID could be used uninitialized (according to valgrind) --- libraries/networking/src/NLPacket.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libraries/networking/src/NLPacket.cpp b/libraries/networking/src/NLPacket.cpp index f946e97bf4..620e60945b 100644 --- a/libraries/networking/src/NLPacket.cpp +++ b/libraries/networking/src/NLPacket.cpp @@ -199,7 +199,9 @@ void NLPacket::readVersion() { } void NLPacket::readSourceID() { - if (!PacketTypeEnum::getNonSourcedPackets().contains(_type)) { + if (PacketTypeEnum::getNonSourcedPackets().contains(_type)) { + _sourceID = NULL_LOCAL_ID; + } else { _sourceID = sourceIDInHeader(*this); } } From e3c8895c8965e0128d002d12aef36aecedd0cdc8 Mon Sep 17 00:00:00 2001 From: Simon Walton Date: Fri, 8 Jun 2018 18:17:03 -0700 Subject: [PATCH 02/16] Take down DependencyManager upon restart --- assignment-client/src/scripts/EntityScriptServer.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/assignment-client/src/scripts/EntityScriptServer.cpp b/assignment-client/src/scripts/EntityScriptServer.cpp index eea8e8b470..5722cccf38 100644 --- a/assignment-client/src/scripts/EntityScriptServer.cpp +++ b/assignment-client/src/scripts/EntityScriptServer.cpp @@ -570,6 +570,8 @@ void EntityScriptServer::aboutToFinish() { entityScriptingInterface->setPacketSender(nullptr); } + DependencyManager::destroy(); + DependencyManager::get()->cleanup(); // cleanup the AudioInjectorManager (and any still running injectors) From 5ae79bcc5e4f4613b42629b9ca3a53e80dda8dd6 Mon Sep 17 00:00:00 2001 From: Simon Walton Date: Mon, 11 Jun 2018 13:05:42 -0700 Subject: [PATCH 03/16] Use weak_ptr for pointers back to parent --- libraries/entities/src/EntityTreeElement.cpp | 6 +++--- libraries/entities/src/EntityTreeElement.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libraries/entities/src/EntityTreeElement.cpp b/libraries/entities/src/EntityTreeElement.cpp index cbcddfc57b..719c065522 100644 --- a/libraries/entities/src/EntityTreeElement.cpp +++ b/libraries/entities/src/EntityTreeElement.cpp @@ -33,7 +33,7 @@ EntityTreeElement::~EntityTreeElement() { OctreeElementPointer EntityTreeElement::createNewElement(unsigned char* octalCode) { auto newChild = EntityTreeElementPointer(new EntityTreeElement(octalCode)); - newChild->setTree(_myTree); + newChild->setTree(getTree()); return newChild; } @@ -44,7 +44,7 @@ void EntityTreeElement::init(unsigned char* octalCode) { OctreeElementPointer EntityTreeElement::addChildAtIndex(int index) { OctreeElementPointer newElement = OctreeElement::addChildAtIndex(index); - std::static_pointer_cast(newElement)->setTree(_myTree); + std::static_pointer_cast(newElement)->setTree(getTree()); return newElement; } @@ -475,7 +475,7 @@ bool EntityTreeElement::removeEntityItem(EntityItemPointer entity, bool deletion int EntityTreeElement::readElementDataFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args) { - return _myTree->readEntityDataFromBuffer(data, bytesLeftToRead, args); + return getTree()->readEntityDataFromBuffer(data, bytesLeftToRead, args); } void EntityTreeElement::addEntityItem(EntityItemPointer entity) { diff --git a/libraries/entities/src/EntityTreeElement.h b/libraries/entities/src/EntityTreeElement.h index 76e1e40812..f9f930a9fc 100644 --- a/libraries/entities/src/EntityTreeElement.h +++ b/libraries/entities/src/EntityTreeElement.h @@ -161,8 +161,8 @@ public: virtual uint16_t size() const; bool hasEntities() const { return size() > 0; } - void setTree(EntityTreePointer tree) { _myTree = tree; } - EntityTreePointer getTree() const { return _myTree; } + void setTree(EntityTreePointer tree) { _myTree.swap(std::weak_ptr(tree)); } + EntityTreePointer getTree() const { return _myTree.lock(); } void addEntityItem(EntityItemPointer entity); @@ -234,7 +234,7 @@ public: protected: virtual void init(unsigned char * octalCode) override; - EntityTreePointer _myTree; + std::weak_ptr _myTree; EntityItems _entityItems; }; From 99a8ecc6db9865d63278e0a59f29f607ffb1d2f8 Mon Sep 17 00:00:00 2001 From: Simon Walton Date: Mon, 11 Jun 2018 13:52:44 -0700 Subject: [PATCH 04/16] Break simulation/entity-tree cycle --- assignment-client/src/entities/EntityTreeHeadlessViewer.cpp | 3 +++ libraries/entities/src/EntityTreeElement.h | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/assignment-client/src/entities/EntityTreeHeadlessViewer.cpp b/assignment-client/src/entities/EntityTreeHeadlessViewer.cpp index 81c42cda1e..3649cf1129 100644 --- a/assignment-client/src/entities/EntityTreeHeadlessViewer.cpp +++ b/assignment-client/src/entities/EntityTreeHeadlessViewer.cpp @@ -17,6 +17,9 @@ EntityTreeHeadlessViewer::EntityTreeHeadlessViewer() } EntityTreeHeadlessViewer::~EntityTreeHeadlessViewer() { + if (_simulation) { + _simulation->setEntityTree(nullptr); // Break shared_ptr cycle. + } } void EntityTreeHeadlessViewer::init() { diff --git a/libraries/entities/src/EntityTreeElement.h b/libraries/entities/src/EntityTreeElement.h index f9f930a9fc..023e908e2c 100644 --- a/libraries/entities/src/EntityTreeElement.h +++ b/libraries/entities/src/EntityTreeElement.h @@ -161,7 +161,7 @@ public: virtual uint16_t size() const; bool hasEntities() const { return size() > 0; } - void setTree(EntityTreePointer tree) { _myTree.swap(std::weak_ptr(tree)); } + void setTree(EntityTreePointer tree) { _myTree = std::weak_ptr(tree); } EntityTreePointer getTree() const { return _myTree.lock(); } void addEntityItem(EntityItemPointer entity); From 9ae3411abea821b5743e91dff30b02e86eb3dfa8 Mon Sep 17 00:00:00 2001 From: Simon Walton Date: Tue, 12 Jun 2018 12:32:27 -0700 Subject: [PATCH 05/16] Have ~OctreeProcessor break cycle instead of using weak pointers --- libraries/entities/src/EntityTreeElement.cpp | 6 +++--- libraries/entities/src/EntityTreeElement.h | 6 +++--- libraries/octree/src/OctreeProcessor.cpp | 9 +++------ libraries/octree/src/OctreeProcessor.h | 3 +-- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/libraries/entities/src/EntityTreeElement.cpp b/libraries/entities/src/EntityTreeElement.cpp index 719c065522..cbcddfc57b 100644 --- a/libraries/entities/src/EntityTreeElement.cpp +++ b/libraries/entities/src/EntityTreeElement.cpp @@ -33,7 +33,7 @@ EntityTreeElement::~EntityTreeElement() { OctreeElementPointer EntityTreeElement::createNewElement(unsigned char* octalCode) { auto newChild = EntityTreeElementPointer(new EntityTreeElement(octalCode)); - newChild->setTree(getTree()); + newChild->setTree(_myTree); return newChild; } @@ -44,7 +44,7 @@ void EntityTreeElement::init(unsigned char* octalCode) { OctreeElementPointer EntityTreeElement::addChildAtIndex(int index) { OctreeElementPointer newElement = OctreeElement::addChildAtIndex(index); - std::static_pointer_cast(newElement)->setTree(getTree()); + std::static_pointer_cast(newElement)->setTree(_myTree); return newElement; } @@ -475,7 +475,7 @@ bool EntityTreeElement::removeEntityItem(EntityItemPointer entity, bool deletion int EntityTreeElement::readElementDataFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args) { - return getTree()->readEntityDataFromBuffer(data, bytesLeftToRead, args); + return _myTree->readEntityDataFromBuffer(data, bytesLeftToRead, args); } void EntityTreeElement::addEntityItem(EntityItemPointer entity) { diff --git a/libraries/entities/src/EntityTreeElement.h b/libraries/entities/src/EntityTreeElement.h index 023e908e2c..76e1e40812 100644 --- a/libraries/entities/src/EntityTreeElement.h +++ b/libraries/entities/src/EntityTreeElement.h @@ -161,8 +161,8 @@ public: virtual uint16_t size() const; bool hasEntities() const { return size() > 0; } - void setTree(EntityTreePointer tree) { _myTree = std::weak_ptr(tree); } - EntityTreePointer getTree() const { return _myTree.lock(); } + void setTree(EntityTreePointer tree) { _myTree = tree; } + EntityTreePointer getTree() const { return _myTree; } void addEntityItem(EntityItemPointer entity); @@ -234,7 +234,7 @@ public: protected: virtual void init(unsigned char * octalCode) override; - std::weak_ptr _myTree; + EntityTreePointer _myTree; EntityItems _entityItems; }; diff --git a/libraries/octree/src/OctreeProcessor.cpp b/libraries/octree/src/OctreeProcessor.cpp index db78e985e6..beaac1198c 100644 --- a/libraries/octree/src/OctreeProcessor.cpp +++ b/libraries/octree/src/OctreeProcessor.cpp @@ -20,12 +20,6 @@ #include "OctreeLogging.h" -OctreeProcessor::OctreeProcessor() : - _tree(NULL), - _managedTree(false) -{ -} - void OctreeProcessor::init() { if (!_tree) { _tree = createTree(); @@ -34,6 +28,9 @@ void OctreeProcessor::init() { } OctreeProcessor::~OctreeProcessor() { + if (_tree) { + _tree->eraseAllOctreeElements(false); + } } void OctreeProcessor::setTree(OctreePointer newTree) { diff --git a/libraries/octree/src/OctreeProcessor.h b/libraries/octree/src/OctreeProcessor.h index 25e280abca..325b33cd15 100644 --- a/libraries/octree/src/OctreeProcessor.h +++ b/libraries/octree/src/OctreeProcessor.h @@ -28,7 +28,6 @@ class OctreeProcessor : public QObject, public QEnableSharedFromThis { Q_OBJECT public: - OctreeProcessor(); virtual ~OctreeProcessor(); virtual char getMyNodeType() const = 0; @@ -61,7 +60,7 @@ protected: virtual OctreePointer createTree() = 0; OctreePointer _tree; - bool _managedTree; + bool _managedTree { false }; SimpleMovingAverage _elementsPerPacket; SimpleMovingAverage _entitiesPerPacket; From 2264425f9fb865f699927d40b836d531e8338d6b Mon Sep 17 00:00:00 2001 From: luiscuenca Date: Thu, 28 Jun 2018 16:41:39 -0700 Subject: [PATCH 06/16] Fix eyelid behaviour --- .../src/avatars-renderer/Head.cpp | 56 ++++++++++++++----- libraries/avatars/src/HeadData.cpp | 38 +++++++------ libraries/avatars/src/HeadData.h | 4 ++ 3 files changed, 66 insertions(+), 32 deletions(-) diff --git a/libraries/avatars-renderer/src/avatars-renderer/Head.cpp b/libraries/avatars-renderer/src/avatars-renderer/Head.cpp index 5800c1404b..0d939dce82 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Head.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/Head.cpp @@ -220,30 +220,56 @@ void Head::calculateMouthShapes(float deltaTime) { void Head::applyEyelidOffset(glm::quat headOrientation) { // Adjusts the eyelid blendshape coefficients so that the eyelid follows the iris as the head pitches. - - if (disableEyelidAdjustment) { + bool isBlinking = (_rightEyeBlinkVelocity != 0.0f && _rightEyeBlinkVelocity != 0.0f); + if (disableEyelidAdjustment || isBlinking) { return; } + const std::vector eyeBlinkBlendShapes = { "EyeBlink_L", "EyeBlink_R" }; + const std::vector eyeOpenBlendShapes = { "EyeOpen_L", "EyeOpen_R" }; + const std::vector browsBlendShapes = { "BrowsU_L", "BrowsU_R" }; + + const float EYE_PITCH_TO_COEFFICIENT = 3.5f; // Empirically determined + const float MAX_EYELID_OFFSET = 1.5f; + const float BLINK_DOWN_MULTIPLIER = 0.25f; + const float OPEN_DOWN_MULTIPLIER = 0.3f; + const float BROW_UP_MULTIPLIER = 0.5f; + glm::quat eyeRotation = rotationBetween(headOrientation * IDENTITY_FORWARD, getLookAtPosition() - _eyePosition); eyeRotation = eyeRotation * glm::angleAxis(safeEulerAngles(headOrientation).y, IDENTITY_UP); // Rotation w.r.t. head float eyePitch = safeEulerAngles(eyeRotation).x; + float eyelidOffset = glm::clamp(abs(eyePitch * EYE_PITCH_TO_COEFFICIENT), 0.0f, MAX_EYELID_OFFSET); - const float EYE_PITCH_TO_COEFFICIENT = 1.6f; // Empirically determined - const float MAX_EYELID_OFFSET = 0.8f; // So that don't fully close eyes when looking way down - float eyelidOffset = glm::clamp(-eyePitch * EYE_PITCH_TO_COEFFICIENT, -1.0f, MAX_EYELID_OFFSET); + std::vector eyeBlinkIndices, eyeOpenIndices, browsIndices; - for (int i = 0; i < 2; i++) { - const int LEFT_EYE = 8; - float eyeCoefficient = _transientBlendshapeCoefficients[i] - _transientBlendshapeCoefficients[LEFT_EYE + i]; - eyeCoefficient = glm::clamp(eyelidOffset + eyeCoefficient * (1.0f - eyelidOffset), -1.0f, 1.0f); - if (eyeCoefficient > 0.0f) { - _transientBlendshapeCoefficients[i] = eyeCoefficient; - _transientBlendshapeCoefficients[LEFT_EYE + i] = 0.0f; + getBlendshapeIndices(eyeBlinkBlendShapes, eyeBlinkIndices); + getBlendshapeIndices(eyeOpenBlendShapes, eyeOpenIndices); + getBlendshapeIndices(browsBlendShapes, browsIndices); - } else { - _transientBlendshapeCoefficients[i] = 0.0f; - _transientBlendshapeCoefficients[LEFT_EYE + i] = -eyeCoefficient; + bool isLookingUp = (eyePitch > 0); + + for (auto& blinkIndex : eyeBlinkIndices) { + float lookingUpCoefficient = -eyelidOffset; + float lookingDownCoefficient = BLINK_DOWN_MULTIPLIER * eyelidOffset; + if (blinkIndex >= 0 && blinkIndex < _transientBlendshapeCoefficients.size()) { + _transientBlendshapeCoefficients[blinkIndex] = isLookingUp ? lookingUpCoefficient : lookingDownCoefficient; + } + + } + + for (auto& openIndex : eyeOpenIndices) { + float lookingUpCoefficient = eyelidOffset; + float lookingDownCoefficient = OPEN_DOWN_MULTIPLIER * eyelidOffset; + if (openIndex >= 0 && openIndex < _transientBlendshapeCoefficients.size()) { + _transientBlendshapeCoefficients[openIndex] = isLookingUp ? lookingUpCoefficient : lookingDownCoefficient; + } + } + + for (auto& browIndex : browsIndices) { + float lookingUpCoefficient = BROW_UP_MULTIPLIER * eyelidOffset; + float lookingDownCoefficient = 0.0f; + if (browIndex >= 0 && browIndex < _transientBlendshapeCoefficients.size()) { + _transientBlendshapeCoefficients[browIndex] = isLookingUp ? lookingUpCoefficient : lookingDownCoefficient; } } } diff --git a/libraries/avatars/src/HeadData.cpp b/libraries/avatars/src/HeadData.cpp index 4119d7a459..c68bb26e34 100644 --- a/libraries/avatars/src/HeadData.cpp +++ b/libraries/avatars/src/HeadData.cpp @@ -33,7 +33,7 @@ HeadData::HeadData(AvatarData* owningAvatar) : _summedBlendshapeCoefficients(QVector(0, 0.0f)), _owningAvatar(owningAvatar) { - + computeBlendshapesLookupMap(); } glm::quat HeadData::getRawOrientation() const { @@ -71,16 +71,10 @@ void HeadData::setOrientation(const glm::quat& orientation) { setHeadOrientation(orientation); } -//Lazily construct a lookup map from the blendshapes -static const QMap& getBlendshapesLookupMap() { - static std::once_flag once; - static QMap blendshapeLookupMap; - std::call_once(once, [&] { - for (int i = 0; i < NUM_FACESHIFT_BLENDSHAPES; i++) { - blendshapeLookupMap[FACESHIFT_BLENDSHAPES[i]] = i; - } - }); - return blendshapeLookupMap; +void HeadData::computeBlendshapesLookupMap(){ + for (int i = 0; i < NUM_FACESHIFT_BLENDSHAPES; i++) { + _blendshapeLookupMap[FACESHIFT_BLENDSHAPES[i]] = i; + } } int HeadData::getNumSummedBlendshapeCoefficients() const { @@ -108,11 +102,10 @@ const QVector& HeadData::getSummedBlendshapeCoefficients() { } void HeadData::setBlendshape(QString name, float val) { - const auto& blendshapeLookupMap = getBlendshapesLookupMap(); //Check to see if the named blendshape exists, and then set its value if it does - auto it = blendshapeLookupMap.find(name); - if (it != blendshapeLookupMap.end()) { + auto it = _blendshapeLookupMap.find(name); + if (it != _blendshapeLookupMap.end()) { if (_blendshapeCoefficients.size() <= it.value()) { _blendshapeCoefficients.resize(it.value() + 1); } @@ -123,6 +116,18 @@ void HeadData::setBlendshape(QString name, float val) { } } +int HeadData::getBlendshapeIndex(const QString& name) { + auto it = _blendshapeLookupMap.find(name); + int index = it != _blendshapeLookupMap.end() ? it.value() : -1; + return index; +} + +void HeadData::getBlendshapeIndices(const std::vector& blendShapeNames, std::vector& indexes) { + for (auto& name : blendShapeNames) { + indexes.push_back(getBlendshapeIndex(name)); + } +} + static const QString JSON_AVATAR_HEAD_ROTATION = QStringLiteral("rotation"); static const QString JSON_AVATAR_HEAD_BLENDSHAPE_COEFFICIENTS = QStringLiteral("blendShapes"); static const QString JSON_AVATAR_HEAD_LEAN_FORWARD = QStringLiteral("leanForward"); @@ -131,10 +136,9 @@ static const QString JSON_AVATAR_HEAD_LOOKAT = QStringLiteral("lookAt"); QJsonObject HeadData::toJson() const { QJsonObject headJson; - const auto& blendshapeLookupMap = getBlendshapesLookupMap(); QJsonObject blendshapesJson; - for (auto name : blendshapeLookupMap.keys()) { - auto index = blendshapeLookupMap[name]; + for (auto name : _blendshapeLookupMap.keys()) { + auto index = _blendshapeLookupMap[name]; float value = 0.0f; if (index < _blendshapeCoefficients.size()) { value += _blendshapeCoefficients[index]; diff --git a/libraries/avatars/src/HeadData.h b/libraries/avatars/src/HeadData.h index f9c4b52139..834629596a 100644 --- a/libraries/avatars/src/HeadData.h +++ b/libraries/avatars/src/HeadData.h @@ -55,6 +55,8 @@ public: void setOrientation(const glm::quat& orientation); void setBlendshape(QString name, float val); + int getBlendshapeIndex(const QString& name); + void getBlendshapeIndices(const std::vector& blendShapeNames, std::vector& indexes); const QVector& getBlendshapeCoefficients() const { return _blendshapeCoefficients; } const QVector& getSummedBlendshapeCoefficients(); int getNumSummedBlendshapeCoefficients() const; @@ -114,6 +116,7 @@ protected: QVector _blendshapeCoefficients; QVector _transientBlendshapeCoefficients; QVector _summedBlendshapeCoefficients; + QMap _blendshapeLookupMap; AvatarData* _owningAvatar; private: @@ -122,6 +125,7 @@ private: HeadData& operator= (const HeadData&); void setHeadOrientation(const glm::quat& orientation); + void computeBlendshapesLookupMap(); }; #endif // hifi_HeadData_h From 24d03ace4c71a686f2b5fc856977745b4a029da1 Mon Sep 17 00:00:00 2001 From: luiscuenca Date: Fri, 29 Jun 2018 14:34:17 -0700 Subject: [PATCH 07/16] Changes from CR and decreased looking at angle to mitigate freaky eyes --- libraries/animation/src/Rig.cpp | 4 +- .../src/avatars-renderer/Head.cpp | 53 ++++++++----------- libraries/avatars/src/HeadData.cpp | 1 - libraries/avatars/src/HeadData.h | 1 + libraries/shared/src/FaceshiftConstants.cpp | 15 ++++++ libraries/shared/src/FaceshiftConstants.h | 6 ++- 6 files changed, 44 insertions(+), 36 deletions(-) diff --git a/libraries/animation/src/Rig.cpp b/libraries/animation/src/Rig.cpp index 0833b28142..b10bba1c25 100644 --- a/libraries/animation/src/Rig.cpp +++ b/libraries/animation/src/Rig.cpp @@ -1434,9 +1434,9 @@ void Rig::updateEyeJoint(int index, const glm::vec3& modelTranslation, const glm glm::quat deltaQuat = desiredQuat * glm::inverse(headQuat); - // limit swing rotation of the deltaQuat by a 30 degree cone. + // limit swing rotation of the deltaQuat by a 25 degree cone. // TODO: use swing twist decomposition constraint instead, for off axis rotation clamping. - const float MAX_ANGLE = 30.0f * RADIANS_PER_DEGREE; + const float MAX_ANGLE = 25.0f * RADIANS_PER_DEGREE; if (fabsf(glm::angle(deltaQuat)) > MAX_ANGLE) { deltaQuat = glm::angleAxis(glm::clamp(glm::angle(deltaQuat), -MAX_ANGLE, MAX_ANGLE), glm::axis(deltaQuat)); } diff --git a/libraries/avatars-renderer/src/avatars-renderer/Head.cpp b/libraries/avatars-renderer/src/avatars-renderer/Head.cpp index 0d939dce82..b76e401761 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Head.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/Head.cpp @@ -225,10 +225,6 @@ void Head::applyEyelidOffset(glm::quat headOrientation) { return; } - const std::vector eyeBlinkBlendShapes = { "EyeBlink_L", "EyeBlink_R" }; - const std::vector eyeOpenBlendShapes = { "EyeOpen_L", "EyeOpen_R" }; - const std::vector browsBlendShapes = { "BrowsU_L", "BrowsU_R" }; - const float EYE_PITCH_TO_COEFFICIENT = 3.5f; // Empirically determined const float MAX_EYELID_OFFSET = 1.5f; const float BLINK_DOWN_MULTIPLIER = 0.25f; @@ -236,40 +232,33 @@ void Head::applyEyelidOffset(glm::quat headOrientation) { const float BROW_UP_MULTIPLIER = 0.5f; glm::quat eyeRotation = rotationBetween(headOrientation * IDENTITY_FORWARD, getLookAtPosition() - _eyePosition); - eyeRotation = eyeRotation * glm::angleAxis(safeEulerAngles(headOrientation).y, IDENTITY_UP); // Rotation w.r.t. head + auto worldUpDirection = _owningAvatar->getWorldOrientation() * Vectors::UNIT_Y; + eyeRotation = eyeRotation * glm::angleAxis(safeEulerAngles(headOrientation).y, worldUpDirection); // Rotation w.r.t. head float eyePitch = safeEulerAngles(eyeRotation).x; float eyelidOffset = glm::clamp(abs(eyePitch * EYE_PITCH_TO_COEFFICIENT), 0.0f, MAX_EYELID_OFFSET); - std::vector eyeBlinkIndices, eyeOpenIndices, browsIndices; - - getBlendshapeIndices(eyeBlinkBlendShapes, eyeBlinkIndices); - getBlendshapeIndices(eyeOpenBlendShapes, eyeOpenIndices); - getBlendshapeIndices(browsBlendShapes, browsIndices); + float blinkUpCoefficient = -eyelidOffset; + float blinkDownCoefficient = BLINK_DOWN_MULTIPLIER * eyelidOffset; + + float openUpCoefficient = eyelidOffset; + float openDownCoefficient = OPEN_DOWN_MULTIPLIER * eyelidOffset; + + float browsUpCoefficient = BROW_UP_MULTIPLIER * eyelidOffset; + float browsDownCoefficient = 0.0f; bool isLookingUp = (eyePitch > 0); - - for (auto& blinkIndex : eyeBlinkIndices) { - float lookingUpCoefficient = -eyelidOffset; - float lookingDownCoefficient = BLINK_DOWN_MULTIPLIER * eyelidOffset; - if (blinkIndex >= 0 && blinkIndex < _transientBlendshapeCoefficients.size()) { - _transientBlendshapeCoefficients[blinkIndex] = isLookingUp ? lookingUpCoefficient : lookingDownCoefficient; - } - - } - - for (auto& openIndex : eyeOpenIndices) { - float lookingUpCoefficient = eyelidOffset; - float lookingDownCoefficient = OPEN_DOWN_MULTIPLIER * eyelidOffset; - if (openIndex >= 0 && openIndex < _transientBlendshapeCoefficients.size()) { - _transientBlendshapeCoefficients[openIndex] = isLookingUp ? lookingUpCoefficient : lookingDownCoefficient; - } - } - for (auto& browIndex : browsIndices) { - float lookingUpCoefficient = BROW_UP_MULTIPLIER * eyelidOffset; - float lookingDownCoefficient = 0.0f; - if (browIndex >= 0 && browIndex < _transientBlendshapeCoefficients.size()) { - _transientBlendshapeCoefficients[browIndex] = isLookingUp ? lookingUpCoefficient : lookingDownCoefficient; + if (isLookingUp) { + for (int i = 0; i < 2; i++) { + _transientBlendshapeCoefficients[EYE_BLINK_INDICES[i]] = blinkUpCoefficient; + _transientBlendshapeCoefficients[EYE_OPEN_INDICES[i]] = openUpCoefficient; + _transientBlendshapeCoefficients[BROWS_U_INDICES[i]] = browsUpCoefficient; + } + } else { + for (int i = 0; i < 2; i++) { + _transientBlendshapeCoefficients[EYE_BLINK_INDICES[i]] = blinkDownCoefficient; + _transientBlendshapeCoefficients[EYE_OPEN_INDICES[i]] = openDownCoefficient; + _transientBlendshapeCoefficients[BROWS_U_INDICES[i]] = browsDownCoefficient; } } } diff --git a/libraries/avatars/src/HeadData.cpp b/libraries/avatars/src/HeadData.cpp index c68bb26e34..19f5efcd16 100644 --- a/libraries/avatars/src/HeadData.cpp +++ b/libraries/avatars/src/HeadData.cpp @@ -17,7 +17,6 @@ #include #include -#include #include #include diff --git a/libraries/avatars/src/HeadData.h b/libraries/avatars/src/HeadData.h index 834629596a..6d211da2cd 100644 --- a/libraries/avatars/src/HeadData.h +++ b/libraries/avatars/src/HeadData.h @@ -20,6 +20,7 @@ #include #include +#include // degrees const float MIN_HEAD_YAW = -180.0f; diff --git a/libraries/shared/src/FaceshiftConstants.cpp b/libraries/shared/src/FaceshiftConstants.cpp index e6c929409a..d5013236fc 100644 --- a/libraries/shared/src/FaceshiftConstants.cpp +++ b/libraries/shared/src/FaceshiftConstants.cpp @@ -64,3 +64,18 @@ const char* FACESHIFT_BLENDSHAPES[] = { }; const int NUM_FACESHIFT_BLENDSHAPES = sizeof(FACESHIFT_BLENDSHAPES) / sizeof(char*); + +const int EYE_BLINK_L_INDEX = 0; +const int EYE_BLINK_R_INDEX = 1; +const int EYE_SQUINT_L_INDEX = 2; +const int EYE_SQUINT_R_INDEX = 3; +const int EYE_OPEN_L_INDEX = 8; +const int EYE_OPEN_R_INDEX = 9; +const int BROWS_U_L_INDEX = 17; +const int BROWS_U_R_INDEX = 18; + + +const int EYE_BLINK_INDICES[] = { EYE_BLINK_L_INDEX, EYE_BLINK_R_INDEX }; +const int EYE_SQUINT_INDICES[] = { EYE_SQUINT_L_INDEX, EYE_SQUINT_R_INDEX }; +const int EYE_OPEN_INDICES[] = { EYE_OPEN_L_INDEX, EYE_OPEN_R_INDEX }; +const int BROWS_U_INDICES[] = { BROWS_U_L_INDEX, BROWS_U_R_INDEX }; \ No newline at end of file diff --git a/libraries/shared/src/FaceshiftConstants.h b/libraries/shared/src/FaceshiftConstants.h index ee6e43fdbc..88012c3d19 100644 --- a/libraries/shared/src/FaceshiftConstants.h +++ b/libraries/shared/src/FaceshiftConstants.h @@ -16,5 +16,9 @@ extern const char* FACESHIFT_BLENDSHAPES[]; /// The size of FACESHIFT_BLENDSHAPES extern const int NUM_FACESHIFT_BLENDSHAPES; - +// Eyes and Brows indices +extern const int EYE_BLINK_INDICES[]; +extern const int EYE_OPEN_INDICES[]; +extern const int BROWS_U_INDICES[]; +extern const int EYE_SQUINT_INDICES[]; #endif // hifi_FaceshiftConstants_h \ No newline at end of file From 97a0edf026513eee77c69e4e1a0ecbabb648aed4 Mon Sep 17 00:00:00 2001 From: luiscuenca Date: Fri, 29 Jun 2018 14:38:43 -0700 Subject: [PATCH 08/16] spaces --- libraries/shared/src/FaceshiftConstants.cpp | 2 +- libraries/shared/src/FaceshiftConstants.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/libraries/shared/src/FaceshiftConstants.cpp b/libraries/shared/src/FaceshiftConstants.cpp index d5013236fc..0d6f718e49 100644 --- a/libraries/shared/src/FaceshiftConstants.cpp +++ b/libraries/shared/src/FaceshiftConstants.cpp @@ -78,4 +78,4 @@ const int BROWS_U_R_INDEX = 18; const int EYE_BLINK_INDICES[] = { EYE_BLINK_L_INDEX, EYE_BLINK_R_INDEX }; const int EYE_SQUINT_INDICES[] = { EYE_SQUINT_L_INDEX, EYE_SQUINT_R_INDEX }; const int EYE_OPEN_INDICES[] = { EYE_OPEN_L_INDEX, EYE_OPEN_R_INDEX }; -const int BROWS_U_INDICES[] = { BROWS_U_L_INDEX, BROWS_U_R_INDEX }; \ No newline at end of file +const int BROWS_U_INDICES[] = { BROWS_U_L_INDEX, BROWS_U_R_INDEX }; diff --git a/libraries/shared/src/FaceshiftConstants.h b/libraries/shared/src/FaceshiftConstants.h index 88012c3d19..4349a3a21e 100644 --- a/libraries/shared/src/FaceshiftConstants.h +++ b/libraries/shared/src/FaceshiftConstants.h @@ -21,4 +21,5 @@ extern const int EYE_BLINK_INDICES[]; extern const int EYE_OPEN_INDICES[]; extern const int BROWS_U_INDICES[]; extern const int EYE_SQUINT_INDICES[]; -#endif // hifi_FaceshiftConstants_h \ No newline at end of file + +#endif // hifi_FaceshiftConstants_h From f770bcd38978bd6fee94661dfbf054c9cac14c50 Mon Sep 17 00:00:00 2001 From: luiscuenca Date: Fri, 29 Jun 2018 17:15:03 -0700 Subject: [PATCH 09/16] Better eyePitch computation --- libraries/avatars-renderer/src/avatars-renderer/Head.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/libraries/avatars-renderer/src/avatars-renderer/Head.cpp b/libraries/avatars-renderer/src/avatars-renderer/Head.cpp index b76e401761..bdee6d9147 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Head.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/Head.cpp @@ -231,10 +231,9 @@ void Head::applyEyelidOffset(glm::quat headOrientation) { const float OPEN_DOWN_MULTIPLIER = 0.3f; const float BROW_UP_MULTIPLIER = 0.5f; - glm::quat eyeRotation = rotationBetween(headOrientation * IDENTITY_FORWARD, getLookAtPosition() - _eyePosition); - auto worldUpDirection = _owningAvatar->getWorldOrientation() * Vectors::UNIT_Y; - eyeRotation = eyeRotation * glm::angleAxis(safeEulerAngles(headOrientation).y, worldUpDirection); // Rotation w.r.t. head - float eyePitch = safeEulerAngles(eyeRotation).x; + glm::vec3 lookAt = glm::normalize(getLookAtPosition() - _eyePosition); + glm::vec3 headUp = headOrientation * Vectors::UNIT_Y; + float eyePitch = (PI / 2.0f) - acos(glm::dot(lookAt, headUp)); float eyelidOffset = glm::clamp(abs(eyePitch * EYE_PITCH_TO_COEFFICIENT), 0.0f, MAX_EYELID_OFFSET); float blinkUpCoefficient = -eyelidOffset; From d2a612580ca3021f74e936e4e81132bd3f4f5ac1 Mon Sep 17 00:00:00 2001 From: Olivier Prat Date: Mon, 2 Jul 2018 12:20:55 +0200 Subject: [PATCH 10/16] Fixed NaN with specular on transparent objects --- libraries/render-utils/src/DeferredGlobalLight.slh | 6 +++--- libraries/render-utils/src/ForwardGlobalLight.slh | 4 ++-- libraries/render-utils/src/LightLocal.slh | 2 +- libraries/render-utils/src/LightingModel.slh | 3 +++ 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/libraries/render-utils/src/DeferredGlobalLight.slh b/libraries/render-utils/src/DeferredGlobalLight.slh index c4894200a3..d92fc0dbfd 100644 --- a/libraries/render-utils/src/DeferredGlobalLight.slh +++ b/libraries/render-utils/src/DeferredGlobalLight.slh @@ -198,7 +198,7 @@ vec3 evalGlobalLightingAlphaBlended(mat4 invViewMat, float shadowAttenuation, fl vec3 directionalSpecular; evalLightingDirectional(directionalDiffuse, directionalSpecular, lightDirection, lightIrradiance, surfaceWS, metallic, fresnel, albedo, shadowAttenuation); color += directionalDiffuse; - color += (ambientSpecular + directionalSpecular) / opacity; + color += evalSpecularWithOpacity(ambientSpecular + directionalSpecular, opacity); return color; } @@ -231,7 +231,7 @@ vec3 evalGlobalLightingAlphaBlendedWithHaze( vec3 directionalSpecular; evalLightingDirectional(directionalDiffuse, directionalSpecular, lightDirection, lightIrradiance, surfaceWS, metallic, fresnel, albedo, shadowAttenuation); color += directionalDiffuse; - color += (ambientSpecular + directionalSpecular) / opacity; + color += evalSpecularWithOpacity(ambientSpecular + directionalSpecular, opacity); // Haze if ((isHazeEnabled() > 0.0) && (hazeParams.hazeMode & HAZE_MODE_IS_ACTIVE) == HAZE_MODE_IS_ACTIVE) { @@ -269,7 +269,7 @@ vec3 evalGlobalLightingAlphaBlendedWithHaze( evalLightingDirectional(directionalDiffuse, directionalSpecular, lightDirection, lightIrradiance, surface, metallic, fresnel, albedo, shadowAttenuation); color += ambientDiffuse + directionalDiffuse; - color += (ambientSpecular + directionalSpecular) / opacity; + color += evalSpecularWithOpacity(ambientSpecular + directionalSpecular, opacity); // Haze if ((isHazeEnabled() > 0.0) && (hazeParams.hazeMode & HAZE_MODE_IS_ACTIVE) == HAZE_MODE_IS_ACTIVE) { diff --git a/libraries/render-utils/src/ForwardGlobalLight.slh b/libraries/render-utils/src/ForwardGlobalLight.slh index 84999f347b..eccc44186c 100644 --- a/libraries/render-utils/src/ForwardGlobalLight.slh +++ b/libraries/render-utils/src/ForwardGlobalLight.slh @@ -197,7 +197,7 @@ vec3 evalGlobalLightingAlphaBlended(mat4 invViewMat, float shadowAttenuation, fl vec3 directionalSpecular; evalLightingDirectional(directionalDiffuse, directionalSpecular, lightDirection, lightIrradiance, surfaceWS, metallic, fresnel, albedo, shadowAttenuation); color += directionalDiffuse; - color += (ambientSpecular + directionalSpecular) / opacity; + color += evalSpecularWithOpacity(ambientSpecular + directionalSpecular, opacity); return color; } @@ -223,7 +223,7 @@ vec3 evalGlobalLightingAlphaBlendedWithHaze( vec3 directionalSpecular; evalLightingDirectional(directionalDiffuse, directionalSpecular, lightDirection, lightIrradiance, surfaceWS, metallic, fresnel, albedo, shadowAttenuation); color += directionalDiffuse; - color += (ambientSpecular + directionalSpecular) / opacity; + color += evalSpecularWithOpacity(ambientSpecular + directionalSpecular, opacity); // Haze // FIXME - temporarily removed until we support it for forward... diff --git a/libraries/render-utils/src/LightLocal.slh b/libraries/render-utils/src/LightLocal.slh index 515a065d2e..06f8871e24 100644 --- a/libraries/render-utils/src/LightLocal.slh +++ b/libraries/render-utils/src/LightLocal.slh @@ -143,6 +143,6 @@ vec4 evalLocalLighting(ivec3 cluster, int numLights, vec3 fragWorldPos, SurfaceD fragSpecular *= isSpecularEnabled(); fragColor.rgb += fragDiffuse; - fragColor.rgb += fragSpecular / opacity; + fragColor.rgb += evalSpecularWithOpacity(fragSpecular, opacity); return fragColor; } \ No newline at end of file diff --git a/libraries/render-utils/src/LightingModel.slh b/libraries/render-utils/src/LightingModel.slh index 3b1c94f949..3ad9cb1395 100644 --- a/libraries/render-utils/src/LightingModel.slh +++ b/libraries/render-utils/src/LightingModel.slh @@ -314,6 +314,9 @@ void evalFragShadingGloss(out vec3 diffuse, out vec3 specular, specular = shading.xyz; } +vec3 evalSpecularWithOpacity(vec3 specular, float opacity) { + return specular / max(opacity, 1e-6); +} <@if not GETFRESNEL0@> <@def GETFRESNEL0@> From bda0c0a89fda027b89c8723ab951621cacfacf9b Mon Sep 17 00:00:00 2001 From: Olivier Prat Date: Tue, 3 Jul 2018 16:51:56 +0200 Subject: [PATCH 11/16] Discard fragments all the time if opacity is under threshold --- libraries/render-utils/src/LightingModel.slh | 2 +- libraries/render-utils/src/MaterialTextures.slh | 2 +- libraries/render-utils/src/forward_model_translucent.slf | 1 + libraries/render-utils/src/model_translucent.slf | 1 + libraries/render-utils/src/model_translucent_fade.slf | 1 + libraries/render-utils/src/model_translucent_normal_map.slf | 1 + .../render-utils/src/model_translucent_normal_map_fade.slf | 1 + libraries/render-utils/src/model_translucent_unlit.slf | 1 + libraries/render-utils/src/model_translucent_unlit_fade.slf | 1 + 9 files changed, 9 insertions(+), 2 deletions(-) diff --git a/libraries/render-utils/src/LightingModel.slh b/libraries/render-utils/src/LightingModel.slh index 3ad9cb1395..fe2d684c32 100644 --- a/libraries/render-utils/src/LightingModel.slh +++ b/libraries/render-utils/src/LightingModel.slh @@ -315,7 +315,7 @@ void evalFragShadingGloss(out vec3 diffuse, out vec3 specular, } vec3 evalSpecularWithOpacity(vec3 specular, float opacity) { - return specular / max(opacity, 1e-6); + return specular / opacity; } <@if not GETFRESNEL0@> diff --git a/libraries/render-utils/src/MaterialTextures.slh b/libraries/render-utils/src/MaterialTextures.slh index 4bcd74eefe..0b83fd1334 100644 --- a/libraries/render-utils/src/MaterialTextures.slh +++ b/libraries/render-utils/src/MaterialTextures.slh @@ -267,7 +267,7 @@ vec3 fetchLightmapMap(vec2 uv) { <@func discardTransparent(opacity)@> { - if (<$opacity$> < 1.0) { + if (<$opacity$> < 1e-6) { discard; } } diff --git a/libraries/render-utils/src/forward_model_translucent.slf b/libraries/render-utils/src/forward_model_translucent.slf index b8d43f15f1..70a3233737 100644 --- a/libraries/render-utils/src/forward_model_translucent.slf +++ b/libraries/render-utils/src/forward_model_translucent.slf @@ -41,6 +41,7 @@ void main(void) { float opacity = getMaterialOpacity(mat) * _alpha; <$evalMaterialOpacity(albedoTex.a, opacity, matKey, opacity)$>; + <$discardTransparent(opacity)$>; vec3 albedo = getMaterialAlbedo(mat); <$evalMaterialAlbedo(albedoTex, albedo, matKey, albedo)$>; diff --git a/libraries/render-utils/src/model_translucent.slf b/libraries/render-utils/src/model_translucent.slf index 71f76c8a8d..b808ca4bab 100644 --- a/libraries/render-utils/src/model_translucent.slf +++ b/libraries/render-utils/src/model_translucent.slf @@ -44,6 +44,7 @@ void main(void) { float opacity = getMaterialOpacity(mat) * _alpha; <$evalMaterialOpacity(albedoTex.a, opacity, matKey, opacity)$>; + <$discardTransparent(opacity)$>; vec3 albedo = getMaterialAlbedo(mat); <$evalMaterialAlbedo(albedoTex, albedo, matKey, albedo)$>; diff --git a/libraries/render-utils/src/model_translucent_fade.slf b/libraries/render-utils/src/model_translucent_fade.slf index 8b40186448..a93adee96b 100644 --- a/libraries/render-utils/src/model_translucent_fade.slf +++ b/libraries/render-utils/src/model_translucent_fade.slf @@ -46,6 +46,7 @@ void main(void) { float opacity = getMaterialOpacity(mat) * _alpha; <$evalMaterialOpacity(albedoTex.a, opacity, matKey, opacity)$>; + <$discardTransparent(opacity)$>; vec3 albedo = getMaterialAlbedo(mat); <$evalMaterialAlbedo(albedoTex, albedo, matKey, albedo)$>; diff --git a/libraries/render-utils/src/model_translucent_normal_map.slf b/libraries/render-utils/src/model_translucent_normal_map.slf index 320e883bb0..750149dc1b 100644 --- a/libraries/render-utils/src/model_translucent_normal_map.slf +++ b/libraries/render-utils/src/model_translucent_normal_map.slf @@ -45,6 +45,7 @@ void main(void) { float opacity = getMaterialOpacity(mat) * _alpha; <$evalMaterialOpacity(albedoTex.a, opacity, matKey, opacity)$>; + <$discardTransparent(opacity)$>; vec3 albedo = getMaterialAlbedo(mat); <$evalMaterialAlbedo(albedoTex, albedo, matKey, albedo)$>; diff --git a/libraries/render-utils/src/model_translucent_normal_map_fade.slf b/libraries/render-utils/src/model_translucent_normal_map_fade.slf index 0e114f7fdd..c7615626ce 100644 --- a/libraries/render-utils/src/model_translucent_normal_map_fade.slf +++ b/libraries/render-utils/src/model_translucent_normal_map_fade.slf @@ -54,6 +54,7 @@ void main(void) { float opacity = getMaterialOpacity(mat) * _alpha; <$evalMaterialOpacity(albedoTex.a, opacity, matKey, opacity)$>; + <$discardTransparent(opacity)$>; vec3 albedo = getMaterialAlbedo(mat); <$evalMaterialAlbedo(albedoTex, albedo, matKey, albedo)$>; diff --git a/libraries/render-utils/src/model_translucent_unlit.slf b/libraries/render-utils/src/model_translucent_unlit.slf index ebe9901616..e5507dd2e0 100644 --- a/libraries/render-utils/src/model_translucent_unlit.slf +++ b/libraries/render-utils/src/model_translucent_unlit.slf @@ -31,6 +31,7 @@ void main(void) { float opacity = getMaterialOpacity(mat) * _alpha; <$evalMaterialOpacity(albedoTex.a, opacity, matKey, opacity)$>; + <$discardTransparent(opacity)$>; vec3 albedo = getMaterialAlbedo(mat); <$evalMaterialAlbedo(albedoTex, albedo, matKey, albedo)$>; diff --git a/libraries/render-utils/src/model_translucent_unlit_fade.slf b/libraries/render-utils/src/model_translucent_unlit_fade.slf index 0f7c3366bb..016db4639f 100644 --- a/libraries/render-utils/src/model_translucent_unlit_fade.slf +++ b/libraries/render-utils/src/model_translucent_unlit_fade.slf @@ -41,6 +41,7 @@ void main(void) { float opacity = getMaterialOpacity(mat) * _alpha; <$evalMaterialOpacity(albedoTex.a, opacity, matKey, opacity)$>; + <$discardTransparent(opacity)$>; vec3 albedo = getMaterialAlbedo(mat); <$evalMaterialAlbedo(albedoTex, albedo, matKey, albedo)$>; From aa115786e36b270657451d562f03390364618175 Mon Sep 17 00:00:00 2001 From: Olivier Prat Date: Tue, 3 Jul 2018 17:27:27 +0200 Subject: [PATCH 12/16] Invalidate uniform buffer cache when binding camera correction --- .../src/gpu/gl/GLBackendPipeline.cpp | 56 ++++++++++--------- .../src/gpu/gl/GLBackendTransform.cpp | 4 +- 2 files changed, 34 insertions(+), 26 deletions(-) diff --git a/libraries/gpu-gl-common/src/gpu/gl/GLBackendPipeline.cpp b/libraries/gpu-gl-common/src/gpu/gl/GLBackendPipeline.cpp index b75f89f7ae..adea3292e1 100644 --- a/libraries/gpu-gl-common/src/gpu/gl/GLBackendPipeline.cpp +++ b/libraries/gpu-gl-common/src/gpu/gl/GLBackendPipeline.cpp @@ -48,12 +48,12 @@ void GLBackend::do_setPipeline(const Batch& batch, size_t paramOffset) { return; } - // check the program cache - // pick the program version - // check the program cache - // pick the program version + // check the program cache + // pick the program version + // check the program cache + // pick the program version #ifdef GPU_STEREO_CAMERA_BUFFER - GLuint glprogram = pipelineObject->_program->getProgram((GLShader::Version) isStereo()); + GLuint glprogram = pipelineObject->_program->getProgram((GLShader::Version)isStereo()); #else GLuint glprogram = pipelineObject->_program->getProgram(); #endif @@ -85,10 +85,11 @@ void GLBackend::do_setPipeline(const Batch& batch, size_t paramOffset) { } else { cameraCorrectionBuffer = syncGPUObject(*_pipeline._cameraCorrectionBufferIdentity._buffer); } + // Invalidate uniform buffer cache slot + _uniform._buffers[_pipeline._cameraCorrectionLocation].reset(); glBindBufferRange(GL_UNIFORM_BUFFER, _pipeline._cameraCorrectionLocation, cameraCorrectionBuffer->_id, 0, sizeof(CameraCorrection)); - } - (void) CHECK_GL_ERROR(); + (void)CHECK_GL_ERROR(); _pipeline._invalidProgram = false; } } @@ -97,7 +98,7 @@ void GLBackend::updatePipeline() { if (_pipeline._invalidProgram) { // doing it here is aproblem for calls to glUniform.... so will do it on assing... glUseProgram(_pipeline._program); - (void) CHECK_GL_ERROR(); + (void)CHECK_GL_ERROR(); _pipeline._invalidProgram = false; } @@ -106,12 +107,12 @@ void GLBackend::updatePipeline() { // first reset to default what should be // the fields which were not to default and are default now resetPipelineState(_pipeline._state->_signature); - + // Update the signature cache with what's going to be touched _pipeline._stateSignatureCache |= _pipeline._state->_signature; // And perform - for (auto command: _pipeline._state->_commands) { + for (auto command : _pipeline._state->_commands) { command->run(this); } } else { @@ -142,8 +143,8 @@ void GLBackend::releaseUniformBuffer(uint32_t slot) { if (buf) { auto* object = Backend::getGPUObject(*buf); if (object) { - glBindBufferBase(GL_UNIFORM_BUFFER, slot, 0); // RELEASE - (void) CHECK_GL_ERROR(); + glBindBufferBase(GL_UNIFORM_BUFFER, slot, 0); // RELEASE + (void)CHECK_GL_ERROR(); } buf.reset(); } @@ -157,8 +158,9 @@ void GLBackend::resetUniformStage() { void GLBackend::do_setUniformBuffer(const Batch& batch, size_t paramOffset) { GLuint slot = batch._params[paramOffset + 3]._uint; - if (slot >(GLuint)MAX_NUM_UNIFORM_BUFFERS) { - qCDebug(gpugllogging) << "GLBackend::do_setUniformBuffer: Trying to set a uniform Buffer at slot #" << slot << " which doesn't exist. MaxNumUniformBuffers = " << getMaxNumUniformBuffers(); + if (slot > (GLuint)MAX_NUM_UNIFORM_BUFFERS) { + qCDebug(gpugllogging) << "GLBackend::do_setUniformBuffer: Trying to set a uniform Buffer at slot #" << slot + << " which doesn't exist. MaxNumUniformBuffers = " << getMaxNumUniformBuffers(); return; } BufferPointer uniformBuffer = batch._buffers.get(batch._params[paramOffset + 2]._uint); @@ -169,7 +171,7 @@ void GLBackend::do_setUniformBuffer(const Batch& batch, size_t paramOffset) { releaseUniformBuffer(slot); return; } - + // check cache before thinking if (_uniform._buffers[slot] == uniformBuffer) { return; @@ -181,7 +183,7 @@ void GLBackend::do_setUniformBuffer(const Batch& batch, size_t paramOffset) { glBindBufferRange(GL_UNIFORM_BUFFER, slot, object->_buffer, rangeStart, rangeSize); _uniform._buffers[slot] = uniformBuffer; - (void) CHECK_GL_ERROR(); + (void)CHECK_GL_ERROR(); } else { releaseUniformBuffer(slot); return; @@ -195,8 +197,8 @@ void GLBackend::releaseResourceTexture(uint32_t slot) { if (object) { GLuint target = object->_target; glActiveTexture(GL_TEXTURE0 + slot); - glBindTexture(target, 0); // RELEASE - (void) CHECK_GL_ERROR(); + glBindTexture(target, 0); // RELEASE + (void)CHECK_GL_ERROR(); } tex.reset(); } @@ -212,11 +214,11 @@ void GLBackend::resetResourceStage() { } } - void GLBackend::do_setResourceBuffer(const Batch& batch, size_t paramOffset) { GLuint slot = batch._params[paramOffset + 1]._uint; if (slot >= (GLuint)MAX_NUM_RESOURCE_BUFFERS) { - qCDebug(gpugllogging) << "GLBackend::do_setResourceBuffer: Trying to set a resource Buffer at slot #" << slot << " which doesn't exist. MaxNumResourceBuffers = " << getMaxNumResourceBuffers(); + qCDebug(gpugllogging) << "GLBackend::do_setResourceBuffer: Trying to set a resource Buffer at slot #" << slot + << " which doesn't exist. MaxNumResourceBuffers = " << getMaxNumResourceBuffers(); return; } @@ -237,7 +239,7 @@ void GLBackend::do_setResourceBuffer(const Batch& batch, size_t paramOffset) { // If successful bind then cache it if (bindResourceBuffer(slot, resourceBuffer)) { _resource._buffers[slot] = resourceBuffer; - } else { // else clear slot and cache + } else { // else clear slot and cache releaseResourceBuffer(slot); return; } @@ -245,8 +247,9 @@ void GLBackend::do_setResourceBuffer(const Batch& batch, size_t paramOffset) { void GLBackend::do_setResourceTexture(const Batch& batch, size_t paramOffset) { GLuint slot = batch._params[paramOffset + 1]._uint; - if (slot >= (GLuint) MAX_NUM_RESOURCE_TEXTURES) { - qCDebug(gpugllogging) << "GLBackend::do_setResourceTexture: Trying to set a resource Texture at slot #" << slot << " which doesn't exist. MaxNumResourceTextures = " << getMaxNumResourceTextures(); + if (slot >= (GLuint)MAX_NUM_RESOURCE_TEXTURES) { + qCDebug(gpugllogging) << "GLBackend::do_setResourceTexture: Trying to set a resource Texture at slot #" << slot + << " which doesn't exist. MaxNumResourceTextures = " << getMaxNumResourceTextures(); return; } @@ -265,11 +268,14 @@ void GLBackend::bindResourceTexture(uint32_t slot, const TexturePointer& resourc void GLBackend::do_setResourceFramebufferSwapChainTexture(const Batch& batch, size_t paramOffset) { GLuint slot = batch._params[paramOffset + 1]._uint; if (slot >= (GLuint)MAX_NUM_RESOURCE_TEXTURES) { - qCDebug(gpugllogging) << "GLBackend::do_setResourceFramebufferSwapChainTexture: Trying to set a resource Texture at slot #" << slot << " which doesn't exist. MaxNumResourceTextures = " << getMaxNumResourceTextures(); + qCDebug(gpugllogging) + << "GLBackend::do_setResourceFramebufferSwapChainTexture: Trying to set a resource Texture at slot #" << slot + << " which doesn't exist. MaxNumResourceTextures = " << getMaxNumResourceTextures(); return; } - auto swapChain = std::static_pointer_cast(batch._swapChains.get(batch._params[paramOffset + 0]._uint)); + auto swapChain = + std::static_pointer_cast(batch._swapChains.get(batch._params[paramOffset + 0]._uint)); if (!swapChain) { releaseResourceTexture(slot); diff --git a/libraries/gpu-gl-common/src/gpu/gl/GLBackendTransform.cpp b/libraries/gpu-gl-common/src/gpu/gl/GLBackendTransform.cpp index 35d292cd46..ed356acf68 100644 --- a/libraries/gpu-gl-common/src/gpu/gl/GLBackendTransform.cpp +++ b/libraries/gpu-gl-common/src/gpu/gl/GLBackendTransform.cpp @@ -168,7 +168,9 @@ void GLBackend::TransformStageState::update(size_t commandIndex, const StereoSta void GLBackend::TransformStageState::bindCurrentCamera(int eye) const { if (_currentCameraOffset != INVALID_OFFSET) { - glBindBufferRange(GL_UNIFORM_BUFFER, TRANSFORM_CAMERA_SLOT, _cameraBuffer, _currentCameraOffset + eye * _cameraUboSize, sizeof(CameraBufferElement)); + static_assert(TRANSFORM_CAMERA_SLOT >= MAX_NUM_UNIFORM_BUFFERS, "TransformCamera may overlap pipeline uniform buffer slots. Invalidate uniform buffer slot cache for safety (call _uniform._buffers[TRANSFORM_CAMERA_SLOT].reset())."); + glBindBufferRange(GL_UNIFORM_BUFFER, TRANSFORM_CAMERA_SLOT, _cameraBuffer, _currentCameraOffset + eye * _cameraUboSize, + sizeof(CameraBufferElement)); } } From 6efb8957081c23c25946894987c616104497cace Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Tue, 3 Jul 2018 13:43:04 -0700 Subject: [PATCH 13/16] Implement MS16413: Improve angularVelocity of printed Snaps --- scripts/system/snapshot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/system/snapshot.js b/scripts/system/snapshot.js index e265ddb621..c4fcb70792 100644 --- a/scripts/system/snapshot.js +++ b/scripts/system/snapshot.js @@ -310,7 +310,7 @@ function printToPolaroid(image_url) { "gravity": { "x": 0, "y": -2.5, "z": 0 }, "velocity": { "x": 0, "y": 1.95, "z": 0 }, - "angularVelocity": { "x": -1.0, "y": 0, "z": -1.3 }, + "angularVelocity": Vec3.multiplyQbyV(MyAvatar.orientation, { "x": -1.0, "y": 0, "z": -1.3 }), "dynamic": true, "collisionsWillMove": true, From 73071df857d50a7ce89721a9d39039d4f9f8c857 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 5 Jul 2018 09:44:23 -0700 Subject: [PATCH 14/16] when displaying the in-world controller model, make buttons and joysticks be children of the base controller model, rather than children of the avatar --- .../system/controllers/controllerDisplay.js | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/scripts/system/controllers/controllerDisplay.js b/scripts/system/controllers/controllerDisplay.js index dc7c9b37bd..8aa0393357 100644 --- a/scripts/system/controllers/controllerDisplay.js +++ b/scripts/system/controllers/controllerDisplay.js @@ -108,14 +108,13 @@ createControllerDisplay = function(config) { for (var partName in controller.parts) { overlayID = this.overlays[i++]; var part = controller.parts[partName]; - localPosition = Vec3.sum(controller.position, Vec3.multiplyQbyV(controller.rotation, part.naturalPosition)); + localPosition = Vec3.subtract(part.naturalPosition, controller.naturalPosition); var localRotation; var value = this.partValues[partName]; var offset, rotation; if (value !== undefined) { if (part.type === "linear") { - var axis = Vec3.multiplyQbyV(controller.rotation, part.axis); - offset = Vec3.multiply(part.maxTranslation * value, axis); + offset = Vec3.multiply(part.maxTranslation * value, part.axis); localPosition = Vec3.sum(localPosition, offset); localRotation = undefined; } else if (part.type === "joystick") { @@ -126,8 +125,8 @@ createControllerDisplay = function(config) { } else { offset = { x: 0, y: 0, z: 0 }; } - localPosition = Vec3.sum(controller.position, Vec3.multiplyQbyV(controller.rotation, Vec3.sum(offset, part.naturalPosition))); - localRotation = Quat.multiply(controller.rotation, rotation); + localPosition = Vec3.sum(offset, localPosition); + localRotation = rotation; } else if (part.type === "rotational") { value = clamp(value, part.minValue, part.maxValue); var pct = (value - part.minValue) / part.maxValue; @@ -139,8 +138,8 @@ createControllerDisplay = function(config) { } else { offset = { x: 0, y: 0, z: 0 }; } - localPosition = Vec3.sum(controller.position, Vec3.multiplyQbyV(controller.rotation, Vec3.sum(offset, part.naturalPosition))); - localRotation = Quat.multiply(controller.rotation, rotation); + localPosition = Vec3.sum(offset, localPosition); + localRotation = rotation; } } if (localRotation !== undefined) { @@ -169,9 +168,11 @@ createControllerDisplay = function(config) { if (controller.naturalPosition) { position = Vec3.sum(Vec3.multiplyQbyV(controller.rotation, controller.naturalPosition), position); + } else { + controller.naturalPosition = { x: 0, y: 0, z: 0 }; } - var overlayID = Overlays.addOverlay("model", { + var baseOverlayID = Overlays.addOverlay("model", { url: controller.modelURL, dimensions: Vec3.multiply(sensorScaleFactor, controller.dimensions), localRotation: controller.rotation, @@ -181,23 +182,21 @@ createControllerDisplay = function(config) { ignoreRayIntersection: true }); - controllerDisplay.overlays.push(overlayID); - overlayID = null; + controllerDisplay.overlays.push(baseOverlayID); if (controller.parts) { for (var partName in controller.parts) { var part = controller.parts[partName]; - var partPosition = Vec3.sum(controller.position, Vec3.multiplyQbyV(controller.rotation, part.naturalPosition)); - var innerRotation = controller.rotation; + var localPosition = Vec3.subtract(part.naturalPosition, controller.naturalPosition); + var localRotation = { x: 0, y: 0, z: 0, w: 1 } controllerDisplay.parts[partName] = controller.parts[partName]; var properties = { url: part.modelURL, - localPosition: partPosition, - localRotation: innerRotation, - parentID: MyAvatar.SELF_ID, - parentJointIndex: controller.jointIndex, + localPosition: localPosition, + localRotation: localRotation, + parentID: baseOverlayID, ignoreRayIntersection: true }; @@ -207,11 +206,10 @@ createControllerDisplay = function(config) { properties['textures'] = textures; } - overlayID = Overlays.addOverlay("model", properties); + var overlayID = Overlays.addOverlay("model", properties); if (part.type === "rotational") { var input = resolveHardware(part.input); - print("Mapping to: ", part.input, input); mapping.from([input]).peek().to(function(partName) { return function(value) { // insert the most recent controller value into controllerDisplay.partValues. From b2e02e20ccf675d2359267b4fa2b122613137be1 Mon Sep 17 00:00:00 2001 From: luiscuenca Date: Thu, 5 Jul 2018 11:47:10 -0700 Subject: [PATCH 15/16] Fix inaccurate delta rotation axis --- libraries/physics/src/CharacterController.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/physics/src/CharacterController.cpp b/libraries/physics/src/CharacterController.cpp index 64eda975cf..bb076c89f2 100755 --- a/libraries/physics/src/CharacterController.cpp +++ b/libraries/physics/src/CharacterController.cpp @@ -269,7 +269,8 @@ void CharacterController::playerStep(btCollisionWorld* collisionWorld, btScalar } btQuaternion deltaRot = desiredRot * startRot.inverse(); float angularSpeed = deltaRot.getAngle() / _followTimeRemaining; - btQuaternion angularDisplacement = btQuaternion(deltaRot.getAxis(), angularSpeed * dt); + glm::vec3 rotationAxis = glm::normalize(glm::axis(bulletToGLM(deltaRot))); // deltaRot.getAxis() is inaccurate + btQuaternion angularDisplacement = btQuaternion(glmToBullet(rotationAxis), angularSpeed * dt); btQuaternion endRot = angularDisplacement * startRot; // in order to accumulate displacement of avatar position, we need to take _shapeLocalOffset into account. From b4b0131065193e152050e0ca8afa454536d08f46 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 5 Jul 2018 14:33:21 -0700 Subject: [PATCH 16/16] grab correct commit hash for conflicting PR --- cmake/macros/SetPackagingParameters.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/macros/SetPackagingParameters.cmake b/cmake/macros/SetPackagingParameters.cmake index 2c8443d510..c40691c632 100644 --- a/cmake/macros/SetPackagingParameters.cmake +++ b/cmake/macros/SetPackagingParameters.cmake @@ -90,7 +90,7 @@ macro(SET_PACKAGING_PARAMETERS) # for the second parent of HEAD (not HEAD) since that is the # SHA of the commit merged to master for the build if (PR_BUILD) - set(_GIT_LOG_FORMAT "%p") + set(_GIT_LOG_FORMAT "%p %h") else () set(_GIT_LOG_FORMAT "%h") endif ()