diff --git a/libraries/controllers/src/controllers/ScriptingInterface.cpp b/libraries/controllers/src/controllers/ScriptingInterface.cpp index 78e9378c18..d32acb3d82 100644 --- a/libraries/controllers/src/controllers/ScriptingInterface.cpp +++ b/libraries/controllers/src/controllers/ScriptingInterface.cpp @@ -95,6 +95,11 @@ namespace controller { return getValue(Input(device, source, ChannelType::BUTTON).getID()); } + float ScriptingInterface::getAxisValue(int source) const { + auto userInputMapper = DependencyManager::get(); + return userInputMapper->getValue(Input((uint32_t)source)); + } + float ScriptingInterface::getAxisValue(StandardAxisChannel source, uint16_t device) const { return getValue(Input(device, source, ChannelType::AXIS).getID()); } diff --git a/libraries/controllers/src/controllers/ScriptingInterface.h b/libraries/controllers/src/controllers/ScriptingInterface.h index 713e864561..b47a6fea31 100644 --- a/libraries/controllers/src/controllers/ScriptingInterface.h +++ b/libraries/controllers/src/controllers/ScriptingInterface.h @@ -81,6 +81,7 @@ namespace controller { Q_INVOKABLE float getValue(const int& source) const; Q_INVOKABLE float getButtonValue(StandardButtonChannel source, uint16_t device = 0) const; Q_INVOKABLE float getAxisValue(StandardAxisChannel source, uint16_t device = 0) const; + Q_INVOKABLE float getAxisValue(int source) const; Q_INVOKABLE Pose getPoseValue(const int& source) const; Q_INVOKABLE Pose getPoseValue(StandardPoseChannel source, uint16_t device = 0) const; diff --git a/libraries/controllers/src/controllers/impl/endpoints/AnyEndpoint.cpp b/libraries/controllers/src/controllers/impl/endpoints/AnyEndpoint.cpp index a3b719b2c1..598dfb6ee8 100644 --- a/libraries/controllers/src/controllers/impl/endpoints/AnyEndpoint.cpp +++ b/libraries/controllers/src/controllers/impl/endpoints/AnyEndpoint.cpp @@ -27,19 +27,27 @@ AnyEndpoint::AnyEndpoint(Endpoint::List children) : Endpoint(Input::INVALID_INPU } } +// The value of an any-point is considered to be the maxiumum absolute value, +// this handles any's of multiple axis values as well as single values as well float AnyEndpoint::peek() const { - float result = 0; + float result = 0.0f; for (auto& child : _children) { - result = std::max(result, child->peek()); + auto childValue = child->peek(); + if (std::abs(childValue) > std::abs(result)) { + result = childValue; + } } return result; } // Fetching the value must trigger any necessary side effects of value() on ALL the children. float AnyEndpoint::value() { - float result = 0; + float result = 0.0f; for (auto& child : _children) { - result = std::max(result, child->value()); + auto childValue = child->value(); + if (std::abs(childValue) > std::abs(result)) { + result = childValue; + } } return result; } diff --git a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp index 70535e7a0a..ad165beba1 100644 --- a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp @@ -374,7 +374,8 @@ void HmdDisplayPlugin::updateFrameData() { } // this offset needs to match GRAB_POINT_SPHERE_OFFSET in scripts/system/libraries/controllers.js - static const vec3 GRAB_POINT_SPHERE_OFFSET = vec3(0.1f, 0.04f, -0.32f); + //static const vec3 GRAB_POINT_SPHERE_OFFSET = vec3(0.1f, 0.04f, -0.32f); + static const vec3 GRAB_POINT_SPHERE_OFFSET = vec3(0.0f, 0.0f, -0.175f); vec3 grabPointOffset = GRAB_POINT_SPHERE_OFFSET; if (i == 0) { grabPointOffset.x *= -1.0f; // this changes between left and right hands diff --git a/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp b/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp index c082c00609..3c34765011 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp @@ -666,7 +666,6 @@ void GLBackend::recycle() const { for (auto pair : externalTexturesTrash) { auto fence = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); pair.second(pair.first, fence); - decrementTextureGPUCount(); } } diff --git a/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp b/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp index 649065ab84..1caecb0b72 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp @@ -20,9 +20,20 @@ std::shared_ptr GLTexture::_textureTransferHelper; // FIXME placeholder for texture memory over-use #define DEFAULT_MAX_MEMORY_MB 256 -#define MIN_FREE_GPU_MEMORY_PERCENTAGE 0.25f #define OVER_MEMORY_PRESSURE 2.0f +// FIXME other apps show things like Oculus home consuming large amounts of GPU memory +// which causes us to blur textures needlessly (since other app GPU memory usage will likely +// be swapped out and not cause any actual impact +//#define CHECK_MIN_FREE_GPU_MEMORY +#ifdef CHECK_MIN_FREE_GPU_MEMORY +#define MIN_FREE_GPU_MEMORY_PERCENTAGE 0.25f +#endif + +// Allow 65% of all available GPU memory to be consumed by textures +// FIXME overly conservative? +#define MAX_CONSUMED_TEXTURE_MEMORY_PERCENTAGE 0.65f + const GLenum GLTexture::CUBE_FACE_LAYOUT[6] = { GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, @@ -107,6 +118,7 @@ float GLTexture::getMemoryPressure() { // If we can't query the dedicated memory just use a fallback fixed value of 256 MB totalGpuMemory = MB_TO_BYTES(DEFAULT_MAX_MEMORY_MB); } else { +#ifdef CHECK_MIN_FREE_GPU_MEMORY // Check the global free GPU memory auto freeGpuMemory = getFreeDedicatedMemory(); if (freeGpuMemory) { @@ -115,21 +127,26 @@ float GLTexture::getMemoryPressure() { if (freeGpuMemory != lastFreeGpuMemory) { lastFreeGpuMemory = freeGpuMemory; if (freePercentage < MIN_FREE_GPU_MEMORY_PERCENTAGE) { - qDebug() << "Exceeded max GPU memory"; + qCDebug(gpugllogging) << "Exceeded min free GPU memory " << freePercentage; return OVER_MEMORY_PRESSURE; } } } +#endif } - // Allow 50% of all available GPU memory to be consumed by textures - // FIXME overly conservative? - availableTextureMemory = (totalGpuMemory >> 1); + availableTextureMemory = static_cast(totalGpuMemory * MAX_CONSUMED_TEXTURE_MEMORY_PERCENTAGE); } // Return the consumed texture memory divided by the available texture memory. auto consumedGpuMemory = Context::getTextureGPUMemoryUsage(); - return (float)consumedGpuMemory / (float)availableTextureMemory; + float memoryPressure = (float)consumedGpuMemory / (float)availableTextureMemory; + static Context::Size lastConsumedGpuMemory = 0; + if (memoryPressure > 1.0f && lastConsumedGpuMemory != consumedGpuMemory) { + lastConsumedGpuMemory = consumedGpuMemory; + qCDebug(gpugllogging) << "Exceeded max allowed texture memory: " << consumedGpuMemory << " / " << availableTextureMemory; + } + return memoryPressure; } diff --git a/libraries/gpu/src/gpu/PackedNormal.slh b/libraries/gpu/src/gpu/PackedNormal.slh index ecb383fc30..1d834b620e 100644 --- a/libraries/gpu/src/gpu/PackedNormal.slh +++ b/libraries/gpu/src/gpu/PackedNormal.slh @@ -23,7 +23,7 @@ vec2 float32x3_to_oct(in vec3 v) { vec3 oct_to_float32x3(in vec2 e) { vec3 v = vec3(e.xy, 1.0 - abs(e.x) - abs(e.y)); - if (v.z < 0) { + if (v.z < 0.0) { v.xy = (1.0 - abs(v.yx)) * signNotZero(v.xy); } return normalize(v); diff --git a/libraries/model/src/model/Light.slh b/libraries/model/src/model/Light.slh index d405848d43..67946abea0 100644 --- a/libraries/model/src/model/Light.slh +++ b/libraries/model/src/model/Light.slh @@ -39,17 +39,18 @@ struct LightAmbient { SphericalHarmonics getLightAmbientSphere(LightAmbient l) { return l._ambientSphere; } + float getLightAmbientIntensity(LightAmbient l) { return l._ambient.x; } bool getLightHasAmbientMap(LightAmbient l) { return l._ambient.y > 0; } float getLightAmbientMapNumMips(LightAmbient l) { return l._ambient.y; } <@func declareLightBuffer(N)@> + <@if N@> uniform lightBuffer { Light lightArray[<$N$>]; }; - Light getLight(int index) { return lightArray[index]; } diff --git a/libraries/networking/src/AssetClient.cpp b/libraries/networking/src/AssetClient.cpp index f5e2caa60d..6a2cbf20cf 100644 --- a/libraries/networking/src/AssetClient.cpp +++ b/libraries/networking/src/AssetClient.cpp @@ -141,7 +141,11 @@ bool haveAssetServer() { } GetMappingRequest* AssetClient::createGetMappingRequest(const AssetPath& path) { - return new GetMappingRequest(path); + auto request = new GetMappingRequest(path); + + request->moveToThread(thread()); + + return request; } GetAllMappingsRequest* AssetClient::createGetAllMappingsRequest() { @@ -305,7 +309,7 @@ void AssetClient::handleAssetGetInfoReply(QSharedPointer messag void AssetClient::handleAssetGetReply(QSharedPointer message, SharedNodePointer senderNode) { Q_ASSERT(QThread::currentThread() == thread()); - auto assetHash = message->read(SHA256_HASH_LENGTH); + auto assetHash = message->readHead(SHA256_HASH_LENGTH); qCDebug(asset_client) << "Got reply for asset: " << assetHash.toHex(); MessageID messageID; @@ -349,8 +353,8 @@ void AssetClient::handleAssetGetReply(QSharedPointer message, S } else { auto weakNode = senderNode.toWeakRef(); - connect(message.data(), &ReceivedMessage::progress, this, [this, weakNode, messageID, length]() { - handleProgressCallback(weakNode, messageID, length); + connect(message.data(), &ReceivedMessage::progress, this, [this, weakNode, messageID, length](qint64 size) { + handleProgressCallback(weakNode, messageID, size, length); }); connect(message.data(), &ReceivedMessage::completed, this, [this, weakNode, messageID]() { handleCompleteCallback(weakNode, messageID); @@ -358,7 +362,8 @@ void AssetClient::handleAssetGetReply(QSharedPointer message, S } } -void AssetClient::handleProgressCallback(const QWeakPointer& node, MessageID messageID, DataOffset length) { +void AssetClient::handleProgressCallback(const QWeakPointer& node, MessageID messageID, + qint64 size, DataOffset length) { auto senderNode = node.toStrongRef(); if (!senderNode) { @@ -381,13 +386,7 @@ void AssetClient::handleProgressCallback(const QWeakPointer& node, Message } auto& callbacks = requestIt->second; - auto& message = callbacks.message; - - if (!message) { - return; - } - - callbacks.progressCallback(message->getSize(), length); + callbacks.progressCallback(size, length); } void AssetClient::handleCompleteCallback(const QWeakPointer& node, MessageID messageID) { diff --git a/libraries/networking/src/AssetClient.h b/libraries/networking/src/AssetClient.h index f951be762d..536a2e3603 100644 --- a/libraries/networking/src/AssetClient.h +++ b/libraries/networking/src/AssetClient.h @@ -93,7 +93,7 @@ private: bool cancelGetAssetRequest(MessageID id); bool cancelUploadAssetRequest(MessageID id); - void handleProgressCallback(const QWeakPointer& node, MessageID messageID, DataOffset length); + void handleProgressCallback(const QWeakPointer& node, MessageID messageID, qint64 size, DataOffset length); void handleCompleteCallback(const QWeakPointer& node, MessageID messageID); struct GetAssetRequestData { diff --git a/libraries/networking/src/ReceivedMessage.cpp b/libraries/networking/src/ReceivedMessage.cpp index 150ae5c91b..02cb58fb2d 100644 --- a/libraries/networking/src/ReceivedMessage.cpp +++ b/libraries/networking/src/ReceivedMessage.cpp @@ -61,7 +61,7 @@ void ReceivedMessage::appendPacket(NLPacket& packet) { _data.append(packet.getPayload(), packet.getPayloadSize()); if (_numPackets % EMIT_PROGRESS_EVERY_X_PACKETS == 0) { - emit progress(); + emit progress(getSize()); } if (packet.getPacketPosition() == NLPacket::PacketPosition::LAST) { diff --git a/libraries/networking/src/ReceivedMessage.h b/libraries/networking/src/ReceivedMessage.h index e9131c074f..3acb7163e7 100644 --- a/libraries/networking/src/ReceivedMessage.h +++ b/libraries/networking/src/ReceivedMessage.h @@ -78,7 +78,7 @@ public: template qint64 readHeadPrimitive(T* data); signals: - void progress(); + void progress(qint64 size); void completed(); private slots: diff --git a/libraries/render-utils/src/DeferredBufferRead.slh b/libraries/render-utils/src/DeferredBufferRead.slh index d7eee23c1f..7c81b2c142 100644 --- a/libraries/render-utils/src/DeferredBufferRead.slh +++ b/libraries/render-utils/src/DeferredBufferRead.slh @@ -52,7 +52,7 @@ DeferredFragment unpackDeferredFragmentNoPosition(vec2 texcoord) { vec4 specularVal; DeferredFragment frag; - frag.depthVal = -1; + frag.depthVal = -1.0; normalVal = texture(normalMap, texcoord); diffuseVal = texture(albedoMap, texcoord); specularVal = texture(specularMap, texcoord); @@ -186,8 +186,8 @@ void unpackMidLowNormalCurvature(vec2 texcoord, out vec4 midNormalCurvature, out lowNormalCurvature = fetchDiffusedCurvature(texcoord); midNormalCurvature.xyz = normalize((midNormalCurvature.xyz - 0.5f) * 2.0f); lowNormalCurvature.xyz = normalize((lowNormalCurvature.xyz - 0.5f) * 2.0f); - midNormalCurvature.w = (midNormalCurvature.w * 2 - 1); - lowNormalCurvature.w = (lowNormalCurvature.w * 2 - 1); + midNormalCurvature.w = (midNormalCurvature.w * 2.0 - 1.0); + lowNormalCurvature.w = (lowNormalCurvature.w * 2.0 - 1.0); } <@endfunc@> diff --git a/libraries/render-utils/src/DeferredBufferWrite.slh b/libraries/render-utils/src/DeferredBufferWrite.slh index aa79781c25..2f6bfaeb61 100755 --- a/libraries/render-utils/src/DeferredBufferWrite.slh +++ b/libraries/render-utils/src/DeferredBufferWrite.slh @@ -27,8 +27,8 @@ float evalOpaqueFinalAlpha(float alpha, float mapAlpha) { } const float DEFAULT_ROUGHNESS = 0.9; -const float DEFAULT_SHININESS = 10; -const float DEFAULT_METALLIC = 0; +const float DEFAULT_SHININESS = 10.0; +const float DEFAULT_METALLIC = 0.0; const vec3 DEFAULT_SPECULAR = vec3(0.1); const vec3 DEFAULT_EMISSIVE = vec3(0.0); const float DEFAULT_OCCLUSION = 1.0; diff --git a/libraries/render-utils/src/DeferredGlobalLight.slh b/libraries/render-utils/src/DeferredGlobalLight.slh index 76194965c1..9ccee8c43f 100755 --- a/libraries/render-utils/src/DeferredGlobalLight.slh +++ b/libraries/render-utils/src/DeferredGlobalLight.slh @@ -25,7 +25,7 @@ // prepareGlobalLight // Transform directions to worldspace vec3 fragNormal = vec3((normal)); - vec3 fragEyeVector = vec3(invViewMat * vec4(-position, 0.0)); + vec3 fragEyeVector = vec3(invViewMat * vec4(-1.0*position, 0.0)); vec3 fragEyeDir = normalize(fragEyeVector); // Get light @@ -150,13 +150,13 @@ vec3 evalLightmappedColor(mat4 invViewMat, float shadowAttenuation, float obscur float facingLight = step(PERPENDICULAR_THRESHOLD, diffuseDot); // Reevaluate the shadow attenuation for light facing fragments - float lightAttenuation = (1 - facingLight) + facingLight * shadowAttenuation; + float lightAttenuation = (1.0 - facingLight) + facingLight * shadowAttenuation; // Diffuse light is the lightmap dimmed by shadow vec3 diffuseLight = lightAttenuation * lightmap; // Ambient light is the lightmap when in shadow - vec3 ambientLight = (1 - lightAttenuation) * lightmap * getLightAmbientIntensity(ambient); + vec3 ambientLight = (1.0 - lightAttenuation) * lightmap * getLightAmbientIntensity(light); return isLightmapEnabled() * obscurance * albedo * (diffuseLight + ambientLight); } diff --git a/libraries/render-utils/src/LightAmbient.slh b/libraries/render-utils/src/LightAmbient.slh index 98f043081e..15e23015cb 100644 --- a/libraries/render-utils/src/LightAmbient.slh +++ b/libraries/render-utils/src/LightAmbient.slh @@ -23,7 +23,7 @@ vec4 evalSkyboxLight(vec3 direction, float lod) { <@func declareEvalAmbientSpecularIrradiance(supportAmbientSphere, supportAmbientMap, supportIfAmbientMapElseAmbientSphere)@> vec3 fresnelSchlickAmbient(vec3 fresnelColor, vec3 lightDir, vec3 halfDir, float gloss) { - return fresnelColor + (max(vec3(gloss), fresnelColor) - fresnelColor) * pow(1.0 - clamp(dot(lightDir, halfDir), 0.0, 1.0), 5); + return fresnelColor + (max(vec3(gloss), fresnelColor) - fresnelColor) * pow(1.0 - clamp(dot(lightDir, halfDir), 0.0, 1.0), 5.0); } <@if supportAmbientMap@> @@ -32,7 +32,7 @@ vec3 fresnelSchlickAmbient(vec3 fresnelColor, vec3 lightDir, vec3 halfDir, float vec3 evalAmbientSpecularIrradiance(LightAmbient ambient, vec3 fragEyeDir, vec3 fragNormal, float roughness, vec3 fresnel) { vec3 direction = -reflect(fragEyeDir, fragNormal); - vec3 ambientFresnel = fresnelSchlickAmbient(fresnel, fragEyeDir, fragNormal, 1 - roughness); + vec3 ambientFresnel = fresnelSchlickAmbient(fresnel, fragEyeDir, fragNormal, 1.0 - roughness); vec3 specularLight; <@if supportIfAmbientMapElseAmbientSphere@> if (getLightHasAmbientMap(ambient)) @@ -75,7 +75,7 @@ void evalLightingAmbient(out vec3 diffuse, out vec3 specular, LightAmbient ambie ) { // Diffuse from ambient - diffuse = (1 - metallic) * sphericalHarmonics_evalSphericalLight(getLightAmbientSphere(ambient), normal).xyz; + diffuse = (1.0 - metallic) * sphericalHarmonics_evalSphericalLight(getLightAmbientSphere(ambient), normal).xyz; // Specular highlight from ambient specular = evalAmbientSpecularIrradiance(ambient, eyeDir, normal, roughness, fresnel) * obscurance * getLightAmbientIntensity(ambient); diff --git a/libraries/render-utils/src/LightPoint.slh b/libraries/render-utils/src/LightPoint.slh index 431731ec18..ac1e415d9d 100644 --- a/libraries/render-utils/src/LightPoint.slh +++ b/libraries/render-utils/src/LightPoint.slh @@ -40,7 +40,7 @@ void evalLightingPoint(out vec3 diffuse, out vec3 specular, Light light, if (isShowLightContour() > 0.0) { // Show edge float edge = abs(2.0 * ((lightVolume_getRadius(light.volume) - fragLightDistance) / (0.1)) - 1.0); - if (edge < 1) { + if (edge < 1.0) { float edgeCoord = exp2(-8.0*edge*edge); diffuse = vec3(edgeCoord * edgeCoord * getLightColor(light)); } diff --git a/libraries/render-utils/src/LightSpot.slh b/libraries/render-utils/src/LightSpot.slh index 6ce21f8823..a38851b039 100644 --- a/libraries/render-utils/src/LightSpot.slh +++ b/libraries/render-utils/src/LightSpot.slh @@ -45,7 +45,7 @@ void evalLightingSpot(out vec3 diffuse, out vec3 specular, Light light, 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) { + if (edge < 1.0) { float edgeCoord = exp2(-8.0*edge*edge); diffuse = vec3(edgeCoord * edgeCoord * getLightColor(light)); } diff --git a/libraries/render-utils/src/LightingModel.slh b/libraries/render-utils/src/LightingModel.slh index 1f5a16afaa..74285aa6a9 100644 --- a/libraries/render-utils/src/LightingModel.slh +++ b/libraries/render-utils/src/LightingModel.slh @@ -124,14 +124,14 @@ float specularDistribution(float roughness, vec3 normal, vec3 halfDir) { float gloss2 = (0.001 + roughness); gloss2 *= gloss2; // pow 2 gloss2 *= gloss2; // pow 4 - float denom = (ndoth * ndoth*(gloss2 - 1) + 1); + float denom = (ndoth * ndoth*(gloss2 - 1.0) + 1.0); float power = gloss2 / (3.14159 * denom * denom); return power; } float specularDistributionGloss(float gloss2, vec3 normal, vec3 halfDir) { float ndoth = clamp(dot(halfDir, normal), 0.0, 1.0); // float gloss2 = pow(0.001 + roughness, 4); - float denom = (ndoth * ndoth*(gloss2 - 1) + 1); + float denom = (ndoth * ndoth*(gloss2 - 1.0) + 1.0); float power = gloss2 / (3.14159 * denom * denom); return power; } @@ -195,7 +195,7 @@ vec4 evalPBRShadingGloss(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, fl float power = specularDistributionGloss(gloss2, fragNormal, halfDir); vec3 specular = fresnelColor * power * diffuse; - return vec4(specular, (1.0 - metallic) * diffuse * (1 - fresnelColor.x)); + return vec4(specular, (1.0 - metallic) * diffuse * (1.0 - fresnelColor.x)); } <@endfunc@> diff --git a/libraries/render-utils/src/SubsurfaceScattering.slh b/libraries/render-utils/src/SubsurfaceScattering.slh index 6d5dd01d8f..42ffafd9ff 100644 --- a/libraries/render-utils/src/SubsurfaceScattering.slh +++ b/libraries/render-utils/src/SubsurfaceScattering.slh @@ -137,7 +137,7 @@ vec3 integrate(float cosTheta, float skinRadius) { uniform sampler2D scatteringLUT; vec3 fetchBRDF(float LdotN, float curvature) { - return texture(scatteringLUT, vec2( clamp(LdotN * 0.5 + 0.5, 0.0, 1.0), clamp(2 * curvature, 0.0, 1.0))).xyz; + return texture(scatteringLUT, vec2( clamp(LdotN * 0.5 + 0.5, 0.0, 1.0), clamp(2.0 * curvature, 0.0, 1.0))).xyz; } vec3 fetchBRDFSpectrum(vec3 LdotNSpectrum, float curvature) { @@ -183,7 +183,7 @@ float tuneCurvatureUnsigned(float curvature) { } float unpackCurvature(float packedCurvature) { - return (packedCurvature * 2 - 1); + return (packedCurvature * 2.0 - 1.0); } vec3 evalScatteringBentNdotL(vec3 normal, vec3 midNormal, vec3 lowNormal, vec3 lightDir) { @@ -210,7 +210,7 @@ vec3 evalSkinBRDF(vec3 lightDir, vec3 normal, vec3 midNormal, vec3 lowNormal, fl return lowNormal * 0.5 + vec3(0.5); } if (showCurvature()) { - return (curvature > 0 ? vec3(curvature, 0.0, 0.0) : vec3(0.0, 0.0, -curvature)); + return (curvature > 0.0 ? vec3(curvature, 0.0, 0.0) : vec3(0.0, 0.0, -curvature)); } vec3 bentNdotL = evalScatteringBentNdotL(normal, midNormal, lowNormal, lightDir); diff --git a/libraries/render-utils/src/deferred_light.slv b/libraries/render-utils/src/deferred_light.slv index 27845bf6a2..74b3749181 100644 --- a/libraries/render-utils/src/deferred_light.slv +++ b/libraries/render-utils/src/deferred_light.slv @@ -26,7 +26,7 @@ void main(void) { ); vec4 pos = UNIT_QUAD[gl_VertexID]; - _texCoord0 = (pos.xy + 1) * 0.5; + _texCoord0 = (pos.xy + 1.0) * 0.5; _texCoord0 *= texcoordFrameTransform.zw; _texCoord0 += texcoordFrameTransform.xy; diff --git a/libraries/render-utils/src/deferred_light_limited.slv b/libraries/render-utils/src/deferred_light_limited.slv new file mode 100644 index 0000000000..0525509f0b --- /dev/null +++ b/libraries/render-utils/src/deferred_light_limited.slv @@ -0,0 +1,57 @@ +<@include gpu/Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// deferred_light_limited.vert +// vertex shader +// +// Created by Sam Gateau on 6/16/16. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +<@include gpu/Transform.slh@> + +<@include gpu/Inputs.slh@> + +<$declareStandardTransform()$> + +uniform vec4 sphereParam; + +out vec4 _texCoord0; + +void main(void) { + if (sphereParam.w != 0.0) { + + // standard transform + TransformCamera cam = getTransformCamera(); + TransformObject obj = getTransformObject(); + <$transformModelToClipPos(cam, obj, inPosition, gl_Position)$>; + + 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()); + } + _texCoord0 = vec4(projected.xy, 0.0, 1.0) * gl_Position.w; + } else { + const float depth = -1.0; //Draw at near plane + const vec4 UNIT_QUAD[4] = vec4[4]( + vec4(-1.0, -1.0, depth, 1.0), + vec4(1.0, -1.0, depth, 1.0), + vec4(-1.0, 1.0, depth, 1.0), + vec4(1.0, 1.0, depth, 1.0) + ); + vec4 pos = UNIT_QUAD[gl_VertexID]; + + _texCoord0 = vec4((pos.xy + 1.0) * 0.5, 0.0, 1.0); + + if (cam_isStereo()) { + _texCoord0.x = 0.5 * (_texCoord0.x + cam_getStereoSide()); + } + gl_Position = pos; + } +} diff --git a/libraries/render-utils/src/directional_ambient_light.slf b/libraries/render-utils/src/directional_ambient_light.slf index 5b591cb01f..6c99d44c5f 100755 --- a/libraries/render-utils/src/directional_ambient_light.slf +++ b/libraries/render-utils/src/directional_ambient_light.slf @@ -2,7 +2,7 @@ <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // -// directional_light.frag +// directional_ambient_light.frag // fragment shader // // Created by Andrzej Kapolka on 9/3/14. diff --git a/libraries/render-utils/src/directional_skybox_light.slf b/libraries/render-utils/src/directional_skybox_light.slf index 6130c8ac8e..d8a2f44042 100755 --- a/libraries/render-utils/src/directional_skybox_light.slf +++ b/libraries/render-utils/src/directional_skybox_light.slf @@ -2,7 +2,7 @@ <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // -// directional_light.frag +// directional_skybox_light.frag // fragment shader // // Created by Sam Gateau on 5/8/2015. diff --git a/plugins/openvr/src/OpenVrDisplayPlugin.cpp b/plugins/openvr/src/OpenVrDisplayPlugin.cpp index 68bb23a84d..c0fa0db214 100644 --- a/plugins/openvr/src/OpenVrDisplayPlugin.cpp +++ b/plugins/openvr/src/OpenVrDisplayPlugin.cpp @@ -635,7 +635,11 @@ void OpenVrDisplayPlugin::postPreview() { _nextSimPoseData = nextSim; }); _nextRenderPoseData = nextRender; + + // FIXME - this looks wrong! _hmdActivityLevel = vr::k_EDeviceActivityLevel_UserInteraction; // _system->GetTrackedDeviceActivityLevel(vr::k_unTrackedDeviceIndex_Hmd); +#else + _hmdActivityLevel = _system->GetTrackedDeviceActivityLevel(vr::k_unTrackedDeviceIndex_Hmd); #endif } diff --git a/scripts/system/away.js b/scripts/system/away.js index c704da83f4..f4a1a22bf6 100644 --- a/scripts/system/away.js +++ b/scripts/system/away.js @@ -16,6 +16,7 @@ (function() { // BEGIN LOCAL_SCOPE +var BASIC_TIMER_INTERVAL = 50; // 50ms = 20hz var OVERLAY_WIDTH = 1920; var OVERLAY_HEIGHT = 1080; var OVERLAY_DATA = { @@ -49,6 +50,21 @@ var AWAY_INTRO = { endFrame: 83.0 }; +// MAIN CONTROL +var isEnabled = true; +var wasMuted; // unknonwn? +var isAway = false; // we start in the un-away state +var wasOverlaysVisible = Menu.isOptionChecked("Overlays"); +var eventMappingName = "io.highfidelity.away"; // goActive on hand controller button events, too. +var eventMapping = Controller.newMapping(eventMappingName); +var avatarPosition = MyAvatar.position; +var wasHmdMounted = HMD.mounted; + + +// some intervals we may create/delete +var avatarMovedInterval; + + // prefetch the kneel animation and hold a ref so it's always resident in memory when we need it. var _animation = AnimationCache.prefetch(AWAY_INTRO.url); @@ -125,41 +141,28 @@ function maybeMoveOverlay() { var halfWayBetweenOldAndLookAt = Vec3.multiply(lookAtChange, EASE_BY_RATIO); var newOverlayPosition = Vec3.sum(lastOverlayPosition, halfWayBetweenOldAndLookAt); lastOverlayPosition = newOverlayPosition; - var actualOverlayPositon = moveCloserToCamera(lastOverlayPosition); Overlays.editOverlay(overlayHMD, { visible: true, position: actualOverlayPositon }); // make sure desktop version is hidden Overlays.editOverlay(overlay, { visible: false }); + + // also remember avatar position + avatarPosition = MyAvatar.position; + } } } function ifAvatarMovedGoActive() { - if (Vec3.distance(MyAvatar.position, avatarPosition) > AVATAR_MOVE_FOR_ACTIVE_DISTANCE) { + var newAvatarPosition = MyAvatar.position; + if (Vec3.distance(newAvatarPosition, avatarPosition) > AVATAR_MOVE_FOR_ACTIVE_DISTANCE) { goActive(); } + avatarPosition = newAvatarPosition; } -// MAIN CONTROL -var isEnabled = true; -var wasMuted, isAway; -var wasOverlaysVisible = Menu.isOptionChecked("Overlays"); -var eventMappingName = "io.highfidelity.away"; // goActive on hand controller button events, too. -var eventMapping = Controller.newMapping(eventMappingName); -var avatarPosition = MyAvatar.position; - -// backward compatible version of getting HMD.mounted, so it works in old clients -function safeGetHMDMounted() { - if (HMD.mounted === undefined) { - return true; - } - return HMD.mounted; -} - -var wasHmdMounted = safeGetHMDMounted(); - -function goAway() { +function goAway(fromStartup) { if (!isEnabled || isAway) { return; } @@ -167,7 +170,6 @@ function goAway() { UserActivityLogger.toggledAway(true); isAway = true; - print('going "away"'); wasMuted = AudioDevice.getMuted(); if (!wasMuted) { AudioDevice.toggleMute(); @@ -189,10 +191,21 @@ function goAway() { // For HMD, the hmd preview will show the system mouse because of allowMouseCapture, // but we want to turn off our Reticle so that we don't get two in preview and a stuck one in headset. Reticle.visible = !HMD.active; - wasHmdMounted = safeGetHMDMounted(); // always remember the correct state + wasHmdMounted = HMD.mounted; // always remember the correct state avatarPosition = MyAvatar.position; - Script.update.connect(ifAvatarMovedGoActive); + + // If we're entering away mode from some other state than startup, then we create our move timer immediately. + // However if we're just stating up, we need to delay this process so that we don't think the initial teleport + // is actually a move. + if (fromStartup === undefined || fromStartup === false) { + avatarMovedInterval = Script.setInterval(ifAvatarMovedGoActive, BASIC_TIMER_INTERVAL); + } else { + var WAIT_FOR_MOVE_ON_STARTUP = 3000; // 3 seconds + Script.setTimeout(function() { + avatarMovedInterval = Script.setInterval(ifAvatarMovedGoActive, BASIC_TIMER_INTERVAL); + }, WAIT_FOR_MOVE_ON_STARTUP); + } } function goActive() { @@ -203,7 +216,6 @@ function goActive() { UserActivityLogger.toggledAway(false); isAway = false; - print('going "active"'); if (!wasMuted) { AudioDevice.toggleMute(); } @@ -230,9 +242,9 @@ function goActive() { if (HMD.active) { Reticle.position = HMD.getHUDLookAtPosition2D(); } - wasHmdMounted = safeGetHMDMounted(); // always remember the correct state + wasHmdMounted = HMD.mounted; // always remember the correct state - Script.update.disconnect(ifAvatarMovedGoActive); + Script.clearInterval(avatarMovedInterval); } function maybeGoActive(event) { @@ -250,10 +262,12 @@ var wasHmdActive = HMD.active; var wasMouseCaptured = Reticle.mouseCaptured; function maybeGoAway() { + // If our active state change (went to or from HMD mode), and we are now in the HMD, go into away if (HMD.active !== wasHmdActive) { wasHmdActive = !wasHmdActive; if (wasHmdActive) { goAway(); + return; } } @@ -264,19 +278,30 @@ function maybeGoAway() { wasMouseCaptured = !wasMouseCaptured; if (!wasMouseCaptured) { goAway(); + return; } } // If you've removed your HMD from your head, and we can detect it, we will also go away... - var hmdMounted = safeGetHMDMounted(); - if (HMD.active && !hmdMounted && wasHmdMounted) { - wasHmdMounted = hmdMounted; - goAway(); + if (HMD.mounted != wasHmdMounted) { + wasHmdMounted = HMD.mounted; + print("HMD mounted changed..."); + + // We're putting the HMD on... switch to those devices + if (HMD.mounted) { + print("NOW mounted..."); + } else { + print("HMD NOW un-mounted..."); + + if (HMD.active) { + goAway(); + return; + } + } } } function setEnabled(value) { - print("setting away enabled: ", value); if (!value) { goActive(); } @@ -293,9 +318,12 @@ var handleMessage = function(channel, message, sender) { Messages.subscribe(CHANNEL_AWAY_ENABLE); Messages.messageReceived.connect(handleMessage); -Script.update.connect(maybeMoveOverlay); +var maybeIntervalTimer = Script.setInterval(function(){ + maybeMoveOverlay(); + maybeGoAway(); +}, BASIC_TIMER_INTERVAL); + -Script.update.connect(maybeGoAway); Controller.mousePressEvent.connect(goActive); Controller.keyPressEvent.connect(maybeGoActive); // Note peek() so as to not interfere with other mappings. @@ -316,11 +344,17 @@ eventMapping.from(Controller.Standard.Start).peek().to(goActive); Controller.enableMapping(eventMappingName); Script.scriptEnding.connect(function () { - Script.update.disconnect(maybeGoAway); + Script.clearInterval(maybeIntervalTimer); goActive(); Controller.disableMapping(eventMappingName); Controller.mousePressEvent.disconnect(goActive); Controller.keyPressEvent.disconnect(maybeGoActive); }); +if (HMD.active && !HMD.mounted) { + print("Starting script, while HMD is active and not mounted..."); + goAway(true); +} + + }()); // END LOCAL_SCOPE diff --git a/scripts/system/controllers/handControllerGrab.js b/scripts/system/controllers/handControllerGrab.js index 2ebf7a828d..6241f6b20e 100644 --- a/scripts/system/controllers/handControllerGrab.js +++ b/scripts/system/controllers/handControllerGrab.js @@ -112,7 +112,7 @@ var CHECK_TOO_FAR_UNEQUIP_TIME = 0.3; // seconds, duration between checks var GRAB_POINT_SPHERE_RADIUS = NEAR_GRAB_RADIUS; -var GRAB_POINT_SPHERE_COLOR = { red: 20, green: 90, blue: 238 }; +var GRAB_POINT_SPHERE_COLOR = { red: 240, green: 240, blue: 240 }; var GRAB_POINT_SPHERE_ALPHA = 0.85; @@ -1075,12 +1075,6 @@ function MyController(hand) { var controllerLocation = getControllerWorldLocation(this.handToController(), true); var worldHandPosition = controllerLocation.position; - if (controllerLocation.valid) { - this.grabPointSphereOn(); - } else { - this.grabPointSphereOff(); - } - var candidateEntities = Entities.findEntities(worldHandPosition, MAX_EQUIP_HOTSPOT_RADIUS); entityPropertiesCache.addEntities(candidateEntities); var potentialEquipHotspot = this.chooseBestEquipHotspot(candidateEntities); @@ -1103,9 +1097,11 @@ function MyController(hand) { if (!this.grabPointIntersectsEntity) { Controller.triggerHapticPulse(1, 20, this.hand); this.grabPointIntersectsEntity = true; + this.grabPointSphereOn(); } } else { this.grabPointIntersectsEntity = false; + this.grabPointSphereOff(); } }; @@ -1427,12 +1423,6 @@ function MyController(hand) { var controllerLocation = getControllerWorldLocation(this.handToController(), true); var handPosition = controllerLocation.position; - if (controllerLocation.valid) { - this.grabPointSphereOn(); - } else { - this.grabPointSphereOff(); - } - var rayPickInfo = this.calcRayPickInfo(this.hand); if (rayPickInfo.entityID) { diff --git a/scripts/system/libraries/controllers.js b/scripts/system/libraries/controllers.js index 9bae46380e..c77ce4578c 100644 --- a/scripts/system/libraries/controllers.js +++ b/scripts/system/libraries/controllers.js @@ -10,9 +10,10 @@ // var GRAB_POINT_SPHERE_OFFSET = { x: 0, y: 0.2, z: 0 }; // var GRAB_POINT_SPHERE_OFFSET = { x: 0.1, y: 0.175, z: 0.04 }; +// var GRAB_POINT_SPHERE_OFFSET = { x: 0.1, y: 0.32, z: 0.04 }; // this offset needs to match the one in libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp -var GRAB_POINT_SPHERE_OFFSET = { x: 0.1, y: 0.32, z: 0.04 }; +var GRAB_POINT_SPHERE_OFFSET = { x: 0.0, y: 0.175, z: 0.0 }; getGrabPointSphereOffset = function(handController) { if (handController === Controller.Standard.RightHand) { diff --git a/scripts/system/users.js b/scripts/system/users.js index 1e1a68fd9c..af88e73362 100644 --- a/scripts/system/users.js +++ b/scripts/system/users.js @@ -1133,6 +1133,7 @@ var usersWindow = (function () { if (VISIBILITY_VALUES.indexOf(myVisibility) === -1) { myVisibility = VISIBILITY_FRIENDS; } + GlobalServices.findableBy = myVisibility; visibilityControl = new PopUpMenu({ prompt: VISIBILITY_PROMPT,