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/interface/src/Application.cpp b/interface/src/Application.cpp index d58338c908..a02e4ce0b1 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -6688,11 +6688,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/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 7196aa1a2c..21a05576fd 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"); diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index d9d4b57c31..40555547e9 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; } 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/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/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/MaterialTextures.slh b/libraries/graphics/src/graphics/MaterialTextures.slh index 20b117132c..5fb7746dc9 100644 --- a/libraries/graphics/src/graphics/MaterialTextures.slh +++ b/libraries/graphics/src/graphics/MaterialTextures.slh @@ -152,28 +152,28 @@ float fetchScatteringMap(vec2 uv) { <@func fetchMaterialTexturesCoord0(matKey, texcoord0, albedo, roughness, normal, metallic, emissive, scattering)@> <@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$>); @@ -207,20 +207,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 +240,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 +264,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/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/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/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/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/scripts/system/edit.js b/scripts/system/edit.js index fe575c2098..f9ebe36025 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/js/draggableNumber.js b/scripts/system/html/js/draggableNumber.js index 951b123e67..e72881e1ae 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,6 +165,7 @@ 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"; @@ -187,6 +201,7 @@ 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); 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..87a45e6402 100644 --- a/scripts/system/html/js/entityProperties.js +++ b/scripts/system/html/js/entityProperties.js @@ -882,7 +882,7 @@ const GROUPS = [ properties: [ { type: "triple", - label: "Alpha", + label: "Spin", properties: [ { label: "Start", @@ -951,8 +951,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 +979,7 @@ const GROUPS = [ { label: "Start", type: "number", - min: 0, + min: -180, max: 180, step: 1, decimals: 0, @@ -990,7 +990,7 @@ const GROUPS = [ { label: "Finish", type: "number", - min: 0, + min: -180, max: 180, step: 1, decimals: 0, @@ -1182,7 +1182,7 @@ const GROUPS = [ }, { label: "Lifetime", - type: "number", + type: "string", unit: "s", propertyID: "lifetime", }, @@ -1370,6 +1370,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 +1642,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 +1668,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 +1681,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 +1714,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 +1726,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 +1740,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 +1755,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); }; } @@ -1877,7 +1881,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; @@ -2100,7 +2104,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 @@ -3451,7 +3455,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/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;