diff --git a/BUILD.md b/BUILD.md index 00b17743e9..25bbc89951 100644 --- a/BUILD.md +++ b/BUILD.md @@ -13,7 +13,7 @@ ### CMake External Project Dependencies -These dependencies need not be installed manually. They are automatically downloaded on the platforms where they are required. +These dependencies need not be installed manually. They are automatically downloaded on the platforms where they are required. - [Bullet Physics Engine](https://github.com/bulletphysics/bullet3/releases): 2.83 - [glm](https://glm.g-truc.net/0.9.8/index.html): 0.9.8 - [Oculus SDK](https://developer.oculus.com/downloads/): 1.11 (Win32) / 0.5 (Mac) @@ -22,7 +22,7 @@ These dependencies need not be installed manually. They are automatically downlo - [QuaZip](https://sourceforge.net/projects/quazip/files/quazip/): 0.7.3 - [SDL2](https://www.libsdl.org/download-2.0.php): 2.0.3 - [Intel Threading Building Blocks](https://www.threadingbuildingblocks.org/): 4.3 -- [vcpkg](https://github.com/highfidelity/vcpkg): +- [vcpkg](https://github.com/highfidelity/vcpkg): - [VHACD](https://github.com/virneo/v-hacd) - [zlib](http://www.zlib.net/): 1.28 (Win32 only) - [nvtt](https://github.com/highfidelity/nvidia-texture-tools): 2.1.1 (customized) @@ -48,6 +48,18 @@ The path it needs to be set to will depend on where and how Qt5 was installed. e export QT_CMAKE_PREFIX_PATH=/usr/local/Cellar/qt5/5.10.1/lib/cmake export QT_CMAKE_PREFIX_PATH=/usr/local/opt/qt5/lib/cmake +#### Vcpkg + +Hifi uses vcpkg to download and build dependencies. +You do not need to install vcpkg. + +Building the dependencies can be lengthy and the resulting files will be stored in your OS temp directory. +However, those files can potentially get cleaned up by the OS, so in order to avoid this and having to redo the lengthy build step, you can set the following environment variable: + +export HIFI_VCPKG_BASE=/path/to/directory + +Where /path/to/directory is the path to a directory where you wish the build files to get stored. + #### Generating build files Create a build directory in the root of your checkout and then run the CMake build from there. This will keep the rest of the directory clean. @@ -80,7 +92,7 @@ In the examples below the variable $NAME would be replaced by the name of the de ### Optional Components -#### Build Options +#### Build Options The following build options can be used when running CMake @@ -89,7 +101,7 @@ The following build options can be used when running CMake * BUILD_TESTS * BUILD_TOOLS -#### Developer Build Options +#### Developer Build Options * USE_GLES * DISABLE_UI diff --git a/BUILD_WIN.md b/BUILD_WIN.md index 073b048911..a81fca5900 100644 --- a/BUILD_WIN.md +++ b/BUILD_WIN.md @@ -19,7 +19,7 @@ If you do not wish to use the Python installation bundled with Visual Studio, yo ### Step 2. Installing CMake -Download and install the latest version of CMake 3.9. +Download and install the latest version of CMake 3.9. Download the file named win64-x64 Installer from the [CMake Website](https://cmake.org/download/). You can access the installer on this [3.9 Version page](https://cmake.org/files/v3.9/). During installation, make sure to check "Add CMake to system PATH for all users" when prompted. @@ -35,20 +35,7 @@ Go to `Control Panel > System > Advanced System Settings > Environment Variables * Set "Variable name": `QT_CMAKE_PREFIX_PATH` * Set "Variable value": `C:\Qt\5.10.1\msvc2017_64\lib\cmake` -### Step 5. Installing [vcpkg](https://github.com/Microsoft/vcpkg) - - * Clone the VCPKG [repository](https://github.com/Microsoft/vcpkg) - * Follow the instructions in the [readme](https://github.com/Microsoft/vcpkg/blob/master/README.md) to bootstrap vcpkg - * Note, you may need to do these in a _Developer Command Prompt_ - * Set an environment variable VCPKG_ROOT to the location of the cloned repository - * Close and re-open any command prompts after setting the environment variable so that they will pick up the change - -### Step 6. Installing OpenSSL via vcpkg - - * In the vcpkg directory, install the 64 bit OpenSSL package with the command `.\vcpkg install openssl:x64-windows` - * Once the build completes you should have a file `ssl.h` in `${VCPKG_ROOT}/installed/x64-windows/include/openssl` - -### Step 7. Running CMake to Generate Build Files +### Step 5. Running CMake to Generate Build Files Run Command Prompt from Start and run the following commands: ``` @@ -58,9 +45,9 @@ cd build cmake .. -G "Visual Studio 15 Win64" ``` -Where `%HIFI_DIR%` is the directory for the highfidelity repository. +Where `%HIFI_DIR%` is the directory for the highfidelity repository. -### Step 8. Making a Build +### Step 6. Making a Build Open `%HIFI_DIR%\build\hifi.sln` using Visual Studio. @@ -68,7 +55,7 @@ Change the Solution Configuration (menu ribbon under the menu bar, next to the g Run from the menu bar `Build > Build Solution`. -### Step 9. Testing Interface +### Step 7. Testing Interface Create another environment variable (see Step #4) * Set "Variable name": `_NO_DEBUG_HEAP` diff --git a/assignment-client/src/avatars/AvatarMixerClientData.cpp b/assignment-client/src/avatars/AvatarMixerClientData.cpp index 76cdf13986..5e36d8beaf 100644 --- a/assignment-client/src/avatars/AvatarMixerClientData.cpp +++ b/assignment-client/src/avatars/AvatarMixerClientData.cpp @@ -152,6 +152,8 @@ void AvatarMixerClientData::processSetTraitsMessage(ReceivedMessage& message, if (packetTraitVersion > instanceVersionRef) { if (traitSize == AvatarTraits::DELETED_TRAIT_SIZE) { _avatar->processDeletedTraitInstance(traitType, instanceID); + // Mixer doesn't need deleted IDs. + _avatar->getAndClearRecentlyDetachedIDs(); // to track a deleted instance but keep version information // the avatar mixer uses the negative value of the sent version diff --git a/domain-server/resources/web/settings/js/settings.js b/domain-server/resources/web/settings/js/settings.js index 3888277c00..2950b8de75 100644 --- a/domain-server/resources/web/settings/js/settings.js +++ b/domain-server/resources/web/settings/js/settings.js @@ -18,9 +18,6 @@ $(document).ready(function(){ Settings.extraGroupsAtIndex = Settings.extraDomainGroupsAtIndex; Settings.afterReloadActions = function() { - // append the domain selection modal - appendDomainIDButtons(); - // call our method to setup the HF account button setupHFAccountButton(); @@ -52,6 +49,11 @@ $(document).ready(function(){ if (cloudWizardExit != undefined) { $('#cloud-domains-alert').show(); } + + $(Settings.DOMAIN_ID_SELECTOR).siblings('span').append("
Changing the domain ID for a Cloud Domain may result in an incorrect status for the domain on your Cloud Domains page."); + } else { + // append the domain selection modal + appendDomainIDButtons(); } handleAction(); @@ -59,9 +61,9 @@ $(document).ready(function(){ Settings.handlePostSettings = function(formJSON) { - if (!verifyAvatarHeights()) { - return false; - } + if (!verifyAvatarHeights()) { + return false; + } // check if we've set the basic http password if (formJSON["security"]) { diff --git a/interface/resources/qml/hifi/Desktop.qml b/interface/resources/qml/hifi/Desktop.qml index f57c612b98..354c8095a0 100644 --- a/interface/resources/qml/hifi/Desktop.qml +++ b/interface/resources/qml/hifi/Desktop.qml @@ -70,8 +70,8 @@ OriginalDesktop.Desktop { anchors.horizontalCenter: settings.constrainToolbarToCenterX ? desktop.horizontalCenter : undefined; // Literal 50 is overwritten by settings from previous session, and sysToolbar.x comes from settings when not constrained. x: sysToolbar.x - buttonModel: tablet.buttons; - shown: tablet.toolbarMode; + buttonModel: tablet ? tablet.buttons : null; + shown: tablet ? tablet.toolbarMode : false; } Settings { diff --git a/interface/resources/qml/hifi/commerce/common/sendAsset/SendAsset.qml b/interface/resources/qml/hifi/commerce/common/sendAsset/SendAsset.qml index 2d0bb2d87b..3125ad1ee6 100644 --- a/interface/resources/qml/hifi/commerce/common/sendAsset/SendAsset.qml +++ b/interface/resources/qml/hifi/commerce/common/sendAsset/SendAsset.qml @@ -36,6 +36,8 @@ Item { property bool isCurrentlySendingAsset: false; property string assetName: ""; property string assetCertID: ""; + property string couponID: ""; + property string authorizationID: ""; property string sendingPubliclyEffectImage; property var http; property var listModelName; @@ -108,6 +110,27 @@ Item { } } + onAuthorizeAssetTransferResult: { + if (!root.visible) { + return; + } + + root.isCurrentlySendingAsset = false; + + if (result.status === 'success') { + root.authorizationID = result.data.authorization_id; + authorizationIDText.text = root.authorizationID; + root.couponID = result.data.coupon_id; + couponIDText.text = root.couponID + if (couponIDTextField.text !== root.couponID) { + console.log("SendAsset: Returned coupon ID doesn't match client-generated coupon ID!"); + } + root.nextActiveView = 'paymentSuccess'; + } else { + root.nextActiveView = 'paymentFailure'; + } + } + onCertificateInfoResult: { if (result.status !== 'success') { console.log("Failed to get certificate info", result.data.message); @@ -269,7 +292,7 @@ Item { RalewaySemiBold { id: sendAssetText; - text: root.assetCertID === "" ? "Send Money To:" : "Gift \"" + root.assetName + "\" To:"; + text: root.assetCertID === "" ? "Send Money To:" : "Send \"" + root.assetName + "\" To:"; // Anchors anchors.top: parent.top; anchors.topMargin: 26; @@ -370,6 +393,51 @@ Item { } } + Item { + id: createCouponButton; + // Anchors + anchors.top: nearbyButton.bottom; + anchors.topMargin: 32; + anchors.horizontalCenter: parent.horizontalCenter; + height: connectionButton.height; + width: connectionButton.width; + + Image { + anchors.top: parent.top; + source: "./images/coupon.svg"; + height: 70; + width: parent.width; + fillMode: Image.PreserveAspectFit; + horizontalAlignment: Image.AlignHCenter; + verticalAlignment: Image.AlignTop; + mipmap: true; + } + + RalewaySemiBold { + text: "Create Coupon"; + // Anchors + anchors.bottom: parent.bottom; + height: 15; + width: parent.width; + // Text size + size: 18; + // Style + color: hifi.colors.baseGray; + horizontalAlignment: Text.AlignHCenter; + } + + MouseArea { + anchors.fill: parent; + onClicked: { + sendAssetStep.referrer = "createCoupon"; + sendAssetStep.selectedRecipientNodeID = ""; + couponIDTextField.text = generateRandomCouponID(); + + root.nextActiveView = "sendAssetStep"; + } + } + } + HifiControlsUit.Button { id: backButton_sendAssetHome; visible: parentAppNavBarHeight === 0; @@ -860,7 +928,7 @@ Item { id: sendAssetStep; z: 996; - property string referrer; // either "connections", "nearby", or "payIn" + property string referrer; // either "connections", "nearby", "payIn", or "createCoupon" property string selectedRecipientNodeID; property string selectedRecipientDisplayName; property string selectedRecipientUserName; @@ -872,7 +940,8 @@ Item { RalewaySemiBold { id: sendAssetText_sendAssetStep; - text: sendAssetStep.referrer === "payIn" && root.assetCertID !== "" ? "Send \"" + root.assetName + "\":" : + text: ((sendAssetStep.referrer === "payIn" || sendAssetStep.referrer === "createCoupon") && + root.assetCertID !== "") ? "Send \"" + root.assetName + "\":" : (root.assetCertID === "" ? "Send Money To:" : "Gift \"" + root.assetName + "\" To:"); // Anchors anchors.top: parent.top; @@ -901,12 +970,13 @@ Item { RalewaySemiBold { id: sendToText_sendAssetStep; - text: (root.assetCertID === "" || sendAssetStep.referrer === "payIn") ? "Send to:" : "Gift to:"; + text: sendAssetStep.referrer === "createCoupon" ? "Coupon ID:" : + (root.assetCertID === "" || sendAssetStep.referrer === "payIn") ? "Send to:" : "Gift to:"; // Anchors anchors.top: parent.top; anchors.left: parent.left; anchors.bottom: parent.bottom; - width: 90; + width: paintedWidth; // Text size size: 18; // Style @@ -915,8 +985,10 @@ Item { } RecipientDisplay { + visible: sendAssetStep.referrer !== "createCoupon"; anchors.top: parent.top; anchors.left: sendToText_sendAssetStep.right; + anchors.leftMargin: 16; anchors.right: changeButton.left; anchors.rightMargin: 12; height: parent.height; @@ -929,6 +1001,68 @@ Item { multiLineDisplay: sendAssetStep.referrer === "nearby" || sendAssetStep.referrer === "payIn"; } + Item { + id: couponIDContainer; + visible: sendAssetStep.referrer === "createCoupon"; + anchors.top: parent.top; + anchors.left: sendToText_sendAssetStep.right; + anchors.right: parent.right; + height: parent.height; + + RalewaySemiBold { + id: couponIDHelp; + text: "[?]"; + // Anchors + anchors.left: parent.left; + anchors.leftMargin: 8; + anchors.verticalCenter: parent.verticalCenter; + height: 30; + width: paintedWidth; + // Text size + size: 18; + // Style + color: hifi.colors.blueAccent; + MouseArea { + anchors.fill: parent; + hoverEnabled: true; + onEntered: { + parent.color = hifi.colors.blueHighlight; + } + onExited: { + parent.color = hifi.colors.blueAccent; + } + onClicked: { + lightboxPopup.titleText = "Coupon ID"; + lightboxPopup.bodyText = "This alphanumeric text string will be used to ensure " + + "that only you can redeem the coupon for the asset that you are sending. Keep it private!"; + lightboxPopup.button1text = "CLOSE"; + lightboxPopup.button1method = function() { + lightboxPopup.visible = false; + } + lightboxPopup.visible = true; + } + } + } + + HifiControlsUit.TextField { + id: couponIDTextField; + colorScheme: root.assetCertID === "" ? hifi.colorSchemes.dark : hifi.colorSchemes.light; + // Anchors + anchors.verticalCenter: parent.verticalCenter; + anchors.left: couponIDHelp.right; + anchors.leftMargin: 16; + anchors.right: parent.right; + height: 50; + // Style + activeFocusOnPress: true; + activeFocusOnTab: true; + + onAccepted: { + optionalMessage.focus = true; + } + } + } + // "CHANGE" button HifiControlsUit.Button { id: changeButton; @@ -939,7 +1073,7 @@ Item { height: 35; width: 100; text: "CHANGE"; - visible: sendAssetStep.referrer !== "payIn"; + visible: sendAssetStep.referrer !== "payIn" && sendAssetStep.referrer !== "createCoupon"; onClicked: { if (sendAssetStep.referrer === "connections") { root.nextActiveView = "chooseRecipientConnection"; @@ -1263,6 +1397,11 @@ Item { root.assetCertID, parseInt(amountTextField.text), optionalMessage.text); + } else if (sendAssetStep.referrer === "createCoupon") { + Commerce.authorizeAssetTransfer(couponIDTextField.text || "", + root.assetCertID, + parseInt(amountTextField.text) || 1, + optionalMessage.text) } } } @@ -1334,18 +1473,24 @@ Item { Rectangle { anchors.top: parent.top; - anchors.topMargin: root.assetCertID === "" || sendAssetStep.referrer === "payIn" ? 15 : 125; + anchors.topMargin: root.assetCertID === "" || sendAssetStep.referrer === "payIn" || + sendAssetStep.referrer === "createCoupon" ? 15 : 125; anchors.left: parent.left; - anchors.leftMargin: root.assetCertID === "" || sendAssetStep.referrer === "payIn" ? 15 : 50; + anchors.leftMargin: root.assetCertID === "" || sendAssetStep.referrer === "payIn" || + sendAssetStep.referrer === "createCoupon" ? 15 : 50; anchors.right: parent.right; - anchors.rightMargin: root.assetCertID === "" || sendAssetStep.referrer === "payIn" ? 15 : 50; + anchors.rightMargin: root.assetCertID === "" || sendAssetStep.referrer === "payIn" || + sendAssetStep.referrer === "createCoupon" ? 15 : 50; anchors.bottom: parent.bottom; - anchors.bottomMargin: root.assetCertID === "" || sendAssetStep.referrer === "payIn" ? 15 : 125; + anchors.bottomMargin: root.assetCertID === "" || sendAssetStep.referrer === "payIn" || + sendAssetStep.referrer === "createCoupon" ? 15 : 125; color: "#FFFFFF"; RalewaySemiBold { id: paymentSentText; - text: root.assetCertID === "" ? "Payment Sent" : (sendAssetStep.referrer === "payIn" ? "Item Sent" : "Gift Sent"); + text: root.assetCertID === "" ? (sendAssetStep.referrer === "createCoupon" ? "Payment Authorized" : "Payment Sent") : + (sendAssetStep.referrer === "createCoupon" ? "Item Transfer Authorized" : + (sendAssetStep.referrer === "payIn" ? "Item Sent" : "Gift Sent")); // Anchors anchors.top: parent.top; anchors.topMargin: 26; @@ -1383,6 +1528,8 @@ Item { onClicked: { if (sendAssetStep.referrer === "payIn") { sendToScript({method: "closeSendAsset"}); + } else if (sendAssetStep.referrer === "createCoupon") { + showDidYouCopyLightbox(); } else { root.nextActiveView = "sendAssetHome"; resetSendAssetData(); @@ -1402,38 +1549,176 @@ Item { anchors.leftMargin: 20; anchors.right: parent.right; anchors.rightMargin: 20; - height: 80; + height: childrenRect.height; - RalewaySemiBold { - id: sendToText_paymentSuccess; - text: "Sent To:"; - // Anchors + Item { + id: sendToScriptContainer_paymentSuccess; + visible: sendAssetStep.referrer === "createCoupon"; anchors.top: parent.top; anchors.left: parent.left; - anchors.bottom: parent.bottom; - width: 90; - // Text size - size: 18; - // Style - color: hifi.colors.baseGray; - verticalAlignment: Text.AlignVCenter; - } - - RecipientDisplay { - anchors.top: parent.top; - anchors.left: sendToText_paymentSuccess.right; anchors.right: parent.right; - height: parent.height; - textColor: hifi.colors.blueAccent; + height: childrenRect.height; - displayName: sendAssetStep.selectedRecipientDisplayName; - userName: sendAssetStep.selectedRecipientUserName; - profilePic: sendAssetStep.selectedRecipientProfilePic !== "" ? ((0 === sendAssetStep.selectedRecipientProfilePic.indexOf("http")) ? - sendAssetStep.selectedRecipientProfilePic : (Account.metaverseServerURL + sendAssetStep.selectedRecipientProfilePic)) : ""; - multiLineDisplay: sendAssetStep.referrer === "nearby" || sendAssetStep.referrer === "payIn"; + RalewaySemiBold { + id: authorizationIDLabel; + text: "Authorization ID:"; + // Anchors + anchors.left: parent.left; + anchors.top: authorizationIDText.top; + width: paintedWidth; + // Text size + size: 18; + // Style + color: hifi.colors.baseGray; + verticalAlignment: Text.AlignVCenter; + } + + RalewayRegular { + id: authorizationIDText; + text: root.authorizationID; + anchors.top: parent.top; + anchors.left: authorizationIDLabel.right; + anchors.leftMargin: 16; + anchors.right: authorizationIDClipboardButton.left; + anchors.rightMargin: 16; + // Text size + size: 18; + // Style + color: hifi.colors.baseGray; + horizontalAlignment: Text.AlignHCenter; + verticalAlignment: Text.AlignVCenter; + wrapMode: Text.WrapAnywhere; + } + + Image { + id: authorizationIDClipboardButton; + source: "images/clipboard.svg"; // clipboard by Bieutuong Bon from the Noun Project + fillMode: Image.PreserveAspectFit; + // Anchors + anchors.right: parent.right; + anchors.top: authorizationIDText.top; + height: 40; + width: height; + + MouseArea { + anchors.fill: parent; + onClicked: { + Window.copyToClipboard(root.authorizationID); + authorizationIDText.text = "Copied to Clipboard!\n"; + authorizationIDClipboardTimer.start(); + } + } + } + + Timer { + id: authorizationIDClipboardTimer; + interval: 2000; + repeat: false; + onTriggered: { + authorizationIDText.text = root.authorizationID; + } + } + + RalewaySemiBold { + id: couponIDLabel; + text: "Coupon ID:"; + // Anchors + anchors.left: parent.left; + anchors.top: couponIDText.top; + width: authorizationIDLabel.width; + // Text size + size: 18; + // Style + color: hifi.colors.baseGray; + verticalAlignment: Text.AlignVCenter; + } + + RalewayRegular { + id: couponIDText; + text: root.couponID; + anchors.top: authorizationIDText.bottom; + anchors.topMargin: 16; + anchors.left: couponIDLabel.right; + anchors.leftMargin: 16; + anchors.right: couponIDClipboardButton.left; + anchors.rightMargin: 16; + // Text size + size: 18; + // Style + color: hifi.colors.baseGray; + horizontalAlignment: Text.AlignHCenter; + verticalAlignment: Text.AlignVCenter; + wrapMode: Text.WrapAnywhere; + } + + Image { + id: couponIDClipboardButton; + source: "images/clipboard.svg"; // clipboard by Bieutuong Bon from the Noun Project + fillMode: Image.PreserveAspectFit; + // Anchors + anchors.right: parent.right; + anchors.top: couponIDText.top; + height: 40; + width: height; + + MouseArea { + anchors.fill: parent; + onClicked: { + Window.copyToClipboard(root.couponID); + couponIDText.text = "Copied to Clipboard!\n"; + couponIDClipboardTimer.start(); + } + } + } + + Timer { + id: couponIDClipboardTimer; + interval: 2000; + repeat: false; + onTriggered: { + couponIDText.text = root.couponID; + } + } } - } - + + Item { + id: sendToRecipientContainer_paymentSuccess; + visible: !sendToScriptContainer_paymentSuccess.visible; + anchors.top: parent.top; + anchors.left: parent.left; + anchors.right: parent.right; + height: 80; + + RalewaySemiBold { + id: sendToText_paymentSuccess; + text: "Sent To:"; + // Anchors + anchors.top: parent.top; + anchors.left: parent.left; + anchors.bottom: parent.bottom; + width: 90; + // Text size + size: 18; + // Style + color: hifi.colors.baseGray; + verticalAlignment: Text.AlignVCenter; + } + + RecipientDisplay { + anchors.top: parent.top; + anchors.left: sendToText_paymentSuccess.right; + anchors.right: parent.right; + height: parent.height; + textColor: hifi.colors.blueAccent; + + displayName: sendAssetStep.selectedRecipientDisplayName; + userName: sendAssetStep.selectedRecipientUserName; + profilePic: sendAssetStep.selectedRecipientProfilePic !== "" ? ((0 === sendAssetStep.selectedRecipientProfilePic.indexOf("http")) ? + sendAssetStep.selectedRecipientProfilePic : (Account.metaverseServerURL + sendAssetStep.selectedRecipientProfilePic)) : ""; + multiLineDisplay: sendAssetStep.referrer === "nearby" || sendAssetStep.referrer === "payIn"; + } + } + } Item { id: giftContainer_paymentSuccess; @@ -1448,7 +1733,8 @@ Item { RalewaySemiBold { id: gift_paymentSuccess; - text: sendAssetStep.referrer === "payIn" ? "Item:" : "Gift:"; + text: sendAssetStep.referrer === "payIn" || sendAssetStep.referrer === "createCoupon" ? + "Item:" : "Gift:"; // Anchors anchors.top: parent.top; anchors.left: parent.left; @@ -1566,6 +1852,8 @@ Item { onClicked: { if (sendAssetStep.referrer === "payIn") { sendToScript({method: "closeSendAsset"}); + } else if (sendAssetStep.referrer === "createCoupon") { + showDidYouCopyLightbox(); } else { root.nextActiveView = "sendAssetHome"; resetSendAssetData(); @@ -1599,13 +1887,17 @@ Item { Rectangle { anchors.top: parent.top; - anchors.topMargin: root.assetCertID === "" || sendAssetStep.referrer === "payIn" ? 15 : 150; + anchors.topMargin: root.assetCertID === "" || sendAssetStep.referrer === "payIn" || + sendAssetStep.referrer === "createCoupon" ? 15 : 150; anchors.left: parent.left; - anchors.leftMargin: root.assetCertID === "" || sendAssetStep.referrer === "payIn" ? 15 : 50; + anchors.leftMargin: root.assetCertID === "" || sendAssetStep.referrer === "payIn" || + sendAssetStep.referrer === "createCoupon" ? 15 : 50; anchors.right: parent.right; - anchors.rightMargin: root.assetCertID === "" || sendAssetStep.referrer === "payIn" ? 15 : 50; + anchors.rightMargin: root.assetCertID === "" || sendAssetStep.referrer === "payIn" || + sendAssetStep.referrer === "createCoupon" ? 15 : 50; anchors.bottom: parent.bottom; - anchors.bottomMargin: root.assetCertID === "" || sendAssetStep.referrer === "payIn" ? 15 : 300; + anchors.bottomMargin: root.assetCertID === "" || sendAssetStep.referrer === "payIn" || + sendAssetStep.referrer === "createCoupon" ? 15 : 300; color: "#FFFFFF"; RalewaySemiBold { @@ -1657,8 +1949,9 @@ Item { RalewaySemiBold { id: paymentFailureDetailText; - text: "The recipient you specified was unable to receive your " + - (root.assetCertID === "" ? "payment." : (sendAssetStep.referrer === "payIn" ? "item." : "gift.")); + text: sendAssetStep.referrer === "createCoupon" ? "The server was unable to handle your request. Please try again later." : + ("The recipient you specified was unable to receive your " + + (root.assetCertID === "" ? "payment." : (sendAssetStep.referrer === "payIn" ? "item." : "gift."))); anchors.top: paymentFailureText.bottom; anchors.topMargin: 20; anchors.left: parent.left; @@ -1676,7 +1969,8 @@ Item { Item { id: sendToContainer_paymentFailure; - visible: root.assetCertID === "" || sendAssetStep.referrer === "payIn"; + visible: (root.assetCertID === "" || sendAssetStep.referrer === "payIn") && + sendAssetStep.referrer !== "createCoupon"; anchors.top: paymentFailureDetailText.bottom; anchors.topMargin: 8; anchors.left: parent.left; @@ -1718,7 +2012,8 @@ Item { Item { id: amountContainer_paymentFailure; visible: root.assetCertID === ""; - anchors.top: sendToContainer_paymentFailure.bottom; + anchors.top: sendToContainer_paymentFailure.visible ? + sendToContainer_paymentFailure.bottom : paymentFailureDetailText.bottom; anchors.topMargin: 16; anchors.left: parent.left; anchors.leftMargin: 20; @@ -1839,6 +2134,11 @@ Item { root.assetCertID, parseInt(amountTextField.text), optionalMessage.text); + } else if (sendAssetStep.referrer === "createCoupon") { + Commerce.authorizeAssetTransfer(couponIDTextField.text || "", + root.assetCertID, + parseInt(amountTextField.text) || 1, + optionalMessage.text) } } } @@ -1867,6 +2167,39 @@ Item { sendAssetStep.referrer = ""; } + function generateRandomCouponID() { + var RANDOM_COUPON_ID_LENGTH = 25; + var randomCouponID = ""; + var possibleCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + + for (var i = 0; i < RANDOM_COUPON_ID_LENGTH; i++) { + randomCouponID += possibleCharacters.charAt(Math.floor(Math.random() * possibleCharacters.length)); + } + + return randomCouponID; + } + + function showDidYouCopyLightbox() { + lightboxPopup.titleText = "Close Confirmation"; + lightboxPopup.bodyText = "Did you copy your Authorization ID and your Coupon ID?\n\n" + + "You won't be able to see your Authorization ID or your Coupon ID once " + + "you close this window."; + lightboxPopup.button1text = "GO BACK"; + lightboxPopup.button1method = function() { + lightboxPopup.visible = false; + } + lightboxPopup.button2text = "I'M ALL SET"; + lightboxPopup.button2method = function() { + lightboxPopup.visible = false; + root.nextActiveView = "sendAssetHome"; + resetSendAssetData(); + if (root.assetName !== "") { + sendSignalToParent({method: "closeSendAsset"}); + } + } + lightboxPopup.visible = true; + } + // // Function Name: fromScript() // @@ -1908,9 +2241,15 @@ Item { sendAssetStep.referrer = "payIn"; sendAssetStep.selectedRecipientNodeID = ""; sendAssetStep.selectedRecipientDisplayName = "Determined by script:"; - sendAssetStep.selectedRecipientUserName = message.username; + sendAssetStep.selectedRecipientUserName = message.username || ""; optionalMessage.text = message.message || "No Message Provided"; + if (sendAssetStep.selectedRecipientUserName === "") { + console.log("SendAsset: Script didn't specify a recipient username!"); + sendAssetHome.visible = false; + return; + } + root.nextActiveView = "sendAssetStep"; break; case 'inspectionCertificate_resetCert': diff --git a/interface/resources/qml/hifi/commerce/common/sendAsset/images/clipboard.svg b/interface/resources/qml/hifi/commerce/common/sendAsset/images/clipboard.svg new file mode 100644 index 0000000000..798fdaaab1 --- /dev/null +++ b/interface/resources/qml/hifi/commerce/common/sendAsset/images/clipboard.svg @@ -0,0 +1 @@ +Created by Bieutuong Bonfrom the Noun Project \ No newline at end of file diff --git a/interface/resources/qml/hifi/commerce/common/sendAsset/images/coupon.svg b/interface/resources/qml/hifi/commerce/common/sendAsset/images/coupon.svg new file mode 100644 index 0000000000..2b7c052589 --- /dev/null +++ b/interface/resources/qml/hifi/commerce/common/sendAsset/images/coupon.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/interface/resources/qml/hifi/commerce/wallet/WalletHome.qml b/interface/resources/qml/hifi/commerce/wallet/WalletHome.qml index 4c8e1e6ca5..cf293a06df 100644 --- a/interface/resources/qml/hifi/commerce/wallet/WalletHome.qml +++ b/interface/resources/qml/hifi/commerce/wallet/WalletHome.qml @@ -270,9 +270,11 @@ Item { model: transactionHistoryModel; delegate: Item { width: parent.width; - height: (model.transaction_type === "pendingCount" && model.count !== 0) ? 40 : ((model.status === "confirmed" || model.status === "invalidated") ? transactionText.height + 30 : 0); + height: (model.transaction_type === "pendingCount" && model.count !== 0) ? 40 : + (transactionContainer.visible ? transactionText.height + 30 : 0); Item { + id: pendingCountContainer; visible: model.transaction_type === "pendingCount" && model.count !== 0; anchors.top: parent.top; anchors.left: parent.left; @@ -291,7 +293,9 @@ Item { } Item { - visible: model.transaction_type !== "pendingCount" && (model.status === "confirmed" || model.status === "invalidated"); + id: transactionContainer; + visible: model.transaction_type !== "pendingCount" && + (model.status === "confirmed" || model.status === "invalidated"); anchors.top: parent.top; anchors.left: parent.left; width: parent.width; diff --git a/interface/resources/qml/hifi/tablet/TabletHome.qml b/interface/resources/qml/hifi/tablet/TabletHome.qml index 1b0165ea94..4d7883522e 100644 --- a/interface/resources/qml/hifi/tablet/TabletHome.qml +++ b/interface/resources/qml/hifi/tablet/TabletHome.qml @@ -115,9 +115,9 @@ Item { property int previousIndex: -1 Repeater { id: pageRepeater - model: Math.ceil(tabletProxy.buttons.rowCount() / TabletEnums.ButtonsOnPage) + model: tabletProxy != null ? Math.ceil(tabletProxy.buttons.rowCount() / TabletEnums.ButtonsOnPage) : 0 onItemAdded: { - item.proxyModel.sourceModel = tabletProxy.buttons; + item.proxyModel.sourceModel = tabletProxy != null ? tabletProxy.buttons : null; item.proxyModel.pageIndex = index; } diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 8e46b0b426..0b53e24a8e 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -6504,11 +6504,16 @@ void Application::resetSensors(bool andReload) { } void Application::hmdVisibleChanged(bool visible) { + // TODO + // calling start and stop will change audio input and ouput to default audio devices. + // we need to add a pause/unpause functionality to AudioClient for this to work properly +#if 0 if (visible) { QMetaObject::invokeMethod(DependencyManager::get().data(), "start", Qt::QueuedConnection); } else { QMetaObject::invokeMethod(DependencyManager::get().data(), "stop", Qt::QueuedConnection); } +#endif } void Application::updateWindowTitle() const { diff --git a/interface/src/AvatarBookmarks.cpp b/interface/src/AvatarBookmarks.cpp index 099171a427..ee639f602d 100644 --- a/interface/src/AvatarBookmarks.cpp +++ b/interface/src/AvatarBookmarks.cpp @@ -58,7 +58,7 @@ void addAvatarEntities(const QVariantList& avatarEntities) { EntityItemPropertiesFromScriptValueHonorReadOnly(scriptProperties, entityProperties); entityProperties.setParentID(myNodeID); - entityProperties.setClientOnly(true); + entityProperties.setEntityHostType(entity::HostType::AVATAR); entityProperties.setOwningAvatarID(myNodeID); entityProperties.setSimulationOwner(myNodeID, AVATAR_ENTITY_SIMULATION_PRIORITY); entityProperties.markAllChanged(); diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 7196aa1a2c..97014550a8 100755 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -807,46 +807,6 @@ void MyAvatar::simulate(float deltaTime) { // before we perform rig animations and IK. updateSensorToWorldMatrix(); - // if we detect the hand controller is at rest, i.e. lying on the table, or the hand is too far away from the hmd - // disable the associated hand controller input. - { - // NOTE: all poses are in sensor space. - auto leftHandIter = _controllerPoseMap.find(controller::Action::LEFT_HAND); - if (leftHandIter != _controllerPoseMap.end() && leftHandIter->second.isValid()) { - _leftHandAtRestDetector.update(leftHandIter->second.getTranslation(), leftHandIter->second.getRotation()); - if (_leftHandAtRestDetector.isAtRest()) { - leftHandIter->second.valid = false; - } - } else { - _leftHandAtRestDetector.invalidate(); - } - - auto rightHandIter = _controllerPoseMap.find(controller::Action::RIGHT_HAND); - if (rightHandIter != _controllerPoseMap.end() && rightHandIter->second.isValid()) { - _rightHandAtRestDetector.update(rightHandIter->second.getTranslation(), rightHandIter->second.getRotation()); - if (_rightHandAtRestDetector.isAtRest()) { - rightHandIter->second.valid = false; - } - } else { - _rightHandAtRestDetector.invalidate(); - } - - auto headIter = _controllerPoseMap.find(controller::Action::HEAD); - - // The 99th percentile man has a spine to fingertip to height ratio of 0.45. Lets increase that by about 10% to 0.5 - // then measure the distance the center of the eyes to the finger tips. To come up with this ratio. - // From "The Measure of Man and Woman: Human Factors in Design, Revised Edition" by Alvin R. Tilley, Henry Dreyfuss Associates - const float MAX_HEAD_TO_HAND_DISTANCE_RATIO = 0.52f; - - float maxHeadHandDistance = getUserHeight() * MAX_HEAD_TO_HAND_DISTANCE_RATIO; - if (glm::length(headIter->second.getTranslation() - leftHandIter->second.getTranslation()) > maxHeadHandDistance) { - leftHandIter->second.valid = false; - } - if (glm::length(headIter->second.getTranslation() - rightHandIter->second.getTranslation()) > maxHeadHandDistance) { - rightHandIter->second.valid = false; - } - } - { PerformanceTimer perfTimer("skeleton"); @@ -927,8 +887,7 @@ void MyAvatar::simulate(float deltaTime) { moveOperator.addEntityToMoveList(entity, newCube); } // send an edit packet to update the entity-server about the queryAABox - // unless it is client-only - if (packetSender && !entity->getClientOnly()) { + if (packetSender && entity->isDomainEntity()) { EntityItemProperties properties = entity->getProperties(); properties.setQueryAACubeDirty(); properties.setLastEdited(now); @@ -939,7 +898,7 @@ void MyAvatar::simulate(float deltaTime) { entity->forEachDescendant([&](SpatiallyNestablePointer descendant) { EntityItemPointer entityDescendant = std::dynamic_pointer_cast(descendant); - if (entityDescendant && !entityDescendant->getClientOnly() && descendant->updateQueryAACube()) { + if (entityDescendant && entityDescendant->isDomainEntity() && descendant->updateQueryAACube()) { EntityItemProperties descendantProperties; descendantProperties.setQueryAACube(descendant->getQueryAACube()); descendantProperties.setLastEdited(now); diff --git a/interface/src/commerce/Ledger.cpp b/interface/src/commerce/Ledger.cpp index b10c9647a0..d72d896638 100644 --- a/interface/src/commerce/Ledger.cpp +++ b/interface/src/commerce/Ledger.cpp @@ -63,6 +63,7 @@ Handler(balance) Handler(inventory) Handler(transferAssetToNode) Handler(transferAssetToUsername) +Handler(authorizeAssetTransfer) Handler(alreadyOwned) Handler(availableUpdates) Handler(updateItem) @@ -203,6 +204,7 @@ QString transactionString(const QJsonObject& valueObject) { int sentMoney = valueObject["sent_money"].toInt(); int receivedMoney = valueObject["received_money"].toInt(); int dateInteger = valueObject["created_at"].toInt(); + QString transactionType = valueObject["transaction_type"].toString(); QString message = valueObject["message"].toString(); QDateTime createdAt(QDateTime::fromSecsSinceEpoch(dateInteger, Qt::UTC)); QString result; @@ -210,8 +212,12 @@ QString transactionString(const QJsonObject& valueObject) { if (sentCerts <= 0 && receivedCerts <= 0 && !KNOWN_USERS.contains(valueObject["sender_name"].toString())) { // this is an hfc transfer. if (sentMoney > 0) { - QString recipient = userLink(valueObject["recipient_name"].toString(), valueObject["place_name"].toString()); - result += QString("Money sent to %1").arg(recipient); + if (transactionType == "escrow") { + result += QString("Money transferred to coupon"); + } else { + QString recipient = userLink(valueObject["recipient_name"].toString(), valueObject["place_name"].toString()); + result += QString("Money sent to %1").arg(recipient); + } } else { QString sender = userLink(valueObject["sender_name"].toString(), valueObject["place_name"].toString()); result += QString("Money from %1").arg(sender); @@ -226,8 +232,12 @@ QString transactionString(const QJsonObject& valueObject) { ) { // this is a non-HFC asset transfer. if (sentCerts > 0) { - QString recipient = userLink(valueObject["recipient_name"].toString(), valueObject["place_name"].toString()); - result += QString("Gift sent to %1").arg(recipient); + if (transactionType == "escrow") { + result += QString("Item transferred to coupon"); + } else { + QString recipient = userLink(valueObject["recipient_name"].toString(), valueObject["place_name"].toString()); + result += QString("Gift sent to %1").arg(recipient); + } } else { QString sender = userLink(valueObject["sender_name"].toString(), valueObject["place_name"].toString()); result += QString("Gift from %1").arg(sender); @@ -428,6 +438,7 @@ void Ledger::transferAssetToUsername(const QString& hfc_key, const QString& user transaction["username"] = username; transaction["quantity"] = amount; transaction["message"] = optionalMessage; + transaction["place_name"] = DependencyManager::get()->getPlaceName(); if (!certificateID.isEmpty()) { transaction["certificate_id"] = certificateID; } @@ -440,6 +451,20 @@ void Ledger::transferAssetToUsername(const QString& hfc_key, const QString& user } } +void Ledger::authorizeAssetTransfer(const QString& hfc_key, const QString& couponID, const QString& certificateID, const int& amount, const QString& optionalMessage) { + QJsonObject transaction; + transaction["public_key"] = hfc_key; + transaction["coupon_id"] = couponID; + transaction["quantity"] = amount; + transaction["message"] = optionalMessage; + if (!certificateID.isEmpty()) { + transaction["certificate_id"] = certificateID; + } + QJsonDocument transactionDoc{ transaction }; + auto transactionString = transactionDoc.toJson(QJsonDocument::Compact); + signedSend("transaction", transactionString, hfc_key, "authorize", "authorizeAssetTransferSuccess", "authorizeAssetTransferFailure"); +} + void Ledger::alreadyOwned(const QString& marketplaceId) { auto wallet = DependencyManager::get(); QString endpoint = "already_owned"; diff --git a/interface/src/commerce/Ledger.h b/interface/src/commerce/Ledger.h index 715d6337ad..2e18f34c8d 100644 --- a/interface/src/commerce/Ledger.h +++ b/interface/src/commerce/Ledger.h @@ -36,6 +36,7 @@ public: void certificateInfo(const QString& certificateId); void transferAssetToNode(const QString& hfc_key, const QString& nodeID, const QString& certificateID, const int& amount, const QString& optionalMessage); void transferAssetToUsername(const QString& hfc_key, const QString& username, const QString& certificateID, const int& amount, const QString& optionalMessage); + void authorizeAssetTransfer(const QString& hfc_key, const QString& couponID, const QString& certificateID, const int& amount, const QString& optionalMessage); void alreadyOwned(const QString& marketplaceId); void getAvailableUpdates(const QString& itemId = "", const int& pageNumber = 1, const int& itemsPerPage = 10); void updateItem(const QString& hfc_key, const QString& certificate_id); @@ -59,6 +60,7 @@ signals: void certificateInfoResult(QJsonObject result); void transferAssetToNodeResult(QJsonObject result); void transferAssetToUsernameResult(QJsonObject result); + void authorizeAssetTransferResult(QJsonObject result); void alreadyOwnedResult(QJsonObject result); void availableUpdatesResult(QJsonObject result); void updateItemResult(QJsonObject result); @@ -86,6 +88,8 @@ public slots: void transferAssetToNodeFailure(QNetworkReply* reply); void transferAssetToUsernameSuccess(QNetworkReply* reply); void transferAssetToUsernameFailure(QNetworkReply* reply); + void authorizeAssetTransferSuccess(QNetworkReply* reply); + void authorizeAssetTransferFailure(QNetworkReply* reply); void alreadyOwnedSuccess(QNetworkReply* reply); void alreadyOwnedFailure(QNetworkReply* reply); void availableUpdatesSuccess(QNetworkReply* reply); diff --git a/interface/src/commerce/QmlCommerce.cpp b/interface/src/commerce/QmlCommerce.cpp index 566f7ba324..00acd40e70 100644 --- a/interface/src/commerce/QmlCommerce.cpp +++ b/interface/src/commerce/QmlCommerce.cpp @@ -38,6 +38,7 @@ QmlCommerce::QmlCommerce() { connect(ledger.data(), &Ledger::updateCertificateStatus, this, &QmlCommerce::updateCertificateStatus); connect(ledger.data(), &Ledger::transferAssetToNodeResult, this, &QmlCommerce::transferAssetToNodeResult); connect(ledger.data(), &Ledger::transferAssetToUsernameResult, this, &QmlCommerce::transferAssetToUsernameResult); + connect(ledger.data(), &Ledger::authorizeAssetTransferResult, this, &QmlCommerce::authorizeAssetTransferResult); connect(ledger.data(), &Ledger::availableUpdatesResult, this, &QmlCommerce::availableUpdatesResult); connect(ledger.data(), &Ledger::updateItemResult, this, &QmlCommerce::updateItemResult); @@ -246,6 +247,21 @@ void QmlCommerce::transferAssetToUsername(const QString& username, ledger->transferAssetToUsername(key, username, certificateID, amount, optionalMessage); } +void QmlCommerce::authorizeAssetTransfer(const QString& couponID, + const QString& certificateID, + const int& amount, + const QString& optionalMessage) { + auto ledger = DependencyManager::get(); + auto wallet = DependencyManager::get(); + QStringList keys = wallet->listPublicKeys(); + if (keys.count() == 0) { + QJsonObject result{ { "status", "fail" }, { "message", "Uninitialized Wallet." } }; + return emit authorizeAssetTransferResult(result); + } + QString key = keys[0]; + ledger->authorizeAssetTransfer(key, couponID, certificateID, amount, optionalMessage); +} + void QmlCommerce::replaceContentSet(const QString& itemHref, const QString& certificateID) { if (!certificateID.isEmpty()) { auto ledger = DependencyManager::get(); diff --git a/interface/src/commerce/QmlCommerce.h b/interface/src/commerce/QmlCommerce.h index c5fbdaf4a4..ad21899ebf 100644 --- a/interface/src/commerce/QmlCommerce.h +++ b/interface/src/commerce/QmlCommerce.h @@ -51,6 +51,7 @@ signals: void transferAssetToNodeResult(QJsonObject result); void transferAssetToUsernameResult(QJsonObject result); + void authorizeAssetTransferResult(QJsonObject result); void contentSetChanged(const QString& contentSetHref); @@ -84,6 +85,7 @@ protected: Q_INVOKABLE void transferAssetToNode(const QString& nodeID, const QString& certificateID, const int& amount, const QString& optionalMessage); Q_INVOKABLE void transferAssetToUsername(const QString& username, const QString& certificateID, const int& amount, const QString& optionalMessage); + Q_INVOKABLE void authorizeAssetTransfer(const QString& couponID, const QString& certificateID, const int& amount, const QString& optionalMessage); Q_INVOKABLE void replaceContentSet(const QString& itemHref, const QString& certificateID); diff --git a/interface/src/scripting/WalletScriptingInterface.cpp b/interface/src/scripting/WalletScriptingInterface.cpp index 93ee60ba5b..60f850adac 100644 --- a/interface/src/scripting/WalletScriptingInterface.cpp +++ b/interface/src/scripting/WalletScriptingInterface.cpp @@ -35,7 +35,7 @@ void WalletScriptingInterface::proveAvatarEntityOwnershipVerification(const QUui QSharedPointer contextOverlayInterface = DependencyManager::get(); EntityItemProperties entityProperties = DependencyManager::get()->getEntityProperties(entityID, contextOverlayInterface->getEntityPropertyFlags()); - if (entityProperties.getClientOnly()) { + if (entityProperties.getEntityHostType() == entity::HostType::AVATAR) { if (!entityID.isNull() && entityProperties.getCertificateID().length() > 0) { contextOverlayInterface->requestOwnershipVerification(entityID); } else { diff --git a/interface/src/ui/overlays/ContextOverlayInterface.cpp b/interface/src/ui/overlays/ContextOverlayInterface.cpp index e8dc022fd9..aecfdba3b8 100644 --- a/interface/src/ui/overlays/ContextOverlayInterface.cpp +++ b/interface/src/ui/overlays/ContextOverlayInterface.cpp @@ -46,7 +46,7 @@ ContextOverlayInterface::ContextOverlayInterface() { _entityPropertyFlags += PROP_DIMENSIONS; _entityPropertyFlags += PROP_REGISTRATION_POINT; _entityPropertyFlags += PROP_CERTIFICATE_ID; - _entityPropertyFlags += PROP_CLIENT_ONLY; + _entityPropertyFlags += PROP_ENTITY_HOST_TYPE; _entityPropertyFlags += PROP_OWNING_AVATAR_ID; auto entityScriptingInterface = DependencyManager::get().data(); @@ -296,7 +296,7 @@ void ContextOverlayInterface::requestOwnershipVerification(const QUuid& entityID auto nodeList = DependencyManager::get(); if (entityProperties.verifyStaticCertificateProperties()) { - if (entityProperties.getClientOnly()) { + if (entityProperties.getEntityHostType() == entity::HostType::AVATAR) { SharedNodePointer entityServer = nodeList->soloNodeOfType(NodeType::EntityServer); if (entityServer) { diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp index fceb146470..b4ea9c20f9 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp @@ -310,7 +310,7 @@ void Avatar::updateAvatarEntities() { PerformanceTimer perfTimer("attachments"); // AVATAR ENTITY UPDATE FLOW - // - if queueEditEntityMessage sees clientOnly flag it does _myAvatar->updateAvatarEntity() + // - if queueEditEntityMessage sees avatarEntity flag it does _myAvatar->updateAvatarEntity() // - updateAvatarEntity saves the bytes and flags the trait instance for the entity as updated // - ClientTraitsHandler::sendChangedTraitsToMixer sends the entity bytes to the mixer which relays them to other interfaces // - AvatarHashMap::processBulkAvatarTraits on other interfaces calls avatar->processTraitInstace @@ -389,7 +389,7 @@ void Avatar::updateAvatarEntities() { QScriptValue scriptProperties = variantMapToScriptValue(asMap, scriptEngine); EntityItemProperties properties; EntityItemPropertiesFromScriptValueHonorReadOnly(scriptProperties, properties); - properties.setClientOnly(true); + properties.setEntityHostType(entity::HostType::AVATAR); properties.setOwningAvatarID(getID()); // there's no entity-server to tell us we're the simulation owner, so always set the diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index d9d4b57c31..92fa21758d 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -2103,8 +2103,9 @@ void AvatarData::setJointMappingsFromNetworkReply() { // before we process this update, make sure that the skeleton model URL hasn't changed // since we made the FST request - if (networkReply->url() != _skeletonModelURL) { + if (networkReply->error() != QNetworkReply::NoError || networkReply->url() != _skeletonModelURL) { qCDebug(avatars) << "Refusing to set joint mappings for FST URL that does not match the current URL"; + networkReply->deleteLater(); return; } @@ -2832,35 +2833,47 @@ void AvatarData::setAvatarEntityData(const AvatarEntityMap& avatarEntityData) { qCDebug(avatars) << "discard suspect AvatarEntityData with size =" << avatarEntityData.size(); return; } + + std::vector deletedEntityIDs; + QList updatedEntityIDs; + _avatarEntitiesLock.withWriteLock([&] { if (_avatarEntityData != avatarEntityData) { + // keep track of entities that were attached to this avatar but no longer are AvatarEntityIDs previousAvatarEntityIDs = QSet::fromList(_avatarEntityData.keys()); _avatarEntityData = avatarEntityData; setAvatarEntityDataChanged(true); + deletedEntityIDs.reserve(previousAvatarEntityIDs.size()); + foreach (auto entityID, previousAvatarEntityIDs) { if (!_avatarEntityData.contains(entityID)) { _avatarEntityDetached.insert(entityID); - - if (_clientTraitsHandler) { - // we have a client traits handler, so we flag this removed entity as deleted - // so that changes are sent next frame - _clientTraitsHandler->markInstancedTraitDeleted(AvatarTraits::AvatarEntity, entityID); - } + deletedEntityIDs.push_back(entityID); } } - if (_clientTraitsHandler) { - // if we have a client traits handler, flag any updated or created entities - // so that we send changes for them next frame - foreach (auto entityID, _avatarEntityData.keys()) { - _clientTraitsHandler->markInstancedTraitUpdated(AvatarTraits::AvatarEntity, entityID); - } - } + updatedEntityIDs = _avatarEntityData.keys(); } }); + + if (_clientTraitsHandler) { + // we have a client traits handler + + // flag removed entities as deleted so that changes are sent next frame + for (auto& deletedEntityID : deletedEntityIDs) { + _clientTraitsHandler->markInstancedTraitDeleted(AvatarTraits::AvatarEntity, deletedEntityID); + } + + // flag any updated or created entities so that we send changes for them next frame + for (auto& entityID : updatedEntityIDs) { + _clientTraitsHandler->markInstancedTraitUpdated(AvatarTraits::AvatarEntity, entityID); + } + } + + } AvatarEntityIDs AvatarData::getAndClearRecentlyDetachedIDs() { diff --git a/libraries/avatars/src/ClientTraitsHandler.cpp b/libraries/avatars/src/ClientTraitsHandler.cpp index a301341a8e..cbc8e93745 100644 --- a/libraries/avatars/src/ClientTraitsHandler.cpp +++ b/libraries/avatars/src/ClientTraitsHandler.cpp @@ -66,7 +66,7 @@ void ClientTraitsHandler::resetForNewMixer() { } void ClientTraitsHandler::sendChangedTraitsToMixer() { - Lock lock(_traitLock); + std::unique_lock lock(_traitLock); if (hasChangedTraits() || _shouldPerformInitialSend) { // we have at least one changed trait to send @@ -90,6 +90,14 @@ void ClientTraitsHandler::sendChangedTraitsToMixer() { _traitStatuses.reset(); _hasChangedTraits = false; + // if this was an initial send of all traits, consider it completed + bool initialSend = _shouldPerformInitialSend; + _shouldPerformInitialSend = false; + + // we can release the lock here since we've taken a copy of statuses + // and will setup the packet using the information in the copy + lock.unlock(); + auto simpleIt = traitStatusesCopy.simpleCBegin(); while (simpleIt != traitStatusesCopy.simpleCEnd()) { // because the vector contains all trait types (for access using trait type as index) @@ -111,12 +119,12 @@ void ClientTraitsHandler::sendChangedTraitsToMixer() { auto instancedIt = traitStatusesCopy.instancedCBegin(); while (instancedIt != traitStatusesCopy.instancedCEnd()) { for (auto& instanceIDValuePair : instancedIt->instances) { - if ((_shouldPerformInitialSend && instanceIDValuePair.value != Deleted) + if ((initialSend && instanceIDValuePair.value != Deleted) || instanceIDValuePair.value == Updated) { // this is a changed trait we need to send or we haven't send out trait information yet // ask the owning avatar to pack it _owningAvatar->packTraitInstance(instancedIt->traitType, instanceIDValuePair.id, *traitsPacketList); - } else if (!_shouldPerformInitialSend && instanceIDValuePair.value == Deleted) { + } else if (!initialSend && instanceIDValuePair.value == Deleted) { // pack delete for this trait instance AvatarTraits::packInstancedTraitDelete(instancedIt->traitType, instanceIDValuePair.id, *traitsPacketList); @@ -127,9 +135,6 @@ void ClientTraitsHandler::sendChangedTraitsToMixer() { } nodeList->sendPacketList(std::move(traitsPacketList), *avatarMixer); - - // if this was an initial send of all traits, consider it completed - _shouldPerformInitialSend = false; } } diff --git a/libraries/display-plugins/src/display-plugins/InterleavedSrgbToLinear.slf b/libraries/display-plugins/src/display-plugins/InterleavedSrgbToLinear.slf index e70053dcd9..66acff616c 100644 --- a/libraries/display-plugins/src/display-plugins/InterleavedSrgbToLinear.slf +++ b/libraries/display-plugins/src/display-plugins/InterleavedSrgbToLinear.slf @@ -14,8 +14,6 @@ void main(void) { ivec2 texCoord = ivec2(floor(varTexCoord0 * vec2(textureData.textureSize))); texCoord.x /= 2; int row = int(floor(gl_FragCoord.y)); - if (row % 2 > 0) { - texCoord.x += (textureData.textureSize.x / 2); - } + texCoord.x += int(row % 2 > 0) * (textureData.textureSize.x / 2); outFragColor = vec4(pow(texelFetch(colorMap, texCoord, 0).rgb, vec3(2.2)), 1.0); } diff --git a/libraries/display-plugins/src/display-plugins/SrgbToLinear.slf b/libraries/display-plugins/src/display-plugins/SrgbToLinear.slf index aad9e71e0e..8b324c81a5 100644 --- a/libraries/display-plugins/src/display-plugins/SrgbToLinear.slf +++ b/libraries/display-plugins/src/display-plugins/SrgbToLinear.slf @@ -9,7 +9,7 @@ layout(location=0) out vec4 outFragColor; float sRGBFloatToLinear(float value) { const float SRGB_ELBOW = 0.04045; - return (value <= SRGB_ELBOW) ? value / 12.92 : pow((value + 0.055) / 1.055, 2.4); + return mix(pow((value + 0.055) / 1.055, 2.4), value / 12.92, float(value <= SRGB_ELBOW)); } vec3 colorToLinearRGB(vec3 srgb) { diff --git a/libraries/entities-renderer/src/RenderableEntityItem.cpp b/libraries/entities-renderer/src/RenderableEntityItem.cpp index aa335bb7d5..75d06191ea 100644 --- a/libraries/entities-renderer/src/RenderableEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableEntityItem.cpp @@ -39,7 +39,7 @@ enum class RenderItemStatusIcon { SIMULATION_OWNER = 3, HAS_ACTIONS = 4, OTHER_SIMULATION_OWNER = 5, - CLIENT_ONLY = 6, + ENTITY_HOST_TYPE = 6, NONE = 255 }; @@ -115,17 +115,20 @@ void EntityRenderer::makeStatusGetters(const EntityItemPointer& entity, Item::St }); statusGetters.push_back([entity, myNodeID] () -> render::Item::Status::Value { - if (entity->getClientOnly()) { + if (entity->isAvatarEntity()) { if (entity->getOwningAvatarID() == myNodeID) { return render::Item::Status::Value(1.0f, render::Item::Status::Value::GREEN, - (unsigned char)RenderItemStatusIcon::CLIENT_ONLY); + (unsigned char)RenderItemStatusIcon::ENTITY_HOST_TYPE); } else { return render::Item::Status::Value(1.0f, render::Item::Status::Value::RED, - (unsigned char)RenderItemStatusIcon::CLIENT_ONLY); + (unsigned char)RenderItemStatusIcon::ENTITY_HOST_TYPE); } + } else if (entity->isLocalEntity()) { + return render::Item::Status::Value(1.0f, render::Item::Status::Value::BLUE, + (unsigned char)RenderItemStatusIcon::ENTITY_HOST_TYPE); } return render::Item::Status::Value(0.0f, render::Item::Status::Value::GREEN, - (unsigned char)RenderItemStatusIcon::CLIENT_ONLY); + (unsigned char)RenderItemStatusIcon::ENTITY_HOST_TYPE); }); } diff --git a/libraries/entities-renderer/src/RenderableMaterialEntityItem.cpp b/libraries/entities-renderer/src/RenderableMaterialEntityItem.cpp index c607f678b6..6451e873c9 100644 --- a/libraries/entities-renderer/src/RenderableMaterialEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableMaterialEntityItem.cpp @@ -126,7 +126,7 @@ void MaterialEntityRenderer::doRender(RenderArgs* args) { batch.setModelTransform(renderTransform); if (args->_renderMode != render::Args::RenderMode::SHADOW_RENDER_MODE) { - drawMaterial->setTextureTransforms(textureTransform); + drawMaterial->setTextureTransforms(textureTransform, MaterialMappingMode::UV, true); // bind the material RenderPipelines::bindMaterial(drawMaterial, batch, args->_enableTexturing); diff --git a/libraries/entities-renderer/src/textured_particle.slv b/libraries/entities-renderer/src/textured_particle.slv index 4d17fe132b..98d25eae2e 100644 --- a/libraries/entities-renderer/src/textured_particle.slv +++ b/libraries/entities-renderer/src/textured_particle.slv @@ -80,10 +80,11 @@ float interpolate3Points(float y1, float y2, float y3, float u) { halfSlope = (y3 - y1) / 2.0f; float slope12 = y2 - y1; float slope23 = y3 - y2; - if (abs(halfSlope) > abs(slope12)) { - halfSlope = slope12; - } else if (abs(halfSlope) > abs(slope23)) { - halfSlope = slope23; + + { + float check = float(abs(halfSlope) > abs(slope12)); + halfSlope = mix(halfSlope, slope12, check); + halfSlope = mix(halfSlope, slope23, (1.0 - check) * float(abs(halfSlope) > abs(slope23))); } } diff --git a/libraries/entities/src/EntityEditPacketSender.cpp b/libraries/entities/src/EntityEditPacketSender.cpp index 4aa66db227..c414a7a4ac 100644 --- a/libraries/entities/src/EntityEditPacketSender.cpp +++ b/libraries/entities/src/EntityEditPacketSender.cpp @@ -84,16 +84,19 @@ void EntityEditPacketSender::queueEditEntityMessage(PacketType type, EntityTreePointer entityTree, EntityItemID entityItemID, const EntityItemProperties& properties) { - if (properties.getClientOnly()) { + if (properties.getEntityHostType() == entity::HostType::AVATAR) { if (!_myAvatar) { - qCWarning(entities) << "Suppressing entity edit message: cannot send clientOnly edit with no myAvatar"; + qCWarning(entities) << "Suppressing entity edit message: cannot send avatar entity edit with no myAvatar"; } else if (properties.getOwningAvatarID() == _myAvatar->getID()) { // this is an avatar-based entity --> update our avatar-data rather than sending to the entity-server queueEditAvatarEntityMessage(type, entityTree, entityItemID, properties); } else { - qCWarning(entities) << "Suppressing entity edit message: cannot send clientOnly edit for another avatar"; + qCWarning(entities) << "Suppressing entity edit message: cannot send avatar entity edit for another avatar"; } return; + } else if (properties.getEntityHostType() == entity::HostType::LOCAL) { + // Don't send edits for local entities + return; } if (entityTree && entityTree->isServerlessMode()) { diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 36ffc68fd3..5855306994 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -119,7 +119,7 @@ EntityPropertyFlags EntityItem::getEntityProperties(EncodeBitstreamParams& param requestedProperties += PROP_PARENT_JOINT_INDEX; requestedProperties += PROP_QUERY_AA_CUBE; - requestedProperties += PROP_CLIENT_ONLY; + requestedProperties += PROP_ENTITY_HOST_TYPE; requestedProperties += PROP_OWNING_AVATAR_ID; requestedProperties += PROP_LAST_EDITED_BY; @@ -172,7 +172,7 @@ OctreeElement::AppendState EntityItem::appendEntityData(OctreePacketData* packet EntityPropertyFlags propertyFlags(PROP_LAST_ITEM); EntityPropertyFlags requestedProperties = getEntityProperties(params); - requestedProperties -= PROP_CLIENT_ONLY; + requestedProperties -= PROP_ENTITY_HOST_TYPE; requestedProperties -= PROP_OWNING_AVATAR_ID; // If we are being called for a subsequent pass at appendEntityData() that failed to completely encode this item, @@ -1278,10 +1278,7 @@ EntityItemProperties EntityItem::getProperties(const EntityPropertyFlags& desire EntityItemProperties properties(propertyFlags); properties._id = getID(); properties._idSet = true; - properties._created = getCreated(); properties._lastEdited = getLastEdited(); - properties.setClientOnly(getClientOnly()); - properties.setOwningAvatarID(getOwningAvatarID()); properties._type = getType(); @@ -1337,7 +1334,7 @@ EntityItemProperties EntityItem::getProperties(const EntityPropertyFlags& desire COPY_ENTITY_PROPERTY_TO_PROPERTIES(localPosition, getLocalPosition); COPY_ENTITY_PROPERTY_TO_PROPERTIES(localRotation, getLocalOrientation); - COPY_ENTITY_PROPERTY_TO_PROPERTIES(clientOnly, getClientOnly); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(entityHostType, getEntityHostType); COPY_ENTITY_PROPERTY_TO_PROPERTIES(owningAvatarID, getOwningAvatarID); COPY_ENTITY_PROPERTY_TO_PROPERTIES(lastEditedBy, getLastEditedBy); @@ -1479,7 +1476,7 @@ bool EntityItem::setProperties(const EntityItemProperties& properties) { SET_ENTITY_PROPERTY_FROM_PROPERTIES(parentJointIndex, setParentJointIndex); SET_ENTITY_PROPERTY_FROM_PROPERTIES(queryAACube, setQueryAACube); - SET_ENTITY_PROPERTY_FROM_PROPERTIES(clientOnly, setClientOnly); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(entityHostType, setEntityHostType); SET_ENTITY_PROPERTY_FROM_PROPERTIES(owningAvatarID, setOwningAvatarID); SET_ENTITY_PROPERTY_FROM_PROPERTIES(lastEditedBy, setLastEditedBy); @@ -2496,7 +2493,7 @@ void EntityItem::dimensionsChanged() { bool EntityItem::getScalesWithParent() const { // keep this logic the same as in EntityItemProperties::getScalesWithParent - if (getClientOnly()) { + if (isAvatarEntity()) { QUuid ancestorID = findAncestorOfType(NestableType::Avatar); return !ancestorID.isNull(); } else { @@ -3277,7 +3274,7 @@ void EntityItem::prepareForSimulationOwnershipBid(EntityItemProperties& properti properties.setSimulationOwner(Physics::getSessionUUID(), priority); setPendingOwnershipPriority(priority); - properties.setClientOnly(getClientOnly()); + properties.setEntityHostType(getEntityHostType()); properties.setOwningAvatarID(getOwningAvatarID()); setLastBroadcast(now); // for debug/physics status icons -} +} \ No newline at end of file diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index c49017b2e0..8c78dd1cd6 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -64,6 +64,18 @@ const uint64_t MAX_INCOMING_SIMULATION_UPDATE_PERIOD = MAX_OUTGOING_SIMULATION_U class MeshProxyList; +#ifdef DOMAIN +#undef DOMAIN +#endif + +namespace entity { +enum class HostType { + DOMAIN = 0, + AVATAR, + LOCAL +}; +} + /// EntityItem class this is the base class for all entity types. It handles the basic properties and functionality available /// to all other entity types. In particular: postion, size, rotation, age, lifetime, velocity, gravity. You can not instantiate /// one directly, instead you must only construct one of it's derived classes with additional features. @@ -478,9 +490,13 @@ public: void setScriptHasFinishedPreload(bool value); bool isScriptPreloadFinished(); - bool getClientOnly() const { return _clientOnly; } - virtual void setClientOnly(bool clientOnly) { _clientOnly = clientOnly; } - // if this entity is client-only, which avatar is it associated with? + bool isDomainEntity() const { return _hostType == entity::HostType::DOMAIN; } + bool isAvatarEntity() const { return _hostType == entity::HostType::AVATAR; } + bool isLocalEntity() const { return _hostType == entity::HostType::LOCAL; } + entity::HostType getEntityHostType() const { return _hostType; } + virtual void setEntityHostType(entity::HostType hostType) { _hostType = hostType; } + + // if this entity is an avatar entity, which avatar is it associated with? QUuid getOwningAvatarID() const { return _owningAvatarID; } virtual void setOwningAvatarID(const QUuid& owningAvatarID) { _owningAvatarID = owningAvatarID; } @@ -673,7 +689,7 @@ protected: QUuid _sourceUUID; /// the server node UUID we came from - bool _clientOnly { false }; + entity::HostType _hostType { entity::HostType::DOMAIN }; bool _transitingWithAvatar{ false }; QUuid _owningAvatarID; diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index c243f772e2..b6307a83da 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -306,6 +306,29 @@ void EntityItemProperties::setMaterialMappingModeFromString(const QString& mater } } +QString EntityItemProperties::getEntityHostTypeAsString() const { + switch (_entityHostType) { + case entity::HostType::DOMAIN: + return "domain"; + case entity::HostType::AVATAR: + return "avatar"; + case entity::HostType::LOCAL: + return "local"; + default: + return ""; + } +} + +void EntityItemProperties::setEntityHostTypeFromString(const QString& entityHostType) { + if (entityHostType == "domain") { + _entityHostType = entity::HostType::DOMAIN; + } else if (entityHostType == "avatar") { + _entityHostType = entity::HostType::AVATAR; + } else if (entityHostType == "local") { + _entityHostType = entity::HostType::LOCAL; + } +} + EntityPropertyFlags EntityItemProperties::getChangedProperties() const { EntityPropertyFlags changedProperties; @@ -385,6 +408,7 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const { CHECK_PROPERTY_CHANGE(PROP_MATERIAL_MAPPING_SCALE, materialMappingScale); CHECK_PROPERTY_CHANGE(PROP_MATERIAL_MAPPING_ROT, materialMappingRot); CHECK_PROPERTY_CHANGE(PROP_MATERIAL_DATA, materialData); + CHECK_PROPERTY_CHANGE(PROP_MATERIAL_REPEAT, materialRepeat); CHECK_PROPERTY_CHANGE(PROP_VISIBLE_IN_SECONDARY_CAMERA, isVisibleInSecondaryCamera); CHECK_PROPERTY_CHANGE(PROP_PARTICLE_SPIN, particleSpin); CHECK_PROPERTY_CHANGE(PROP_SPIN_SPREAD, spinSpread); @@ -453,7 +477,7 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const { CHECK_PROPERTY_CHANGE(PROP_GHOSTING_ALLOWED, ghostingAllowed); CHECK_PROPERTY_CHANGE(PROP_FILTER_URL, filterURL); - CHECK_PROPERTY_CHANGE(PROP_CLIENT_ONLY, clientOnly); + CHECK_PROPERTY_CHANGE(PROP_ENTITY_HOST_TYPE, entityHostType); CHECK_PROPERTY_CHANGE(PROP_OWNING_AVATAR_ID, owningAvatarID); CHECK_PROPERTY_CHANGE(PROP_SHAPE, shape); @@ -489,12 +513,18 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const { * @property {Entities.EntityType} type - The entity type. You cannot change the type of an entity after it's created. (Though * its value may switch among "Box", "Shape", and "Sphere" depending on changes to * the shape property set for entities of these types.) Read-only. - * @property {boolean} clientOnly=false - If true then the entity is an avatar entity; otherwise it is a server - * entity. An avatar entity follows you to each domain you visit, rendering at the same world coordinates unless it's - * parented to your avatar. Value cannot be changed after the entity is created.
- * The value can also be set at entity creation by using the clientOnly parameter in + * @property {EntityHostType} entityHostType="domain" - How this entity will behave, including if and how it is sent to other people. + * The value can only be set at entity creation by using the entityHostType parameter in * {@link Entities.addEntity}. - * @property {Uuid} owningAvatarID=Uuid.NULL - The session ID of the owning avatar if clientOnly is + * @property {boolean} avatarEntity=false - If true then the entity is an avatar entity; An avatar entity follows you to each domain you visit, + * rendering at the same world coordinates unless it's parented to your avatar. Value cannot be changed after the entity is created.
+ * The value can only be set at entity creation by using the entityHostType parameter in + * {@link Entities.addEntity}. clientOnly is an alias. + * @property {boolean} localEntity=false - If true then the entity is a local entity; Local entities only render for you and are not sent over the wire. + * Value cannot be changed after the entity is created.
+ * The value can only be set at entity creation by using the entityHostType parameter in + * {@link Entities.addEntity}. + * @property {Uuid} owningAvatarID=Uuid.NULL - The session ID of the owning avatar if avatarEntity is * true, otherwise {@link Uuid|Uuid.NULL}. Read-only. * * @property {string} created - The UTC date and time that the entity was created, in ISO 8601 format as @@ -594,7 +624,7 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const { * @property {number} parentJointIndex=65535 - The joint of the entity or avatar that this entity is parented to. Use * 65535 or -1 to parent to the entity or avatar's position and orientation rather than a joint. * @property {Vec3} localPosition=0,0,0 - The position of the entity relative to its parent if the entity is parented, - * otherwise the same value as position. If the entity is parented to an avatar and is clientOnly + * otherwise the same value as position. If the entity is parented to an avatar and is an avatarEntity * so that it scales with the avatar, this value remains the original local position value while the avatar scale changes. * @property {Quat} localRotation=0,0,0,1 - The rotation of the entity relative to its parent if the entity is parented, * otherwise the same value as rotation. @@ -602,8 +632,8 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const { * otherwise the same value as velocity. * @property {Vec3} localAngularVelocity=0,0,0 - The angular velocity of the entity relative to its parent if the entity is * parented, otherwise the same value as position. - * @property {Vec3} localDimensions - The dimensions of the entity. If the entity is parented to an avatar and is - * clientOnly so that it scales with the avatar, this value remains the original dimensions value while the + * @property {Vec3} localDimensions - The dimensions of the entity. If the entity is parented to an avatar and is an + * avatarEntity so that it scales with the avatar, this value remains the original dimensions value while the * avatar scale changes. * * @property {Entities.BoundingBox} boundingBox - The axis-aligned bounding box that tightly encloses the entity. @@ -628,7 +658,7 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const { * @property {boolean} cloneDynamic=false - If true then clones created from this entity will have their * dynamic property set to true. * @property {boolean} cloneAvatarEntity=false - If true then clones created from this entity will be created as - * avatar entities: their clientOnly property will be set to true. + * avatar entities: their avatarEntity property will be set to true. * @property {Uuid} cloneOriginID - The ID of the entity that this entity was cloned from. * * @property {Entities.Grab} grab - The grab-related properties. @@ -739,7 +769,7 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const { * overlay's ID. * To apply a material to an avatar, set the material entity's parentID property to the avatar's session UUID. * To apply a material to your avatar such that it persists across domains and log-ins, create the material as an avatar entity - * by setting the clientOnly parameter in {@link Entities.addEntity} to true. + * by setting the entityHostType parameter in {@link Entities.addEntity} to "avatar". * Material entities render as non-scalable spheres if they don't have their parent set. * @typedef {object} Entities.EntityProperties-Material * @property {string} materialURL="" - URL to a {@link MaterialResource}. If you append ?name to the URL, the @@ -754,7 +784,8 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const { * Otherwise the property value is parsed as an unsigned integer, specifying the mesh index to modify. Invalid values are * parsed to 0. * @property {string} materialMappingMode="uv" - How the material is mapped to the entity. Either "uv" or - * "projected". Currently, only "uv" is supported. + * "projected". In "uv" mode, the material will be evaluated within the UV space of the mesh it is applied to. In + * "projected" mode, the 3D transform of the Material Entity will be used to evaluate the texture coordinates for the material. * @property {Vec2} materialMappingPos=0,0 - Offset position in UV-space of the top left of the material, range * { x: 0, y: 0 }{ x: 1, y: 1 }. * @property {Vec2} materialMappingScale=1,1 - How much to scale the material within the parent's UV-space. @@ -762,6 +793,8 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const { * @property {string} materialData="" - Used to store {@link MaterialResource} data as a JSON string. You can use * JSON.parse() to parse the string into a JavaScript object which you can manipulate the properties of, and * use JSON.stringify() to convert the object into a string to put in the property. + * @property {boolean} materialRepeat=true - If true, the material will repeat. If false, fragments outside of texCoord 0 - 1 will be discarded. + * Works in both "uv" and "projected" modes. * @example Color a sphere using a Material entity. * var entityID = Entities.addEntity({ * type: "Sphere", @@ -1485,6 +1518,7 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine, bool COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_MATERIAL_MAPPING_SCALE, materialMappingScale); COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_MATERIAL_MAPPING_ROT, materialMappingRot); COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_MATERIAL_DATA, materialData); + COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_MATERIAL_REPEAT, materialRepeat); } /**jsdoc @@ -1527,8 +1561,8 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine, bool COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_LOCAL_ANGULAR_VELOCITY, localAngularVelocity); COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_LOCAL_DIMENSIONS, localDimensions); - COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_CLIENT_ONLY, clientOnly); // Gettable but not settable except at entity creation - COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_OWNING_AVATAR_ID, owningAvatarID); // Gettable but not settable + COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(PROP_ENTITY_HOST_TYPE, entityHostType, getEntityHostTypeAsString()); // Gettable but not settable except at entity creation + COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_OWNING_AVATAR_ID, owningAvatarID); // Gettable but not settable COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_CLONEABLE, cloneable); COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_CLONE_LIFETIME, cloneLifetime); @@ -1567,12 +1601,14 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine, bool COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER_NO_SKIP(renderInfo, renderInfo); // Gettable but not settable } - // FIXME: These properties should already have been set above. if (!psuedoPropertyFlagsActive || psueudoPropertyFlags.test(EntityPsuedoPropertyFlag::ClientOnly)) { - properties.setProperty("clientOnly", convertScriptValue(engine, getClientOnly())); + properties.setProperty("clientOnly", convertScriptValue(engine, getEntityHostType() == entity::HostType::AVATAR)); } - if (!psuedoPropertyFlagsActive || psueudoPropertyFlags.test(EntityPsuedoPropertyFlag::OwningAvatarID)) { - properties.setProperty("owningAvatarID", convertScriptValue(engine, getOwningAvatarID())); + if (!psuedoPropertyFlagsActive || psueudoPropertyFlags.test(EntityPsuedoPropertyFlag::AvatarEntity)) { + properties.setProperty("avatarEntity", convertScriptValue(engine, getEntityHostType() == entity::HostType::AVATAR)); + } + if (!psuedoPropertyFlagsActive || psueudoPropertyFlags.test(EntityPsuedoPropertyFlag::LocalEntity)) { + properties.setProperty("localEntity", convertScriptValue(engine, getEntityHostType() == entity::HostType::LOCAL)); } // FIXME - I don't think these properties are supported any more @@ -1666,6 +1702,7 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object, bool COPY_PROPERTY_FROM_QSCRIPTVALUE(materialMappingScale, vec2, setMaterialMappingScale); COPY_PROPERTY_FROM_QSCRIPTVALUE(materialMappingRot, float, setMaterialMappingRot); COPY_PROPERTY_FROM_QSCRIPTVALUE(materialData, QString, setMaterialData); + COPY_PROPERTY_FROM_QSCRIPTVALUE(materialRepeat, bool, setMaterialRepeat); COPY_PROPERTY_FROM_QSCRIPTVALUE(isVisibleInSecondaryCamera, bool, setIsVisibleInSecondaryCamera); COPY_PROPERTY_FROM_QSCRIPTVALUE(particleSpin, float, setParticleSpin); COPY_PROPERTY_FROM_QSCRIPTVALUE(spinSpread, float, setSpinSpread); @@ -1761,7 +1798,7 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object, bool COPY_PROPERTY_FROM_QSCRIPTVALUE(ghostingAllowed, bool, setGhostingAllowed); COPY_PROPERTY_FROM_QSCRIPTVALUE(filterURL, QString, setFilterURL); - COPY_PROPERTY_FROM_QSCRIPTVALUE(clientOnly, bool, setClientOnly); + COPY_PROPERTY_FROM_QSCRIPTVALUE_ENUM(entityHostType, EntityHostType); COPY_PROPERTY_FROM_QSCRIPTVALUE(owningAvatarID, QUuid, setOwningAvatarID); COPY_PROPERTY_FROM_QSCRIPTVALUE(dpi, uint16_t, setDPI); @@ -1927,7 +1964,7 @@ void EntityItemProperties::merge(const EntityItemProperties& other) { COPY_PROPERTY_IF_CHANGED(ghostingAllowed); COPY_PROPERTY_IF_CHANGED(filterURL); - COPY_PROPERTY_IF_CHANGED(clientOnly); + COPY_PROPERTY_IF_CHANGED(entityHostType); COPY_PROPERTY_IF_CHANGED(owningAvatarID); COPY_PROPERTY_IF_CHANGED(dpi); @@ -2061,6 +2098,7 @@ void EntityItemProperties::entityPropertyFlagsFromScriptValue(const QScriptValue ADD_PROPERTY_TO_MAP(PROP_MATERIAL_MAPPING_SCALE, MaterialMappingScale, materialMappingScale, vec2); ADD_PROPERTY_TO_MAP(PROP_MATERIAL_MAPPING_ROT, MaterialMappingRot, materialMappingRot, float); ADD_PROPERTY_TO_MAP(PROP_MATERIAL_DATA, MaterialData, materialData, QString); + ADD_PROPERTY_TO_MAP(PROP_MATERIAL_REPEAT, MaterialRepeat, materialRepeat, bool); ADD_PROPERTY_TO_MAP(PROP_VISIBLE_IN_SECONDARY_CAMERA, IsVisibleInSecondaryCamera, isVisibleInSecondaryCamera, bool); @@ -2511,6 +2549,7 @@ OctreeElement::AppendState EntityItemProperties::encodeEntityEditPacket(PacketTy APPEND_ENTITY_PROPERTY(PROP_MATERIAL_MAPPING_SCALE, properties.getMaterialMappingScale()); APPEND_ENTITY_PROPERTY(PROP_MATERIAL_MAPPING_ROT, properties.getMaterialMappingRot()); APPEND_ENTITY_PROPERTY(PROP_MATERIAL_DATA, properties.getMaterialData()); + APPEND_ENTITY_PROPERTY(PROP_MATERIAL_REPEAT, properties.getMaterialRepeat()); } APPEND_ENTITY_PROPERTY(PROP_NAME, properties.getName()); @@ -2898,6 +2937,7 @@ bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_MATERIAL_MAPPING_SCALE, vec2, setMaterialMappingScale); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_MATERIAL_MAPPING_ROT, float, setMaterialMappingRot); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_MATERIAL_DATA, QString, setMaterialData); + READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_MATERIAL_REPEAT, bool, setMaterialRepeat); } READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_NAME, QString, setName); @@ -3137,6 +3177,7 @@ void EntityItemProperties::markAllChanged() { _materialMappingScaleChanged = true; _materialMappingRotChanged = true; _materialDataChanged = true; + _materialRepeatChanged = true; // Certifiable Properties _itemNameChanged = true; @@ -3213,7 +3254,7 @@ void EntityItemProperties::markAllChanged() { _ghostingAllowedChanged = true; _filterURLChanged = true; - _clientOnlyChanged = true; + _entityHostTypeChanged = true; _owningAvatarIDChanged = true; _dpiChanged = true; @@ -3587,6 +3628,9 @@ QList EntityItemProperties::listChangedProperties() { if (materialDataChanged()) { out += "materialData"; } + if (materialRepeatChanged()) { + out += "materialRepeat"; + } if (isVisibleInSecondaryCameraChanged()) { out += "isVisibleInSecondaryCamera"; } @@ -3712,8 +3756,8 @@ QList EntityItemProperties::listChangedProperties() { out += "queryAACube"; } - if (clientOnlyChanged()) { - out += "clientOnly"; + if (entityHostTypeChanged()) { + out += "entityHostType"; } if (owningAvatarIDChanged()) { out += "owningAvatarID"; @@ -3788,7 +3832,7 @@ bool EntityItemProperties::getScalesWithParent() const { if (success && parent) { bool avatarAncestor = (parent->getNestableType() == NestableType::Avatar || parent->hasAncestorOfType(NestableType::Avatar)); - scalesWithParent = getClientOnly() && avatarAncestor; + scalesWithParent = getEntityHostType() == entity::HostType::AVATAR && avatarAncestor; } } return scalesWithParent; @@ -3946,7 +3990,13 @@ void EntityItemProperties::convertToCloneProperties(const EntityItemID& entityID setParentJointIndex(-1); setLifetime(getCloneLifetime()); setDynamic(getCloneDynamic()); - setClientOnly(getCloneAvatarEntity()); + if (getEntityHostType() != entity::HostType::LOCAL) { + setEntityHostType(getCloneAvatarEntity() ? entity::HostType::AVATAR : entity::HostType::DOMAIN); + } else { + // Local Entities clone as local entities + setEntityHostType(entity::HostType::LOCAL); + setCollisionless(true); + } setCreated(usecTimestampNow()); setLastEdited(usecTimestampNow()); setCloneable(ENTITY_ITEM_DEFAULT_CLONEABLE); diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index c91ccda5aa..71dc1606f4 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -241,6 +241,7 @@ public: DEFINE_PROPERTY_REF(PROP_MATERIAL_MAPPING_SCALE, MaterialMappingScale, materialMappingScale, glm::vec2, glm::vec2(1.0f)); DEFINE_PROPERTY_REF(PROP_MATERIAL_MAPPING_ROT, MaterialMappingRot, materialMappingRot, float, 0); DEFINE_PROPERTY_REF(PROP_MATERIAL_DATA, MaterialData, materialData, QString, ""); + DEFINE_PROPERTY_REF(PROP_MATERIAL_REPEAT, MaterialRepeat, materialRepeat, bool, true); DEFINE_PROPERTY(PROP_VISIBLE_IN_SECONDARY_CAMERA, IsVisibleInSecondaryCamera, isVisibleInSecondaryCamera, bool, ENTITY_ITEM_DEFAULT_VISIBLE_IN_SECONDARY_CAMERA); @@ -279,7 +280,7 @@ public: DEFINE_PROPERTY(PROP_GHOSTING_ALLOWED, GhostingAllowed, ghostingAllowed, bool, ZoneEntityItem::DEFAULT_GHOSTING_ALLOWED); DEFINE_PROPERTY(PROP_FILTER_URL, FilterURL, filterURL, QString, ZoneEntityItem::DEFAULT_FILTER_URL); - DEFINE_PROPERTY(PROP_CLIENT_ONLY, ClientOnly, clientOnly, bool, false); + DEFINE_PROPERTY_REF_ENUM(PROP_ENTITY_HOST_TYPE, EntityHostType, entityHostType, entity::HostType, entity::HostType::DOMAIN); DEFINE_PROPERTY_REF(PROP_OWNING_AVATAR_ID, OwningAvatarID, owningAvatarID, QUuid, UNKNOWN_ENTITY_ID); DEFINE_PROPERTY_REF(PROP_DPI, DPI, dpi, uint16_t, ENTITY_ITEM_DEFAULT_DPI); @@ -589,7 +590,7 @@ inline QDebug operator<<(QDebug debug, const EntityItemProperties& properties) { DEBUG_PROPERTY_IF_CHANGED(debug, properties, GhostingAllowed, ghostingAllowed, ""); DEBUG_PROPERTY_IF_CHANGED(debug, properties, FilterURL, filterURL, ""); - DEBUG_PROPERTY_IF_CHANGED(debug, properties, ClientOnly, clientOnly, ""); + DEBUG_PROPERTY_IF_CHANGED(debug, properties, EntityHostTypeAsString, entityHostType, ""); DEBUG_PROPERTY_IF_CHANGED(debug, properties, OwningAvatarID, owningAvatarID, ""); DEBUG_PROPERTY_IF_CHANGED(debug, properties, LastEditedBy, lastEditedBy, ""); diff --git a/libraries/entities/src/EntityPropertyFlags.cpp b/libraries/entities/src/EntityPropertyFlags.cpp index c077b153b8..4977cdc537 100644 --- a/libraries/entities/src/EntityPropertyFlags.cpp +++ b/libraries/entities/src/EntityPropertyFlags.cpp @@ -121,7 +121,7 @@ QDebug& operator<<(QDebug& dbg, const EntityPropertyFlags& f) { result = f.getHasProperty(PROP_FALLOFF_RADIUS) ? result + "falloffRadius " : result; result = f.getHasProperty(PROP_FLYING_ALLOWED) ? result + "flyingAllowed " : result; result = f.getHasProperty(PROP_GHOSTING_ALLOWED) ? result + "ghostingAllowed " : result; - result = f.getHasProperty(PROP_CLIENT_ONLY) ? result + "clientOnly " : result; + result = f.getHasProperty(PROP_ENTITY_HOST_TYPE) ? result + "entityHostType " : result; result = f.getHasProperty(PROP_OWNING_AVATAR_ID) ? result + "owningAvatarID " : result; result = f.getHasProperty(PROP_SHAPE) ? result + "shape " : result; result = f.getHasProperty(PROP_DPI) ? result + "dpi " : result; @@ -175,6 +175,7 @@ QDebug& operator<<(QDebug& dbg, const EntityPropertyFlags& f) { result = f.getHasProperty(PROP_MATERIAL_MAPPING_SCALE) ? result + "materialMappingScale " : result; result = f.getHasProperty(PROP_MATERIAL_MAPPING_ROT) ? result + "materialMappingRot " : result; result = f.getHasProperty(PROP_MATERIAL_DATA) ? result + "materialData " : result; + result = f.getHasProperty(PROP_MATERIAL_REPEAT) ? result + "materialRepeat " : result; result = f.getHasProperty(PROP_VISIBLE_IN_SECONDARY_CAMERA) ? result + "visibleInSecondaryCamera " : result; result = f.getHasProperty(PROP_PARTICLE_SPIN) ? result + "particleSpin " : result; result = f.getHasProperty(PROP_SPIN_START) ? result + "spinStart " : result; diff --git a/libraries/entities/src/EntityPropertyFlags.h b/libraries/entities/src/EntityPropertyFlags.h index d2f687fbd3..49e5980ffe 100644 --- a/libraries/entities/src/EntityPropertyFlags.h +++ b/libraries/entities/src/EntityPropertyFlags.h @@ -176,7 +176,7 @@ enum EntityPropertyList { PROP_FLYING_ALLOWED, // can avatars in a zone fly? PROP_GHOSTING_ALLOWED, // can avatars in a zone turn off physics? - PROP_CLIENT_ONLY, // doesn't go over wire + PROP_ENTITY_HOST_TYPE, // doesn't go over wire PROP_OWNING_AVATAR_ID, // doesn't go over wire PROP_SHAPE, @@ -275,6 +275,8 @@ enum EntityPropertyList { PROP_GRAB_EQUIPPABLE_INDICATOR_SCALE, PROP_GRAB_EQUIPPABLE_INDICATOR_OFFSET, + PROP_MATERIAL_REPEAT, + //////////////////////////////////////////////////////////////////////////////////////////////////// // ATTENTION: add new properties to end of list just ABOVE this line PROP_AFTER_LAST_ITEM, diff --git a/libraries/entities/src/EntityPsuedoPropertyFlags.h b/libraries/entities/src/EntityPsuedoPropertyFlags.h index 0b051a4c74..26c2a14015 100644 --- a/libraries/entities/src/EntityPsuedoPropertyFlags.h +++ b/libraries/entities/src/EntityPsuedoPropertyFlags.h @@ -32,6 +32,8 @@ namespace EntityPsuedoPropertyFlag { RenderInfo, ClientOnly, OwningAvatarID, + AvatarEntity, + LocalEntity, NumFlags }; diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 5487ae33b0..4a634899c4 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -470,7 +470,7 @@ void synchronizeEditedGrabProperties(EntityItemProperties& properties, const QSt } -QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties, bool clientOnly) { +QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties, const QString& entityHostTypeString) { PROFILE_RANGE(script_entities, __FUNCTION__); _activityTracking.addedEntityCount++; @@ -479,9 +479,13 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties const auto sessionID = nodeList->getSessionUUID(); EntityItemProperties propertiesWithSimID = properties; - if (clientOnly) { - propertiesWithSimID.setClientOnly(clientOnly); + propertiesWithSimID.setEntityHostTypeFromString(entityHostTypeString); + if (propertiesWithSimID.getEntityHostType() == entity::HostType::AVATAR) { propertiesWithSimID.setOwningAvatarID(sessionID); + } else if (propertiesWithSimID.getEntityHostType() == entity::HostType::LOCAL) { + // For now, local entities are always collisionless + // TODO: create a separate, local physics simulation that just handles local entities (and MyAvatar?) + propertiesWithSimID.setCollisionless(true); } propertiesWithSimID.setLastEditedBy(sessionID); @@ -570,8 +574,11 @@ QUuid EntityScriptingInterface::cloneEntity(QUuid entityIDToClone) { bool cloneAvatarEntity = properties.getCloneAvatarEntity(); properties.convertToCloneProperties(entityIDToClone); - if (cloneAvatarEntity) { - return addEntity(properties, true); + if (properties.getEntityHostType() == entity::HostType::LOCAL) { + // Local entities are only cloned locally + return addEntity(properties, "local"); + } else if (cloneAvatarEntity) { + return addEntity(properties, "avatar"); } else { // setLastEdited timestamp to 0 to ensure this entity gets updated with the properties // from the server-created entity, don't change this unless you know what you are doing @@ -683,6 +690,10 @@ QScriptValue EntityScriptingInterface::getMultipleEntityPropertiesInternal(QScri psuedoPropertyFlags.set(EntityPsuedoPropertyFlag::ClientOnly); } else if (extendedPropertyString == "owningAvatarID") { psuedoPropertyFlags.set(EntityPsuedoPropertyFlag::OwningAvatarID); + } else if (extendedPropertyString == "avatarEntity") { + psuedoPropertyFlags.set(EntityPsuedoPropertyFlag::AvatarEntity); + } else if (extendedPropertyString == "localEntity") { + psuedoPropertyFlags.set(EntityPsuedoPropertyFlag::LocalEntity); } }; @@ -786,7 +797,7 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& return; } - if (entity->getClientOnly() && entity->getOwningAvatarID() != sessionID) { + if (entity->isAvatarEntity() && entity->getOwningAvatarID() != sessionID) { // don't edit other avatar's avatarEntities properties = EntityItemProperties(); return; @@ -829,7 +840,11 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& } // set these to make EntityItemProperties::getScalesWithParent() work correctly - properties.setClientOnly(entity->getClientOnly()); + entity::HostType entityHostType = entity->getEntityHostType(); + properties.setEntityHostType(entityHostType); + if (entityHostType == entity::HostType::LOCAL) { + properties.setCollisionless(true); + } properties.setOwningAvatarID(entity->getOwningAvatarID()); properties.setActionData(entity->getDynamicData()); @@ -956,7 +971,7 @@ void EntityScriptingInterface::deleteEntity(QUuid id) { auto nodeList = DependencyManager::get(); const QUuid myNodeID = nodeList->getSessionUUID(); - if (entity->getClientOnly() && entity->getOwningAvatarID() != myNodeID) { + if (entity->isAvatarEntity() && entity->getOwningAvatarID() != myNodeID) { // don't delete other avatar's avatarEntities shouldSendDeleteToServer = false; return; @@ -966,11 +981,11 @@ void EntityScriptingInterface::deleteEntity(QUuid id) { shouldSendDeleteToServer = false; } else { // only delete local entities, server entities will round trip through the server filters - if (entity->getClientOnly() || _entityTree->isServerlessMode()) { + if (entity->isAvatarEntity() || _entityTree->isServerlessMode()) { shouldSendDeleteToServer = false; _entityTree->deleteEntity(entityID); - if (entity->getClientOnly() && getEntityPacketSender()->getMyAvatar()) { + if (entity->isAvatarEntity() && getEntityPacketSender()->getMyAvatar()) { getEntityPacketSender()->getMyAvatar()->clearAvatarEntity(entityID, false); } } @@ -1637,14 +1652,14 @@ bool EntityScriptingInterface::actionWorker(const QUuid& entityID, return; } - if (entity->getClientOnly() && entity->getOwningAvatarID() != myNodeID) { + if (entity->isAvatarEntity() && entity->getOwningAvatarID() != myNodeID) { return; } doTransmit = actor(simulation, entity); _entityTree->entityChanged(entity); if (doTransmit) { - properties.setClientOnly(entity->getClientOnly()); + properties.setEntityHostType(entity->getEntityHostType()); properties.setOwningAvatarID(entity->getOwningAvatarID()); } }); diff --git a/libraries/entities/src/EntityScriptingInterface.h b/libraries/entities/src/EntityScriptingInterface.h index df7b0df9a1..ff1149fb06 100644 --- a/libraries/entities/src/EntityScriptingInterface.h +++ b/libraries/entities/src/EntityScriptingInterface.h @@ -233,13 +233,29 @@ public slots: */ Q_INVOKABLE bool canReplaceContent(); + /**jsdoc + *

How an entity is sent over the wire.

+ * + * + * + * + * + * + * + * + * + *
ValueDescription
domainDomain entities are sent over the entity server to everyone else
avatarAvatar entities are sent over the avatar entity and are associated with one avatar
localLocal entities are not sent over the wire and will only render for you, locally
+ * @typedef {string} EntityHostType + */ + /**jsdoc * Add a new entity with specified properties. * @function Entities.addEntity * @param {Entities.EntityProperties} properties - The properties of the entity to create. - * @param {boolean} [clientOnly=false] - If true, or if clientOnly is set true in - * the properties, the entity is created as an avatar entity; otherwise it is created on the server. An avatar entity + * @param {EntityHostType} [entityHostType="domain"] - If "avatar" the entity is created as an avatar entity. An avatar entity * follows you to each domain you visit, rendering at the same world coordinates unless it's parented to your avatar. + * If "local", the entity is created as a local entity, which will only render for you and isn't sent over the wire. + * Otherwise it is created as a normal entity and sent over the entity server. * @returns {Uuid} The ID of the entity if successfully created, otherwise {@link Uuid|Uuid.NULL}. * @example Create a box entity in front of your avatar. * var entityID = Entities.addEntity({ @@ -250,7 +266,19 @@ public slots: * }); * print("Entity created: " + entityID); */ - Q_INVOKABLE QUuid addEntity(const EntityItemProperties& properties, bool clientOnly = false); + Q_INVOKABLE QUuid addEntity(const EntityItemProperties& properties, const QString& entityHostTypeString); + + /**jsdoc + * Add a new entity with specified properties. + * @function Entities.addEntity + * @param {Entities.EntityProperties} properties - The properties of the entity to create. + * @param {boolean} [avatarEntity=false] - Whether to create an avatar entity or a domain entity + * @returns {Uuid} The ID of the entity if successfully created, otherwise {@link Uuid|Uuid.NULL}. + */ + Q_INVOKABLE QUuid addEntity(const EntityItemProperties& properties, bool avatarEntity = false) { + QString entityHostType = avatarEntity ? "avatar" : "domain"; + return addEntity(properties, entityHostType); + } /// temporary method until addEntity can be used from QJSEngine /// Deliberately not adding jsdoc, only used internally. @@ -896,8 +924,7 @@ public slots: Q_INVOKABLE bool appendPoint(QUuid entityID, const glm::vec3& point); /**jsdoc - * Dumps debug information about all entities in Interface's local in-memory tree of entities it knows about — domain - * and client-only — to the program log. + * Dumps debug information about all entities in Interface's local in-memory tree of entities it knows about to the program log. * @function Entities.dumpTree */ Q_INVOKABLE void dumpTree() const; @@ -1870,7 +1897,7 @@ signals: /**jsdoc * Triggered when an entity is added to Interface's local in-memory tree of entities it knows about. This may occur when * entities are loaded upon visiting a domain, when the user rotates their view so that more entities become visible, and - * when a domain or client-only entity is added (e.g., by {@Entities.addEntity|addEntity}). + * when any type of entity is added (e.g., by {@Entities.addEntity|addEntity}). * @function Entities.addingEntity * @param {Uuid} entityID - The ID of the entity added. * @returns {Signal} diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index fee8d72fe7..b23be66ade 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -542,7 +542,7 @@ EntityItemPointer EntityTree::addEntity(const EntityItemID& entityID, const Enti return nullptr; } - if (!properties.getClientOnly() && getIsClient() && + if (properties.getEntityHostType() == entity::HostType::DOMAIN && getIsClient() && !nodeList->getThisNodeCanRez() && !nodeList->getThisNodeCanRezTmp() && !nodeList->getThisNodeCanRezCertified() && !nodeList->getThisNodeCanRezTmpCertified() && !_serverlessDomain && !isClone) { return nullptr; @@ -2669,7 +2669,15 @@ bool EntityTree::readFromMap(QVariantMap& map) { entityItemID = EntityItemID(QUuid::createUuid()); } - if (properties.getClientOnly()) { + // Convert old clientOnly bool to new entityHostType enum + // (must happen before setOwningAvatarID below) + if (contentVersion < (int)EntityVersion::EntityHostTypes) { + if (entityMap.contains("clientOnly")) { + properties.setEntityHostType(entityMap["clientOnly"].toBool() ? entity::HostType::AVATAR : entity::HostType::DOMAIN); + } + } + + if (properties.getEntityHostType() == entity::HostType::AVATAR) { auto nodeList = DependencyManager::get(); const QUuid myNodeID = nodeList->getSessionUUID(); properties.setOwningAvatarID(myNodeID); diff --git a/libraries/entities/src/MaterialEntityItem.cpp b/libraries/entities/src/MaterialEntityItem.cpp index 825dd83348..cec602a5e1 100644 --- a/libraries/entities/src/MaterialEntityItem.cpp +++ b/libraries/entities/src/MaterialEntityItem.cpp @@ -41,6 +41,7 @@ EntityItemProperties MaterialEntityItem::getProperties(const EntityPropertyFlags COPY_ENTITY_PROPERTY_TO_PROPERTIES(materialMappingScale, getMaterialMappingScale); COPY_ENTITY_PROPERTY_TO_PROPERTIES(materialMappingRot, getMaterialMappingRot); COPY_ENTITY_PROPERTY_TO_PROPERTIES(materialData, getMaterialData); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(materialRepeat, getMaterialRepeat); return properties; } @@ -55,6 +56,7 @@ bool MaterialEntityItem::setProperties(const EntityItemProperties& properties) { SET_ENTITY_PROPERTY_FROM_PROPERTIES(materialMappingScale, setMaterialMappingScale); SET_ENTITY_PROPERTY_FROM_PROPERTIES(materialMappingRot, setMaterialMappingRot); SET_ENTITY_PROPERTY_FROM_PROPERTIES(materialData, setMaterialData); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(materialRepeat, setMaterialRepeat); if (somethingChanged) { bool wantDebug = false; @@ -85,6 +87,7 @@ int MaterialEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* da READ_ENTITY_PROPERTY(PROP_MATERIAL_MAPPING_SCALE, glm::vec2, setMaterialMappingScale); READ_ENTITY_PROPERTY(PROP_MATERIAL_MAPPING_ROT, float, setMaterialMappingRot); READ_ENTITY_PROPERTY(PROP_MATERIAL_DATA, QString, setMaterialData); + READ_ENTITY_PROPERTY(PROP_MATERIAL_REPEAT, bool, setMaterialRepeat); return bytesRead; } @@ -99,6 +102,7 @@ EntityPropertyFlags MaterialEntityItem::getEntityProperties(EncodeBitstreamParam requestedProperties += PROP_MATERIAL_MAPPING_SCALE; requestedProperties += PROP_MATERIAL_MAPPING_ROT; requestedProperties += PROP_MATERIAL_DATA; + requestedProperties += PROP_MATERIAL_REPEAT; return requestedProperties; } @@ -119,6 +123,7 @@ void MaterialEntityItem::appendSubclassData(OctreePacketData* packetData, Encode APPEND_ENTITY_PROPERTY(PROP_MATERIAL_MAPPING_SCALE, getMaterialMappingScale()); APPEND_ENTITY_PROPERTY(PROP_MATERIAL_MAPPING_ROT, getMaterialMappingRot()); APPEND_ENTITY_PROPERTY(PROP_MATERIAL_DATA, getMaterialData()); + APPEND_ENTITY_PROPERTY(PROP_MATERIAL_REPEAT, getMaterialRepeat()); } void MaterialEntityItem::debugDump() const { @@ -128,6 +133,7 @@ void MaterialEntityItem::debugDump() const { qCDebug(entities) << " material url:" << _materialURL; qCDebug(entities) << " current material name:" << _currentMaterialName.c_str(); qCDebug(entities) << " material mapping mode:" << _materialMappingMode; + qCDebug(entities) << " material repeat:" << _materialRepeat; qCDebug(entities) << " priority:" << _priority; qCDebug(entities) << " parent material name:" << _parentMaterialName; qCDebug(entities) << " material mapping pos:" << _materialMappingPos; @@ -140,7 +146,12 @@ void MaterialEntityItem::debugDump() const { } void MaterialEntityItem::setUnscaledDimensions(const glm::vec3& value) { - EntityItem::setUnscaledDimensions(ENTITY_ITEM_DEFAULT_DIMENSIONS); + _desiredDimensions = value; + if (_materialMappingMode == MaterialMappingMode::UV) { + EntityItem::setUnscaledDimensions(ENTITY_ITEM_DEFAULT_DIMENSIONS); + } else if (_materialMappingMode == MaterialMappingMode::PROJECTED) { + EntityItem::setUnscaledDimensions(value); + } } std::shared_ptr MaterialEntityItem::getMaterial() const { @@ -208,6 +219,23 @@ void MaterialEntityItem::setMaterialData(const QString& materialData) { } } +void MaterialEntityItem::setMaterialMappingMode(MaterialMappingMode mode) { + if (_materialMappingMode != mode) { + removeMaterial(); + _materialMappingMode = mode; + setUnscaledDimensions(_desiredDimensions); + applyMaterial(); + } +} + +void MaterialEntityItem::setMaterialRepeat(bool repeat) { + if (_materialRepeat != repeat) { + removeMaterial(); + _materialRepeat = repeat; + applyMaterial(); + } +} + void MaterialEntityItem::setMaterialMappingPos(const glm::vec2& materialMappingPos) { if (_materialMappingPos != materialMappingPos) { removeMaterial(); @@ -256,6 +284,22 @@ void MaterialEntityItem::setParentID(const QUuid& parentID) { } } +void MaterialEntityItem::locationChanged(bool tellPhysics) { + EntityItem::locationChanged(); + if (_materialMappingMode == MaterialMappingMode::PROJECTED) { + removeMaterial(); + applyMaterial(); + } +} + +void MaterialEntityItem::dimensionsChanged() { + EntityItem::dimensionsChanged(); + if (_materialMappingMode == MaterialMappingMode::PROJECTED) { + removeMaterial(); + applyMaterial(); + } +} + void MaterialEntityItem::removeMaterial() { graphics::MaterialPointer material = getMaterial(); if (!material) { @@ -289,11 +333,19 @@ void MaterialEntityItem::applyMaterial() { if (!material || parentID.isNull()) { return; } + Transform textureTransform; - textureTransform.setTranslation(glm::vec3(_materialMappingPos, 0.0f)); - textureTransform.setRotation(glm::vec3(0.0f, 0.0f, glm::radians(_materialMappingRot))); - textureTransform.setScale(glm::vec3(_materialMappingScale, 1.0f)); - material->setTextureTransforms(textureTransform); + if (_materialMappingMode == MaterialMappingMode::UV) { + textureTransform.setTranslation(glm::vec3(_materialMappingPos, 0.0f)); + textureTransform.setRotation(glm::vec3(0.0f, 0.0f, glm::radians(_materialMappingRot))); + textureTransform.setScale(glm::vec3(_materialMappingScale, 1.0f)); + } else if (_materialMappingMode == MaterialMappingMode::PROJECTED) { + textureTransform = getTransform(); + textureTransform.postScale(getUnscaledDimensions()); + // Pass the inverse transform here so we don't need to compute it in the shaders + textureTransform.evalFromRawMatrix(textureTransform.getInverseMatrix()); + } + material->setTextureTransforms(textureTransform, _materialMappingMode, _materialRepeat); graphics::MaterialLayer materialLayer = graphics::MaterialLayer(material, getPriority()); diff --git a/libraries/entities/src/MaterialEntityItem.h b/libraries/entities/src/MaterialEntityItem.h index 8aaa833db9..ba142d7719 100644 --- a/libraries/entities/src/MaterialEntityItem.h +++ b/libraries/entities/src/MaterialEntityItem.h @@ -58,7 +58,10 @@ public: void setCurrentMaterialName(const std::string& currentMaterialName); MaterialMappingMode getMaterialMappingMode() const { return _materialMappingMode; } - void setMaterialMappingMode(MaterialMappingMode mode) { _materialMappingMode = mode; } + void setMaterialMappingMode(MaterialMappingMode mode); + + bool getMaterialRepeat() const { return _materialRepeat; } + void setMaterialRepeat(bool repeat); quint16 getPriority() const { return _priority; } void setPriority(quint16 priority); @@ -80,6 +83,9 @@ public: void setParentID(const QUuid& parentID) override; + void locationChanged(bool tellPhysics) override; + void dimensionsChanged() override; + void applyMaterial(); void removeMaterial(); @@ -104,8 +110,10 @@ private: // emissiveMap, albedoMap (set opacityMap = albedoMap for transparency), metallicMap or specularMap, roughnessMap or glossMap, // normalMap or bumpMap, occlusionMap, lightmapMap (broken, FIXME), scatteringMap (only works if normal mapped) QString _materialURL; - // Type of material. "uv" or "projected". NOT YET IMPLEMENTED, only UV is used + // Type of material. "uv" or "projected". MaterialMappingMode _materialMappingMode { UV }; + bool _materialRepeat { true }; + glm::vec3 _desiredDimensions; // Priority for this material when applying it to its parent. Only the highest priority material will be used. Materials with the same priority are (essentially) randomly sorted. // Base materials that come with models always have priority 0. quint16 _priority { 0 }; diff --git a/libraries/gpu/src/gpu/Noise.slh b/libraries/gpu/src/gpu/Noise.slh index d300e71ba9..a6a658cbd1 100644 --- a/libraries/gpu/src/gpu/Noise.slh +++ b/libraries/gpu/src/gpu/Noise.slh @@ -231,7 +231,8 @@ float snoise(vec2 v) { // Other corners vec2 i1; - i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0); + float check = float(x0.x > x0.y); + i1 = vec2(check, 1.0 - check); vec4 x12 = x0.xyxy + C.xxzz; x12.xy -= i1; diff --git a/libraries/graphics/src/graphics/Material.cpp b/libraries/graphics/src/graphics/Material.cpp index 1b0e7ee67e..be99cea681 100755 --- a/libraries/graphics/src/graphics/Material.cpp +++ b/libraries/graphics/src/graphics/Material.cpp @@ -130,9 +130,11 @@ void Material::setTextureMap(MapChannel channel, const TextureMapPointer& textur if (channel == MaterialKey::LIGHTMAP_MAP) { // update the texcoord1 with lightmap _schemaBuffer.edit()._texcoordTransforms[1] = (textureMap ? textureMap->getTextureTransform().getMatrix() : glm::mat4()); - _schemaBuffer.edit()._lightmapParams = (textureMap ? glm::vec4(textureMap->getLightmapOffsetScale(), 0.0, 0.0) : glm::vec4(0.0, 1.0, 0.0, 0.0)); + _schemaBuffer.edit()._lightmapParams = (textureMap ? glm::vec2(textureMap->getLightmapOffsetScale()) : glm::vec2(0.0, 1.0)); } + _schemaBuffer.edit()._materialParams = (textureMap ? glm::vec2(textureMap->getMappingMode(), textureMap->getRepeat()) : glm::vec2(MaterialMappingMode::UV, 1.0)); + _schemaBuffer.edit()._key = (uint32)_key._flags.to_ulong(); } @@ -211,13 +213,16 @@ bool Material::calculateMaterialInfo() const { return _hasCalculatedTextureInfo; } -void Material::setTextureTransforms(const Transform& transform) { +void Material::setTextureTransforms(const Transform& transform, MaterialMappingMode mode, bool repeat) { for (auto &textureMapItem : _textureMaps) { if (textureMapItem.second) { textureMapItem.second->setTextureTransform(transform); + textureMapItem.second->setMappingMode(mode); + textureMapItem.second->setRepeat(repeat); } } for (int i = 0; i < NUM_TEXCOORD_TRANSFORMS; i++) { _schemaBuffer.edit()._texcoordTransforms[i] = transform.getMatrix(); } -} \ No newline at end of file + _schemaBuffer.edit()._materialParams = glm::vec2(mode, repeat); +} diff --git a/libraries/graphics/src/graphics/Material.h b/libraries/graphics/src/graphics/Material.h index 914a36d055..9711bd9000 100755 --- a/libraries/graphics/src/graphics/Material.h +++ b/libraries/graphics/src/graphics/Material.h @@ -22,6 +22,8 @@ #include #include +#include "MaterialMappingMode.h" + class Transform; namespace graphics { @@ -330,7 +332,11 @@ public: // Texture Coord Transform Array glm::mat4 _texcoordTransforms[NUM_TEXCOORD_TRANSFORMS]; - glm::vec4 _lightmapParams{ 0.0, 1.0, 0.0, 0.0 }; + glm::vec2 _lightmapParams { 0.0, 1.0 }; + + // x: material mode (0 for UV, 1 for PROJECTED) + // y: 1 for texture repeat, 0 for discard outside of 0 - 1 + glm::vec2 _materialParams { 0.0, 1.0 }; Schema() {} }; @@ -353,7 +359,7 @@ public: size_t getTextureSize() const { calculateMaterialInfo(); return _textureSize; } bool hasTextureInfo() const { return _hasCalculatedTextureInfo; } - void setTextureTransforms(const Transform& transform); + void setTextureTransforms(const Transform& transform, MaterialMappingMode mode, bool repeat); const std::string& getName() const { return _name; } diff --git a/libraries/graphics/src/graphics/Material.slh b/libraries/graphics/src/graphics/Material.slh index 62632f993b..dfd4a8eec4 100644 --- a/libraries/graphics/src/graphics/Material.slh +++ b/libraries/graphics/src/graphics/Material.slh @@ -19,20 +19,25 @@ const int MAX_TEXCOORDS = 2; struct TexMapArray { mat4 _texcoordTransforms0; mat4 _texcoordTransforms1; - vec4 _lightmapParams; + vec2 _lightmapParams; + vec2 _materialParams; }; <@func declareMaterialTexMapArrayBuffer()@> -<@func evalTexMapArrayTexcoord0(texMapArray, inTexcoord0, outTexcoord0)@> +<@func evalTexMapArrayTexcoord0(texMapArray, inTexcoord0, worldPosition, outTexcoord0)@> { - <$outTexcoord0$> = (<$texMapArray$>._texcoordTransforms0 * vec4(<$inTexcoord0$>.st, 0.0, 1.0)).st; + <$outTexcoord0$> = mix(<$texMapArray$>._texcoordTransforms0 * vec4(<$inTexcoord0$>.st, 0.0, 1.0), + <$texMapArray$>._texcoordTransforms0 * <$worldPosition$> + vec4(0.5), + <$texMapArray$>._materialParams.x).st; } <@endfunc@> -<@func evalTexMapArrayTexcoord1(texMapArray, inTexcoord1, outTexcoord1)@> +<@func evalTexMapArrayTexcoord1(texMapArray, inTexcoord1, worldPosition, outTexcoord1)@> { - <$outTexcoord1$> = (<$texMapArray$>._texcoordTransforms1 * vec4(<$inTexcoord1$>.st, 0.0, 1.0)).st; + <$outTexcoord1$> = mix(<$texMapArray$>._texcoordTransforms1 * vec4(<$inTexcoord1$>.st, 0.0, 1.0), + <$texMapArray$>._texcoordTransforms1 * <$worldPosition$> + vec4(0.5), + <$texMapArray$>._materialParams.x).st; } <@endfunc@> diff --git a/libraries/graphics/src/graphics/MaterialTextures.slh b/libraries/graphics/src/graphics/MaterialTextures.slh index 20b117132c..1cbee33238 100644 --- a/libraries/graphics/src/graphics/MaterialTextures.slh +++ b/libraries/graphics/src/graphics/MaterialTextures.slh @@ -151,29 +151,32 @@ float fetchScatteringMap(vec2 uv) { <@func fetchMaterialTexturesCoord0(matKey, texcoord0, albedo, roughness, normal, metallic, emissive, scattering)@> + if (getTexMapArray()._materialParams.y != 1.0 && clamp(<$texcoord0$>, vec2(0.0), vec2(1.0)) != <$texcoord0$>) { + discard; + } <@if albedo@> - vec4 <$albedo$> = (((<$matKey$> & (ALBEDO_MAP_BIT | OPACITY_MASK_MAP_BIT | OPACITY_TRANSLUCENT_MAP_BIT)) != 0) ? fetchAlbedoMap(<$texcoord0$>) : vec4(1.0)); + vec4 <$albedo$> = mix(vec4(1.0), fetchAlbedoMap(<$texcoord0$>), float((<$matKey$> & (ALBEDO_MAP_BIT | OPACITY_MASK_MAP_BIT | OPACITY_TRANSLUCENT_MAP_BIT)) != 0)); <@endif@> <@if roughness@> - float <$roughness$> = (((<$matKey$> & ROUGHNESS_MAP_BIT) != 0) ? fetchRoughnessMap(<$texcoord0$>) : 1.0); + float <$roughness$> = mix(1.0, fetchRoughnessMap(<$texcoord0$>), float((<$matKey$> & ROUGHNESS_MAP_BIT) != 0)); <@endif@> <@if normal@> - vec3 <$normal$> = (((<$matKey$> & NORMAL_MAP_BIT) != 0) ? fetchNormalMap(<$texcoord0$>) : vec3(0.0, 1.0, 0.0)); + vec3 <$normal$> = mix(vec3(0.0, 1.0, 0.0), fetchNormalMap(<$texcoord0$>), float((<$matKey$> & NORMAL_MAP_BIT) != 0)); <@endif@> <@if metallic@> - float <$metallic$> = (((<$matKey$> & METALLIC_MAP_BIT) != 0) ? fetchMetallicMap(<$texcoord0$>) : 0.0); + float <$metallic$> = float((<$matKey$> & METALLIC_MAP_BIT) != 0) * fetchMetallicMap(<$texcoord0$>); <@endif@> <@if emissive@> - vec3 <$emissive$> = (((<$matKey$> & EMISSIVE_MAP_BIT) != 0) ? fetchEmissiveMap(<$texcoord0$>) : vec3(0.0)); + vec3 <$emissive$> = float((<$matKey$> & EMISSIVE_MAP_BIT) != 0) * fetchEmissiveMap(<$texcoord0$>); <@endif@> <@if scattering@> - float <$scattering$> = (((<$matKey$> & SCATTERING_MAP_BIT) != 0) ? fetchScatteringMap(<$texcoord0$>) : 0.0); + float <$scattering$> = float((<$matKey$> & SCATTERING_MAP_BIT) != 0) * fetchScatteringMap(<$texcoord0$>); <@endif@> <@endfunc@> <@func fetchMaterialTexturesCoord1(matKey, texcoord1, occlusion, lightmap)@> <@if occlusion@> - float <$occlusion$> = (((<$matKey$> & OCCLUSION_MAP_BIT) != 0) ? fetchOcclusionMap(<$texcoord1$>) : 1.0); + float <$occlusion$> = mix(1.0, fetchOcclusionMap(<$texcoord1$>), float((<$matKey$> & OCCLUSION_MAP_BIT) != 0)); <@endif@> <@if lightmap@> vec3 <$lightmap$> = fetchLightmapMap(<$texcoord1$>); @@ -188,7 +191,7 @@ float fetchScatteringMap(vec2 uv) { LAYOUT(binding=GRAPHICS_TEXTURE_MATERIAL_EMISSIVE_LIGHTMAP) uniform sampler2D emissiveMap; vec3 fetchLightmapMap(vec2 uv) { - vec2 lightmapParams = getTexMapArray()._lightmapParams.xy; + vec2 lightmapParams = getTexMapArray()._lightmapParams; return (vec3(lightmapParams.x) + lightmapParams.y * texture(emissiveMap, uv).rgb); } <@endfunc@> @@ -207,20 +210,19 @@ vec3 fetchLightmapMap(vec2 uv) { <@func evalMaterialAlbedo(fetchedAlbedo, materialAlbedo, matKey, albedo)@> { - <$albedo$>.xyz = (((<$matKey$> & ALBEDO_VAL_BIT) != 0) ? <$materialAlbedo$> : vec3(1.0)); - - if (((<$matKey$> & ALBEDO_MAP_BIT) != 0)) { - <$albedo$>.xyz *= <$fetchedAlbedo$>.xyz; - } + <$albedo$>.xyz = mix(vec3(1.0), <$materialAlbedo$>, float((<$matKey$> & ALBEDO_VAL_BIT) != 0)); + <$albedo$>.xyz *= mix(vec3(1.0), <$fetchedAlbedo$>.xyz, float((<$matKey$> & ALBEDO_MAP_BIT) != 0)); } <@endfunc@> <@func evalMaterialOpacity(fetchedOpacity, materialOpacity, matKey, opacity)@> { const float OPACITY_MASK_THRESHOLD = 0.5; - <$opacity$> = (((<$matKey$> & (OPACITY_TRANSLUCENT_MAP_BIT | OPACITY_MASK_MAP_BIT)) != 0) ? - (((<$matKey$> & OPACITY_MASK_MAP_BIT) != 0) ? step(OPACITY_MASK_THRESHOLD, <$fetchedOpacity$>) : <$fetchedOpacity$>) : - 1.0) * <$materialOpacity$>; + <$opacity$> = mix(1.0, + mix(<$fetchedOpacity$>, + step(OPACITY_MASK_THRESHOLD, <$fetchedOpacity$>), + float((<$matKey$> & OPACITY_MASK_MAP_BIT) != 0)), + float((<$matKey$> & (OPACITY_TRANSLUCENT_MAP_BIT | OPACITY_MASK_MAP_BIT)) != 0)) * <$materialOpacity$>; } <@endfunc@> @@ -241,19 +243,19 @@ vec3 fetchLightmapMap(vec2 uv) { <@func evalMaterialRoughness(fetchedRoughness, materialRoughness, matKey, roughness)@> { - <$roughness$> = (((<$matKey$> & ROUGHNESS_MAP_BIT) != 0) ? <$fetchedRoughness$> : <$materialRoughness$>); + <$roughness$> = mix(<$materialRoughness$>, <$fetchedRoughness$>, float((<$matKey$> & ROUGHNESS_MAP_BIT) != 0)); } <@endfunc@> <@func evalMaterialMetallic(fetchedMetallic, materialMetallic, matKey, metallic)@> { - <$metallic$> = (((<$matKey$> & METALLIC_MAP_BIT) != 0) ? <$fetchedMetallic$> : <$materialMetallic$>); + <$metallic$> = mix(<$materialMetallic$>, <$fetchedMetallic$>, float((<$matKey$> & METALLIC_MAP_BIT) != 0)); } <@endfunc@> <@func evalMaterialEmissive(fetchedEmissive, materialEmissive, matKey, emissive)@> { - <$emissive$> = (((<$matKey$> & EMISSIVE_MAP_BIT) != 0) ? <$fetchedEmissive$> : <$materialEmissive$>); + <$emissive$> = mix(<$materialEmissive$>, <$fetchedEmissive$>, float((<$matKey$> & EMISSIVE_MAP_BIT) != 0)); } <@endfunc@> @@ -265,7 +267,7 @@ vec3 fetchLightmapMap(vec2 uv) { <@func evalMaterialScattering(fetchedScattering, materialScattering, matKey, scattering)@> { - <$scattering$> = (((<$matKey$> & SCATTERING_MAP_BIT) != 0) ? <$fetchedScattering$> : <$materialScattering$>); + <$scattering$> = mix(<$materialScattering$>, <$fetchedScattering$>, float((<$matKey$> & SCATTERING_MAP_BIT) != 0)); } <@endfunc@> diff --git a/libraries/graphics/src/graphics/TextureMap.h b/libraries/graphics/src/graphics/TextureMap.h index 1678d9df98..eea9d2b31b 100755 --- a/libraries/graphics/src/graphics/TextureMap.h +++ b/libraries/graphics/src/graphics/TextureMap.h @@ -14,6 +14,7 @@ #include "gpu/Texture.h" #include "Transform.h" +#include "MaterialMappingMode.h" namespace graphics { @@ -30,6 +31,12 @@ public: void setTextureTransform(const Transform& texcoordTransform); const Transform& getTextureTransform() const { return _texcoordTransform; } + void setMappingMode(MaterialMappingMode mode) { _mappingMode = mode; } + MaterialMappingMode getMappingMode() const { return _mappingMode; } + + void setRepeat(bool repeat) { _repeat = repeat; } + bool getRepeat() const { return _repeat; } + void setUseAlphaChannel(bool useAlpha) { _useAlphaChannel = useAlpha; } bool useAlphaChannel() const { return _useAlphaChannel; } @@ -41,6 +48,8 @@ protected: Transform _texcoordTransform; glm::vec2 _lightmapOffsetScale{ 0.0f, 1.0f }; + MaterialMappingMode _mappingMode { MaterialMappingMode::UV }; + bool _repeat { true }; bool _useAlphaChannel{ false }; }; diff --git a/libraries/graphics/src/graphics/skybox.slf b/libraries/graphics/src/graphics/skybox.slf index b24bf0f583..c20dd94bf4 100755 --- a/libraries/graphics/src/graphics/skybox.slf +++ b/libraries/graphics/src/graphics/skybox.slf @@ -30,11 +30,9 @@ void main(void) { vec3 color = skybox.color.rgb; // blend is only set if there is a cubemap - if (skybox.color.a > 0.0) { - color = texture(cubeMap, coord).rgb; - if (skybox.color.a < 1.0) { - color *= skybox.color.rgb; - } - } + float check = float(skybox.color.a > 0.0); + color = mix(color, texture(cubeMap, coord).rgb, check); + color *= mix(vec3(1.0), skybox.color.rgb, check * float(skybox.color.a < 1.0)); + _fragColor = vec4(color, 0.0); } diff --git a/libraries/networking/src/udt/PacketHeaders.cpp b/libraries/networking/src/udt/PacketHeaders.cpp index 18e439aa77..fad38d565b 100644 --- a/libraries/networking/src/udt/PacketHeaders.cpp +++ b/libraries/networking/src/udt/PacketHeaders.cpp @@ -33,7 +33,7 @@ PacketVersion versionForPacketType(PacketType packetType) { case PacketType::EntityEdit: case PacketType::EntityData: case PacketType::EntityPhysics: - return static_cast(EntityVersion::FixedLightSerialization); + return static_cast(EntityVersion::EntityHostTypes); case PacketType::EntityQuery: return static_cast(EntityQueryPacketVersion::ConicalFrustums); case PacketType::AvatarIdentity: diff --git a/libraries/networking/src/udt/PacketHeaders.h b/libraries/networking/src/udt/PacketHeaders.h index f3bc115410..b46eb3e9e4 100644 --- a/libraries/networking/src/udt/PacketHeaders.h +++ b/libraries/networking/src/udt/PacketHeaders.h @@ -244,7 +244,9 @@ enum class EntityVersion : PacketVersion { BloomEffect, GrabProperties, ScriptGlmVectors, - FixedLightSerialization + FixedLightSerialization, + MaterialRepeat, + EntityHostTypes }; enum class EntityScriptCallMethodVersion : PacketVersion { diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index c920665279..4b635ef0be 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -80,8 +80,8 @@ EntityMotionState::EntityMotionState(btCollisionShape* shape, EntityItemPointer // rather than pass the legit shape pointer to the ObjectMotionState ctor above. setShape(shape); - if (_entity->getClientOnly() && _entity->getOwningAvatarID() != Physics::getSessionUUID()) { - // client-only entities are always thus, so we cache this fact in _ownershipState + if (_entity->isAvatarEntity() && _entity->getOwningAvatarID() != Physics::getSessionUUID()) { + // avatar entities entities are always thus, so we cache this fact in _ownershipState _ownershipState = EntityMotionState::OwnershipState::Unownable; } @@ -430,7 +430,7 @@ bool EntityMotionState::shouldSendUpdate(uint32_t simulationStep) { assert(entityTreeIsLocked()); // this case is prevented by setting _ownershipState to UNOWNABLE in EntityMotionState::ctor - assert(!(_entity->getClientOnly() && _entity->getOwningAvatarID() != Physics::getSessionUUID())); + assert(!(_entity->isAvatarEntity() && _entity->getOwningAvatarID() != Physics::getSessionUUID())); if (_entity->getTransitingWithAvatar()) { return false; @@ -595,7 +595,7 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_ EntityTreeElementPointer element = _entity->getElement(); EntityTreePointer tree = element ? element->getTree() : nullptr; - properties.setClientOnly(_entity->getClientOnly()); + properties.setEntityHostType(_entity->getEntityHostType()); properties.setOwningAvatarID(_entity->getOwningAvatarID()); entityPacketSender->queueEditEntityMessage(PacketType::EntityPhysics, tree, id, properties); @@ -610,7 +610,7 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_ EntityItemProperties newQueryCubeProperties; newQueryCubeProperties.setQueryAACube(descendant->getQueryAACube()); newQueryCubeProperties.setLastEdited(properties.getLastEdited()); - newQueryCubeProperties.setClientOnly(entityDescendant->getClientOnly()); + newQueryCubeProperties.setEntityHostType(entityDescendant->getEntityHostType()); newQueryCubeProperties.setOwningAvatarID(entityDescendant->getOwningAvatarID()); entityPacketSender->queueEditEntityMessage(PacketType::EntityPhysics, tree, diff --git a/libraries/physics/src/PhysicalEntitySimulation.cpp b/libraries/physics/src/PhysicalEntitySimulation.cpp index ab8bfb8290..8e5248f6a9 100644 --- a/libraries/physics/src/PhysicalEntitySimulation.cpp +++ b/libraries/physics/src/PhysicalEntitySimulation.cpp @@ -79,7 +79,7 @@ void PhysicalEntitySimulation::removeEntityInternal(EntityItemPointer entity) { _deadEntities.insert(entity); } } - if (entity->getClientOnly()) { + if (entity->isAvatarEntity()) { _deadAvatarEntities.insert(entity); } } @@ -339,7 +339,7 @@ void PhysicalEntitySimulation::handleDeactivatedMotionStates(const VectorOfMotio EntityItemPointer entity = entityState->getEntity(); _entitiesToSort.insert(entity); if (!serverlessMode) { - if (entity->getClientOnly()) { + if (entity->isAvatarEntity()) { switch (entityState->getOwnershipState()) { case EntityMotionState::OwnershipState::PendingBid: _bids.removeFirst(entityState); diff --git a/libraries/qml/src/qml/OffscreenSurface.cpp b/libraries/qml/src/qml/OffscreenSurface.cpp index 91532534e3..abab5391e2 100644 --- a/libraries/qml/src/qml/OffscreenSurface.cpp +++ b/libraries/qml/src/qml/OffscreenSurface.cpp @@ -389,6 +389,10 @@ void OffscreenSurface::finishQmlLoad(QQmlComponent* qmlComponent, } // Allow child windows to be destroyed from JS QQmlEngine::setObjectOwnership(newObject, QQmlEngine::JavaScriptOwnership); + + // add object to the manual deletion list + _sharedObject->addToDeletionList(newObject); + newObject->setParent(parent); newItem->setParentItem(parent); } else { diff --git a/libraries/qml/src/qml/impl/SharedObject.cpp b/libraries/qml/src/qml/impl/SharedObject.cpp index 259defdb48..5bcca0821f 100644 --- a/libraries/qml/src/qml/impl/SharedObject.cpp +++ b/libraries/qml/src/qml/impl/SharedObject.cpp @@ -15,6 +15,7 @@ #include #include +#include #include #include @@ -96,6 +97,15 @@ SharedObject::~SharedObject() { } #endif + // already deleted objects will be reset to null by QPointer so it should be safe just iterate here + for (auto qmlObject : _deletionList) { + if (qmlObject) { + // manually delete not-deleted-yet qml items + QQmlEngine::setObjectOwnership(qmlObject, QQmlEngine::CppOwnership); + delete qmlObject; + } + } + if (_rootItem) { delete _rootItem; _rootItem = nullptr; @@ -412,6 +422,11 @@ bool SharedObject::fetchTexture(TextureAndFence& textureAndFence) { return true; } +void hifi::qml::impl::SharedObject::addToDeletionList(QObject * object) +{ + _deletionList.append(QPointer(object)); +} + void SharedObject::setProxyWindow(QWindow* window) { #ifndef DISABLE_QML _proxyWindow = window; diff --git a/libraries/qml/src/qml/impl/SharedObject.h b/libraries/qml/src/qml/impl/SharedObject.h index 002679c44d..ce9fcd46d2 100644 --- a/libraries/qml/src/qml/impl/SharedObject.h +++ b/libraries/qml/src/qml/impl/SharedObject.h @@ -66,7 +66,7 @@ public: void resume(); bool isPaused() const; bool fetchTexture(TextureAndFence& textureAndFence); - + void addToDeletionList(QObject* object); private: bool event(QEvent* e) override; @@ -91,6 +91,8 @@ private: void onAboutToQuit(); void updateTextureAndFence(const TextureAndFence& newTextureAndFence); + QList> _deletionList; + // Texture management TextureAndFence _latestTextureAndFence{ 0, 0 }; QQuickItem* _item{ nullptr }; diff --git a/libraries/render-utils/src/DeferredBufferRead.slh b/libraries/render-utils/src/DeferredBufferRead.slh index f3b8c0404a..868b93ff91 100644 --- a/libraries/render-utils/src/DeferredBufferRead.slh +++ b/libraries/render-utils/src/DeferredBufferRead.slh @@ -76,15 +76,10 @@ DeferredFragment unpackDeferredFragmentNoPosition(vec2 texcoord) { // Diffuse color and unpack the mode and the metallicness frag.albedo = diffuseVal.xyz; - frag.scattering = 0.0; unpackModeMetallic(diffuseVal.w, frag.mode, frag.metallic); frag.obscurance = min(specularVal.w, frag.obscurance); - - if (frag.mode == FRAG_MODE_SCATTERING) { - frag.scattering = specularVal.x; - } - + frag.scattering = float(frag.mode == FRAG_MODE_SCATTERING) * specularVal.x; frag.fresnel = getFresnelF0(frag.metallic, diffuseVal.xyz); return frag; @@ -122,14 +117,11 @@ DeferredFragment unpackDeferredFragmentNoPositionNoAmbient(vec2 texcoord) { <$declareDeferredFrameTransform()$> vec4 unpackDeferredPosition(float depthValue, vec2 texcoord) { - int side = 0; - if (isStereo()) { - if (texcoord.x > 0.5) { - texcoord.x -= 0.5; - side = 1; - } - texcoord.x *= 2.0; - } + float check = float(isStereo()); + float check2 = check * float(texcoord.x > 0.5); + texcoord.x -= check2 * 0.5; + int side = int(check2); + texcoord.x *= 1.0 + check; return vec4(evalEyePositionFromZdb(side, depthValue, texcoord), 1.0); } @@ -142,19 +134,17 @@ vec4 unpackDeferredPositionFromZdb(vec2 texcoord) { vec4 unpackDeferredPositionFromZeye(vec2 texcoord) { float Zeye = -texture(linearZeyeMap, texcoord).x; - int side = 0; - if (isStereo()) { - if (texcoord.x > 0.5) { - texcoord.x -= 0.5; - side = 1; - } - texcoord.x *= 2.0; - } + + float check = float(isStereo()); + float check2 = check * float(texcoord.x > 0.5); + texcoord.x -= check2 * 0.5; + int side = int(check2); + texcoord.x *= 1.0 + check; + return vec4(evalEyePositionFromZeye(side, Zeye, texcoord), 1.0); } DeferredFragment unpackDeferredFragment(DeferredFrameTransform deferredTransform, vec2 texcoord) { - float depthValue = texture(depthMap, texcoord).r; DeferredFragment frag = unpackDeferredFragmentNoPosition(texcoord); diff --git a/libraries/render-utils/src/DeferredBufferWrite.slh b/libraries/render-utils/src/DeferredBufferWrite.slh index 9602bc4bf4..ea32c5ecb3 100644 --- a/libraries/render-utils/src/DeferredBufferWrite.slh +++ b/libraries/render-utils/src/DeferredBufferWrite.slh @@ -32,9 +32,11 @@ void packDeferredFragment(vec3 normal, float alpha, vec3 albedo, float roughness if (alpha != 1.0) { discard; } - _fragColor0 = vec4(albedo, ((scattering > 0.0) ? packScatteringMetallic(metallic) : packShadedMetallic(metallic))); + + float check = float(scattering > 0.0); + _fragColor0 = vec4(albedo, mix(packShadedMetallic(metallic), packScatteringMetallic(metallic), check)); _fragColor1 = vec4(packNormal(normal), clamp(roughness, 0.0, 1.0)); - _fragColor2 = vec4(((scattering > 0.0) ? vec3(scattering) : emissive), occlusion); + _fragColor2 = vec4(mix(emissive, vec3(scattering), check), occlusion); _fragColor3 = vec4(isEmissiveEnabled() * emissive, 1.0); } diff --git a/libraries/render-utils/src/DeferredTransform.slh b/libraries/render-utils/src/DeferredTransform.slh index 9b3ad213c6..93a3e61c51 100644 --- a/libraries/render-utils/src/DeferredTransform.slh +++ b/libraries/render-utils/src/DeferredTransform.slh @@ -116,6 +116,7 @@ bool isStereo() { float getStereoSideWidth(int resolutionLevel) { return float(int(frameTransform._stereoInfo.y) >> resolutionLevel); } + float getStereoSideHeight(int resolutionLevel) { return float(int(frameTransform._pixelInfo.w) >> resolutionLevel); } @@ -125,7 +126,7 @@ vec2 getStereoSideSize(int resolutionLevel) { } ivec4 getStereoSideInfoFromWidth(int xPos, int sideWidth) { - return ivec4(xPos < sideWidth ? ivec2(0, 0) : ivec2(1, sideWidth), sideWidth, isStereo()); + return ivec4((1 - int(xPos < sideWidth)) * ivec2(1, sideWidth), sideWidth, isStereo()); } ivec4 getStereoSideInfo(int xPos, int resolutionLevel) { diff --git a/libraries/render-utils/src/Fade.slh b/libraries/render-utils/src/Fade.slh index cdbdf1f91d..cd1e06f52e 100644 --- a/libraries/render-utils/src/Fade.slh +++ b/libraries/render-utils/src/Fade.slh @@ -85,10 +85,8 @@ float evalFadeGradient(FadeObjectParams params, vec3 position) { } float evalFadeAlpha(FadeObjectParams params, vec3 position) { - float alpha = evalFadeGradient(params, position)-params.threshold; - if (fadeParameters[params.category]._isInverted != 0) { - alpha = -alpha; - } + float alpha = evalFadeGradient(params, position) - params.threshold; + alpha *= 1.0 - 2.0 * float(fadeParameters[params.category]._isInverted); return alpha; } @@ -166,4 +164,4 @@ layout(location=RENDER_UTILS_ATTR_FADE3) out vec4 _fadeData3; _fadeData3 = inTexCoord4; <@endfunc@> -<@endif@> \ No newline at end of file +<@endif@> diff --git a/libraries/render-utils/src/Haze.slf b/libraries/render-utils/src/Haze.slf index 8d90b4c816..170e69eb2d 100644 --- a/libraries/render-utils/src/Haze.slf +++ b/libraries/render-utils/src/Haze.slf @@ -25,14 +25,13 @@ LAYOUT(binding=RENDER_UTILS_TEXTURE_HAZE_LINEAR_DEPTH) uniform sampler2D linearD vec4 unpackPositionFromZeye(vec2 texcoord) { float Zeye = -texture(linearDepthMap, texcoord).x; - int side = 0; - if (isStereo()) { - if (texcoord.x > 0.5) { - texcoord.x -= 0.5; - side = 1; - } - texcoord.x *= 2.0; - } + + float check = float(isStereo()); + float check2 = check * float(texcoord.x > 0.5); + texcoord.x -= check2 * 0.5; + int side = int(check2); + texcoord.x *= 1.0 + check; + return vec4(evalEyePositionFromZeye(side, Zeye, texcoord), 1.0); } diff --git a/libraries/render-utils/src/Haze.slh b/libraries/render-utils/src/Haze.slh index a7654da8d2..0bf1d5d689 100644 --- a/libraries/render-utils/src/Haze.slh +++ b/libraries/render-utils/src/Haze.slh @@ -63,20 +63,17 @@ vec3 computeHazeColorKeyLightAttenuation(vec3 color, vec3 lightDirectionWS, vec3 // Height at which haze density is reduced by 95% (default set to 2000.0 for safety ,this should never happen) float height_95p = 2000.0; const float log_p_005 = log(0.05); + if (hazeParams.hazeKeyLightAltitudeFactor > 0.0f) { height_95p = -log_p_005 / hazeParams.hazeKeyLightAltitudeFactor; } // Note that we need the sine to be positive - float sin_pitch = abs(lightDirectionWS.y); - - float distance; const float minimumSinPitch = 0.001; - if (sin_pitch < minimumSinPitch) { - distance = height_95p / minimumSinPitch; - } else { - distance = height_95p / sin_pitch; - } + float sin_pitch = abs(lightDirectionWS.y); + sin_pitch = max(sin_pitch, minimumSinPitch); + + float distance = height_95p / sin_pitch; // Integration is from the fragment towards the light source // Note that the haze base reference affects only the haze density as function of altitude @@ -128,6 +125,7 @@ vec4 computeHazeColor(vec3 fragPositionES, vec3 fragPositionWS, vec3 eyePosition } vec4 potentialFragColor; + const float EPSILON = 0.0000001f; if ((hazeParams.hazeMode & HAZE_MODE_IS_MODULATE_COLOR) == HAZE_MODE_IS_MODULATE_COLOR) { // Compute separately for each colour @@ -143,9 +141,9 @@ vec4 computeHazeColor(vec3 fragPositionES, vec3 fragPositionWS, vec3 eyePosition const float slopeThreshold = 0.01; float deltaHeight = fragPositionWS.y - eyeWorldHeight; - if (abs(deltaHeight) > slopeThreshold) { - float t = hazeParams.hazeHeightFactor * deltaHeight; - hazeIntegral *= (1.0 - exp (-t)) / t; + float t = hazeParams.hazeHeightFactor * deltaHeight; + if (abs(t) > EPSILON) { + hazeIntegral *= mix(1.0, (1.0 - exp(-t)) / t, float(abs(deltaHeight) > slopeThreshold)); } vec3 hazeAmount = 1.0 - exp(-hazeIntegral); @@ -171,13 +169,9 @@ vec4 computeHazeColor(vec3 fragPositionES, vec3 fragPositionWS, vec3 eyePosition const float slopeThreshold = 0.01; float deltaHeight = fragPositionWS.y - eyeWorldHeight; - if (abs(deltaHeight) > slopeThreshold) { - float t = hazeParams.hazeHeightFactor * deltaHeight; - // Protect from wild values - const float EPSILON = 0.0000001f; - if (abs(t) > EPSILON) { - hazeIntegral *= (1.0 - exp (-t)) / t; - } + float t = hazeParams.hazeHeightFactor * deltaHeight; + if (abs(t) > EPSILON) { + hazeIntegral *= mix(1.0, (1.0 - exp(-t)) / t, float(abs(deltaHeight) > slopeThreshold)); } float hazeAmount = 1.0 - exp(-hazeIntegral); @@ -189,9 +183,7 @@ vec4 computeHazeColor(vec3 fragPositionES, vec3 fragPositionWS, vec3 eyePosition // Mix with background at far range const float BLEND_DISTANCE = 27000.0f; vec4 outFragColor = potentialFragColor; - if (distance > BLEND_DISTANCE) { - outFragColor.a *= hazeParams.backgroundBlend; - } + outFragColor.a *= mix(1.0, hazeParams.backgroundBlend, float(distance > BLEND_DISTANCE)); return outFragColor; } diff --git a/libraries/render-utils/src/Highlight.slh b/libraries/render-utils/src/Highlight.slh index 264b57acbb..85ff352207 100644 --- a/libraries/render-utils/src/Highlight.slh +++ b/libraries/render-utils/src/Highlight.slh @@ -45,11 +45,9 @@ void main(void) { highlightedDepth = -evalZeyeFromZdb(highlightedDepth); sceneDepth = -evalZeyeFromZdb(sceneDepth); - if (sceneDepth < highlightedDepth) { - outFragColor = vec4(params._fillOccludedColor, params._fillOccludedAlpha); - } else { - outFragColor = vec4(params._fillUnoccludedColor, params._fillUnoccludedAlpha); - } + outFragColor = mix(vec4(params._fillUnoccludedColor, params._fillUnoccludedAlpha), + vec4(params._fillOccludedColor, params._fillOccludedAlpha), + float(sceneDepth < highlightedDepth)); <@else@> discard; <@endif@> @@ -67,14 +65,13 @@ void main(void) { float outlinedDepth = 0.0; float sumOutlineDepth = 0.0; - for (y=0 ; y=0.0 && uv.y<=1.0) { - for (x=0 ; x=0.0 && uv.x<=1.0) - { + if (uv.y >= 0.0 && uv.y <= 1.0) { + for (x = 0; x < params._blurKernelSize; x++) { + if (uv.x >= 0.0 && uv.x <= 1.0) { outlinedDepth = texture(highlightedDepthMap, uv).x; float touch = (outlinedDepth < FAR_Z) ? 1.0 : 0.0; sumOutlineDepth = max(outlinedDepth * touch, sumOutlineDepth); @@ -86,11 +83,7 @@ void main(void) { } } - if (intensity > 0.0) { - // sumOutlineDepth /= intensity; - } else { - sumOutlineDepth = FAR_Z; - } + sumOutlineDepth = mix(FAR_Z, sumOutlineDepth, float(intensity > 0.0)); intensity /= weight; if (intensity < OPACITY_EPSILON) { @@ -106,11 +99,9 @@ void main(void) { sceneDepth = -evalZeyeFromZdb(sceneDepth); // Are we occluded? - if (sceneDepth < outlinedDepth) { - outFragColor = vec4(params._outlineOccludedColor, intensity * params._outlineOccludedAlpha); - } else { - outFragColor = vec4(params._outlineUnoccludedColor, intensity * params._outlineUnoccludedAlpha); - } + outFragColor = mix(vec4(params._outlineUnoccludedColor, intensity * params._outlineUnoccludedAlpha), + vec4(params._outlineOccludedColor, intensity * params._outlineOccludedAlpha), + float(sceneDepth < outlinedDepth)); } } diff --git a/libraries/render-utils/src/LightClusterGrid.slh b/libraries/render-utils/src/LightClusterGrid.slh index 62af92e6ce..cd944489ec 100644 --- a/libraries/render-utils/src/LightClusterGrid.slh +++ b/libraries/render-utils/src/LightClusterGrid.slh @@ -83,7 +83,7 @@ int clusterGrid_getClusterLightId(int index, int offset) { return element; */ int element = _clusterGridContent[GRID_FETCH_BUFFER((elementIndex >> 1))]; - return (((elementIndex & 0x00000001) == 1) ? (element >> 16) : element) & 0x0000FFFF; + return (element >> (16 * int((elementIndex & 0x00000001) == 1))) & 0x0000FFFF; } diff --git a/libraries/render-utils/src/LightClusterGrid_shared.slh b/libraries/render-utils/src/LightClusterGrid_shared.slh index 6d43e71920..cf58ce56ff 100644 --- a/libraries/render-utils/src/LightClusterGrid_shared.slh +++ b/libraries/render-utils/src/LightClusterGrid_shared.slh @@ -5,6 +5,14 @@ #define float_exp2 exp2 #endif +#ifdef __cplusplus +# define _MIN glm::min +# define _ABS(x) (int)fabsf(x) +#else +# define _MIN min +# define _ABS abs +#endif + float frustumGrid_depthRampGridToVolume(float ngrid) { // return ngrid; // return sqrt(ngrid); @@ -87,14 +95,9 @@ ivec3 frustumGrid_indexToCluster(int index) { } vec3 frustumGrid_clusterPosToEye(vec3 clusterPos) { - vec3 cvpos = clusterPos; - - vec3 volumePos = frustumGrid_gridToVolume(cvpos, frustumGrid.dims); - vec3 eyePos = frustumGrid_volumeToEye(volumePos, frustumGrid.eyeToGridProj, frustumGrid.rangeNear, frustumGrid.rangeFar); - return eyePos; } @@ -116,27 +119,19 @@ int frustumGrid_eyeDepthToClusterLayer(float eyeZ) { int gridZ = int(frustumGrid_volumeToGridDepth(volumeZ, frustumGrid.dims)); - if (gridZ >= frustumGrid.dims.z) { - gridZ = frustumGrid.dims.z; - } - - - return gridZ; + return _MIN(gridZ, frustumGrid.dims.z); } ivec3 frustumGrid_eyeToClusterPos(vec3 eyePos) { // make sure the frontEyePos is always in the front to eval the grid pos correctly vec3 frontEyePos = eyePos; - frontEyePos.z = (eyePos.z > 0.0f ? -eyePos.z : eyePos.z); + frontEyePos.z = -_ABS(eyePos.z); vec3 volumePos = frustumGrid_eyeToVolume(frontEyePos, frustumGrid.eyeToGridProj, frustumGrid.rangeNear, frustumGrid.rangeFar); vec3 gridPos = frustumGrid_volumeToGrid(volumePos, frustumGrid.dims); - - if (gridPos.z >= float(frustumGrid.dims.z)) { - gridPos.z = float(frustumGrid.dims.z); - } + gridPos.z = _MIN(gridPos.z, float(frustumGrid.dims.z)); ivec3 igridPos = ivec3(floor(gridPos)); @@ -154,7 +149,7 @@ ivec3 frustumGrid_eyeToClusterPos(vec3 eyePos) { int frustumGrid_eyeToClusterDirH(vec3 eyeDir) { if (eyeDir.z >= 0.0f) { - return (eyeDir.x > 0.0f ? frustumGrid.dims.x : -1); + return int(eyeDir.x > 0.0f) * (frustumGrid.dims.x + 1) - 1; } float eyeDepth = -eyeDir.z; @@ -168,7 +163,7 @@ int frustumGrid_eyeToClusterDirH(vec3 eyeDir) { int frustumGrid_eyeToClusterDirV(vec3 eyeDir) { if (eyeDir.z >= 0.0f) { - return (eyeDir.y > 0.0f ? frustumGrid.dims.y : -1); + return int(eyeDir.y > 0.0f) * (frustumGrid.dims.y + 1) - 1; } float eyeDepth = -eyeDir.z; @@ -196,4 +191,4 @@ vec4 frustumGrid_worldToEye(vec4 worldPos) { // <@if 1@> // Trigger Scribe include - // <@endif@> End C++ compatible \ No newline at end of file + // <@endif@> End C++ compatible diff --git a/libraries/render-utils/src/LightPoint.slh b/libraries/render-utils/src/LightPoint.slh index 1a361e3717..6100627105 100644 --- a/libraries/render-utils/src/LightPoint.slh +++ b/libraries/render-utils/src/LightPoint.slh @@ -41,12 +41,10 @@ void evalLightingPoint(out vec3 diffuse, out vec3 specular, Light light, specular *= lightEnergy * isSpecularEnabled(); if (isShowLightContour() > 0.0) { - // Show edge + // Show edges float edge = abs(2.0 * ((lightVolume_getRadius(light.volume) - fragLightDistance) / (0.1)) - 1.0); - if (edge < 1.0) { - float edgeCoord = exp2(-8.0*edge*edge); - diffuse = vec3(edgeCoord * edgeCoord * getLightColor(light)); - } + float edgeCoord = exp2(-8.0 * edge * edge); + diffuse = mix(diffuse, vec3(edgeCoord * edgeCoord * getLightColor(light)), float(edge < 1.0)); } } @@ -59,13 +57,11 @@ bool evalLightPointEdge(out vec3 color, Light light, vec4 fragLightDirLen, vec3 // Allright we re valid in the volume float fragLightDistance = fragLightDirLen.w; vec3 fragLightDir = fragLightDirLen.xyz; - + // Show edges float edge = abs(2.0 * ((lightVolume_getRadius(light.volume) - fragLightDistance) / (0.1)) - 1.0); - if (edge < 1.0) { - float edgeCoord = exp2(-8.0*edge*edge); - color = vec3(edgeCoord * edgeCoord * getLightColor(light)); - } + float edgeCoord = exp2(-8.0 * edge * edge); + color = mix(color, vec3(edgeCoord * edgeCoord * getLightColor(light)), float(edge < 1.0)); return (edge < 1.0); } diff --git a/libraries/render-utils/src/LightSpot.slh b/libraries/render-utils/src/LightSpot.slh index 2546c0225c..7fea9856d8 100644 --- a/libraries/render-utils/src/LightSpot.slh +++ b/libraries/render-utils/src/LightSpot.slh @@ -46,11 +46,9 @@ void evalLightingSpot(out vec3 diffuse, out vec3 specular, Light light, float edgeDistR = (lightVolume_getRadius(light.volume) - fragLightDistance); float edgeDistS = dot(fragLightDistance * vec2(cosSpotAngle, sqrt(1.0 - cosSpotAngle * cosSpotAngle)), -lightVolume_getSpotOutsideNormal2(light.volume)); float edgeDist = min(edgeDistR, edgeDistS); - float edge = abs(2.0 * (edgeDist / (0.1)) - 1.0); - if (edge < 1.0) { - float edgeCoord = exp2(-8.0*edge*edge); - diffuse = vec3(edgeCoord * edgeCoord * getLightColor(light)); - } + float edge = abs(2.0 * (edgeDist * 10.0) - 1.0); + float edgeCoord = exp2(-8.0 * edge * edge); + diffuse = mix(diffuse, vec3(edgeCoord * edgeCoord * getLightColor(light)), float(edge < 1.0)); } } @@ -67,15 +65,11 @@ bool evalLightSpotEdge(out vec3 color, Light light, vec4 fragLightDirLen, float float edgeDistR = (lightVolume_getRadius(light.volume) - fragLightDistance); float edgeDistS = dot(fragLightDistance * vec2(cosSpotAngle, sqrt(1.0 - cosSpotAngle * cosSpotAngle)), -lightVolume_getSpotOutsideNormal2(light.volume)); float edgeDist = min(edgeDistR, edgeDistS); - float edge = abs(2.0 * (edgeDist / (0.1)) - 1.0); - if (edge < 1.0) { - float edgeCoord = exp2(-8.0*edge*edge); - color = vec3(edgeCoord * edgeCoord * getLightColor(light)); - } + float edge = abs(2.0 * (edgeDist * 10.0) - 1.0); + float edgeCoord = exp2(-8.0 * edge * edge); + color = mix(color, vec3(edgeCoord * edgeCoord * getLightColor(light)), float(edge < 1.0)); return (edge < 1.0); } <@endfunc@> - - diff --git a/libraries/render-utils/src/Shadow.slh b/libraries/render-utils/src/Shadow.slh index 9506c9805d..b503844554 100644 --- a/libraries/render-utils/src/Shadow.slh +++ b/libraries/render-utils/src/Shadow.slh @@ -115,18 +115,10 @@ float evalShadowAttenuation(vec3 worldLightDir, vec4 worldPosition, float viewDe isPixelOnCascade.z = isShadowCascadeProjectedOnPixel(cascadeShadowCoords[2]); isPixelOnCascade.w = isShadowCascadeProjectedOnPixel(cascadeShadowCoords[3]); - if (isPixelOnCascade.x) { - cascadeAttenuations.x = evalShadowCascadeAttenuation(0, offsets, cascadeShadowCoords[0], oneMinusNdotL); - } - if (isPixelOnCascade.y) { - cascadeAttenuations.y = evalShadowCascadeAttenuation(1, offsets, cascadeShadowCoords[1], oneMinusNdotL); - } - if (isPixelOnCascade.z) { - cascadeAttenuations.z = evalShadowCascadeAttenuation(2, offsets, cascadeShadowCoords[2], oneMinusNdotL); - } - if (isPixelOnCascade.w) { - cascadeAttenuations.w = evalShadowCascadeAttenuation(3, offsets, cascadeShadowCoords[3], oneMinusNdotL); - } + cascadeAttenuations.x = mix(1.0, evalShadowCascadeAttenuation(0, offsets, cascadeShadowCoords[0], oneMinusNdotL), float(isPixelOnCascade.x)); + cascadeAttenuations.y = mix(1.0, evalShadowCascadeAttenuation(1, offsets, cascadeShadowCoords[1], oneMinusNdotL), float(isPixelOnCascade.y)); + cascadeAttenuations.z = mix(1.0, evalShadowCascadeAttenuation(2, offsets, cascadeShadowCoords[2], oneMinusNdotL), float(isPixelOnCascade.z)); + cascadeAttenuations.w = mix(1.0, evalShadowCascadeAttenuation(3, offsets, cascadeShadowCoords[3], oneMinusNdotL), float(isPixelOnCascade.w)); cascadeWeights.x = evalShadowCascadeWeight(cascadeShadowCoords[0]); cascadeWeights.y = evalShadowCascadeWeight(cascadeShadowCoords[1]); diff --git a/libraries/render-utils/src/Skinning.slh b/libraries/render-utils/src/Skinning.slh index 63246e85a1..30d5efd64e 100644 --- a/libraries/render-utils/src/Skinning.slh +++ b/libraries/render-utils/src/Skinning.slh @@ -81,9 +81,7 @@ void evalSkinning(ivec4 skinClusterIndex, vec4 skinClusterWeight, vec4 inPositio // to ensure that we rotate along the shortest arc, reverse dual quaternions with negative polarity. float dqClusterWeight = clusterWeight; - if (dot(real, polarityReference) < 0.0) { - dqClusterWeight = -clusterWeight; - } + dqClusterWeight *= mix(1.0, -1.0, float(dot(real, polarityReference) < 0.0)); sAccum += scale * clusterWeight; rAccum += real * dqClusterWeight; @@ -102,12 +100,11 @@ void evalSkinning(ivec4 skinClusterIndex, vec4 skinClusterWeight, vec4 inPositio // sAccum.w indicates the amount of cauterization for this vertex. // 0 indicates no cauterization and 1 indicates full cauterization. // TODO: make this cauterization smoother or implement full dual-quaternion scale support. - const float CAUTERIZATION_THRESHOLD = 0.1; - if (sAccum.w > CAUTERIZATION_THRESHOLD) { - skinnedPosition = cAccum; - } else { - sAccum.w = 1.0; - skinnedPosition = m * (sAccum * inPosition); + { + const float CAUTERIZATION_THRESHOLD = 0.1; + float check = float(sAccum.w > CAUTERIZATION_THRESHOLD); + sAccum.w = mix(1.0, sAccum.w, check); + skinnedPosition = mix(m * (sAccum * inPosition), cAccum, check); } <@if USE_NORMAL@> diff --git a/libraries/render-utils/src/SubsurfaceScattering.slh b/libraries/render-utils/src/SubsurfaceScattering.slh index 66b3ab1ea0..b4981110f2 100644 --- a/libraries/render-utils/src/SubsurfaceScattering.slh +++ b/libraries/render-utils/src/SubsurfaceScattering.slh @@ -82,8 +82,6 @@ vec3 integrate(float cosTheta, float skinRadius) { while (a <= (_PI)) { float sampleAngle = theta + a; float diffuse = clamp(cos(sampleAngle), 0.0, 1.0); - //if (diffuse < 0.0) diffuse = 0.0; - //if (diffuse > 1.0) diffuse = 1.0; // Distance. float sampleDist = abs(2.0 * skinRadius * sin(a * 0.5)); @@ -180,7 +178,8 @@ vec3 evalSkinBRDF(vec3 lightDir, vec3 normal, vec3 midNormal, vec3 lowNormal, fl return lowNormal * 0.5 + vec3(0.5); } if (showCurvature()) { - return (curvature > 0.0 ? vec3(curvature, 0.0, 0.0) : vec3(0.0, 0.0, -curvature)); + float check = float(curvature > 0.0); + return vec3(check * curvature, 0.0, (1.0 - check) * -curvature); } vec3 bentNdotL = evalScatteringBentNdotL(normal, midNormal, lowNormal, lightDir); diff --git a/libraries/render-utils/src/deferred_light_limited.slv b/libraries/render-utils/src/deferred_light_limited.slv index 1c835aacf7..0126d54664 100644 --- a/libraries/render-utils/src/deferred_light_limited.slv +++ b/libraries/render-utils/src/deferred_light_limited.slv @@ -37,9 +37,7 @@ void main(void) { #ifdef GPU_TRANSFORM_IS_STEREO #ifdef GPU_TRANSFORM_STEREO_SPLIT_SCREEN #else - if (cam_isStereo()) { - projected.x = 0.5 * (projected.x + cam_getStereoSide()); - } + projected.x = mix(projected.x, 0.5 * (projected.x + cam_getStereoSide()), float(cam_isStereo())); #endif #endif _texCoord01 = vec4(projected.xy, 0.0, 1.0) * gl_Position.w; @@ -66,9 +64,7 @@ void main(void) { #ifdef GPU_TRANSFORM_IS_STEREO #ifdef GPU_TRANSFORM_STEREO_SPLIT_SCREEN #else - if (cam_isStereo()) { - _texCoord01.x = 0.5 * (_texCoord01.x + cam_getStereoSide()); - } + _texCoord01.x = mix(_texCoord01.x, 0.5 * (_texCoord01.x + cam_getStereoSide()), float(cam_isStereo())); #endif #endif diff --git a/libraries/render-utils/src/deferred_light_point.slv b/libraries/render-utils/src/deferred_light_point.slv index 3e6329be83..c77ead439c 100644 --- a/libraries/render-utils/src/deferred_light_point.slv +++ b/libraries/render-utils/src/deferred_light_point.slv @@ -47,8 +47,6 @@ void main(void) { vec4 projected = gl_Position / gl_Position.w; projected.xy = (projected.xy + 1.0) * 0.5; - if (cam_isStereo()) { - projected.x = 0.5 * (projected.x + cam_getStereoSide()); - } + projected.x = mix(projected.x, 0.5 * (projected.x + cam_getStereoSide()), float(cam_isStereo())); _texCoord0 = vec4(projected.xy, 0.0, 1.0) * gl_Position.w; } diff --git a/libraries/render-utils/src/deferred_light_spot.slv b/libraries/render-utils/src/deferred_light_spot.slv index 0370acc6bc..332bb96167 100644 --- a/libraries/render-utils/src/deferred_light_spot.slv +++ b/libraries/render-utils/src/deferred_light_spot.slv @@ -60,9 +60,7 @@ void main(void) { #ifdef GPU_TRANSFORM_IS_STEREO #ifdef GPU_TRANSFORM_STEREO_SPLIT_SCREEN #else - if (cam_isStereo()) { - projected.x = 0.5 * (projected.x + cam_getStereoSide()); - } + projected.x = mix(projected.x, 0.5 * (projected.x + cam_getStereoSide()), float(cam_isStereo())); #endif #endif _texCoord0 = vec4(projected.xy, 0.0, 1.0) * gl_Position.w; diff --git a/libraries/render-utils/src/deformed_model.slv b/libraries/render-utils/src/deformed_model.slv index 039ad0a7d9..8c6d3d049d 100644 --- a/libraries/render-utils/src/deformed_model.slv +++ b/libraries/render-utils/src/deformed_model.slv @@ -44,13 +44,13 @@ void main(void) { _color.rgb = color_sRGBToLinear(inColor.rgb); _color.a = inColor.a; - TexMapArray texMapArray = getTexMapArray(); - <$evalTexMapArrayTexcoord0(texMapArray, inTexCoord0, _texCoord01.xy)$> - <$evalTexMapArrayTexcoord1(texMapArray, inTexCoord1, _texCoord01.zw)$> - // standard transform TransformCamera cam = getTransformCamera(); TransformObject obj = getTransformObject(); <$transformModelToWorldAndEyeAndClipPos(cam, obj, deformedPosition, _positionWS, _positionES, gl_Position)$> <$transformModelToWorldDir(cam, obj, deformedNormal, _normalWS.xyz)$> + + TexMapArray texMapArray = getTexMapArray(); + <$evalTexMapArrayTexcoord0(texMapArray, inTexCoord0, _positionWS, _texCoord01.xy)$> + <$evalTexMapArrayTexcoord1(texMapArray, inTexCoord1, _positionWS, _texCoord01.zw)$> } diff --git a/libraries/render-utils/src/deformed_model_dq.slv b/libraries/render-utils/src/deformed_model_dq.slv index 2165f3b9a4..56ac1b6558 100644 --- a/libraries/render-utils/src/deformed_model_dq.slv +++ b/libraries/render-utils/src/deformed_model_dq.slv @@ -41,13 +41,13 @@ void main(void) { _color.rgb = color_sRGBToLinear(inColor.rgb); _color.a = inColor.a; - TexMapArray texMapArray = getTexMapArray(); - <$evalTexMapArrayTexcoord0(texMapArray, inTexCoord0, _texCoord01.xy)$> - <$evalTexMapArrayTexcoord1(texMapArray, inTexCoord1, _texCoord01.zw)$> - // standard transform TransformCamera cam = getTransformCamera(); TransformObject obj = getTransformObject(); <$transformModelToWorldAndEyeAndClipPos(cam, obj, deformedPosition, _positionWS, _positionES, gl_Position)$> <$transformModelToWorldDir(cam, obj, deformedNormal, _normalWS.xyz)$> + + TexMapArray texMapArray = getTexMapArray(); + <$evalTexMapArrayTexcoord0(texMapArray, inTexCoord0, _positionWS, _texCoord01.xy)$> + <$evalTexMapArrayTexcoord1(texMapArray, inTexCoord1, _positionWS, _texCoord01.zw)$> } diff --git a/libraries/render-utils/src/deformed_model_normal_map.slv b/libraries/render-utils/src/deformed_model_normal_map.slv index 8627b5b856..85e164b639 100644 --- a/libraries/render-utils/src/deformed_model_normal_map.slv +++ b/libraries/render-utils/src/deformed_model_normal_map.slv @@ -43,14 +43,14 @@ void main(void) { _color.rgb = color_sRGBToLinear(inColor.rgb); _color.a = inColor.a; - TexMapArray texMapArray = getTexMapArray(); - <$evalTexMapArrayTexcoord0(texMapArray, inTexCoord0, _texCoord01.xy)$> - <$evalTexMapArrayTexcoord1(texMapArray, inTexCoord1, _texCoord01.zw)$> - // standard transform TransformCamera cam = getTransformCamera(); TransformObject obj = getTransformObject(); <$transformModelToWorldAndEyeAndClipPos(cam, obj, deformedPosition, _positionWS, _positionES, gl_Position)$> <$transformModelToWorldDir(cam, obj, deformedNormal, _normalWS.xyz)$> <$transformModelToWorldDir(cam, obj, deformedTangent, _tangentWS.xyz)$> + + TexMapArray texMapArray = getTexMapArray(); + <$evalTexMapArrayTexcoord0(texMapArray, inTexCoord0, _positionWS, _texCoord01.xy)$> + <$evalTexMapArrayTexcoord1(texMapArray, inTexCoord1, _positionWS, _texCoord01.zw)$> } diff --git a/libraries/render-utils/src/deformed_model_normal_map_dq.slv b/libraries/render-utils/src/deformed_model_normal_map_dq.slv index b45d94938a..807d343643 100644 --- a/libraries/render-utils/src/deformed_model_normal_map_dq.slv +++ b/libraries/render-utils/src/deformed_model_normal_map_dq.slv @@ -44,14 +44,14 @@ void main(void) { _color.rgb = color_sRGBToLinear(inColor.rgb); _color.a = inColor.a; - TexMapArray texMapArray = getTexMapArray(); - <$evalTexMapArrayTexcoord0(texMapArray, inTexCoord0, _texCoord01.xy)$> - <$evalTexMapArrayTexcoord1(texMapArray, inTexCoord1, _texCoord01.zw)$> - // standard transform TransformCamera cam = getTransformCamera(); TransformObject obj = getTransformObject(); <$transformModelToWorldAndEyeAndClipPos(cam, obj, deformedPosition, _positionWS, _positionES, gl_Position)$> <$transformModelToWorldDir(cam, obj, deformedNormal, _normalWS.xyz)$> <$transformModelToWorldDir(cam, obj, deformedTangent, _tangentWS.xyz)$> + + TexMapArray texMapArray = getTexMapArray(); + <$evalTexMapArrayTexcoord0(texMapArray, inTexCoord0, _positionWS, _texCoord01.xy)$> + <$evalTexMapArrayTexcoord1(texMapArray, inTexCoord1, _positionWS, _texCoord01.zw)$> } diff --git a/libraries/render-utils/src/directional_ambient_light.slf b/libraries/render-utils/src/directional_ambient_light.slf index 15d00f713e..b1cfc26c66 100644 --- a/libraries/render-utils/src/directional_ambient_light.slf +++ b/libraries/render-utils/src/directional_ambient_light.slf @@ -33,16 +33,15 @@ void main(void) { float shadowAttenuation = 1.0; - if (frag.mode == FRAG_MODE_UNLIT) { - discard; - } else if (frag.mode == FRAG_MODE_LIGHTMAPPED) { + if (frag.mode == FRAG_MODE_UNLIT || frag.mode == FRAG_MODE_LIGHTMAPPED) { discard; } else { vec4 midNormalCurvature = vec4(0); vec4 lowNormalCurvature = vec4(0); - if (frag.mode == FRAG_MODE_SCATTERING) { - unpackMidLowNormalCurvature(_texCoord0, midNormalCurvature, lowNormalCurvature); - } + unpackMidLowNormalCurvature(_texCoord0, midNormalCurvature, lowNormalCurvature); + float check = float(frag.mode == FRAG_MODE_SCATTERING); + midNormalCurvature = check * midNormalCurvature; + lowNormalCurvature = check * lowNormalCurvature; vec3 color = evalAmbientSphereGlobalColor( getViewInverse(), diff --git a/libraries/render-utils/src/directional_ambient_light_shadow.slf b/libraries/render-utils/src/directional_ambient_light_shadow.slf index d6cdf78f19..6b9fb80232 100644 --- a/libraries/render-utils/src/directional_ambient_light_shadow.slf +++ b/libraries/render-utils/src/directional_ambient_light_shadow.slf @@ -35,16 +35,16 @@ void main(void) { vec3 worldLightDirection = getLightDirection(shadowLight); float shadowAttenuation = evalShadowAttenuation(worldLightDirection, worldPos, -viewPos.z, frag.normal); - if (frag.mode == FRAG_MODE_UNLIT) { - discard; - } else if (frag.mode == FRAG_MODE_LIGHTMAPPED) { + if (frag.mode == FRAG_MODE_UNLIT || frag.mode == FRAG_MODE_LIGHTMAPPED) { discard; } else { vec4 midNormalCurvature = vec4(0); vec4 lowNormalCurvature = vec4(0); - if (frag.mode == FRAG_MODE_SCATTERING) { - unpackMidLowNormalCurvature(_texCoord0, midNormalCurvature, lowNormalCurvature); - } + unpackMidLowNormalCurvature(_texCoord0, midNormalCurvature, lowNormalCurvature); + float check = float(frag.mode == FRAG_MODE_SCATTERING); + midNormalCurvature = check * midNormalCurvature; + lowNormalCurvature = check * lowNormalCurvature; + vec3 color = evalAmbientSphereGlobalColor( getViewInverse(), shadowAttenuation, diff --git a/libraries/render-utils/src/directional_skybox_light.slf b/libraries/render-utils/src/directional_skybox_light.slf index b27d759dd4..b820b3d17f 100644 --- a/libraries/render-utils/src/directional_skybox_light.slf +++ b/libraries/render-utils/src/directional_skybox_light.slf @@ -31,16 +31,16 @@ void main(void) { float shadowAttenuation = 1.0; // Light mapped or not ? - if (frag.mode == FRAG_MODE_UNLIT) { - discard; - } else if (frag.mode == FRAG_MODE_LIGHTMAPPED) { + if (frag.mode == FRAG_MODE_UNLIT || frag.mode == FRAG_MODE_LIGHTMAPPED) { discard; } else { vec4 midNormalCurvature = vec4(0); vec4 lowNormalCurvature = vec4(0); - if (frag.mode == FRAG_MODE_SCATTERING) { - unpackMidLowNormalCurvature(_texCoord0, midNormalCurvature, lowNormalCurvature); - } + unpackMidLowNormalCurvature(_texCoord0, midNormalCurvature, lowNormalCurvature); + float check = float(frag.mode == FRAG_MODE_SCATTERING); + midNormalCurvature = check * midNormalCurvature; + lowNormalCurvature = check * lowNormalCurvature; + vec3 color = evalSkyboxGlobalColor( getViewInverse(), shadowAttenuation, diff --git a/libraries/render-utils/src/directional_skybox_light_shadow.slf b/libraries/render-utils/src/directional_skybox_light_shadow.slf index 292f7348e3..8716d60d54 100644 --- a/libraries/render-utils/src/directional_skybox_light_shadow.slf +++ b/libraries/render-utils/src/directional_skybox_light_shadow.slf @@ -36,16 +36,16 @@ void main(void) { float shadowAttenuation = evalShadowAttenuation(worldLightDirection, worldPos, -viewPos.z, frag.normal); // Light mapped or not ? - if (frag.mode == FRAG_MODE_UNLIT) { - discard; - } else if (frag.mode == FRAG_MODE_LIGHTMAPPED) { + if (frag.mode == FRAG_MODE_UNLIT || frag.mode == FRAG_MODE_LIGHTMAPPED) { discard; } else { vec4 midNormalCurvature = vec4(0); vec4 lowNormalCurvature = vec4(0); - if (frag.mode == FRAG_MODE_SCATTERING) { - unpackMidLowNormalCurvature(_texCoord0, midNormalCurvature, lowNormalCurvature); - } + unpackMidLowNormalCurvature(_texCoord0, midNormalCurvature, lowNormalCurvature); + float check = float(frag.mode == FRAG_MODE_SCATTERING); + midNormalCurvature = check * midNormalCurvature; + lowNormalCurvature = check * lowNormalCurvature; + vec3 color = evalSkyboxGlobalColor( getViewInverse(), shadowAttenuation, diff --git a/libraries/render-utils/src/drawWorkloadProxy.slv b/libraries/render-utils/src/drawWorkloadProxy.slv index 7a01702107..9dfcf8415c 100644 --- a/libraries/render-utils/src/drawWorkloadProxy.slv +++ b/libraries/render-utils/src/drawWorkloadProxy.slv @@ -62,7 +62,5 @@ void main(void) { varColor = vec4(REGION_COLOR[region].xyz, proxy.sphere.w); - if (region == 4) { - gl_Position = vec4(0.0); - } + gl_Position = mix(gl_Position, vec4(0.0), float(region == 4)); } diff --git a/libraries/render-utils/src/glowLine.slv b/libraries/render-utils/src/glowLine.slv index 167aeb8c9e..3471bc2f98 100644 --- a/libraries/render-utils/src/glowLine.slv +++ b/libraries/render-utils/src/glowLine.slv @@ -53,14 +53,9 @@ void main(void) { // Add or subtract the orthogonal vector based on a different vertex ID // calculation - if (gl_VertexID < 2) { - distanceFromCenter = -1.0; - eye.xyz -= orthogonal; - } else { - distanceFromCenter = 1.0; - eye.xyz += orthogonal; - } + distanceFromCenter = 1.0 - 2.0 * float(gl_VertexID < 2); + eye.xyz += distanceFromCenter * orthogonal; // Finally, put the eyespace vertex into clip space <$transformEyeToClipPos(cam, eye, gl_Position)$> -} \ No newline at end of file +} diff --git a/libraries/render-utils/src/grid.slf b/libraries/render-utils/src/grid.slf index 8e9b35dace..408a9ca190 100644 --- a/libraries/render-utils/src/grid.slf +++ b/libraries/render-utils/src/grid.slf @@ -34,12 +34,10 @@ layout(location=0) out vec4 outFragColor; void main(void) { Grid grid = getGrid(); - float alpha; - if (grid.edge.z == 0.0) { - alpha = paintGrid(varTexCoord0, grid.offset.xy, grid.period.xy, grid.edge.xy); - } else { - alpha = paintGridMajorMinor(varTexCoord0, grid.offset, grid.period, grid.edge); - } + float alpha = mix(paintGridMajorMinor(varTexCoord0, grid.offset, grid.period, grid.edge), + paintGrid(varTexCoord0, grid.offset.xy, grid.period.xy, grid.edge.xy), + float(grid.edge.z == 0.0)); + if (alpha == 0.0) { discard; } diff --git a/libraries/render-utils/src/lightClusters_drawClusterContent.slf b/libraries/render-utils/src/lightClusters_drawClusterContent.slf index 27cb838566..80013bc3cc 100644 --- a/libraries/render-utils/src/lightClusters_drawClusterContent.slf +++ b/libraries/render-utils/src/lightClusters_drawClusterContent.slf @@ -90,6 +90,6 @@ void main(void) { numLightTouching++; } - _fragColor = vec4(colorRamp(1.0 - (float(numLightTouching) / 12.0f)), (numLightTouching > 0 ? 0.5 + 0.5 * numLightsScale : 0.0)); + _fragColor = vec4(colorRamp(1.0 - (float(numLightTouching) / 12.0f)), float(numLightTouching > 0) * (0.5 + 0.5 * numLightsScale)); } diff --git a/libraries/render-utils/src/lightClusters_drawClusterContent.slv b/libraries/render-utils/src/lightClusters_drawClusterContent.slv index 1303cf3926..c30252da41 100644 --- a/libraries/render-utils/src/lightClusters_drawClusterContent.slv +++ b/libraries/render-utils/src/lightClusters_drawClusterContent.slv @@ -69,5 +69,5 @@ void main(void) { TransformCamera cam = getTransformCamera(); <$transformWorldToClipPos(cam, worldPos, gl_Position)$> - varColor = vec4(colorWheel(fract(float(gpu_InstanceID()) / float(frustumGrid_numClusters()))), (numLights >0 ? 0.9 : 0.1)); + varColor = vec4(colorWheel(fract(float(gpu_InstanceID()) / float(frustumGrid_numClusters()))), 0.1 + 0.8 * float(numLights > 0)); } \ No newline at end of file diff --git a/libraries/render-utils/src/lightClusters_drawClusterFromDepth.slf b/libraries/render-utils/src/lightClusters_drawClusterFromDepth.slf index abbd86dd70..0e3f8a5ea5 100644 --- a/libraries/render-utils/src/lightClusters_drawClusterFromDepth.slf +++ b/libraries/render-utils/src/lightClusters_drawClusterFromDepth.slf @@ -62,12 +62,10 @@ void main(void) { float relClusterId = float(clusterPos.z * summedDims.x + clusterPos.y * summedDims.y + clusterPos.x) / float(frustumGrid_numClusters()); - if (relClusterId < 0.0) { - _fragColor = vec4(0.0); - } else if (relClusterId >= 1.0) { - _fragColor = vec4(vec3(1.0), 0.2); - } else { - _fragColor = vec4(colorWheel(fract(relClusterId)), (numLights > 0 ? 0.05 + 0.95 * numLightsScale : 0.0)); - } + _fragColor = mix(mix(vec4(colorWheel(fract(relClusterId)), float(numLights > 0) * (0.05 + 0.95 * numLightsScale)), + vec4(vec3(1.0), 0.2), + float(relClusterId >= 1.0)), + vec4(0.0), + float(relClusterId < 0.0)); } diff --git a/libraries/render-utils/src/lightClusters_drawClusterFromDepth.slv b/libraries/render-utils/src/lightClusters_drawClusterFromDepth.slv index d35c7cb20b..a5c037cc7a 100644 --- a/libraries/render-utils/src/lightClusters_drawClusterFromDepth.slv +++ b/libraries/render-utils/src/lightClusters_drawClusterFromDepth.slv @@ -62,5 +62,5 @@ void main(void) { TransformCamera cam = getTransformCamera(); <$transformWorldToClipPos(cam, worldPos, gl_Position)$> - varColor = vec4(colorWheel(fract(float(gpu_InstanceID()) / float(frustumGrid_numClusters()))), 0.9); + varColor = vec4(colorWheel(fract(float(gpu_InstanceID()) / float(frustumGrid_numClusters()))), 0.9); } \ No newline at end of file diff --git a/libraries/render-utils/src/lightClusters_drawGrid.slv b/libraries/render-utils/src/lightClusters_drawGrid.slv index c4aff45beb..8d557d01c8 100644 --- a/libraries/render-utils/src/lightClusters_drawGrid.slv +++ b/libraries/render-utils/src/lightClusters_drawGrid.slv @@ -69,5 +69,5 @@ void main(void) { TransformCamera cam = getTransformCamera(); <$transformWorldToClipPos(cam, worldPos, gl_Position)$> - varColor = vec4(colorWheel(fract(float(gpu_InstanceID()) / float(frustumGrid_numClusters()))), (numLights > 0 ? 0.9 : 0.0)); + varColor = vec4(colorWheel(fract(float(gpu_InstanceID()) / float(frustumGrid_numClusters()))), float(numLights > 0) * 0.9); } \ No newline at end of file diff --git a/libraries/render-utils/src/local_lights_drawOutline.slf b/libraries/render-utils/src/local_lights_drawOutline.slf index fc1d416f96..a2b4cc1d10 100644 --- a/libraries/render-utils/src/local_lights_drawOutline.slf +++ b/libraries/render-utils/src/local_lights_drawOutline.slf @@ -96,9 +96,8 @@ void main(void) { vec3 fragLightDir = fragLightDirLen.xyz; vec3 color = vec3(0.0); - if (evalLightPointEdge(color, light, fragLightDirLen, fragEyeDir)) { - _fragColor.rgb += color; - } + float check = float(evalLightPointEdge(color, light, fragLightDirLen, fragEyeDir)); + _fragColor.rgb += check * color; } for (int i = cluster.x; i < numLights; i++) { @@ -130,10 +129,8 @@ void main(void) { numLightTouching++; vec3 color = vec3(0.0); - - if (evalLightSpotEdge(color, light, fragLightDirLen, cosSpotAngle, fragEyeDir)) { - _fragColor.rgb += color; - } + float check = float(evalLightSpotEdge(color, light, fragLightDirLen, cosSpotAngle, fragEyeDir)); + _fragColor.rgb += check * color; } } diff --git a/libraries/render-utils/src/model.slv b/libraries/render-utils/src/model.slv index f3d315c7a4..88cbd1e18c 100644 --- a/libraries/render-utils/src/model.slv +++ b/libraries/render-utils/src/model.slv @@ -31,13 +31,13 @@ void main(void) { _color.rgb = color_sRGBToLinear(inColor.rgb); _color.a = inColor.a; - TexMapArray texMapArray = getTexMapArray(); - <$evalTexMapArrayTexcoord0(texMapArray, inTexCoord0, _texCoord01.xy)$> - <$evalTexMapArrayTexcoord1(texMapArray, inTexCoord1, _texCoord01.zw)$> - // standard transform TransformCamera cam = getTransformCamera(); TransformObject obj = getTransformObject(); <$transformModelToWorldAndEyeAndClipPos(cam, obj, inPosition, _positionWS, _positionES, gl_Position)$> <$transformModelToWorldDir(cam, obj, inNormal.xyz, _normalWS)$> + + TexMapArray texMapArray = getTexMapArray(); + <$evalTexMapArrayTexcoord0(texMapArray, inTexCoord0, _positionWS, _texCoord01.xy)$> + <$evalTexMapArrayTexcoord1(texMapArray, inTexCoord1, _positionWS, _texCoord01.zw)$> } diff --git a/libraries/render-utils/src/model_normal_map.slv b/libraries/render-utils/src/model_normal_map.slv index 94d8a43b6e..0fd9a8b582 100644 --- a/libraries/render-utils/src/model_normal_map.slv +++ b/libraries/render-utils/src/model_normal_map.slv @@ -32,14 +32,14 @@ void main(void) { _color.rgb = color_sRGBToLinear(inColor.rgb); _color.a = inColor.a; - TexMapArray texMapArray = getTexMapArray(); - <$evalTexMapArrayTexcoord0(texMapArray, inTexCoord0, _texCoord01.xy)$> - <$evalTexMapArrayTexcoord1(texMapArray, inTexCoord1, _texCoord01.zw)$> - // standard transform TransformCamera cam = getTransformCamera(); TransformObject obj = getTransformObject(); <$transformModelToWorldAndEyeAndClipPos(cam, obj, inPosition, _positionWS, _positionES, gl_Position)$> <$transformModelToWorldDir(cam, obj, inNormal.xyz, _normalWS)$> <$transformModelToWorldDir(cam, obj, inTangent.xyz, _tangentWS)$> + + TexMapArray texMapArray = getTexMapArray(); + <$evalTexMapArrayTexcoord0(texMapArray, inTexCoord0, _positionWS, _texCoord01.xy)$> + <$evalTexMapArrayTexcoord1(texMapArray, inTexCoord1, _positionWS, _texCoord01.zw)$> } diff --git a/libraries/render-utils/src/parabola.slv b/libraries/render-utils/src/parabola.slv index 53dfc75cfe..6032452d1d 100644 --- a/libraries/render-utils/src/parabola.slv +++ b/libraries/render-utils/src/parabola.slv @@ -48,11 +48,8 @@ void main(void) { } else { normal = vec4(normalize(cross(_parabolaData.velocity, _parabolaData.acceleration)), 0); } - if (gl_VertexID % 2 == 0) { - pos += 0.5 * _parabolaData.width * normal; - } else { - pos -= 0.5 * _parabolaData.width * normal; - } + + pos += 0.5 * _parabolaData.width * normal * (-1.0 + 2.0 * float(gl_VertexID % 2 == 0)); <$transformModelToClipPos(cam, obj, pos, gl_Position)$> -} \ No newline at end of file +} diff --git a/libraries/render-utils/src/sdf_text3D.slf b/libraries/render-utils/src/sdf_text3D.slf index 35e670eef8..b070fc44cf 100644 --- a/libraries/render-utils/src/sdf_text3D.slf +++ b/libraries/render-utils/src/sdf_text3D.slf @@ -39,13 +39,8 @@ const float taaBias = pow(2.0, TAA_TEXTURE_LOD_BIAS); float evalSDF(vec2 texCoord) { // retrieve signed distance float sdf = textureLod(Font, texCoord, TAA_TEXTURE_LOD_BIAS).g; - if (params.outline.x > 0.0) { - if (sdf > interiorCutoff) { - sdf = 1.0 - sdf; - } else { - sdf += outlineExpansion; - } - } + sdf = mix(sdf, mix(sdf + outlineExpansion, 1.0 - sdf, float(sdf > interiorCutoff)), float(params.outline.x > 0.0)); + // Rely on TAA for anti-aliasing return step(0.5, sdf); } @@ -57,16 +52,11 @@ void main() { // Perform 4x supersampling for anisotropic filtering float a; a = evalSDF(_texCoord0); - a += evalSDF(_texCoord0+dxTexCoord); - a += evalSDF(_texCoord0+dyTexCoord); - a += evalSDF(_texCoord0+dxTexCoord+dyTexCoord); + a += evalSDF(_texCoord0 + dxTexCoord); + a += evalSDF(_texCoord0 + dyTexCoord); + a += evalSDF(_texCoord0 + dxTexCoord + dyTexCoord); a *= 0.25; - // discard if invisible - if (a < 0.01) { - discard; - } - packDeferredFragment( normalize(_normalWS), a * params.color.a, diff --git a/libraries/render-utils/src/sdf_text3D_transparent.slf b/libraries/render-utils/src/sdf_text3D_transparent.slf index cc4cdfb72f..2fbfb2ca43 100644 --- a/libraries/render-utils/src/sdf_text3D_transparent.slf +++ b/libraries/render-utils/src/sdf_text3D_transparent.slf @@ -30,31 +30,32 @@ layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01; #define _texCoord0 _texCoord01.xy #define _texCoord1 _texCoord01.zw -const float gamma = 2.2; -const float smoothing = 32.0; +#define TAA_TEXTURE_LOD_BIAS -3.0 + const float interiorCutoff = 0.8; const float outlineExpansion = 0.2; +const float taaBias = pow(2.0, TAA_TEXTURE_LOD_BIAS); + +float evalSDF(vec2 texCoord) { + // retrieve signed distance + float sdf = textureLod(Font, texCoord, TAA_TEXTURE_LOD_BIAS).g; + sdf = mix(sdf, mix(sdf + outlineExpansion, 1.0 - sdf, float(sdf > interiorCutoff)), float(params.outline.x > 0.0)); + + // Rely on TAA for anti-aliasing + return step(0.5, sdf); +} void main() { - // retrieve signed distance - float sdf = texture(Font, _texCoord0).g; - if (params.outline.x > 0.0) { - if (sdf > interiorCutoff) { - sdf = 1.0 - sdf; - } else { - sdf += outlineExpansion; - } - } - // perform adaptive anti-aliasing of the edges - // The larger we're rendering, the less anti-aliasing we need - float s = smoothing * length(fwidth(_texCoord0)); - float w = clamp(s, 0.0, 0.5); - float a = smoothstep(0.5 - w, 0.5 + w, sdf); - - // discard if invisible - if (a < 0.01) { - discard; - } + vec2 dxTexCoord = dFdx(_texCoord0) * 0.5 * taaBias; + vec2 dyTexCoord = dFdy(_texCoord0) * 0.5 * taaBias; + + // Perform 4x supersampling for anisotropic filtering + float a; + a = evalSDF(_texCoord0); + a += evalSDF(_texCoord0 + dxTexCoord); + a += evalSDF(_texCoord0 + dyTexCoord); + a += evalSDF(_texCoord0 + dxTexCoord + dyTexCoord); + a *= 0.25; packDeferredFragmentTranslucent( normalize(_normalWS), diff --git a/libraries/render-utils/src/simple.slf b/libraries/render-utils/src/simple.slf index dac01aac89..d2ddaa8e55 100644 --- a/libraries/render-utils/src/simple.slf +++ b/libraries/render-utils/src/simple.slf @@ -54,7 +54,7 @@ void main(void) { vec3 specular = DEFAULT_SPECULAR; float shininess = DEFAULT_SHININESS; float emissiveAmount = 0.0; - + #ifdef PROCEDURAL #ifdef PROCEDURAL_V1 diff --git a/libraries/render-utils/src/simple_textured.slf b/libraries/render-utils/src/simple_textured.slf index b308b57345..9494edb890 100644 --- a/libraries/render-utils/src/simple_textured.slf +++ b/libraries/render-utils/src/simple_textured.slf @@ -12,6 +12,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +<@include gpu/Color.slh@> <@include DeferredBufferWrite.slh@> <@include render-utils/ShaderConstants.h@> @@ -28,11 +29,13 @@ layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01; void main(void) { vec4 texel = texture(originalTexture, _texCoord0); + texel = mix(color_sRGBAToLinear(texel), texel, float(_color.a <= 0.0)); + texel.rgb *= _color.rgb; packDeferredFragment( normalize(_normalWS), 1.0, - _color.rgb * texel.rgb, + texel.rgb, DEFAULT_ROUGHNESS, DEFAULT_METALLIC, DEFAULT_EMISSIVE, diff --git a/libraries/render-utils/src/simple_textured_fade.slf b/libraries/render-utils/src/simple_textured_fade.slf index 9132505d8e..5ca21a71ac 100644 --- a/libraries/render-utils/src/simple_textured_fade.slf +++ b/libraries/render-utils/src/simple_textured_fade.slf @@ -39,26 +39,24 @@ void main(void) { <$fetchFadeObjectParamsInstanced(fadeParams)$> applyFade(fadeParams, _positionWS.xyz, fadeEmissive); - + vec4 texel = texture(originalTexture, _texCoord0); - float colorAlpha = _color.a; - if (_color.a <= 0.0) { - texel = color_sRGBAToLinear(texel); - colorAlpha = -_color.a; - } + texel = mix(color_sRGBAToLinear(texel), texel, float(_color.a <= 0.0)); + texel.rgb *= _color.rgb; + texel.a = abs(_color.a); const float ALPHA_THRESHOLD = 0.999; - if (colorAlpha * texel.a < ALPHA_THRESHOLD) { + if (texel.a < ALPHA_THRESHOLD) { packDeferredFragmentTranslucent( normalize(_normalWS), - colorAlpha * texel.a, - _color.rgb * texel.rgb + fadeEmissive, + texel.a, + texel.rgb + fadeEmissive, DEFAULT_ROUGHNESS); } else { packDeferredFragment( normalize(_normalWS), 1.0, - _color.rgb * texel.rgb, + texel.rgb, DEFAULT_ROUGHNESS, DEFAULT_METALLIC, DEFAULT_EMISSIVE + fadeEmissive, diff --git a/libraries/render-utils/src/simple_textured_unlit.slf b/libraries/render-utils/src/simple_textured_unlit.slf index 87fecee9cd..2d8f228f1c 100644 --- a/libraries/render-utils/src/simple_textured_unlit.slf +++ b/libraries/render-utils/src/simple_textured_unlit.slf @@ -28,24 +28,22 @@ layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01; #define _texCoord1 _texCoord01.zw void main(void) { - vec4 texel = texture(originalTexture, _texCoord0.st); - float colorAlpha = _color.a; - if (_color.a <= 0.0) { - texel = color_sRGBAToLinear(texel); - colorAlpha = -_color.a; - } + vec4 texel = texture(originalTexture, _texCoord0); + texel = mix(color_sRGBAToLinear(texel), texel, float(_color.a <= 0.0)); + texel.rgb *= _color.rgb; + texel.a = abs(_color.a); const float ALPHA_THRESHOLD = 0.999; - if (colorAlpha * texel.a < ALPHA_THRESHOLD) { + if (texel.a < ALPHA_THRESHOLD) { packDeferredFragmentTranslucent( normalize(_normalWS), - colorAlpha * texel.a, - _color.rgb * texel.rgb, + texel.a, + texel.rgb, DEFAULT_ROUGHNESS); } else { packDeferredFragmentUnlit( normalize(_normalWS), 1.0, - _color.rgb * texel.rgb); + texel.rgb); } } \ No newline at end of file diff --git a/libraries/render-utils/src/simple_textured_unlit_fade.slf b/libraries/render-utils/src/simple_textured_unlit_fade.slf index edaa3b592a..442be14a8e 100644 --- a/libraries/render-utils/src/simple_textured_unlit_fade.slf +++ b/libraries/render-utils/src/simple_textured_unlit_fade.slf @@ -40,24 +40,22 @@ void main(void) { <$fetchFadeObjectParamsInstanced(fadeParams)$> applyFade(fadeParams, _positionWS.xyz, fadeEmissive); - vec4 texel = texture(originalTexture, _texCoord0.st); - float colorAlpha = _color.a; - if (_color.a <= 0.0) { - texel = color_sRGBAToLinear(texel); - colorAlpha = -_color.a; - } + vec4 texel = texture(originalTexture, _texCoord0); + texel = mix(color_sRGBAToLinear(texel), texel, float(_color.a <= 0.0)); + texel.rgb *= _color.rgb; + texel.a = abs(_color.a); const float ALPHA_THRESHOLD = 0.999; - if (colorAlpha * texel.a < ALPHA_THRESHOLD) { + if (texel.a < ALPHA_THRESHOLD) { packDeferredFragmentTranslucent( normalize(_normalWS), - colorAlpha * texel.a, - _color.rgb * texel.rgb+fadeEmissive, + texel.a, + texel.rgb + fadeEmissive, DEFAULT_ROUGHNESS); } else { packDeferredFragmentUnlit( normalize(_normalWS), 1.0, - _color.rgb * texel.rgb+fadeEmissive); + texel.rgb + fadeEmissive); } } \ No newline at end of file diff --git a/libraries/render-utils/src/simple_transparent_textured.slf b/libraries/render-utils/src/simple_transparent_textured.slf index e1ed522c64..1a9d14e2fa 100644 --- a/libraries/render-utils/src/simple_transparent_textured.slf +++ b/libraries/render-utils/src/simple_transparent_textured.slf @@ -12,6 +12,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +<@include gpu/Color.slh@> <@include DeferredBufferWrite.slh@> <@include render-utils/ShaderConstants.h@> @@ -28,11 +29,13 @@ layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01; void main(void) { vec4 texel = texture(originalTexture, _texCoord0); - float colorAlpha = _color.a * texel.a; + texel = mix(color_sRGBAToLinear(texel), texel, float(_color.a <= 0.0)); + texel.rgb *= _color.rgb; + texel.a *= abs(_color.a); packDeferredFragmentTranslucent( normalize(_normalWS), - colorAlpha, - _color.rgb * texel.rgb, + texel.a, + texel.rgb, DEFAULT_ROUGHNESS); } \ No newline at end of file diff --git a/libraries/render-utils/src/simple_transparent_textured_fade.slf b/libraries/render-utils/src/simple_transparent_textured_fade.slf index 5fac67e1d2..75a88dc581 100644 --- a/libraries/render-utils/src/simple_transparent_textured_fade.slf +++ b/libraries/render-utils/src/simple_transparent_textured_fade.slf @@ -46,14 +46,10 @@ void main(void) { <$fetchFadeObjectParamsInstanced(fadeParams)$> applyFade(fadeParams, _positionWS.xyz, fadeEmissive); - vec4 texel = texture(originalTexture, _texCoord0.st); - float opacity = _color.a; - if (_color.a <= 0.0) { - texel = color_sRGBAToLinear(texel); - opacity = -_color.a; - } - opacity *= texel.a; - vec3 albedo = _color.rgb * texel.rgb; + vec4 texel = texture(originalTexture, _texCoord0); + texel = mix(color_sRGBAToLinear(texel), texel, float(_color.a <= 0.0)); + texel.rgb *= _color.rgb; + texel.a *= abs(_color.a); vec3 fragPosition = _positionES.xyz; vec3 fragNormal = normalize(_normalWS); @@ -66,12 +62,11 @@ void main(void) { 1.0, fragPosition, fragNormal, - albedo, + texel.rgb, DEFAULT_FRESNEL, 0.0f, fadeEmissive, DEFAULT_ROUGHNESS, - opacity), - opacity); - + texel.a), + texel.a); } \ No newline at end of file diff --git a/libraries/render-utils/src/simple_transparent_textured_unlit.slf b/libraries/render-utils/src/simple_transparent_textured_unlit.slf index bf3dbbdf88..3f4abfc730 100644 --- a/libraries/render-utils/src/simple_transparent_textured_unlit.slf +++ b/libraries/render-utils/src/simple_transparent_textured_unlit.slf @@ -27,11 +27,10 @@ layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01; layout(location=0) out vec4 _fragColor0; void main(void) { - vec4 texel = texture(originalTexture, _texCoord0.st); - float colorAlpha = _color.a; - if (_color.a <= 0.0) { - texel = color_sRGBAToLinear(texel); - colorAlpha = -_color.a; - } - _fragColor0 = vec4(_color.rgb * texel.rgb, colorAlpha * texel.a); + vec4 texel = texture(originalTexture, _texCoord0); + texel = mix(color_sRGBAToLinear(texel), texel, float(_color.a <= 0.0)); + texel.rgb *= _color.rgb; + texel.a *= abs(_color.a); + + _fragColor0 = texel; } \ No newline at end of file diff --git a/libraries/render-utils/src/simple_transparent_textured_unlit_fade.slf b/libraries/render-utils/src/simple_transparent_textured_unlit_fade.slf index 943f361ead..e46426ec7a 100644 --- a/libraries/render-utils/src/simple_transparent_textured_unlit_fade.slf +++ b/libraries/render-utils/src/simple_transparent_textured_unlit_fade.slf @@ -39,11 +39,10 @@ void main(void) { <$fetchFadeObjectParamsInstanced(fadeParams)$> applyFade(fadeParams, _positionWS.xyz, fadeEmissive); - vec4 texel = texture(originalTexture, _texCoord0.st); - float colorAlpha = _color.a; - if (_color.a <= 0.0) { - texel = color_sRGBAToLinear(texel); - colorAlpha = -_color.a; - } - _fragColor0 = vec4(_color.rgb * texel.rgb + fadeEmissive, colorAlpha * texel.a); + vec4 texel = texture(originalTexture, _texCoord0); + texel = mix(color_sRGBAToLinear(texel), texel, float(_color.a <= 0.0)); + texel.rgb *= _color.rgb; + texel.a *= abs(_color.a); + + _fragColor0 = vec4(texel.rgb + fadeEmissive, texel.a); } \ No newline at end of file diff --git a/libraries/render-utils/src/ssao.slh b/libraries/render-utils/src/ssao.slh index b683dc38f1..50d3b31dde 100644 --- a/libraries/render-utils/src/ssao.slh +++ b/libraries/render-utils/src/ssao.slh @@ -219,26 +219,24 @@ vec3 getTapLocationClampedSSAO(int sampleNumber, float spinAngle, float outerRad } bool redoTap = false; - if ((tapPos.x < 0.5)) { - tapPos.x = -tapPos.x; - redoTap = true; - } else if ((tapPos.x > sideImageSize.x - 0.5)) { - tapPos.x -= (sideImageSize.x - tapPos.x); - redoTap = true; + { + float check1 = float(tapPos.x < 0.5); + float check2 = (1.0 - check1) * float(tapPos.x > sideImageSize.x - 0.5); + tapPos.x = tapPos.x - 2.0 * tapPos.x * check1 - check2 * (sideImageSize.x - tapPos.x); + redoTap = (check1 > 0.0 || check2 > 0.0); } - if ((tapPos.y < 0.5)) { - tapPos.y = -tapPos.y; - redoTap = true; - } else if ((tapPos.y > sideImageSize.y - 0.5)) { - tapPos.y -= (sideImageSize.y - tapPos.y); - redoTap = true; + { + float check1 = float(tapPos.y < 0.5); + float check2 = (1.0 - check1) * float(tapPos.y > sideImageSize.y - 0.5); + tapPos.y = tapPos.y - 2.0 * tapPos.y * check1 - check2 * (sideImageSize.y - tapPos.y); + redoTap = (check1 > 0.0 || check2 > 0.0); } - if (redoTap) { - tap.xy = tapPos - pixelPos; - tap.z = length(tap.xy); - tap.z = 0.0; + { + float check = float(redoTap); + tap.xy = mix(tap.xy, tapPos - pixelPos, check); + tap.z = (1.0 - check) * tap.z; } return tap; diff --git a/libraries/render-utils/src/ssao_debugOcclusion.slf b/libraries/render-utils/src/ssao_debugOcclusion.slf index 75e3ed5194..5b2ce4b0b5 100644 --- a/libraries/render-utils/src/ssao_debugOcclusion.slf +++ b/libraries/render-utils/src/ssao_debugOcclusion.slf @@ -39,6 +39,7 @@ layout(location=0) out vec4 outFragColor; void main(void) { // Stereo side info based on the real viewport size of this pass vec2 sideDepthSize = getDepthTextureSideSize(0); + // Pixel Debugged vec2 cursorUV = getDebugCursorTexcoord(); vec2 cursorPixelPos = cursorUV * sideDepthSize; @@ -46,6 +47,5 @@ void main(void) { ivec2 fragUVPos = ivec2(cursorPixelPos); // TODO - outFragColor = packOcclusionOutput(0.0, 0.0, vec3(0.0, 0.0, 1.0)); } diff --git a/libraries/render-utils/src/ssao_makeOcclusion.slf b/libraries/render-utils/src/ssao_makeOcclusion.slf index 5dfa879c69..fdccaecaed 100644 --- a/libraries/render-utils/src/ssao_makeOcclusion.slf +++ b/libraries/render-utils/src/ssao_makeOcclusion.slf @@ -43,6 +43,7 @@ void main(void) { } else { sideOcclusionSize = ivec2( getOcclusionSideSize() ); } + ivec4 side = getStereoSideInfoFromWidth(fragPixelPos.x, sideOcclusionSize.x); // From now on, fragUVPos is the UV pos in the side fragUVPos = getSideUVFromFramebufferUV(side, fragUVPos); diff --git a/libraries/render-utils/src/stencil_drawMask.slf b/libraries/render-utils/src/stencil_drawMask.slf index 5ba09a8264..2ae5853960 100644 --- a/libraries/render-utils/src/stencil_drawMask.slf +++ b/libraries/render-utils/src/stencil_drawMask.slf @@ -18,6 +18,9 @@ float aspectRatio = 0.95; void main(void) { vec2 pos = varTexCoord0 * 2.0 - vec2(1.0); - pos.x = aspectRatio * (pos.x * (pos.x > 0.0 ? 2.0 : -2.0) - 1.0); - if (1.0 - dot(pos.xy, pos.xy) > 0.0 ) discard; + pos.x = aspectRatio * (pos.x * mix(-2.0, 2.0, float(pos.x > 0.0)) - 1.0); + + if (1.0 - dot(pos.xy, pos.xy) > 0.0) { + discard; + } } diff --git a/libraries/render-utils/src/subsurfaceScattering_drawScattering.slf b/libraries/render-utils/src/subsurfaceScattering_drawScattering.slf index 877c31c23d..ac5907803c 100644 --- a/libraries/render-utils/src/subsurfaceScattering_drawScattering.slf +++ b/libraries/render-utils/src/subsurfaceScattering_drawScattering.slf @@ -93,14 +93,14 @@ vec3 drawScatteringTableUV(vec2 cursor, vec2 texcoord) { vec3 color = vec3(0.0); bool keep = false; for (int c = 0; c < 3; c++) { - if (distance[c] > threshold) { - keep = true; - color[c] += 1.0; - } + bool check = distance[c] > threshold; + keep = keep || check; + color[c] += float(check); } - if (!keep) - discard; + if (!keep) { + discard; + } return color; } diff --git a/libraries/render-utils/src/surfaceGeometry_makeCurvature.slf b/libraries/render-utils/src/surfaceGeometry_makeCurvature.slf index 363fd0d4f8..dd9b98b5e5 100644 --- a/libraries/render-utils/src/surfaceGeometry_makeCurvature.slf +++ b/libraries/render-utils/src/surfaceGeometry_makeCurvature.slf @@ -67,11 +67,7 @@ vec3 getRawNormal(vec2 texcoord) { vec3 getWorldNormal(vec2 texcoord) { vec3 rawNormal = getRawNormal(texcoord); - if (isFullResolution()) { - return unpackNormal(rawNormal); - } else { - return normalize((rawNormal - vec3(0.5)) * 2.0); - } + return mix(normalize((rawNormal - vec3(0.5)) * 2.0), unpackNormal(rawNormal), float(isFullResolution())); } vec3 getWorldNormalDiff(vec2 texcoord, vec2 delta) { @@ -93,7 +89,7 @@ void main(void) { vec2 texcoordPos; ivec4 stereoSide; ivec2 framePixelPos = getPixelPosTexcoordPosAndSide(gl_FragCoord.xy, pixelPos, texcoordPos, stereoSide); - vec2 stereoSideClip = vec2(stereoSide.x, (isStereo() ? 0.5 : 1.0)); + vec2 stereoSideClip = vec2(stereoSide.x, 1.0 - 0.5 * float(isStereo())); // Texcoord to fetch in the deferred texture are the exact UVs comming from vertex shader // sideToFrameTexcoord(stereoSideClip, texcoordPos); @@ -128,8 +124,8 @@ void main(void) { // Calculate dF/du and dF/dv vec2 viewportScale = perspectiveScale * getInvWidthHeight(); - vec2 du = vec2( viewportScale.x * (float(stereoSide.w) > 0.0 ? 0.5 : 1.0), 0.0f ); - vec2 dv = vec2( 0.0f, viewportScale.y ); + vec2 du = vec2(viewportScale.x * (1.0 - 0.5 * float(stereoSide.w > 0)), 0.0); + vec2 dv = vec2( 0.0f, viewportScale.y); vec4 dFdu = vec4(getWorldNormalDiff(frameTexcoordPos, du), getEyeDepthDiff(frameTexcoordPos, du)); vec4 dFdv = vec4(getWorldNormalDiff(frameTexcoordPos, dv), getEyeDepthDiff(frameTexcoordPos, dv)); diff --git a/libraries/render-utils/src/taa.slf b/libraries/render-utils/src/taa.slf index a2b58d3050..25320179f5 100644 --- a/libraries/render-utils/src/taa.slf +++ b/libraries/render-utils/src/taa.slf @@ -35,17 +35,11 @@ void main() { vec2 prevFragUV = taa_fetchSourceAndHistory(fragUV, fragVel, sourceColor, historyColor); vec3 nextColor = sourceColor; - - if (taa_constrainColor()) { - // clamp history to neighbourhood of current sample - historyColor = taa_evalConstrainColor(sourceColor, fragUV, fragVel, historyColor); - } - - if (taa_feedbackColor()) { - nextColor = taa_evalFeedbackColor(sourceColor, historyColor, params.blend); - } else { - nextColor = mix(historyColor, sourceColor, params.blend); - } + + // clamp history to neighbourhood of current sample + historyColor = mix(historyColor, taa_evalConstrainColor(sourceColor, fragUV, fragVel, historyColor), float(taa_constrainColor())); + + nextColor = mix(mix(historyColor, sourceColor, params.blend), taa_evalFeedbackColor(sourceColor, historyColor, params.blend), float(taa_feedbackColor())); outFragColor = vec4(taa_resolveColor(nextColor), 1.0); } diff --git a/libraries/render-utils/src/taa.slh b/libraries/render-utils/src/taa.slh index 784c0824d5..ed9162516e 100644 --- a/libraries/render-utils/src/taa.slh +++ b/libraries/render-utils/src/taa.slh @@ -121,21 +121,17 @@ float taa_fetchDepth(vec2 uv) { } -#define ZCMP_GT(a, b) (a > b) +#define ZCMP_GT(a, b) float(a > b) vec2 taa_getImageSize() { vec2 imageSize = getWidthHeight(0); - if (isStereo()) { - imageSize.x *= 2.0; - } + imageSize.x *= 1.0 + float(isStereo()); return imageSize; } vec2 taa_getTexelSize() { vec2 texelSize = getInvWidthHeight(); - if (isStereo()) { - texelSize.x *= 0.5; - } + texelSize.x *= 1.0 - 0.5 * float(isStereo()); return texelSize; } @@ -158,16 +154,16 @@ vec3 taa_findClosestFragment3x3(vec2 uv) vec3 dbr = vec3( 1, 1, taa_fetchDepth(uv + dv + du)); vec3 dmin = dtl; - if (ZCMP_GT(dmin.z, dtc.z)) dmin = dtc; - if (ZCMP_GT(dmin.z, dtr.z)) dmin = dtr; + dmin = mix(dmin, dtc, ZCMP_GT(dmin.z, dtc.z)); + dmin = mix(dmin, dtr, ZCMP_GT(dmin.z, dtr.z)); - if (ZCMP_GT(dmin.z, dml.z)) dmin = dml; - if (ZCMP_GT(dmin.z, dmc.z)) dmin = dmc; - if (ZCMP_GT(dmin.z, dmr.z)) dmin = dmr; + dmin = mix(dmin, dml, ZCMP_GT(dmin.z, dml.z)); + dmin = mix(dmin, dmc, ZCMP_GT(dmin.z, dmc.z)); + dmin = mix(dmin, dmr, ZCMP_GT(dmin.z, dmr.z)); - if (ZCMP_GT(dmin.z, dbl.z)) dmin = dbl; - if (ZCMP_GT(dmin.z, dbc.z)) dmin = dbc; - if (ZCMP_GT(dmin.z, dbr.z)) dmin = dbr; + dmin = mix(dmin, dbl, ZCMP_GT(dmin.z, dbl.z)); + dmin = mix(dmin, dbc, ZCMP_GT(dmin.z, dbc.z)); + dmin = mix(dmin, dbr, ZCMP_GT(dmin.z, dbr.z)); return vec3(uv + dd.xy * dmin.xy, dmin.z); } @@ -189,49 +185,46 @@ vec2 taa_fetchVelocityMapBest(vec2 uv) { vec2 dbc = taa_fetchVelocityMap(uv + dv); vec2 dbr = taa_fetchVelocityMap(uv + dv + du); - vec3 best = vec3(dtl, dot(dtl,dtl)); + vec3 best = vec3(dtl, dot(dtl, dtl)); - float testSpeed = dot(dtc,dtc); - if (testSpeed > best.z) { best = vec3(dtc, testSpeed); } - testSpeed = dot(dtr,dtr); - if (testSpeed > best.z) { best = vec3(dtr, testSpeed); } + float testSpeed = dot(dtc, dtc); + mix(best, vec3(dtc, testSpeed), float(testSpeed > best.z)); + testSpeed = dot(dtr, dtr); + mix(best, vec3(dtr, testSpeed), float(testSpeed > best.z)); - testSpeed = dot(dml,dml); - if (testSpeed > best.z) { best = vec3(dml, testSpeed); } - testSpeed = dot(dmc,dmc); - if (testSpeed > best.z) { best = vec3(dmc, testSpeed); } - testSpeed = dot(dmr,dmr); - if (testSpeed > best.z) { best = vec3(dmr, testSpeed); } + testSpeed = dot(dml, dml); + mix(best, vec3(dml, testSpeed), float(testSpeed > best.z)); + testSpeed = dot(dmc, dmc); + mix(best, vec3(dmc, testSpeed), float(testSpeed > best.z)); + testSpeed = dot(dmr, dmr); + mix(best, vec3(dmr, testSpeed), float(testSpeed > best.z)); - testSpeed = dot(dbl,dbl); - if (testSpeed > best.z) { best = vec3(dbl, testSpeed); } - testSpeed = dot(dbc,dbc); - if (testSpeed > best.z) { best = vec3(dbc, testSpeed); } - testSpeed = dot(dbr,dbr); - if (testSpeed > best.z) { best = vec3(dbr, testSpeed); } + testSpeed = dot(dbl, dbl); + mix(best, vec3(dbl, testSpeed), float(testSpeed > best.z)); + testSpeed = dot(dbc, dbc); + mix(best, vec3(dbc, testSpeed), float(testSpeed > best.z)); + testSpeed = dot(dbr, dbr); + mix(best, vec3(dbr, testSpeed), float(testSpeed > best.z)); return best.xy; } vec2 taa_fromFragUVToEyeUVAndSide(vec2 fragUV, out int stereoSide) { vec2 eyeUV = fragUV; - stereoSide = 0; - if (isStereo()) { - if (eyeUV.x > 0.5) { - eyeUV.x -= 0.5; - stereoSide = 1; - } - eyeUV.x *= 2.0; - } + + float check = float(isStereo()); + float check2 = float(eyeUV.x > 0.5); + eyeUV.x -= check * check2 * 0.5; + stereoSide = int(check * check2); + eyeUV.x *= 1.0 + check; return eyeUV; } vec2 taa_fromEyeUVToFragUV(vec2 eyeUV, int stereoSide) { vec2 fragUV = eyeUV; - if (isStereo()) { - fragUV.x *= 0.5; - fragUV.x += float(stereoSide)*0.5; - } + float check = float(isStereo()); + fragUV.x *= 1.0 - 0.5 * check; + fragUV.x += check * float(stereoSide) * 0.5; return fragUV; } @@ -247,10 +240,8 @@ vec2 taa_fetchSourceAndHistory(vec2 fragUV, vec2 fragVelocity, out vec3 sourceCo vec2 prevFragUV = taa_computePrevFragAndEyeUV(fragUV, fragVelocity, prevEyeUV); sourceColor = taa_fetchSourceMap(fragUV).xyz; - historyColor = sourceColor; - if (!(any(lessThan(prevEyeUV, vec2(0.0))) || any(greaterThan(prevEyeUV, vec2(1.0))))) { - historyColor = taa_fetchHistoryMap(prevFragUV).xyz; - } + historyColor = mix(sourceColor, taa_fetchHistoryMap(prevFragUV).xyz, float(!(any(lessThan(prevEyeUV, vec2(0.0))) || any(greaterThan(prevEyeUV, vec2(1.0)))))); + return prevFragUV; } @@ -405,10 +396,11 @@ vec3 taa_clampColor(vec3 colorMin, vec3 colorMax, vec3 colorSource, vec3 color) vec3 a_unit = abs(v_unit); float ma_unit = max(a_unit.x, max(a_unit.y, a_unit.z)); - if (ma_unit > 1.0) + if (ma_unit > 1.0) { return p_clip + v_clip / ma_unit; - else - return q;// point inside aabb + } else { + return q;// point inside aabb + } } vec3 taa_evalConstrainColor(vec3 sourceColor, vec2 sourceUV, vec2 sourceVel, vec3 candidateColor) { @@ -514,10 +506,6 @@ vec3 taa_evalFXAA(vec2 fragUV) { // compare luma of new samples to the luma range of the original neighborhood // if the new samples exceed this range, just use the first two samples instead of all four - if (lumaB < lumaMin || lumaB > lumaMax) { - return rgbA; - } else { - return rgbB; - } + return mix(rgbB, rgbA, float(lumaB < lumaMin || lumaB > lumaMax)); } diff --git a/libraries/render-utils/src/taa_blend.slf b/libraries/render-utils/src/taa_blend.slf index 50575a6a07..0999b2482f 100644 --- a/libraries/render-utils/src/taa_blend.slf +++ b/libraries/render-utils/src/taa_blend.slf @@ -83,32 +83,21 @@ void main(void) { if ((prevOrbPosToPixLength < tenPercentHeight) && (cursorVelocityLength > 0.5)) { vec2 prevOrbPosToPix_uv = cursorPrevUV + prevOrbPosToPix * texelSize / taa_getDebugOrbZoom(); vec3 preOrbColor = vec3(0.0); - if (!(any(lessThan(prevOrbPosToPix_uv, vec2(0.0))) || any(greaterThan(prevOrbPosToPix_uv, vec2(1.0))))) { - preOrbColor = texture(historyMap, prevOrbPosToPix_uv).xyz; - } - if (prevOrbPosToPixLength < orbPixThreshold) { - preOrbColor = vec3(1.0, 0.0, 1.0); - } + + preOrbColor = mix(preOrbColor, texture(historyMap, prevOrbPosToPix_uv).xyz, float(!(any(lessThan(prevOrbPosToPix_uv, vec2(0.0))) || any(greaterThan(prevOrbPosToPix_uv, vec2(1.0)))))); + preOrbColor = mix(preOrbColor, vec3(1.0, 0.0, 1.0), float(prevOrbPosToPixLength < orbPixThreshold)); float distanceToNext = length(imageSize * (cursorUV - prevOrbPosToPix_uv)); - if (distanceToNext < orbPixThreshold) { - preOrbColor = vec3(1.0, 0.5, 0.0); - } + preOrbColor = mix(preOrbColor, vec3(1.0, 0.5, 0.0), float(distanceToNext < orbPixThreshold)); outFragColor = vec4(preOrbColor, 1.0); return; } if (nextOrbPosToPixLength < tenPercentHeight) { vec2 nextOrbPosToPix_uv = cursorUV + nextOrbPosToPix * texelSize / taa_getDebugOrbZoom(); vec3 nextOrbColor = vec3(0.0); - if (!(any(lessThan(nextOrbPosToPix_uv, vec2(0.0))) || any(greaterThan(nextOrbPosToPix_uv, vec2(1.0))))) { - nextOrbColor = texture(nextMap, nextOrbPosToPix_uv).xyz; - } + nextOrbColor = mix(nextOrbColor, texture(nextMap, nextOrbPosToPix_uv).xyz, float(!(any(lessThan(nextOrbPosToPix_uv, vec2(0.0))) || any(greaterThan(nextOrbPosToPix_uv, vec2(1.0)))))); float distanceToPrev = length(imageSize * (cursorPrevUV - nextOrbPosToPix_uv)); - if (distanceToPrev < orbPixThreshold) { - nextOrbColor = vec3(1.0, 0.0, 1.0); - } - if (nextOrbPosToPixLength < orbPixThreshold) { - nextOrbColor = vec3(1.0, 0.5, 0.0); - } + nextOrbColor = mix(nextOrbColor, vec3(1.0, 0.0, 1.0), float(distanceToPrev < orbPixThreshold)); + nextOrbColor = mix(nextOrbColor, vec3(1.0, 0.5, 0.0), float(nextOrbPosToPixLength < orbPixThreshold)); outFragColor = vec4(nextOrbColor, 1.0); return; @@ -141,16 +130,9 @@ void main(void) { outFragColor = vec4(nextColor, 1.0); vec3 prevColor = nextColor; + prevColor = mix(prevColor, texture(historyMap, prevTexCoord).xyz, float(!(any(lessThan(prevTexCoord, vec2(0.0))) || any(greaterThan(prevTexCoord, vec2(1.0)))))); - if (!(any(lessThan(prevTexCoord, vec2(0.0))) || any(greaterThan(prevTexCoord, vec2(1.0))))) { - prevColor = texture(historyMap, prevTexCoord).xyz; - } + outFragColor.xyz = mix(prevColor, vec3(1, 0, 1), clamp(distance(prevColor, nextColor) - 0.01, 0.0, 1.0)); - outFragColor.xyz = mix(prevColor, vec3(1,0,1), clamp(distance(prevColor, nextColor) - 0.01, 0.0, 1.0)); - - if (pixVelocityLength > params.debugShowVelocityThreshold) { - vec3 speedColor = taa_getVelocityColorAboveThreshold(pixVelocityLength); - - outFragColor = vec4(0.0, 1.0, 1.0, 1.0); - } + outFragColor = mix(outFragColor, vec4(0.0, 1.0, 1.0, 1.0), float(pixVelocityLength > params.debugShowVelocityThreshold)); } diff --git a/libraries/render-utils/src/zone_drawAmbient.slf b/libraries/render-utils/src/zone_drawAmbient.slf index f20d83e913..d780fd0de2 100644 --- a/libraries/render-utils/src/zone_drawAmbient.slf +++ b/libraries/render-utils/src/zone_drawAmbient.slf @@ -44,7 +44,7 @@ void main(void) { // vec3 ambient = sphericalHarmonics_evalSphericalLight(getLightAmbientSphere(lightAmbient), fragNormal).xyz; // _fragColor = vec4( 0.5 * (fragNormal + vec3(1.0)), 1.0); - vec3 color = (sphereUV.x > 0.0 ? ambientMap : ambientSH); + vec3 color = mix(ambientSH, ambientMap, float(sphereUV.x > 0.0)); color = color * 1.0 - base.w + base.xyz * base.w; const float INV_GAMMA_22 = 1.0 / 2.2; diff --git a/libraries/render-utils/src/zone_drawSkybox.slf b/libraries/render-utils/src/zone_drawSkybox.slf index f8d1326b3a..743b48d0bf 100644 --- a/libraries/render-utils/src/zone_drawSkybox.slf +++ b/libraries/render-utils/src/zone_drawSkybox.slf @@ -35,16 +35,11 @@ void main(void) { vec3 color = skybox.color.rgb; // blend is only set if there is a cubemap - if (skybox.color.a > 0.0) { - color = texture(skyboxMap, direction).rgb; - if (skybox.color.a < 1.0) { - color *= skybox.color.rgb; - } - } + float check = float(skybox.color.a > 0.0); + color = mix(color, texture(skyboxMap, direction).rgb, check); + color *= mix(vec3(1.0), skybox.color.rgb, check * float(skybox.color.a < 1.0)); color = color * 1.0 - base.w + base.xyz * base.w; const float INV_GAMMA_22 = 1.0 / 2.2; _fragColor = vec4(pow(color, vec3(INV_GAMMA_22)), 1.0); } - - diff --git a/libraries/render/src/render/BlurTask.slh b/libraries/render/src/render/BlurTask.slh index fa4b9a4a4f..ff4e76a429 100644 --- a/libraries/render/src/render/BlurTask.slh +++ b/libraries/render/src/render/BlurTask.slh @@ -98,10 +98,11 @@ vec4 pixelShaderGaussian(vec2 texcoord, vec2 direction, vec2 pixelStep) { totalWeight += weight; } } - - if (totalWeight>0.0) { + + if (totalWeight > 0.0) { srcBlurred /= totalWeight; } + srcBlurred.a = getOutputAlpha(); return srcBlurred; } @@ -159,10 +160,11 @@ vec4 pixelShaderGaussianDepthAware(vec2 texcoord, vec2 direction, vec2 pixelStep totalWeight += weight; } } - - if (totalWeight>0.0) { + + if (totalWeight > 0.0) { srcBlurred /= totalWeight; } + return srcBlurred; } diff --git a/libraries/render/src/render/drawCellBounds.slv b/libraries/render/src/render/drawCellBounds.slv index 24cc6254fd..216f1ea299 100644 --- a/libraries/render/src/render/drawCellBounds.slv +++ b/libraries/render/src/render/drawCellBounds.slv @@ -51,7 +51,7 @@ void main(void) { vec4 pos = UNIT_BOX[UNIT_BOX_LINE_INDICES[gl_VertexID]]; int cellIsEmpty = sign(inCellLocation.w); - ivec4 cellLocation = ivec4(inCellLocation.xyz, (inCellLocation.w < 0 ? -inCellLocation.w : inCellLocation.w)); + ivec4 cellLocation = ivec4(inCellLocation.xyz, abs(inCellLocation.w)); vec4 cellBound = evalBound(cellLocation); pos.xyz = cellBound.xyz + vec3(cellBound.w) * pos.xyz; @@ -62,4 +62,4 @@ void main(void) { <$transformModelToClipPos(cam, obj, pos, gl_Position)$> varColor = vec4(colorWheel(fract(float(inCellLocation.w) / 5.0)), 0.8 + 0.2 * float(cellIsEmpty)); -} \ No newline at end of file +} diff --git a/libraries/render/src/render/drawItemBounds.slf b/libraries/render/src/render/drawItemBounds.slf index 90faaff05c..0fed67beb6 100644 --- a/libraries/render/src/render/drawItemBounds.slf +++ b/libraries/render/src/render/drawItemBounds.slf @@ -18,11 +18,7 @@ layout(location=0) out vec4 outFragColor; void main(void) { float var = step(fract(varTexcoord.x * varTexcoord.y * 1.0), 0.5); - if (varColor.a == 0.0) { - outFragColor = vec4(mix(vec3(0.0), varColor.xyz, var), mix(0.0, 1.0, var)); - - } else { - outFragColor = vec4(mix(vec3(1.0), varColor.xyz, var), varColor.a); - } - + outFragColor = mix(vec4(mix(vec3(1.0), varColor.xyz, var), varColor.a), + vec4(mix(vec3(0.0), varColor.xyz, var), var), + float(varColor.a == 0.0)); } diff --git a/libraries/render/src/render/drawItemBounds.slv b/libraries/render/src/render/drawItemBounds.slv index bb8e6a2886..32cfe1c131 100644 --- a/libraries/render/src/render/drawItemBounds.slv +++ b/libraries/render/src/render/drawItemBounds.slv @@ -98,11 +98,6 @@ void main(void) { TransformObject obj = getTransformObject(); <$transformModelToClipPos(cam, obj, pos, gl_Position)$> - if (params.color.w < 0.0) { - varColor = vec4(colorWheel(float(boundID)/(-params.color.w)), 1.0); - } else { - varColor = vec4(colorWheel(float(params.color.w)), 1.0); - } + varColor = mix(vec4(colorWheel(float(params.color.w)), 1.0), vec4(colorWheel(float(boundID)/(-params.color.w)), 1.0), float(params.color.w < 0.0)); varTexcoord = vec2(cubeVec.w, length(boundDim)); - } \ No newline at end of file diff --git a/libraries/render/src/render/drawItemStatus.slf b/libraries/render/src/render/drawItemStatus.slf index e88cf4c920..ca7f2273cd 100644 --- a/libraries/render/src/render/drawItemStatus.slf +++ b/libraries/render/src/render/drawItemStatus.slf @@ -22,10 +22,9 @@ vec2 getIconTexcoord(float icon, vec2 uv) { } void main(void) { - if (varTexcoord.z < 254.5) { - outFragColor = texture(_icons, getIconTexcoord(varTexcoord.z, varTexcoord.xy)) * varColor; - } else { - vec2 centerDir = varTexcoord.xy * 2.0f - 1.0f; - outFragColor = vec4(varColor.xyz, 1.0 - step(1.0f, dot(centerDir.xy, centerDir.xy))); - } + vec2 centerDir = varTexcoord.xy * 2.0f - 1.0f; + + outFragColor = mix(vec4(varColor.xyz, 1.0 - step(1.0f, dot(centerDir.xy, centerDir.xy))), + texture(_icons, getIconTexcoord(varTexcoord.z, varTexcoord.xy)) * varColor, + float(varTexcoord.z < 254.5)); } diff --git a/plugins/openvr/src/OpenVrDisplayPlugin.cpp b/plugins/openvr/src/OpenVrDisplayPlugin.cpp index 99c861871d..11ef222172 100644 --- a/plugins/openvr/src/OpenVrDisplayPlugin.cpp +++ b/plugins/openvr/src/OpenVrDisplayPlugin.cpp @@ -319,6 +319,7 @@ public: glBindVertexArray(0); glDeleteVertexArrays(1, &_vao); _canvas->doneCurrent(); + _canvas->moveToThread(_plugin.thread()); } void update(const CompositeInfo& newCompositeInfo) { _queue.push(newCompositeInfo); } @@ -485,6 +486,7 @@ bool OpenVrDisplayPlugin::internalActivate() { _submitCanvas->doneCurrent(); }); } + _submitCanvas->moveToThread(_submitThread.get()); } return Parent::internalActivate(); diff --git a/scripts/system/assets/data/createAppTooltips.json b/scripts/system/assets/data/createAppTooltips.json index 720d4537ee..3a25402588 100644 --- a/scripts/system/assets/data/createAppTooltips.json +++ b/scripts/system/assets/data/createAppTooltips.json @@ -267,7 +267,7 @@ "jsPropertyName": "parentMaterialName" }, "selectSubmesh": { - "tooltip": "If enabled, \"Select Submesh\" property will show up, otherwise \"Material Name to Replace\" will be shown.", + "tooltip": "If enabled, \"Submesh to Replace\" property will show up, otherwise \"Material to Replace\" will be shown.", "skipJSProperty": true }, "priority": { diff --git a/scripts/system/attachedEntitiesManager.js b/scripts/system/attachedEntitiesManager.js index c0144e772f..061e27f595 100644 --- a/scripts/system/attachedEntitiesManager.js +++ b/scripts/system/attachedEntitiesManager.js @@ -186,7 +186,7 @@ function AttachedEntitiesManager() { delete wearProps.actionData; delete wearProps.sittingPoints; delete wearProps.boundingBox; - delete wearProps.clientOnly; + delete wearProps.avatarEntity; delete wearProps.owningAvatarID; delete wearProps.localPosition; delete wearProps.localRotation; diff --git a/scripts/system/avatarapp.js b/scripts/system/avatarapp.js index 396e1e3824..81a6447aae 100644 --- a/scripts/system/avatarapp.js +++ b/scripts/system/avatarapp.js @@ -328,8 +328,8 @@ function isGrabbable(entityID) { return false; } - var properties = Entities.getEntityProperties(entityID, ['clientOnly', 'grab.grabbable']); - if (properties.clientOnly) { + var properties = Entities.getEntityProperties(entityID, ['avatarEntity', 'grab.grabbable']); + if (properties.avatarEntity) { return properties.grab.grabbable; } @@ -337,8 +337,8 @@ function isGrabbable(entityID) { } function setGrabbable(entityID, grabbable) { - var properties = Entities.getEntityProperties(entityID, ['clientOnly']); - if (properties.clientOnly) { + var properties = Entities.getEntityProperties(entityID, ['avatarEntity']); + if (properties.avatarEntity) { Entities.editEntity(entityID, { grab: { grabbable: grabbable }}); } } diff --git a/scripts/system/edit.js b/scripts/system/edit.js index 077d50ddde..039f4f1e22 100644 --- a/scripts/system/edit.js +++ b/scripts/system/edit.js @@ -554,8 +554,9 @@ var toolBar = (function () { } } - SelectionManager.saveProperties(); entityID = Entities.addEntity(properties); + SelectionManager.addEntity(entityID, false, this); + SelectionManager.saveProperties(); pushCommandForSelections([{ entityID: entityID, properties: properties @@ -1273,6 +1274,7 @@ function mouseClickEvent(event) { } else { selectionManager.addEntity(foundEntity, true, this); } + selectionManager.saveProperties(); if (wantDebug) { print("Model selected: " + foundEntity); @@ -2130,12 +2132,17 @@ function applyEntityProperties(data) { entityID = DELETED_ENTITY_MAP[entityID]; } Entities.deleteEntity(entityID); + var index = selectedEntityIDs.indexOf(entityID); + if (index >= 0) { + selectedEntityIDs.splice(index, 1); + } } // We might be getting an undo while edit.js is disabled. If that is the case, don't set // our selections, causing the edit widgets to display. if (isActive) { selectionManager.setSelections(selectedEntityIDs, this); + selectionManager.saveProperties(); } } @@ -2324,7 +2331,6 @@ var PropertiesTool = function (opts) { } var i, properties, dY, diff, newPosition; if (data.type === "update") { - selectionManager.saveProperties(); if (selectionManager.selections.length > 1) { for (i = 0; i < selectionManager.selections.length; i++) { Entities.editEntity(selectionManager.selections[i], data.properties); @@ -2360,8 +2366,12 @@ var PropertiesTool = function (opts) { entityListTool.sendUpdate(); } } - pushCommandForSelections(); - blockPropertyUpdates = data.blockUpdateCallback === true; + if (data.onlyUpdateEntities) { + blockPropertyUpdates = true; + } else { + pushCommandForSelections(); + SelectionManager.saveProperties(); + } selectionManager._update(false, this); blockPropertyUpdates = false; } else if (data.type === 'saveUserData' || data.type === 'saveMaterialData') { @@ -2473,8 +2483,6 @@ var PropertiesTool = function (opts) { tooltips: Script.require('./assets/data/createAppTooltips.json'), hmdActive: HMD.active, }); - } else if (data.type === "updateProperties") { - updateSelections(true); } }; @@ -2739,17 +2747,16 @@ keyUpEventFromUIWindow = function(keyUpEvent) { selectionManager.pasteEntities(); } else if (keyUpEvent.controlKey && keyUpEvent.keyCodeString === "D") { selectionManager.duplicateSelection(); - } else if (keyUpEvent.controlKey && !keyUpEvent.shiftKey && keyUpEvent.keyCodeString === "Z") { - undoHistory.undo(); + } else if (!isOnMacPlatform && keyUpEvent.controlKey && !keyUpEvent.shiftKey && keyUpEvent.keyCodeString === "Z") { + undoHistory.undo(); // undo is only handled via handleMenuItem on Mac } else if (keyUpEvent.controlKey && !keyUpEvent.shiftKey && keyUpEvent.keyCodeString === "P") { parentSelectedEntities(); } else if (keyUpEvent.controlKey && keyUpEvent.shiftKey && keyUpEvent.keyCodeString === "P") { unparentSelectedEntities(); - } else if ( - (keyUpEvent.controlKey && keyUpEvent.shiftKey && keyUpEvent.keyCodeString === "Z") || - (keyUpEvent.controlKey && keyUpEvent.keyCodeString === "Y")) { - - undoHistory.redo(); + } else if (!isOnMacPlatform && + ((keyUpEvent.controlKey && keyUpEvent.shiftKey && keyUpEvent.keyCodeString === "Z") || + (keyUpEvent.controlKey && keyUpEvent.keyCodeString === "Y"))) { + undoHistory.redo(); // redo is only handled via handleMenuItem on Mac } else if (WANT_DEBUG_MISSING_SHORTCUTS) { console.warn("unhandled key event: " + JSON.stringify(keyUpEvent)) } diff --git a/scripts/system/html/css/edit-style.css b/scripts/system/html/css/edit-style.css index 415d8e567f..d7d88ce91e 100644 --- a/scripts/system/html/css/edit-style.css +++ b/scripts/system/html/css/edit-style.css @@ -598,6 +598,7 @@ div.section[collapsed="true"], div.section[collapsed="true"] > .section-header { .triple-label { text-transform: uppercase; + text-align: center; padding: 6px 0; } @@ -605,6 +606,10 @@ div.section[collapsed="true"], div.section[collapsed="true"] > .section-header { margin-right: 10px; } +.triple-item.rgb.fstuple { + display: block !important; +} + .section-header[collapsed="true"] { margin-bottom: -21px; } @@ -911,14 +916,17 @@ div.refresh input[type="button"] { clear: both; } +.draggable-number-container { + flex: 0 1 124px; +} .draggable-number { position: relative; -} -.draggable-number div { height: 28px; - width: 124px; + flex: 0 1 124px; } -.draggable-number.text { + +.draggable-number .text { + position: absolute; display: inline-block; color: #afafaf; background-color: #252525; @@ -930,11 +938,12 @@ div.refresh input[type="button"] { width: 100%; line-height: 2; box-sizing: border-box; + z-index: 1; } -.draggable-number.text:hover { +.draggable-number .text:hover { cursor: ew-resize; } -.draggable-number span { +.draggable-number .left-arrow, .draggable-number .right-arrow { position: absolute; display: inline-block; font-family: HiFi-Glyphs; @@ -944,12 +953,12 @@ div.refresh input[type="button"] { .draggable-number span:hover { cursor: default; } -.draggable-number.left-arrow { +.draggable-number .left-arrow { top: 3px; left: 0px; transform: rotate(180deg); } -.draggable-number.right-arrow { +.draggable-number .right-arrow { top: 3px; right: 0px; } @@ -1514,6 +1523,7 @@ input.rename-entity { width: 258px; min-height: 20px; padding: 5px; + z-index: 100; } .create-app-tooltip .create-app-tooltip-description { @@ -1629,10 +1639,6 @@ input.number-slider { flex-flow: column; } -.flex-column + .flex-column { - padding-left: 50px; -} - .flex-center { align-items: center; } diff --git a/scripts/system/html/js/draggableNumber.js b/scripts/system/html/js/draggableNumber.js index 951b123e67..4e3a32b0f2 100644 --- a/scripts/system/html/js/draggableNumber.js +++ b/scripts/system/html/js/draggableNumber.js @@ -7,6 +7,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html const DELTA_X_FOCUS_THRESHOLD = 1; +const ENTER_KEY = 13; function DraggableNumber(min, max, step, decimals, dragStart, dragEnd) { this.min = min; @@ -38,7 +39,7 @@ DraggableNumber.prototype = { }, mouseDown: function(event) { - if (event.target === this.elText) { + if (event.target === this.elText && !this.isDisabled()) { this.initialMouseEvent = event; this.lastMouseEvent = event; document.addEventListener("mousemove", this.onDocumentMouseMove); @@ -47,7 +48,7 @@ DraggableNumber.prototype = { }, mouseUp: function(event) { - if (event.target === this.elText && this.initialMouseEvent) { + if (!this.dragging && event.target === this.elText && this.initialMouseEvent) { let dx = event.clientX - this.initialMouseEvent.clientX; if (Math.abs(dx) <= DELTA_X_FOCUS_THRESHOLD) { this.showInput(); @@ -58,32 +59,33 @@ DraggableNumber.prototype = { }, documentMouseMove: function(event) { - if (this.initialMouseEvent) { + if (!this.dragging && this.initialMouseEvent) { let dxFromInitial = event.clientX - this.initialMouseEvent.clientX; - if (Math.abs(dxFromInitial) > DELTA_X_FOCUS_THRESHOLD && this.lastMouseEvent) { - let initialValue = this.elInput.value; - let dx = event.clientX - this.lastMouseEvent.clientX; - let changeValue = dx !== 0; - if (changeValue) { - while (dx !== 0) { - if (dx > 0) { - this.elInput.stepUp(); - --dx; - } else { - this.elInput.stepDown(); - ++dx; - } - } - this.inputChange(); - if (this.valueChangeFunction) { - this.valueChangeFunction(); + if (Math.abs(dxFromInitial) > DELTA_X_FOCUS_THRESHOLD) { + if (this.dragStartFunction) { + this.dragStartFunction(); + } + this.dragging = true; + } + this.lastMouseEvent = event; + } + if (this.dragging && this.lastMouseEvent) { + let initialValue = this.elInput.value; + let dx = event.clientX - this.lastMouseEvent.clientX; + let changeValue = dx !== 0; + if (changeValue) { + while (dx !== 0) { + if (dx > 0) { + this.elInput.stepUp(); + --dx; + } else { + this.elInput.stepDown(); + ++dx; } } - if (!this.dragging) { - if (this.dragStartFunction) { - this.dragStartFunction(); - } - this.dragging = true; + this.inputChange(); + if (this.valueChangeFunction) { + this.valueChangeFunction(); } } this.lastMouseEvent = event; @@ -103,18 +105,22 @@ DraggableNumber.prototype = { }, stepUp: function() { - this.elInput.stepUp(); - this.inputChange(); - if (this.valueChangeFunction) { - this.valueChangeFunction(); + if (!this.isDisabled()) { + this.elInput.stepUp(); + this.inputChange(); + if (this.valueChangeFunction) { + this.valueChangeFunction(); + } } }, stepDown: function() { - this.elInput.stepDown(); - this.inputChange(); - if (this.valueChangeFunction) { - this.valueChangeFunction(); + if (!this.isDisabled()) { + this.elInput.stepDown(); + this.inputChange(); + if (this.valueChangeFunction) { + this.valueChangeFunction(); + } } }, @@ -128,9 +134,6 @@ DraggableNumber.prototype = { }, setValueChangeFunction: function(valueChangeFunction) { - if (this.valueChangeFunction) { - this.elInput.removeEventListener("change", this.valueChangeFunction); - } this.valueChangeFunction = valueChangeFunction.bind(this.elInput); this.elInput.addEventListener("change", this.valueChangeFunction); }, @@ -142,6 +145,16 @@ DraggableNumber.prototype = { inputBlur: function(ev) { this.hideInput(); }, + + keyPress: function(event) { + if (event.keyCode === ENTER_KEY) { + this.inputBlur(); + } + }, + + isDisabled: function() { + return this.elText.getAttribute("disabled") === "disabled"; + }, initialize: function() { this.onMouseDown = this.mouseDown.bind(this); @@ -152,12 +165,13 @@ DraggableNumber.prototype = { this.onStepDown = this.stepDown.bind(this); this.onInputChange = this.inputChange.bind(this); this.onInputBlur = this.inputBlur.bind(this); + this.onKeyPress = this.keyPress.bind(this); this.elDiv = document.createElement('div'); this.elDiv.className = "draggable-number"; - this.elText = document.createElement('label'); - this.elText.className = "draggable-number text"; + this.elText = document.createElement('span'); + this.elText.className = "text"; this.elText.innerText = " "; this.elText.style.visibility = "visible"; this.elText.addEventListener("mousedown", this.onMouseDown); @@ -165,15 +179,15 @@ DraggableNumber.prototype = { this.elLeftArrow = document.createElement('span'); this.elRightArrow = document.createElement('span'); - this.elLeftArrow.className = 'draggable-number left-arrow'; + this.elLeftArrow.className = 'left-arrow'; this.elLeftArrow.innerHTML = 'D'; this.elLeftArrow.addEventListener("click", this.onStepDown); - this.elRightArrow.className = 'draggable-number right-arrow'; + this.elRightArrow.className = 'right-arrow'; this.elRightArrow.innerHTML = 'D'; this.elRightArrow.addEventListener("click", this.onStepUp); this.elInput = document.createElement('input'); - this.elInput.className = "draggable-number input"; + this.elInput.className = "input"; this.elInput.setAttribute("type", "number"); if (this.min !== undefined) { this.elInput.setAttribute("min", this.min); @@ -187,11 +201,12 @@ DraggableNumber.prototype = { this.elInput.style.opacity = 0; this.elInput.addEventListener("change", this.onInputChange); this.elInput.addEventListener("blur", this.onInputBlur); + this.elInput.addEventListener("keypress", this.onKeyPress); this.elInput.addEventListener("focus", this.showInput.bind(this)); this.elDiv.appendChild(this.elLeftArrow); + this.elDiv.appendChild(this.elText); this.elDiv.appendChild(this.elInput); this.elDiv.appendChild(this.elRightArrow); - this.elDiv.appendChild(this.elText); } }; diff --git a/scripts/system/html/js/entityList.js b/scripts/system/html/js/entityList.js index 84ad59df36..15353db48e 100644 --- a/scripts/system/html/js/entityList.js +++ b/scripts/system/html/js/entityList.js @@ -1186,7 +1186,8 @@ function loaded() { }; document.addEventListener("keyup", function (keyUpEvent) { - if (keyUpEvent.target.nodeName === "INPUT") { + const FILTERED_NODE_NAMES = ["INPUT", "TEXTAREA"]; + if (FILTERED_NODE_NAMES.includes(keyUpEvent.target.nodeName)) { return; } diff --git a/scripts/system/html/js/entityProperties.js b/scripts/system/html/js/entityProperties.js index 14ed2b77e3..1026fbfdeb 100644 --- a/scripts/system/html/js/entityProperties.js +++ b/scripts/system/html/js/entityProperties.js @@ -556,22 +556,24 @@ const GROUPS = [ { id: "save", label: "Save Material Data", className: "black", onClick: saveMaterialData } ], propertyID: "materialData", }, + { + label: "Select Submesh", + type: "bool", + propertyID: "selectSubmesh", + }, { label: "Submesh to Replace", type: "number", min: 0, step: 1, propertyID: "submeshToReplace", + indentedLabel: true, }, { - label: "Material Name to Replace", + label: "Material to Replace", type: "string", propertyID: "materialNameToReplace", - }, - { - label: "Select Submesh", - type: "bool", - propertyID: "selectSubmesh", + indentedLabel: true, }, { label: "Priority", @@ -579,10 +581,18 @@ const GROUPS = [ min: 0, propertyID: "priority", }, + { + label: "Material Mapping Mode", + type: "dropdown", + options: { + uv: "UV space", projected: "3D projected" + }, + propertyID: "materialMappingMode", + }, { label: "Material Position", type: "vec2", - vec2Type: "xy", + vec2Type: "xyz", min: 0, max: 1, step: 0.1, @@ -593,11 +603,11 @@ const GROUPS = [ { label: "Material Scale", type: "vec2", - vec2Type: "wh", + vec2Type: "xyz", min: 0, step: 0.1, decimals: 4, - subLabels: [ "width", "height" ], + subLabels: [ "x", "y" ], propertyID: "materialMappingScale", }, { @@ -608,6 +618,11 @@ const GROUPS = [ unit: "deg", propertyID: "materialMappingRot", }, + { + label: "Material Repeat", + type: "bool", + propertyID: "materialRepeat", + }, ] }, { @@ -882,7 +897,7 @@ const GROUPS = [ properties: [ { type: "triple", - label: "Alpha", + label: "Spin", properties: [ { label: "Start", @@ -951,8 +966,8 @@ const GROUPS = [ { label: "Start", type: "number", - min: -180, - max: 0, + min: 0, + max: 180, step: 1, decimals: 0, multiplier: DEGREES_TO_RADIANS, @@ -979,7 +994,7 @@ const GROUPS = [ { label: "Start", type: "number", - min: 0, + min: -180, max: 180, step: 1, decimals: 0, @@ -990,7 +1005,7 @@ const GROUPS = [ { label: "Finish", type: "number", - min: 0, + min: -180, max: 180, step: 1, decimals: 0, @@ -1182,7 +1197,7 @@ const GROUPS = [ }, { label: "Lifetime", - type: "number", + type: "string", unit: "s", propertyID: "lifetime", }, @@ -1370,6 +1385,7 @@ const GROUPS_PER_TYPE = { }; const EDITOR_TIMEOUT_DURATION = 1500; +const IMAGE_DEBOUNCE_TIMEOUT = 250; const DEBOUNCE_TIMEOUT = 125; const COLOR_MIN = 0; @@ -1641,7 +1657,7 @@ function updateVisibleSpaceModeProperties() { * PROPERTY UPDATE FUNCTIONS */ -function updateProperty(originalPropertyName, propertyValue, isParticleProperty, blockUpdateCallback) { +function updateProperty(originalPropertyName, propertyValue, isParticleProperty) { let propertyUpdate = {}; // if this is a compound property name (i.e. animation.running) then split it by . up to 3 times let splitPropertyName = originalPropertyName.split('.'); @@ -1667,7 +1683,11 @@ function updateProperty(originalPropertyName, propertyValue, isParticleProperty, }); particleSyncDebounce(); } else { - updateProperties(propertyUpdate, blockUpdateCallback); + // only update the entity property value itself if in the middle of dragging + // prevent undo command push, saving new property values, and property update + // callback until drag is complete (additional update sent via dragEnd callback) + let onlyUpdateEntity = properties[originalPropertyName] && properties[originalPropertyName].dragging === true; + updateProperties(propertyUpdate, onlyUpdateEntity); } } @@ -1676,15 +1696,15 @@ var particleSyncDebounce = _.debounce(function () { particlePropertyUpdates = {}; }, DEBOUNCE_TIMEOUT); -function updateProperties(propertiesToUpdate, blockUpdateCallback) { - if (blockUpdateCallback === undefined) { - blockUpdateCallback = false; +function updateProperties(propertiesToUpdate, onlyUpdateEntity) { + if (onlyUpdateEntity === undefined) { + onlyUpdateEntity = false; } EventBridge.emitWebEvent(JSON.stringify({ id: lastEntityID, type: "update", properties: propertiesToUpdate, - blockUpdateCallback: blockUpdateCallback + onlyUpdateEntities: onlyUpdateEntity })); } @@ -1709,9 +1729,8 @@ function createDragStartFunction(property) { function createDragEndFunction(property) { return function() { property.dragging = false; - EventBridge.emitWebEvent(JSON.stringify({ - type: "updateProperties" - })); + // send an additonal update post-dragging to consider whole property change from dragStart to dragEnd to be 1 action + this.valueChangeFunction(); }; } @@ -1722,7 +1741,7 @@ function createEmitNumberPropertyUpdateFunction(property) { multiplier = 1; } let value = parseFloat(this.value) * multiplier; - updateProperty(property.name, value, property.isParticleProperty, property.dragging); + updateProperty(property.name, value, property.isParticleProperty); }; } @@ -1736,7 +1755,7 @@ function createEmitVec2PropertyUpdateFunction(property) { x: property.elNumberX.elInput.value * multiplier, y: property.elNumberY.elInput.value * multiplier }; - updateProperty(property.name, newValue, property.isParticleProperty, property.dragging); + updateProperty(property.name, newValue, property.isParticleProperty); }; } @@ -1751,7 +1770,7 @@ function createEmitVec3PropertyUpdateFunction(property) { y: property.elNumberY.elInput.value * multiplier, z: property.elNumberZ.elInput.value * multiplier }; - updateProperty(property.name, newValue, property.isParticleProperty, property.dragging); + updateProperty(property.name, newValue, property.isParticleProperty); }; } @@ -1858,7 +1877,7 @@ function createNumberProperty(property, elProperty) { let elementID = property.elementID; let propertyData = property.data; - elProperty.className = "draggable-number"; + elProperty.className += " draggable-number-container"; let dragStartFunction = createDragStartFunction(property); let dragEndFunction = createDragEndFunction(property); @@ -1877,7 +1896,7 @@ function createNumberProperty(property, elProperty) { elProperty.appendChild(elDraggableNumber.elDiv); if (propertyData.buttons !== undefined) { - addButtons(elDraggableNumber.elText, elementID, propertyData.buttons, false); + addButtons(elDraggableNumber.elDiv, elementID, propertyData.buttons, false); } return elDraggableNumber; @@ -1937,7 +1956,7 @@ function createColorProperty(property, elProperty) { let elementID = property.elementID; let propertyData = property.data; - elProperty.className = "rgb fstuple"; + elProperty.className += " rgb fstuple"; let elColorPicker = document.createElement('div'); elColorPicker.className = "color-picker"; @@ -1978,6 +1997,7 @@ function createColorProperty(property, elProperty) { color: '000000', submit: false, // We don't want to have a submission button onShow: function(colpick) { + console.log("Showing"); $(colorPickerID).attr('active', 'true'); // The original color preview within the picker needs to be updated on show because // prior to the picker being shown we don't have access to the selections' starting color. @@ -2100,7 +2120,7 @@ function createTextureProperty(property, elProperty) { elDiv.classList.remove("no-preview"); elDiv.classList.add("no-texture"); } - }, DEBOUNCE_TIMEOUT * 2); + }, IMAGE_DEBOUNCE_TIMEOUT); elInput.imageLoad = imageLoad; elInput.oninput = function (event) { // Add throttle @@ -2879,20 +2899,20 @@ function loaded() { for (let i = 0; i < propertyData.properties.length; ++i) { let innerPropertyData = propertyData.properties[i]; - let elWrapper = createElementFromHTML('
'); + let elWrapper = createElementFromHTML('
'); + elProperty.appendChild(elWrapper); let propertyID = innerPropertyData.propertyID; let propertyName = innerPropertyData.propertyName !== undefined ? innerPropertyData.propertyName : propertyID; let propertyElementID = "property-" + propertyID; propertyElementID = propertyElementID.replace('.', '-'); - elWrapper.appendChild(createElementFromHTML(`
${innerPropertyData.label}
`)); - elProperty.appendChild(elWrapper); - - let property = createProperty(innerPropertyData, propertyElementID, propertyName, propertyID, elWrapper.childNodes[0]); + let property = createProperty(innerPropertyData, propertyElementID, propertyName, propertyID, elWrapper); property.isParticleProperty = group.id.includes("particles"); property.elContainer = elContainer; property.spaceMode = propertySpaceMode; + + elWrapper.appendChild(createElementFromHTML(`
${innerPropertyData.label}
`)); if (property.type !== 'placeholder') { properties[propertyID] = property; @@ -3451,7 +3471,8 @@ function loaded() { }; document.addEventListener("keyup", function (keyUpEvent) { - if (keyUpEvent.target.nodeName === "INPUT") { + const FILTERED_NODE_NAMES = ["INPUT", "TEXTAREA"]; + if (FILTERED_NODE_NAMES.includes(keyUpEvent.target.nodeName)) { return; } let {code, key, keyCode, altKey, ctrlKey, metaKey, shiftKey} = keyUpEvent; diff --git a/scripts/system/html/js/gridControls.js b/scripts/system/html/js/gridControls.js index b2d5988938..3e5bfa1e2f 100644 --- a/scripts/system/html/js/gridControls.js +++ b/scripts/system/html/js/gridControls.js @@ -118,7 +118,8 @@ function loaded() { }; document.addEventListener("keyup", function (keyUpEvent) { - if (keyUpEvent.target.nodeName === "INPUT") { + const FILTERED_NODE_NAMES = ["INPUT", "TEXTAREA"]; + if (FILTERED_NODE_NAMES.includes(keyUpEvent.target.nodeName)) { return; } let {code, key, keyCode, altKey, ctrlKey, metaKey, shiftKey} = keyUpEvent; diff --git a/scripts/system/libraries/WebTablet.js b/scripts/system/libraries/WebTablet.js index 8e5b41deda..f29edd8ff9 100644 --- a/scripts/system/libraries/WebTablet.js +++ b/scripts/system/libraries/WebTablet.js @@ -97,9 +97,8 @@ cleanUpOldMaterialEntities = function() { * @param width [number] width in meters of the tablet model * @param dpi [number] dpi of web surface used to show the content. * @param hand [number] -1 indicates no hand, Controller.Standard.RightHand or Controller.Standard.LeftHand - * @param clientOnly [bool] true indicates tablet model is only visible to client. */ -WebTablet = function (url, width, dpi, hand, clientOnly, location, visible) { +WebTablet = function (url, width, dpi, hand, location, visible) { var _this = this; diff --git a/scripts/system/libraries/entitySelectionTool.js b/scripts/system/libraries/entitySelectionTool.js index e10678a611..1f0bc9404c 100644 --- a/scripts/system/libraries/entitySelectionTool.js +++ b/scripts/system/libraries/entitySelectionTool.js @@ -264,7 +264,7 @@ SelectionManager = (function() { if (properties === undefined) { properties = Entities.getEntityProperties(originalEntityID); } - if (!properties.locked && (!properties.clientOnly || properties.owningAvatarID === MyAvatar.sessionUUID)) { + if (!properties.locked && (!properties.avatarEntity || properties.owningAvatarID === MyAvatar.sessionUUID)) { if (nonDynamicEntityIsBeingGrabbedByAvatar(properties)) { properties.parentID = null; properties.parentJointIndex = null; diff --git a/scripts/system/makeUserConnection.js b/scripts/system/makeUserConnection.js index d205d368dd..4b59f050c9 100644 --- a/scripts/system/makeUserConnection.js +++ b/scripts/system/makeUserConnection.js @@ -229,6 +229,15 @@ } animationData.rightHandRotation = Quat.fromPitchYawRollDegrees(90, 0, 90); animationData.rightHandType = 0; // RotationAndPosition, see IKTargets.h + + // turn on the right hand grip overlay + animationData.rightHandOverlayAlpha = 1.0; + + // make sure the right hand grip animation is the "grasp", not pointing or thumbs up. + animationData.isRightHandGrasp = true; + animationData.isRightIndexPoint = false; + animationData.isRightThumbRaise = false; + animationData.isRightIndexPointAndThumbRaise = false; } function shakeHandsAnimation() { return animationData; diff --git a/scripts/system/marketplaces/marketplace.js b/scripts/system/marketplaces/marketplace.js index d90695c767..d3e5c96739 100644 --- a/scripts/system/marketplaces/marketplace.js +++ b/scripts/system/marketplaces/marketplace.js @@ -30,7 +30,7 @@ var TOOLBAR_MARGIN_Y = 0; var marketplaceVisible = false; var marketplaceWebTablet; -// We persist clientOnly data in the .ini file, and reconsistitute it on restart. +// We persist avatarEntity data in the .ini file, and reconsistitute it on restart. // To keep things consistent, we pickle the tablet data in Settings, and kill any existing such on restart and domain change. var persistenceKey = "io.highfidelity.lastDomainTablet"; diff --git a/scripts/system/nameTag.js b/scripts/system/nameTag.js index 69e5dac1bf..147da25779 100644 --- a/scripts/system/nameTag.js +++ b/scripts/system/nameTag.js @@ -12,7 +12,7 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -const CLIENTONLY = false; +const AVATARENTITY = false; const ENTITY_CHECK_INTERVAL = 5000; // ms = 5 seconds const STARTUP_DELAY = 2000; // ms = 2 second const OLD_AGE = 3500; // we recreate the entity if older than this time in seconds @@ -43,7 +43,7 @@ function addNameTag() { dimensions: dimensionsFromName(), position: nameTagPosition } - nameTagEntityID = Entities.addEntity(nameTagProperties, CLIENTONLY); + nameTagEntityID = Entities.addEntity(nameTagProperties, AVATARENTITY); } function updateNameTag() { diff --git a/scripts/system/tablet-ui/tabletUI.js b/scripts/system/tablet-ui/tabletUI.js index 9a22014895..f9e9165f2e 100644 --- a/scripts/system/tablet-ui/tabletUI.js +++ b/scripts/system/tablet-ui/tabletUI.js @@ -108,7 +108,7 @@ tabletScalePercentage = getTabletScalePercentageFromSettings(); UIWebTablet = new WebTablet("hifi/tablet/TabletRoot.qml", DEFAULT_WIDTH * (tabletScalePercentage / 100), - null, activeHand, true, null, false); + null, activeHand, null, false); UIWebTablet.register(); HMD.tabletID = UIWebTablet.tabletEntityID; HMD.homeButtonID = UIWebTablet.homeButtonID;