From d4112f0e3691f2a7a56ea3124083050e0c928b74 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 3 Apr 2017 14:57:02 -0700 Subject: [PATCH 01/19] use full relative filepath for texture caching/referencing --- libraries/fbx/src/FBXReader.cpp | 17 ++++++++--------- libraries/fbx/src/FBXReader.h | 2 -- libraries/fbx/src/FBXReader_Material.cpp | 9 ++------- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/libraries/fbx/src/FBXReader.cpp b/libraries/fbx/src/FBXReader.cpp index 64ee0bc869..7bab0415f8 100644 --- a/libraries/fbx/src/FBXReader.cpp +++ b/libraries/fbx/src/FBXReader.cpp @@ -376,10 +376,10 @@ public: }; bool checkMaterialsHaveTextures(const QHash& materials, - const QHash& textureFilenames, const QMultiMap& _connectionChildMap) { + const QHash& textureFilepaths, const QMultiMap& _connectionChildMap) { foreach (const QString& materialID, materials.keys()) { foreach (const QString& childID, _connectionChildMap.values(materialID)) { - if (textureFilenames.contains(childID)) { + if (textureFilepaths.contains(childID)) { return true; } } @@ -833,11 +833,10 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS const int MODEL_UV_SCALING_MIN_SIZE = 2; const int CROPPING_MIN_SIZE = 4; if (subobject.name == "RelativeFilename" && subobject.properties.length() >= RELATIVE_FILENAME_MIN_SIZE) { - QByteArray filename = subobject.properties.at(0).toByteArray(); - QByteArray filepath = filename.replace('\\', '/'); - filename = fileOnUrl(filepath, url); + QByteArray filepath = subobject.properties.at(0).toByteArray(); + filepath = filepath.replace('\\', '/'); + _textureFilepaths.insert(getID(object.properties), filepath); - _textureFilenames.insert(getID(object.properties), filename); } else if (subobject.name == "TextureName" && subobject.properties.length() >= TEXTURE_NAME_MIN_SIZE) { // trim the name from the timestamp QString name = QString(subobject.properties.at(0).toByteArray()); @@ -930,7 +929,7 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS QByteArray content; foreach (const FBXNode& subobject, object.children) { if (subobject.name == "RelativeFilename") { - filepath= subobject.properties.at(0).toByteArray(); + filepath = subobject.properties.at(0).toByteArray(); filepath = filepath.replace('\\', '/'); } else if (subobject.name == "Content" && !subobject.properties.isEmpty()) { @@ -1502,7 +1501,7 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS geometry.materials = _fbxMaterials; // see if any materials have texture children - bool materialsHaveTextures = checkMaterialsHaveTextures(_fbxMaterials, _textureFilenames, _connectionChildMap); + bool materialsHaveTextures = checkMaterialsHaveTextures(_fbxMaterials, _textureFilepaths, _connectionChildMap); for (QMap::iterator it = meshes.begin(); it != meshes.end(); it++) { ExtractedMesh& extracted = it.value(); @@ -1547,7 +1546,7 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS materialIndex++; - } else if (_textureFilenames.contains(childID)) { + } else if (_textureFilepaths.contains(childID)) { FBXTexture texture = getTexture(childID); for (int j = 0; j < extracted.partMaterialTextures.size(); j++) { int partTexture = extracted.partMaterialTextures.at(j).second; diff --git a/libraries/fbx/src/FBXReader.h b/libraries/fbx/src/FBXReader.h index f73088e7a1..79133c4c4a 100644 --- a/libraries/fbx/src/FBXReader.h +++ b/libraries/fbx/src/FBXReader.h @@ -413,8 +413,6 @@ public: QHash _textureNames; // Hashes the original RelativeFilename of textures QHash _textureFilepaths; - // Hashes the place to look for textures, in case they are not inlined - QHash _textureFilenames; // Hashes texture content by filepath, in case they are inlined QHash _textureContent; QHash _textureParams; diff --git a/libraries/fbx/src/FBXReader_Material.cpp b/libraries/fbx/src/FBXReader_Material.cpp index ca2ec557b4..2f63d894fd 100644 --- a/libraries/fbx/src/FBXReader_Material.cpp +++ b/libraries/fbx/src/FBXReader_Material.cpp @@ -85,12 +85,7 @@ FBXTexture FBXReader::getTexture(const QString& textureID) { FBXTexture texture; const QByteArray& filepath = _textureFilepaths.value(textureID); texture.content = _textureContent.value(filepath); - - if (texture.content.isEmpty()) { // the content is not inlined - texture.filename = _textureFilenames.value(textureID); - } else { // use supplied filepath for inlined content - texture.filename = filepath; - } + texture.filename = filepath; texture.name = _textureNames.value(textureID); texture.transform.setIdentity(); @@ -155,7 +150,7 @@ void FBXReader::consolidateFBXMaterials(const QVariantHash& mapping) { // FBX files generated by 3DSMax have an intermediate texture parent, apparently foreach(const QString& childTextureID, _connectionChildMap.values(diffuseTextureID)) { - if (_textureFilenames.contains(childTextureID)) { + if (_textureFilepaths.contains(childTextureID)) { diffuseTexture = getTexture(diffuseTextureID); } } From b9fffc10f8dca69f064fb688735002edb67d4dfc Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Mon, 3 Apr 2017 15:51:19 -0700 Subject: [PATCH 02/19] Fix entity "unlock" edits not being propagated to clients The lastEditedBy property was not being updated when changing the locked property of entities from true to false. --- libraries/entities/src/EntityTree.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index d7471474a6..f544a4e5c7 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -182,6 +182,7 @@ bool EntityTree::updateEntityWithElement(EntityItemPointer entity, const EntityI if (!wantsLocked) { EntityItemProperties tempProperties; tempProperties.setLocked(wantsLocked); + tempProperties.setLastEdited(properties.getLastEdited()); bool success; AACube queryCube = entity->getQueryAACube(success); From b9783d768eecb64011385bf9aa74fd014c19eabd Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 4 Apr 2017 11:08:30 -0700 Subject: [PATCH 03/19] remove fileOnUrl since it is no longer used --- libraries/fbx/src/FBXReader.cpp | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/libraries/fbx/src/FBXReader.cpp b/libraries/fbx/src/FBXReader.cpp index 7bab0415f8..0245851256 100644 --- a/libraries/fbx/src/FBXReader.cpp +++ b/libraries/fbx/src/FBXReader.cpp @@ -443,20 +443,6 @@ FBXLight extractLight(const FBXNode& object) { return light; } -QByteArray fileOnUrl(const QByteArray& filepath, const QString& url) { - QString path = QFileInfo(url).path(); - QByteArray filename = filepath; - QFileInfo checkFile(path + "/" + filepath); - - // check if the file exists at the RelativeFilename - if (!(checkFile.exists() && checkFile.isFile())) { - // if not, assume it is in the fbx directory - filename = filename.mid(filename.lastIndexOf('/') + 1); - } - - return filename; -} - FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QString& url) { const FBXNode& node = _fbxNode; QMap meshes; From 4e07a6a865b36f583b551b581bfc2a02163ba5dd Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 4 Apr 2017 14:02:00 -0700 Subject: [PATCH 04/19] add new logic for absolute texture paths in FBX --- libraries/fbx/src/FBXReader.cpp | 40 +++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/libraries/fbx/src/FBXReader.cpp b/libraries/fbx/src/FBXReader.cpp index 0245851256..33b0f40f40 100644 --- a/libraries/fbx/src/FBXReader.cpp +++ b/libraries/fbx/src/FBXReader.cpp @@ -443,6 +443,43 @@ FBXLight extractLight(const FBXNode& object) { return light; } +QByteArray fixedTextureFilepath(QByteArray fbxRelativeFilepath, const QString& urlString) { + // first setup a QFileInfo for the passed relative filepath + auto fileInfo = QFileInfo { fbxRelativeFilepath }; + + if (fileInfo.isRelative()) { + // the RelativeFilename pulled from the FBX is already correctly relative + // so simply return this as the filepath to use + return fbxRelativeFilepath; + } else { + // the RelativeFilename pulled from the FBX is an absolute path + + // use the URL to figure out where the FBX is being loaded from + auto url = QUrl { urlString }; + auto filename = fileInfo.fileName(); + + if (url.scheme() == "file") { + // the FBX is being loaded from the local filesystem + + // in order to match the behaviour with a local FBX, first check if a file with this filename + // is right beside the FBX + QFileInfo fileBesideFBX { QFileInfo(urlString).path() + "/" + filename }; + + if (fileBesideFBX.exists() && fileBesideFBX.isFile()) { + // we found a file that matches right beside the FBX, return just the filename as the relative path + return filename.toUtf8(); + } else { + // did not find a matching file beside the FBX, return the absolute path found in the FBX + return fbxRelativeFilepath; + } + } else { + // this is a remote file, meaning we can't really do anything with the absolute path to the texture + // so assume it will be right beside the fbx + return filename.toUtf8(); + } + } +} + FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QString& url) { const FBXNode& node = _fbxNode; QMap meshes; @@ -819,8 +856,7 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS const int MODEL_UV_SCALING_MIN_SIZE = 2; const int CROPPING_MIN_SIZE = 4; if (subobject.name == "RelativeFilename" && subobject.properties.length() >= RELATIVE_FILENAME_MIN_SIZE) { - QByteArray filepath = subobject.properties.at(0).toByteArray(); - filepath = filepath.replace('\\', '/'); + auto filepath = fixedTextureFilepath(subobject.properties.at(0).toByteArray(), url); _textureFilepaths.insert(getID(object.properties), filepath); } else if (subobject.name == "TextureName" && subobject.properties.length() >= TEXTURE_NAME_MIN_SIZE) { From 0a7100e2d855eb10c5bfb2ec9114ff0678b804ed Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 4 Apr 2017 14:32:30 -0700 Subject: [PATCH 05/19] pass URLs to readFBX, not just URL path --- libraries/fbx/src/FBXReader.cpp | 13 ++++++------- libraries/fbx/src/FBXReader.h | 10 +++++----- libraries/fbx/src/FBXReader_Mesh.cpp | 2 +- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/libraries/fbx/src/FBXReader.cpp b/libraries/fbx/src/FBXReader.cpp index 33b0f40f40..8696e26fde 100644 --- a/libraries/fbx/src/FBXReader.cpp +++ b/libraries/fbx/src/FBXReader.cpp @@ -443,7 +443,7 @@ FBXLight extractLight(const FBXNode& object) { return light; } -QByteArray fixedTextureFilepath(QByteArray fbxRelativeFilepath, const QString& urlString) { +QByteArray fixedTextureFilepath(QByteArray fbxRelativeFilepath, QUrl url) { // first setup a QFileInfo for the passed relative filepath auto fileInfo = QFileInfo { fbxRelativeFilepath }; @@ -455,15 +455,14 @@ QByteArray fixedTextureFilepath(QByteArray fbxRelativeFilepath, const QString& u // the RelativeFilename pulled from the FBX is an absolute path // use the URL to figure out where the FBX is being loaded from - auto url = QUrl { urlString }; auto filename = fileInfo.fileName(); - if (url.scheme() == "file") { + if (url.isLocalFile()) { // the FBX is being loaded from the local filesystem // in order to match the behaviour with a local FBX, first check if a file with this filename // is right beside the FBX - QFileInfo fileBesideFBX { QFileInfo(urlString).path() + "/" + filename }; + QFileInfo fileBesideFBX { QFileInfo(url.toLocalFile()).path() + "/" + filename }; if (fileBesideFBX.exists() && fileBesideFBX.isFile()) { // we found a file that matches right beside the FBX, return just the filename as the relative path @@ -480,7 +479,7 @@ QByteArray fixedTextureFilepath(QByteArray fbxRelativeFilepath, const QString& u } } -FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QString& url) { +FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QUrl& url) { const FBXNode& node = _fbxNode; QMap meshes; QHash modelIDsToNames; @@ -1839,13 +1838,13 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS return geometryPtr; } -FBXGeometry* readFBX(const QByteArray& model, const QVariantHash& mapping, const QString& url, bool loadLightmaps, float lightmapLevel) { +FBXGeometry* readFBX(const QByteArray& model, const QVariantHash& mapping, const QUrl& url, bool loadLightmaps, float lightmapLevel) { QBuffer buffer(const_cast(&model)); buffer.open(QIODevice::ReadOnly); return readFBX(&buffer, mapping, url, loadLightmaps, lightmapLevel); } -FBXGeometry* readFBX(QIODevice* device, const QVariantHash& mapping, const QString& url, bool loadLightmaps, float lightmapLevel) { +FBXGeometry* readFBX(QIODevice* device, const QVariantHash& mapping, const QUrl& url, bool loadLightmaps, float lightmapLevel) { FBXReader reader; reader._fbxNode = FBXReader::parseFBX(device); reader._loadLightmaps = loadLightmaps; diff --git a/libraries/fbx/src/FBXReader.h b/libraries/fbx/src/FBXReader.h index 79133c4c4a..dd746322e9 100644 --- a/libraries/fbx/src/FBXReader.h +++ b/libraries/fbx/src/FBXReader.h @@ -268,7 +268,7 @@ class FBXGeometry { public: using Pointer = std::shared_ptr; - QString originalURL; + QUrl originalURL; QString author; QString applicationName; ///< the name of the application that generated the model @@ -330,11 +330,11 @@ Q_DECLARE_METATYPE(FBXGeometry::Pointer) /// Reads FBX geometry from the supplied model and mapping data. /// \exception QString if an error occurs in parsing -FBXGeometry* readFBX(const QByteArray& model, const QVariantHash& mapping, const QString& url = "", bool loadLightmaps = true, float lightmapLevel = 1.0f); +FBXGeometry* readFBX(const QByteArray& model, const QVariantHash& mapping, const QUrl& url = QUrl(), bool loadLightmaps = true, float lightmapLevel = 1.0f); /// Reads FBX geometry from the supplied model and mapping data. /// \exception QString if an error occurs in parsing -FBXGeometry* readFBX(QIODevice* device, const QVariantHash& mapping, const QString& url = "", bool loadLightmaps = true, float lightmapLevel = 1.0f); +FBXGeometry* readFBX(QIODevice* device, const QVariantHash& mapping, const QUrl& url = QUrl(), bool loadLightmaps = true, float lightmapLevel = 1.0f); class TextureParam { public: @@ -402,11 +402,11 @@ public: FBXNode _fbxNode; static FBXNode parseFBX(QIODevice* device); - FBXGeometry* extractFBXGeometry(const QVariantHash& mapping, const QString& url); + FBXGeometry* extractFBXGeometry(const QVariantHash& mapping, const QUrl& url); ExtractedMesh extractMesh(const FBXNode& object, unsigned int& meshIndex); QHash meshes; - static void buildModelMesh(FBXMesh& extractedMesh, const QString& url); + static void buildModelMesh(FBXMesh& extractedMesh, const QUrl& url); FBXTexture getTexture(const QString& textureID); diff --git a/libraries/fbx/src/FBXReader_Mesh.cpp b/libraries/fbx/src/FBXReader_Mesh.cpp index 4e153dfe3a..a6d70408ae 100644 --- a/libraries/fbx/src/FBXReader_Mesh.cpp +++ b/libraries/fbx/src/FBXReader_Mesh.cpp @@ -388,7 +388,7 @@ ExtractedMesh FBXReader::extractMesh(const FBXNode& object, unsigned int& meshIn return data.extracted; } -void FBXReader::buildModelMesh(FBXMesh& extractedMesh, const QString& url) { +void FBXReader::buildModelMesh(FBXMesh& extractedMesh, const QUrl& url) { static QString repeatedMessage = LogHandler::getInstance().addRepeatedMessageRegex("buildModelMesh failed -- .*"); unsigned int totalSourceIndices = 0; From 137e73cf210e6e74f5ef9c349fb75d526b18439d Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 4 Apr 2017 14:42:03 -0700 Subject: [PATCH 06/19] check absolute path before relative path --- libraries/fbx/src/FBXReader.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/libraries/fbx/src/FBXReader.cpp b/libraries/fbx/src/FBXReader.cpp index 8696e26fde..e731261804 100644 --- a/libraries/fbx/src/FBXReader.cpp +++ b/libraries/fbx/src/FBXReader.cpp @@ -460,16 +460,13 @@ QByteArray fixedTextureFilepath(QByteArray fbxRelativeFilepath, QUrl url) { if (url.isLocalFile()) { // the FBX is being loaded from the local filesystem - // in order to match the behaviour with a local FBX, first check if a file with this filename - // is right beside the FBX - QFileInfo fileBesideFBX { QFileInfo(url.toLocalFile()).path() + "/" + filename }; - - if (fileBesideFBX.exists() && fileBesideFBX.isFile()) { - // we found a file that matches right beside the FBX, return just the filename as the relative path - return filename.toUtf8(); - } else { - // did not find a matching file beside the FBX, return the absolute path found in the FBX + if (fileInfo.exists() && fileInfo.isFile()) { + // found a file at the absolute path in the FBX, return that path return fbxRelativeFilepath; + } else { + // didn't find a file at the absolute path, assume it is right beside the FBX + // return just the filename as the relative path + return filename.toUtf8(); } } else { // this is a remote file, meaning we can't really do anything with the absolute path to the texture From 0b57b9897021e4dbe272d6f4a9941f9d383b0d81 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 4 Apr 2017 14:53:14 -0700 Subject: [PATCH 07/19] change readFBX calls to use QUrl where possible --- libraries/animation/src/AnimationCache.cpp | 2 +- libraries/model-networking/src/model-networking/ModelCache.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/animation/src/AnimationCache.cpp b/libraries/animation/src/AnimationCache.cpp index 6594482085..23c9d1d0b5 100644 --- a/libraries/animation/src/AnimationCache.cpp +++ b/libraries/animation/src/AnimationCache.cpp @@ -74,7 +74,7 @@ void AnimationReader::run() { // Parse the FBX directly from the QNetworkReply FBXGeometry::Pointer fbxgeo; if (_url.path().toLower().endsWith(".fbx")) { - fbxgeo.reset(readFBX(_data, QVariantHash(), _url.path())); + fbxgeo.reset(readFBX(_data, QVariantHash(), _url)); } else { QString errorStr("usupported format"); emit onError(299, errorStr); diff --git a/libraries/model-networking/src/model-networking/ModelCache.cpp b/libraries/model-networking/src/model-networking/ModelCache.cpp index dd3193073d..142ea74af4 100644 --- a/libraries/model-networking/src/model-networking/ModelCache.cpp +++ b/libraries/model-networking/src/model-networking/ModelCache.cpp @@ -173,7 +173,7 @@ void GeometryReader::run() { FBXGeometry::Pointer fbxGeometry; if (_url.path().toLower().endsWith(".fbx")) { - fbxGeometry.reset(readFBX(_data, _mapping, _url.path())); + fbxGeometry.reset(readFBX(_data, _mapping, _url)); if (fbxGeometry->meshes.size() == 0 && fbxGeometry->joints.size() == 0) { throw QString("empty geometry, possibly due to an unsupported FBX version"); } From 70eada0f76a8ff829b64f952a6d1af1f0a628435 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 4 Apr 2017 15:01:18 -0700 Subject: [PATCH 08/19] replace backslashes in parsed fbx relative filepaths --- libraries/fbx/src/FBXReader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/fbx/src/FBXReader.cpp b/libraries/fbx/src/FBXReader.cpp index e731261804..8288403337 100644 --- a/libraries/fbx/src/FBXReader.cpp +++ b/libraries/fbx/src/FBXReader.cpp @@ -444,8 +444,8 @@ FBXLight extractLight(const FBXNode& object) { } QByteArray fixedTextureFilepath(QByteArray fbxRelativeFilepath, QUrl url) { - // first setup a QFileInfo for the passed relative filepath - auto fileInfo = QFileInfo { fbxRelativeFilepath }; + // first setup a QFileInfo for the passed relative filepath, with backslashes replaced by forward slashes + auto fileInfo = QFileInfo { fbxRelativeFilepath.replace("\\", "/") }; if (fileInfo.isRelative()) { // the RelativeFilename pulled from the FBX is already correctly relative From e4021c168e7ef32b27d6cf2c17f2ef22bcf7cd99 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 5 Apr 2017 16:52:22 -0700 Subject: [PATCH 09/19] add special handling for abs drive letter paths from windows --- libraries/fbx/src/FBXReader.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libraries/fbx/src/FBXReader.cpp b/libraries/fbx/src/FBXReader.cpp index 8288403337..bcd2be3384 100644 --- a/libraries/fbx/src/FBXReader.cpp +++ b/libraries/fbx/src/FBXReader.cpp @@ -447,7 +447,15 @@ QByteArray fixedTextureFilepath(QByteArray fbxRelativeFilepath, QUrl url) { // first setup a QFileInfo for the passed relative filepath, with backslashes replaced by forward slashes auto fileInfo = QFileInfo { fbxRelativeFilepath.replace("\\", "/") }; - if (fileInfo.isRelative()) { +#ifndef Q_OS_WIN + // it turns out that absolute windows paths starting with drive letters look like relative paths to QFileInfo on UNIX + // so we add a check for that here to work around it + bool isRelative = fbxRelativeFilepath[1] != ':' && fileInfo.isRelative(); +#else + bool isRelative = fileInfo.isRelative(); +#endif + + if (isRelative) { // the RelativeFilename pulled from the FBX is already correctly relative // so simply return this as the filepath to use return fbxRelativeFilepath; From 42262aac78843dc9a8f7e58445f42471fd055b2a Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Wed, 5 Apr 2017 18:41:43 -0700 Subject: [PATCH 10/19] OpenVR: upgrade to version 1.0.6, for better generic tracker support --- cmake/externals/openvr/CMakeLists.txt | 4 ++-- plugins/openvr/src/OpenVrDisplayPlugin.cpp | 8 ++++---- plugins/openvr/src/OpenVrHelpers.cpp | 2 +- plugins/openvr/src/ViveControllerManager.cpp | 12 +++++++++--- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/cmake/externals/openvr/CMakeLists.txt b/cmake/externals/openvr/CMakeLists.txt index 19a9dd1f15..cb4aafcf8b 100644 --- a/cmake/externals/openvr/CMakeLists.txt +++ b/cmake/externals/openvr/CMakeLists.txt @@ -7,8 +7,8 @@ string(TOUPPER ${EXTERNAL_NAME} EXTERNAL_NAME_UPPER) ExternalProject_Add( ${EXTERNAL_NAME} - URL https://github.com/ValveSoftware/openvr/archive/v1.0.3.zip - URL_MD5 b484b12901917cc739e40389583c8b0d + URL https://github.com/ValveSoftware/openvr/archive/v1.0.6.zip + URL_MD5 f6892cd3a3078f505d03b4297f5a1951 CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND "" diff --git a/plugins/openvr/src/OpenVrDisplayPlugin.cpp b/plugins/openvr/src/OpenVrDisplayPlugin.cpp index 9f95e64361..1adfa8d333 100644 --- a/plugins/openvr/src/OpenVrDisplayPlugin.cpp +++ b/plugins/openvr/src/OpenVrDisplayPlugin.cpp @@ -277,8 +277,8 @@ public: glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); static const vr::VRTextureBounds_t leftBounds{ 0, 0, 0.5f, 1 }; static const vr::VRTextureBounds_t rightBounds{ 0.5f, 0, 1, 1 }; - - vr::Texture_t texture{ (void*)_colors[currentColorBuffer], vr::API_OpenGL, vr::ColorSpace_Auto }; + + vr::Texture_t texture{ (void*)_colors[currentColorBuffer], vr::TextureType_OpenGL, vr::ColorSpace_Auto }; vr::VRCompositor()->Submit(vr::Eye_Left, &texture, &leftBounds); vr::VRCompositor()->Submit(vr::Eye_Right, &texture, &rightBounds); _plugin._presentRate.increment(); @@ -422,7 +422,7 @@ bool OpenVrDisplayPlugin::internalActivate() { withNonPresentThreadLock([&] { openvr_for_each_eye([&](vr::Hmd_Eye eye) { _eyeOffsets[eye] = toGlm(_system->GetEyeToHeadTransform(eye)); - _eyeProjections[eye] = toGlm(_system->GetProjectionMatrix(eye, DEFAULT_NEAR_CLIP, DEFAULT_FAR_CLIP, vr::API_OpenGL)); + _eyeProjections[eye] = toGlm(_system->GetProjectionMatrix(eye, DEFAULT_NEAR_CLIP, DEFAULT_FAR_CLIP)); }); // FIXME Calculate the proper combined projection by using GetProjectionRaw values from both eyes _cullingProjection = _eyeProjections[0]; @@ -639,7 +639,7 @@ void OpenVrDisplayPlugin::hmdPresent() { _submitThread->waitForPresent(); } else { GLuint glTexId = getGLBackend()->getTextureID(_compositeFramebuffer->getRenderBuffer(0)); - vr::Texture_t vrTexture { (void*)glTexId, vr::API_OpenGL, vr::ColorSpace_Auto }; + vr::Texture_t vrTexture { (void*)glTexId, vr::TextureType_OpenGL, vr::ColorSpace_Auto }; vr::VRCompositor()->Submit(vr::Eye_Left, &vrTexture, &OPENVR_TEXTURE_BOUNDS_LEFT); vr::VRCompositor()->Submit(vr::Eye_Right, &vrTexture, &OPENVR_TEXTURE_BOUNDS_RIGHT); vr::VRCompositor()->PostPresentHandoff(); diff --git a/plugins/openvr/src/OpenVrHelpers.cpp b/plugins/openvr/src/OpenVrHelpers.cpp index 29ef640bf3..d9db757b2f 100644 --- a/plugins/openvr/src/OpenVrHelpers.cpp +++ b/plugins/openvr/src/OpenVrHelpers.cpp @@ -114,7 +114,7 @@ void releaseOpenVrSystem() { // HACK: workaround openvr crash, call submit with an invalid texture, right before VR_Shutdown. const GLuint INVALID_GL_TEXTURE_HANDLE = -1; - vr::Texture_t vrTexture{ (void*)INVALID_GL_TEXTURE_HANDLE, vr::API_OpenGL, vr::ColorSpace_Auto }; + vr::Texture_t vrTexture{ (void*)INVALID_GL_TEXTURE_HANDLE, vr::TextureType_OpenGL, vr::ColorSpace_Auto }; static vr::VRTextureBounds_t OPENVR_TEXTURE_BOUNDS_LEFT{ 0, 0, 0.5f, 1 }; static vr::VRTextureBounds_t OPENVR_TEXTURE_BOUNDS_RIGHT{ 0.5f, 0, 1, 1 }; diff --git a/plugins/openvr/src/ViveControllerManager.cpp b/plugins/openvr/src/ViveControllerManager.cpp index 8cedee2d8f..6fe640b618 100644 --- a/plugins/openvr/src/ViveControllerManager.cpp +++ b/plugins/openvr/src/ViveControllerManager.cpp @@ -140,9 +140,15 @@ void ViveControllerManager::InputDevice::update(float deltaTime, const controlle handleHandController(deltaTime, leftHandDeviceIndex, inputCalibrationData, true); handleHandController(deltaTime, rightHandDeviceIndex, inputCalibrationData, false); - // collect raw poses + // collect poses for all generic trackers for (int i = 0; i < vr::k_unMaxTrackedDeviceCount; i++) { - handleTrackedObject(i, inputCalibrationData); + if (_system->GetTrackedDeviceClass(i) == vr::TrackedDeviceClass_GenericTracker) { + handleTrackedObject(i, inputCalibrationData); + } else { + uint32_t poseIndex = controller::TRACKED_OBJECT_00 + i; + controller::Pose invalidPose; + _poseStateMap[poseIndex] = invalidPose; + } } // handle haptics @@ -203,7 +209,7 @@ void ViveControllerManager::InputDevice::handleHandController(float deltaTime, u handlePoseEvent(deltaTime, inputCalibrationData, mat, linearVelocity, angularVelocity, isLeftHand); vr::VRControllerState_t controllerState = vr::VRControllerState_t(); - if (_system->GetControllerState(deviceIndex, &controllerState)) { + if (_system->GetControllerState(deviceIndex, &controllerState, sizeof(vr::VRControllerState_t))) { // process each button for (uint32_t i = 0; i < vr::k_EButton_Max; ++i) { auto mask = vr::ButtonMaskFromId((vr::EVRButtonId)i); From 057a9feaf133a181a6a1a91843eb21e0beedb41f Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Thu, 6 Apr 2017 09:39:38 -0700 Subject: [PATCH 11/19] Don't crash if KTX file is invalid --- libraries/gpu/src/gpu/Texture_ktx.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/libraries/gpu/src/gpu/Texture_ktx.cpp b/libraries/gpu/src/gpu/Texture_ktx.cpp index 8befdf3e16..28de0c70eb 100644 --- a/libraries/gpu/src/gpu/Texture_ktx.cpp +++ b/libraries/gpu/src/gpu/Texture_ktx.cpp @@ -72,6 +72,15 @@ Size KtxStorage::getMipFaceSize(uint16 level, uint8 face) const { } void Texture::setKtxBacking(const std::string& filename) { + // Check the KTX file for validity before using it as backing storage + { + ktx::StoragePointer storage { new storage::FileStorage(filename.c_str()) }; + auto ktxPointer = ktx::KTX::create(storage); + if (!ktxPointer) { + return; + } + } + auto newBacking = std::unique_ptr(new KtxStorage(filename)); setStorage(newBacking); } @@ -185,7 +194,12 @@ ktx::KTXUniquePointer Texture::serialize(const Texture& texture) { } Texture* Texture::unserialize(const std::string& ktxfile, TextureUsageType usageType, Usage usage, const Sampler::Desc& sampler) { - ktx::KTXDescriptor descriptor { ktx::KTX::create(ktx::StoragePointer { new storage::FileStorage(ktxfile.c_str()) })->toDescriptor() }; + std::unique_ptr ktxPointer = ktx::KTX::create(ktx::StoragePointer { new storage::FileStorage(ktxfile.c_str()) }); + if (!ktxPointer) { + return nullptr; + } + + ktx::KTXDescriptor descriptor { ktxPointer->toDescriptor() }; const auto& header = descriptor.header; Format mipFormat = Format::COLOR_BGRA_32; From e0a14223457d9dedee7ff1b0020e3eeaff5f58d4 Mon Sep 17 00:00:00 2001 From: David Kelly Date: Thu, 6 Apr 2017 12:07:51 -0700 Subject: [PATCH 12/19] pal selection changes --- interface/resources/qml/hifi/Pal.qml | 11 ++++++++--- interface/resources/qml/styles-uit/HifiConstants.qml | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/interface/resources/qml/hifi/Pal.qml b/interface/resources/qml/hifi/Pal.qml index 66803621ec..2f10f0fdf5 100644 --- a/interface/resources/qml/hifi/Pal.qml +++ b/interface/resources/qml/hifi/Pal.qml @@ -436,7 +436,7 @@ Rectangle { rowDelegate: Rectangle { // The only way I know to specify a row height. // Size height: rowHeight + (styleData.selected ? 15 : 0); - color: rowColor(styleData.selected, styleData.alternate); + color: nearbyRowColor(styleData.selected, styleData.alternate); } // This Item refers to the contents of each Cell @@ -764,7 +764,7 @@ Rectangle { rowDelegate: Rectangle { // Size height: rowHeight; - color: rowColor(styleData.selected, styleData.alternate); + color: connectionsRowColor(styleData.selected, styleData.alternate); } // This Item refers to the contents of each Cell @@ -1184,9 +1184,12 @@ Rectangle { } } - function rowColor(selected, alternate) { + function nearbyRowColor(selected, alternate) { return selected ? hifi.colors.orangeHighlight : alternate ? hifi.colors.tableRowLightEven : hifi.colors.tableRowLightOdd; } + function connectionsRowColor(selected, alternate) { + return selected ? hifi.colors.lightBlueHighlight : alternate ? hifi.colors.tableRowLightEven : hifi.colors.tableRowLightOdd; + } function findNearbySessionIndex(sessionId, optionalData) { // no findIndex in .qml var data = optionalData || nearbyUserModelData, length = data.length; for (var i = 0; i < length; i++) { @@ -1257,6 +1260,8 @@ Rectangle { selectionTimer.userIndex = userIndex; selectionTimer.start(); } + // in any case make sure we are in the nearby tab + activeTab="nearbyTab"; break; // Received an "updateUsername()" request from the JS case 'updateUsername': diff --git a/interface/resources/qml/styles-uit/HifiConstants.qml b/interface/resources/qml/styles-uit/HifiConstants.qml index 386af206e1..7b6efbd573 100644 --- a/interface/resources/qml/styles-uit/HifiConstants.qml +++ b/interface/resources/qml/styles-uit/HifiConstants.qml @@ -72,6 +72,7 @@ Item { readonly property color magentaAccent: "#A2277C" readonly property color checkboxCheckedRed: "#FF0000" readonly property color checkboxCheckedBorderRed: "#D00000" + readonly property color lightBlueHighlight: "#d6f6ff" // Semitransparent readonly property color darkGray30: "#4d121212" From d163b343681f35e90136e7505c073e3021fb475e Mon Sep 17 00:00:00 2001 From: Trent Polack Date: Thu, 6 Apr 2017 15:57:32 -0400 Subject: [PATCH 13/19] Link to coding standards. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 00e7cbc45b..6294981e9a 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,8 @@ Documentation ========= Documentation is available at [docs.highfidelity.com](https://docs.highfidelity.com), if something is missing, please suggest it via a new job on Worklist (add to the hifi-docs project). +There is also detailed [documentation on our coding standards](https://wiki.highfidelity.com/wiki/Coding_Standards). + Build Instructions ========= All information required to build is found in the [build guide](BUILD.md). From 4e49774d0efff81324ee6d13171a379089aaafeb Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Thu, 6 Apr 2017 13:20:00 -0700 Subject: [PATCH 14/19] Moved device class check into handleTrackedObject --- plugins/openvr/src/ViveControllerManager.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/plugins/openvr/src/ViveControllerManager.cpp b/plugins/openvr/src/ViveControllerManager.cpp index 6fe640b618..86b37135d2 100644 --- a/plugins/openvr/src/ViveControllerManager.cpp +++ b/plugins/openvr/src/ViveControllerManager.cpp @@ -142,13 +142,7 @@ void ViveControllerManager::InputDevice::update(float deltaTime, const controlle // collect poses for all generic trackers for (int i = 0; i < vr::k_unMaxTrackedDeviceCount; i++) { - if (_system->GetTrackedDeviceClass(i) == vr::TrackedDeviceClass_GenericTracker) { - handleTrackedObject(i, inputCalibrationData); - } else { - uint32_t poseIndex = controller::TRACKED_OBJECT_00 + i; - controller::Pose invalidPose; - _poseStateMap[poseIndex] = invalidPose; - } + handleTrackedObject(i, inputCalibrationData); } // handle haptics @@ -177,6 +171,7 @@ void ViveControllerManager::InputDevice::handleTrackedObject(uint32_t deviceInde uint32_t poseIndex = controller::TRACKED_OBJECT_00 + deviceIndex; if (_system->IsTrackedDeviceConnected(deviceIndex) && + _system->GetTrackedDeviceClass(deviceIndex) == vr::TrackedDeviceClass_GenericTracker && _nextSimPoseData.vrPoses[deviceIndex].bPoseIsValid && poseIndex <= controller::TRACKED_OBJECT_15) { From 9577102c229f503846d731315d789672ed541f3a Mon Sep 17 00:00:00 2001 From: howard-stearns Date: Thu, 6 Apr 2017 14:45:08 -0700 Subject: [PATCH 15/19] fix sorting by pal connections-tab friends column --- interface/resources/qml/hifi/Pal.qml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/interface/resources/qml/hifi/Pal.qml b/interface/resources/qml/hifi/Pal.qml index d627fb54f9..9e93ddc8d7 100644 --- a/interface/resources/qml/hifi/Pal.qml +++ b/interface/resources/qml/hifi/Pal.qml @@ -756,7 +756,7 @@ Rectangle { resizable: false; } TableViewColumn { - role: "friends"; + role: "connection"; title: "FRIEND"; width: actionButtonWidth; movable: false; @@ -834,16 +834,16 @@ Rectangle { // "Friends" checkbox HifiControlsUit.CheckBox { id: friendsCheckBox; - visible: styleData.role === "friends" && model && model.userName !== myData.userName; + visible: styleData.role === "connection" && model && model.userName !== myData.userName; // you would think that this would work: // anchors.verticalCenter: connectionsNameCard.avImage.verticalCenter // but no! you cannot anchor to a non-sibling or parent. So: - x: parent.width/2 - boxSize/2 - y: connectionsNameCard.avImage.y + connectionsNameCard.avImage.height/2 - boxSize/2 - checked: model ? (model["connection"] === "friend" ? true : false) : false; + x: parent.width/2 - boxSize/2; + y: connectionsNameCard.avImage.y + connectionsNameCard.avImage.height/2 - boxSize/2; + checked: model && (model.connection === "friend"); boxSize: 24; onClicked: { - var newValue = !(model["connection"] === "friend"); + var newValue = model.connection !== "friend"; connectionsUserModel.setProperty(model.userIndex, styleData.role, newValue); connectionsUserModelData[model.userIndex][styleData.role] = newValue; // Defensive programming pal.sendToScript({method: newValue ? 'addFriend' : 'removeFriend', params: model.userName}); From aae7349c40df89931373b7e0de1cd939cd4254b5 Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 6 Apr 2017 18:31:03 -0700 Subject: [PATCH 16/19] trying to understand the bug with nvidia new driver --- libraries/gl/src/gl/Config.h | 2 +- libraries/render-utils/src/DeferredBufferRead.slh | 6 ++++-- libraries/render-utils/src/DeferredFramebuffer.cpp | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/libraries/gl/src/gl/Config.h b/libraries/gl/src/gl/Config.h index 9efae96f2a..07cf65c03a 100644 --- a/libraries/gl/src/gl/Config.h +++ b/libraries/gl/src/gl/Config.h @@ -29,7 +29,7 @@ #include // Uncomment this define and recompile to be able to avoid code path preventing to be able to run nsight graphics debug -//#define HIFI_ENABLE_NSIGHT_DEBUG 1 +#define HIFI_ENABLE_NSIGHT_DEBUG 1 #endif diff --git a/libraries/render-utils/src/DeferredBufferRead.slh b/libraries/render-utils/src/DeferredBufferRead.slh index 7c81b2c142..fff7973871 100644 --- a/libraries/render-utils/src/DeferredBufferRead.slh +++ b/libraries/render-utils/src/DeferredBufferRead.slh @@ -67,8 +67,10 @@ DeferredFragment unpackDeferredFragmentNoPosition(vec2 texcoord) { frag.scattering = 0.0; unpackModeMetallic(diffuseVal.w, frag.mode, frag.metallic); - //frag.emissive = specularVal.xyz; - frag.obscurance = min(specularVal.w, frag.obscurance); + + // frag.obscurance = min(specularVal.w, frag.obscurance); + + frag.obscurance = specularVal.w; if (frag.mode == FRAG_MODE_SCATTERING) { diff --git a/libraries/render-utils/src/DeferredFramebuffer.cpp b/libraries/render-utils/src/DeferredFramebuffer.cpp index 52329931d0..5d345f0851 100644 --- a/libraries/render-utils/src/DeferredFramebuffer.cpp +++ b/libraries/render-utils/src/DeferredFramebuffer.cpp @@ -55,7 +55,7 @@ void DeferredFramebuffer::allocate() { _deferredColorTexture = gpu::TexturePointer(gpu::Texture::createRenderBuffer(colorFormat, width, height, gpu::Texture::SINGLE_MIP, defaultSampler)); _deferredNormalTexture = gpu::TexturePointer(gpu::Texture::createRenderBuffer(linearFormat, width, height, gpu::Texture::SINGLE_MIP, defaultSampler)); - _deferredSpecularTexture = gpu::TexturePointer(gpu::Texture::createRenderBuffer(colorFormat, width, height, gpu::Texture::SINGLE_MIP, defaultSampler)); + _deferredSpecularTexture = gpu::TexturePointer(gpu::Texture::createRenderBuffer(linearFormat, width, height, gpu::Texture::SINGLE_MIP, defaultSampler)); _deferredFramebuffer->setRenderBuffer(0, _deferredColorTexture); _deferredFramebuffer->setRenderBuffer(1, _deferredNormalTexture); From da1355dc3247da05dc8436fdbaa358160c1638ec Mon Sep 17 00:00:00 2001 From: Sam Cake Date: Fri, 7 Apr 2017 01:03:07 -0700 Subject: [PATCH 17/19] Introducing a fix to the graphics bug --- libraries/gl/src/gl/Config.h | 2 +- .../render-utils/src/DebugDeferredBuffer.cpp | 23 ++++++++++++++++--- libraries/render-utils/src/LightAmbient.slh | 13 +++++------ .../src/debug_deferred_buffer.slf | 9 ++++++-- .../utilities/render/deferredLighting.qml | 3 ++- 5 files changed, 36 insertions(+), 14 deletions(-) diff --git a/libraries/gl/src/gl/Config.h b/libraries/gl/src/gl/Config.h index 07cf65c03a..9efae96f2a 100644 --- a/libraries/gl/src/gl/Config.h +++ b/libraries/gl/src/gl/Config.h @@ -29,7 +29,7 @@ #include // Uncomment this define and recompile to be able to avoid code path preventing to be able to run nsight graphics debug -#define HIFI_ENABLE_NSIGHT_DEBUG 1 +//#define HIFI_ENABLE_NSIGHT_DEBUG 1 #endif diff --git a/libraries/render-utils/src/DebugDeferredBuffer.cpp b/libraries/render-utils/src/DebugDeferredBuffer.cpp index 9ffd94af38..8b505bbe97 100644 --- a/libraries/render-utils/src/DebugDeferredBuffer.cpp +++ b/libraries/render-utils/src/DebugDeferredBuffer.cpp @@ -85,13 +85,30 @@ static const std::string DEFAULT_NORMAL_SHADER { " return vec4(vec3(0.5) + (frag.normal * 0.5), 1.0);" " }" }; - +/* static const std::string DEFAULT_OCCLUSION_SHADER{ "vec4 getFragmentColor() {" - " DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);" - " return vec4(vec3(pow(frag.obscurance, 1.0 / 2.2)), 1.0);" + // " DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);" + // " return vec4(vec3(pow(frag.obscurance, 1.0 / 2.2)), 1.0);" + // " return vec4(vec3(pow(texture(specularMap, uv).a, 1.0 / 2.2)), 1.0);" + " return vec4(vec3(texture(specularMap, uv).w), 1.0);" " }" }; +*/ +static const std::string DEFAULT_OCCLUSION_SHADER{ + "vec4 getFragmentColor() {" + // " DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);" + // " return vec4(vec3(pow(frag.obscurance, 1.0 / 2.2)), 1.0);" + " vec4 midNormalCurvature;" + " vec4 lowNormalCurvature;" + " unpackMidLowNormalCurvature(uv, midNormalCurvature, lowNormalCurvature);" + " float ambientOcclusion = curvatureAO(lowNormalCurvature.a * 20.0f) * 0.5f;" + " float ambientOcclusionHF = curvatureAO(midNormalCurvature.a * 8.0f) * 0.5f;" + " ambientOcclusion = min(ambientOcclusion, ambientOcclusionHF);" + " return vec4(vec3(ambientOcclusion), 1.0);" + " }" +}; + static const std::string DEFAULT_EMISSIVE_SHADER{ "vec4 getFragmentColor() {" diff --git a/libraries/render-utils/src/LightAmbient.slh b/libraries/render-utils/src/LightAmbient.slh index b919108115..5f74b46d3e 100644 --- a/libraries/render-utils/src/LightAmbient.slh +++ b/libraries/render-utils/src/LightAmbient.slh @@ -62,7 +62,7 @@ vec3 evalAmbientSpecularIrradiance(LightAmbient ambient, vec3 fragEyeDir, vec3 f <@if supportScattering@> float curvatureAO(in float k) { - return 1.0f - (0.0022f * k * k) + (0.0776f * k) + 0.7369; + return 1.0f - (0.0022f * k * k) + (0.0776f * k) + 0.7369f; } <@endif@> @@ -83,13 +83,12 @@ void evalLightingAmbient(out vec3 diffuse, out vec3 specular, LightAmbient ambie specular = evalAmbientSpecularIrradiance(ambient, eyeDir, normal, roughness) * ambientFresnel; <@if supportScattering@> - float ambientOcclusion = curvatureAO(lowNormalCurvature.w * 20.0f) * 0.5f; - float ambientOcclusionHF = curvatureAO(midNormalCurvature.w * 8.0f) * 0.5f; - ambientOcclusion = min(ambientOcclusion, ambientOcclusionHF); - - obscurance = min(obscurance, ambientOcclusion); - if (scattering * isScatteringEnabled() > 0.0) { + float ambientOcclusion = curvatureAO(lowNormalCurvature.w * 20.0f) * 0.5f; + float ambientOcclusionHF = curvatureAO(midNormalCurvature.w * 8.0f) * 0.5f; + ambientOcclusion = min(ambientOcclusion, ambientOcclusionHF); + + obscurance = min(obscurance, ambientOcclusion); // Diffuse from ambient diffuse = sphericalHarmonics_evalSphericalLight(getLightAmbientSphere(ambient), lowNormalCurvature.xyz).xyz; diff --git a/libraries/render-utils/src/debug_deferred_buffer.slf b/libraries/render-utils/src/debug_deferred_buffer.slf index c018e5e526..e9750f0054 100644 --- a/libraries/render-utils/src/debug_deferred_buffer.slf +++ b/libraries/render-utils/src/debug_deferred_buffer.slf @@ -16,15 +16,20 @@ <@include gpu/Color.slh@> <$declareColorWheel()$> + uniform sampler2D linearDepthMap; uniform sampler2D halfLinearDepthMap; uniform sampler2D halfNormalMap; uniform sampler2D occlusionMap; uniform sampler2D occlusionBlurredMap; -uniform sampler2D curvatureMap; -uniform sampler2D diffusedCurvatureMap; uniform sampler2D scatteringMap; +<$declareDeferredCurvature()$> + +float curvatureAO(float k) { + return 1.0f - (0.0022f * k * k) + (0.0776f * k) + 0.7369f; +} + in vec2 uv; out vec4 outFragColor; diff --git a/scripts/developer/utilities/render/deferredLighting.qml b/scripts/developer/utilities/render/deferredLighting.qml index c7ec8e1153..a444338c0f 100644 --- a/scripts/developer/utilities/render/deferredLighting.qml +++ b/scripts/developer/utilities/render/deferredLighting.qml @@ -63,7 +63,8 @@ Column { "Directional:LightingModel:enableDirectionalLight", "Point:LightingModel:enablePointLight", "Spot:LightingModel:enableSpotLight", - "Light Contour:LightingModel:showLightContour" + "Light Contour:LightingModel:showLightContour", + "Shadow:RenderShadowTask:enabled" ] CheckBox { text: modelData.split(":")[0] From b1a4bc329be3ad754e4e079620e4f6d30ef0419e Mon Sep 17 00:00:00 2001 From: Sam Cake Date: Fri, 7 Apr 2017 01:10:18 -0700 Subject: [PATCH 18/19] Introducing a fix to the graphics bug --- .../render-utils/src/DebugDeferredBuffer.cpp | 46 +++++++++---------- .../render-utils/src/DebugDeferredBuffer.h | 1 + .../render-utils/src/DeferredBufferRead.slh | 6 +-- .../utilities/render/deferredLighting.qml | 1 + 4 files changed, 25 insertions(+), 29 deletions(-) diff --git a/libraries/render-utils/src/DebugDeferredBuffer.cpp b/libraries/render-utils/src/DebugDeferredBuffer.cpp index 8b505bbe97..e534628c83 100644 --- a/libraries/render-utils/src/DebugDeferredBuffer.cpp +++ b/libraries/render-utils/src/DebugDeferredBuffer.cpp @@ -85,30 +85,14 @@ static const std::string DEFAULT_NORMAL_SHADER { " return vec4(vec3(0.5) + (frag.normal * 0.5), 1.0);" " }" }; -/* -static const std::string DEFAULT_OCCLUSION_SHADER{ - "vec4 getFragmentColor() {" - // " DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);" - // " return vec4(vec3(pow(frag.obscurance, 1.0 / 2.2)), 1.0);" - // " return vec4(vec3(pow(texture(specularMap, uv).a, 1.0 / 2.2)), 1.0);" - " return vec4(vec3(texture(specularMap, uv).w), 1.0);" - " }" -}; -*/ -static const std::string DEFAULT_OCCLUSION_SHADER{ - "vec4 getFragmentColor() {" - // " DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);" - // " return vec4(vec3(pow(frag.obscurance, 1.0 / 2.2)), 1.0);" - " vec4 midNormalCurvature;" - " vec4 lowNormalCurvature;" - " unpackMidLowNormalCurvature(uv, midNormalCurvature, lowNormalCurvature);" - " float ambientOcclusion = curvatureAO(lowNormalCurvature.a * 20.0f) * 0.5f;" - " float ambientOcclusionHF = curvatureAO(midNormalCurvature.a * 8.0f) * 0.5f;" - " ambientOcclusion = min(ambientOcclusion, ambientOcclusionHF);" - " return vec4(vec3(ambientOcclusion), 1.0);" - " }" -}; +static const std::string DEFAULT_OCCLUSION_SHADER{ + "vec4 getFragmentColor() {" + // " DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);" + // " return vec4(vec3(pow(frag.obscurance, 1.0 / 2.2)), 1.0);" + " return vec4(vec3(pow(texture(specularMap, uv).a, 1.0 / 2.2)), 1.0);" + " }" +}; static const std::string DEFAULT_EMISSIVE_SHADER{ "vec4 getFragmentColor() {" @@ -211,6 +195,18 @@ static const std::string DEFAULT_DIFFUSED_NORMAL_CURVATURE_SHADER{ " }" }; +static const std::string DEFAULT_CURVATURE_OCCLUSION_SHADER{ + "vec4 getFragmentColor() {" + " vec4 midNormalCurvature;" + " vec4 lowNormalCurvature;" + " unpackMidLowNormalCurvature(uv, midNormalCurvature, lowNormalCurvature);" + " float ambientOcclusion = curvatureAO(lowNormalCurvature.a * 20.0f) * 0.5f;" + " float ambientOcclusionHF = curvatureAO(midNormalCurvature.a * 8.0f) * 0.5f;" + " ambientOcclusion = min(ambientOcclusion, ambientOcclusionHF);" + " return vec4(vec3(ambientOcclusion), 1.0);" + " }" +}; + static const std::string DEFAULT_DEBUG_SCATTERING_SHADER{ "vec4 getFragmentColor() {" " return vec4(pow(vec3(texture(scatteringMap, uv).xyz), vec3(1.0 / 2.2)), 1.0);" @@ -220,7 +216,7 @@ static const std::string DEFAULT_DEBUG_SCATTERING_SHADER{ static const std::string DEFAULT_AMBIENT_OCCLUSION_SHADER{ "vec4 getFragmentColor() {" - " return vec4(vec3(texture(obscuranceMap, uv).xyz), 1.0);" + " return vec4(vec3(texture(obscuranceMap, uv).x), 1.0);" // When drawing color " return vec4(vec3(texture(occlusionMap, uv).xyz), 1.0);" // when drawing normal" return vec4(normalize(texture(occlusionMap, uv).xyz * 2.0 - vec3(1.0)), 1.0);" " }" @@ -305,6 +301,8 @@ std::string DebugDeferredBuffer::getShaderSourceCode(Mode mode, std::string cust return DEFAULT_DIFFUSED_CURVATURE_SHADER; case DiffusedNormalCurvatureMode: return DEFAULT_DIFFUSED_NORMAL_CURVATURE_SHADER; + case CurvatureOcclusionMode: + return DEFAULT_CURVATURE_OCCLUSION_SHADER; case ScatteringDebugMode: return DEFAULT_DEBUG_SCATTERING_SHADER; case AmbientOcclusionMode: diff --git a/libraries/render-utils/src/DebugDeferredBuffer.h b/libraries/render-utils/src/DebugDeferredBuffer.h index eb1a541d2e..be775e052f 100644 --- a/libraries/render-utils/src/DebugDeferredBuffer.h +++ b/libraries/render-utils/src/DebugDeferredBuffer.h @@ -72,6 +72,7 @@ protected: NormalCurvatureMode, DiffusedCurvatureMode, DiffusedNormalCurvatureMode, + CurvatureOcclusionMode, ScatteringDebugMode, AmbientOcclusionMode, AmbientOcclusionBlurredMode, diff --git a/libraries/render-utils/src/DeferredBufferRead.slh b/libraries/render-utils/src/DeferredBufferRead.slh index fff7973871..315de30fea 100644 --- a/libraries/render-utils/src/DeferredBufferRead.slh +++ b/libraries/render-utils/src/DeferredBufferRead.slh @@ -67,11 +67,7 @@ DeferredFragment unpackDeferredFragmentNoPosition(vec2 texcoord) { frag.scattering = 0.0; unpackModeMetallic(diffuseVal.w, frag.mode, frag.metallic); - - // frag.obscurance = min(specularVal.w, frag.obscurance); - - frag.obscurance = specularVal.w; - + frag.obscurance = min(specularVal.w, frag.obscurance); if (frag.mode == FRAG_MODE_SCATTERING) { frag.scattering = specularVal.x; diff --git a/scripts/developer/utilities/render/deferredLighting.qml b/scripts/developer/utilities/render/deferredLighting.qml index a444338c0f..778e0e1905 100644 --- a/scripts/developer/utilities/render/deferredLighting.qml +++ b/scripts/developer/utilities/render/deferredLighting.qml @@ -151,6 +151,7 @@ Column { ListElement { text: "Mid Normal"; color: "White" } ListElement { text: "Low Curvature"; color: "White" } ListElement { text: "Low Normal"; color: "White" } + ListElement { text: "Curvature Occlusion"; color: "White" } ListElement { text: "Debug Scattering"; color: "White" } ListElement { text: "Ambient Occlusion"; color: "White" } ListElement { text: "Ambient Occlusion Blurred"; color: "White" } From ab3d39951edc406d7d4bb22c5d3d801703a6950c Mon Sep 17 00:00:00 2001 From: samcake Date: Fri, 7 Apr 2017 02:03:31 -0700 Subject: [PATCH 19/19] Revert "Fixing the rendering bug triggered with Nvidia driver 381.65" --- .../render-utils/src/DebugDeferredBuffer.cpp | 21 +++---------------- .../render-utils/src/DebugDeferredBuffer.h | 1 - .../render-utils/src/DeferredBufferRead.slh | 2 ++ .../render-utils/src/DeferredFramebuffer.cpp | 2 +- libraries/render-utils/src/LightAmbient.slh | 13 ++++++------ .../src/debug_deferred_buffer.slf | 9 ++------ .../utilities/render/deferredLighting.qml | 4 +--- 7 files changed, 16 insertions(+), 36 deletions(-) diff --git a/libraries/render-utils/src/DebugDeferredBuffer.cpp b/libraries/render-utils/src/DebugDeferredBuffer.cpp index e534628c83..9ffd94af38 100644 --- a/libraries/render-utils/src/DebugDeferredBuffer.cpp +++ b/libraries/render-utils/src/DebugDeferredBuffer.cpp @@ -88,9 +88,8 @@ static const std::string DEFAULT_NORMAL_SHADER { static const std::string DEFAULT_OCCLUSION_SHADER{ "vec4 getFragmentColor() {" - // " DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);" - // " return vec4(vec3(pow(frag.obscurance, 1.0 / 2.2)), 1.0);" - " return vec4(vec3(pow(texture(specularMap, uv).a, 1.0 / 2.2)), 1.0);" + " DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);" + " return vec4(vec3(pow(frag.obscurance, 1.0 / 2.2)), 1.0);" " }" }; @@ -195,18 +194,6 @@ static const std::string DEFAULT_DIFFUSED_NORMAL_CURVATURE_SHADER{ " }" }; -static const std::string DEFAULT_CURVATURE_OCCLUSION_SHADER{ - "vec4 getFragmentColor() {" - " vec4 midNormalCurvature;" - " vec4 lowNormalCurvature;" - " unpackMidLowNormalCurvature(uv, midNormalCurvature, lowNormalCurvature);" - " float ambientOcclusion = curvatureAO(lowNormalCurvature.a * 20.0f) * 0.5f;" - " float ambientOcclusionHF = curvatureAO(midNormalCurvature.a * 8.0f) * 0.5f;" - " ambientOcclusion = min(ambientOcclusion, ambientOcclusionHF);" - " return vec4(vec3(ambientOcclusion), 1.0);" - " }" -}; - static const std::string DEFAULT_DEBUG_SCATTERING_SHADER{ "vec4 getFragmentColor() {" " return vec4(pow(vec3(texture(scatteringMap, uv).xyz), vec3(1.0 / 2.2)), 1.0);" @@ -216,7 +203,7 @@ static const std::string DEFAULT_DEBUG_SCATTERING_SHADER{ static const std::string DEFAULT_AMBIENT_OCCLUSION_SHADER{ "vec4 getFragmentColor() {" - " return vec4(vec3(texture(obscuranceMap, uv).x), 1.0);" + " return vec4(vec3(texture(obscuranceMap, uv).xyz), 1.0);" // When drawing color " return vec4(vec3(texture(occlusionMap, uv).xyz), 1.0);" // when drawing normal" return vec4(normalize(texture(occlusionMap, uv).xyz * 2.0 - vec3(1.0)), 1.0);" " }" @@ -301,8 +288,6 @@ std::string DebugDeferredBuffer::getShaderSourceCode(Mode mode, std::string cust return DEFAULT_DIFFUSED_CURVATURE_SHADER; case DiffusedNormalCurvatureMode: return DEFAULT_DIFFUSED_NORMAL_CURVATURE_SHADER; - case CurvatureOcclusionMode: - return DEFAULT_CURVATURE_OCCLUSION_SHADER; case ScatteringDebugMode: return DEFAULT_DEBUG_SCATTERING_SHADER; case AmbientOcclusionMode: diff --git a/libraries/render-utils/src/DebugDeferredBuffer.h b/libraries/render-utils/src/DebugDeferredBuffer.h index be775e052f..eb1a541d2e 100644 --- a/libraries/render-utils/src/DebugDeferredBuffer.h +++ b/libraries/render-utils/src/DebugDeferredBuffer.h @@ -72,7 +72,6 @@ protected: NormalCurvatureMode, DiffusedCurvatureMode, DiffusedNormalCurvatureMode, - CurvatureOcclusionMode, ScatteringDebugMode, AmbientOcclusionMode, AmbientOcclusionBlurredMode, diff --git a/libraries/render-utils/src/DeferredBufferRead.slh b/libraries/render-utils/src/DeferredBufferRead.slh index 315de30fea..7c81b2c142 100644 --- a/libraries/render-utils/src/DeferredBufferRead.slh +++ b/libraries/render-utils/src/DeferredBufferRead.slh @@ -67,8 +67,10 @@ DeferredFragment unpackDeferredFragmentNoPosition(vec2 texcoord) { frag.scattering = 0.0; unpackModeMetallic(diffuseVal.w, frag.mode, frag.metallic); + //frag.emissive = specularVal.xyz; frag.obscurance = min(specularVal.w, frag.obscurance); + if (frag.mode == FRAG_MODE_SCATTERING) { frag.scattering = specularVal.x; } diff --git a/libraries/render-utils/src/DeferredFramebuffer.cpp b/libraries/render-utils/src/DeferredFramebuffer.cpp index 5d345f0851..52329931d0 100644 --- a/libraries/render-utils/src/DeferredFramebuffer.cpp +++ b/libraries/render-utils/src/DeferredFramebuffer.cpp @@ -55,7 +55,7 @@ void DeferredFramebuffer::allocate() { _deferredColorTexture = gpu::TexturePointer(gpu::Texture::createRenderBuffer(colorFormat, width, height, gpu::Texture::SINGLE_MIP, defaultSampler)); _deferredNormalTexture = gpu::TexturePointer(gpu::Texture::createRenderBuffer(linearFormat, width, height, gpu::Texture::SINGLE_MIP, defaultSampler)); - _deferredSpecularTexture = gpu::TexturePointer(gpu::Texture::createRenderBuffer(linearFormat, width, height, gpu::Texture::SINGLE_MIP, defaultSampler)); + _deferredSpecularTexture = gpu::TexturePointer(gpu::Texture::createRenderBuffer(colorFormat, width, height, gpu::Texture::SINGLE_MIP, defaultSampler)); _deferredFramebuffer->setRenderBuffer(0, _deferredColorTexture); _deferredFramebuffer->setRenderBuffer(1, _deferredNormalTexture); diff --git a/libraries/render-utils/src/LightAmbient.slh b/libraries/render-utils/src/LightAmbient.slh index 5f74b46d3e..b919108115 100644 --- a/libraries/render-utils/src/LightAmbient.slh +++ b/libraries/render-utils/src/LightAmbient.slh @@ -62,7 +62,7 @@ vec3 evalAmbientSpecularIrradiance(LightAmbient ambient, vec3 fragEyeDir, vec3 f <@if supportScattering@> float curvatureAO(in float k) { - return 1.0f - (0.0022f * k * k) + (0.0776f * k) + 0.7369f; + return 1.0f - (0.0022f * k * k) + (0.0776f * k) + 0.7369; } <@endif@> @@ -83,12 +83,13 @@ void evalLightingAmbient(out vec3 diffuse, out vec3 specular, LightAmbient ambie specular = evalAmbientSpecularIrradiance(ambient, eyeDir, normal, roughness) * ambientFresnel; <@if supportScattering@> - if (scattering * isScatteringEnabled() > 0.0) { - float ambientOcclusion = curvatureAO(lowNormalCurvature.w * 20.0f) * 0.5f; - float ambientOcclusionHF = curvatureAO(midNormalCurvature.w * 8.0f) * 0.5f; - ambientOcclusion = min(ambientOcclusion, ambientOcclusionHF); + float ambientOcclusion = curvatureAO(lowNormalCurvature.w * 20.0f) * 0.5f; + float ambientOcclusionHF = curvatureAO(midNormalCurvature.w * 8.0f) * 0.5f; + ambientOcclusion = min(ambientOcclusion, ambientOcclusionHF); - obscurance = min(obscurance, ambientOcclusion); + obscurance = min(obscurance, ambientOcclusion); + + if (scattering * isScatteringEnabled() > 0.0) { // Diffuse from ambient diffuse = sphericalHarmonics_evalSphericalLight(getLightAmbientSphere(ambient), lowNormalCurvature.xyz).xyz; diff --git a/libraries/render-utils/src/debug_deferred_buffer.slf b/libraries/render-utils/src/debug_deferred_buffer.slf index e9750f0054..c018e5e526 100644 --- a/libraries/render-utils/src/debug_deferred_buffer.slf +++ b/libraries/render-utils/src/debug_deferred_buffer.slf @@ -16,20 +16,15 @@ <@include gpu/Color.slh@> <$declareColorWheel()$> - uniform sampler2D linearDepthMap; uniform sampler2D halfLinearDepthMap; uniform sampler2D halfNormalMap; uniform sampler2D occlusionMap; uniform sampler2D occlusionBlurredMap; +uniform sampler2D curvatureMap; +uniform sampler2D diffusedCurvatureMap; uniform sampler2D scatteringMap; -<$declareDeferredCurvature()$> - -float curvatureAO(float k) { - return 1.0f - (0.0022f * k * k) + (0.0776f * k) + 0.7369f; -} - in vec2 uv; out vec4 outFragColor; diff --git a/scripts/developer/utilities/render/deferredLighting.qml b/scripts/developer/utilities/render/deferredLighting.qml index 778e0e1905..c7ec8e1153 100644 --- a/scripts/developer/utilities/render/deferredLighting.qml +++ b/scripts/developer/utilities/render/deferredLighting.qml @@ -63,8 +63,7 @@ Column { "Directional:LightingModel:enableDirectionalLight", "Point:LightingModel:enablePointLight", "Spot:LightingModel:enableSpotLight", - "Light Contour:LightingModel:showLightContour", - "Shadow:RenderShadowTask:enabled" + "Light Contour:LightingModel:showLightContour" ] CheckBox { text: modelData.split(":")[0] @@ -151,7 +150,6 @@ Column { ListElement { text: "Mid Normal"; color: "White" } ListElement { text: "Low Curvature"; color: "White" } ListElement { text: "Low Normal"; color: "White" } - ListElement { text: "Curvature Occlusion"; color: "White" } ListElement { text: "Debug Scattering"; color: "White" } ListElement { text: "Ambient Occlusion"; color: "White" } ListElement { text: "Ambient Occlusion Blurred"; color: "White" }