summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Yein Jo <yeinj@google.com> 2023-06-03 00:22:43 +0000
committer Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> 2023-06-03 00:22:43 +0000
commitd32b8176bbf19160df27e7d5a14bc0cf7f10f467 (patch)
tree9c299be135e04d0885471944d4ac00d202e4a16e
parent9f2c83d6131502f5751743fd36bcc92e7338ad38 (diff)
parente5d0666cd89a8a0ca83d18cfb4342e2943f1ceb5 (diff)
Merge "Polish turbulence noise to be more cloudy and softer." into udc-dev am: 4c274db7ce am: e5d0666cd8
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/23532226 Change-Id: I82726c942af9a51de0f0a989f29b3b409bb5fa94 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/turbulencenoise/TurbulenceNoiseAnimationConfig.kt16
-rw-r--r--packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/turbulencenoise/TurbulenceNoiseShader.kt44
-rw-r--r--packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/turbulencenoise/TurbulenceNoiseView.kt4
-rw-r--r--packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaControlPanel.java21
4 files changed, 65 insertions, 20 deletions
diff --git a/packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/turbulencenoise/TurbulenceNoiseAnimationConfig.kt b/packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/turbulencenoise/TurbulenceNoiseAnimationConfig.kt
index 89871fa7d875..2cd587ffbc45 100644
--- a/packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/turbulencenoise/TurbulenceNoiseAnimationConfig.kt
+++ b/packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/turbulencenoise/TurbulenceNoiseAnimationConfig.kt
@@ -56,7 +56,19 @@ data class TurbulenceNoiseAnimationConfig(
val easeOutDuration: Float = DEFAULT_EASING_DURATION_IN_MILLIS,
val pixelDensity: Float = 1f,
val blendMode: BlendMode = DEFAULT_BLEND_MODE,
- val onAnimationEnd: Runnable? = null
+ val onAnimationEnd: Runnable? = null,
+ /**
+ * Variants in noise. Higher number means more contrast; lower number means less contrast but
+ * make the noise dimmed. You may want to increase the [lumaMatteBlendFactor] to compensate.
+ * Expected range [0, 1].
+ */
+ val lumaMatteBlendFactor: Float = DEFAULT_LUMA_MATTE_BLEND_FACTOR,
+ /**
+ * Offset for the overall brightness in noise. Higher number makes the noise brighter. You may
+ * want to use this if you have made the noise softer using [lumaMatteBlendFactor]. Expected
+ * range [0, 1].
+ */
+ val lumaMatteOverallBrightness: Float = DEFAULT_LUMA_MATTE_OVERALL_BRIGHTNESS
) {
companion object {
const val DEFAULT_MAX_DURATION_IN_MILLIS = 30_000f // Max 30 sec
@@ -66,6 +78,8 @@ data class TurbulenceNoiseAnimationConfig(
const val DEFAULT_NOISE_SPEED_Z = 0.3f
const val DEFAULT_OPACITY = 150 // full opacity is 255.
const val DEFAULT_COLOR = Color.WHITE
+ const val DEFAULT_LUMA_MATTE_BLEND_FACTOR = 1f
+ const val DEFAULT_LUMA_MATTE_OVERALL_BRIGHTNESS = 0f
const val DEFAULT_BACKGROUND_COLOR = Color.BLACK
val DEFAULT_BLEND_MODE = BlendMode.SRC_OVER
}
diff --git a/packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/turbulencenoise/TurbulenceNoiseShader.kt b/packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/turbulencenoise/TurbulenceNoiseShader.kt
index d1ba7c4de35c..d3c57c91405a 100644
--- a/packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/turbulencenoise/TurbulenceNoiseShader.kt
+++ b/packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/turbulencenoise/TurbulenceNoiseShader.kt
@@ -37,6 +37,8 @@ class TurbulenceNoiseShader(useFractal: Boolean = false) :
uniform float in_opacity;
uniform float in_pixelDensity;
uniform float in_inverseLuma;
+ uniform half in_lumaMatteBlendFactor;
+ uniform half in_lumaMatteOverallBrightness;
layout(color) uniform vec4 in_color;
layout(color) uniform vec4 in_backgroundColor;
"""
@@ -48,18 +50,21 @@ class TurbulenceNoiseShader(useFractal: Boolean = false) :
uv.x *= in_aspectRatio;
vec3 noiseP = vec3(uv + in_noiseMove.xy, in_noiseMove.z) * in_gridNum;
- float luma = abs(in_inverseLuma - simplex3d(noiseP)) * in_opacity;
+ // Bring it to [0, 1] range.
+ float luma = (simplex3d(noiseP) * in_inverseLuma) * 0.5 + 0.5;
+ luma = saturate(luma * in_lumaMatteBlendFactor + in_lumaMatteOverallBrightness)
+ * in_opacity;
vec3 mask = maskLuminosity(in_color.rgb, luma);
vec3 color = in_backgroundColor.rgb + mask * 0.6;
- // Add dither with triangle distribution to avoid color banding. Ok to dither in the
+ // Add dither with triangle distribution to avoid color banding. Dither in the
// shader here as we are in gamma space.
float dither = triangleNoise(p * in_pixelDensity) / 255.;
// The result color should be pre-multiplied, i.e. [R*A, G*A, B*A, A], thus need to
// multiply rgb with a to get the correct result.
- color = (color + dither.rrr) * in_color.a;
- return vec4(color, in_color.a);
+ color = (color + dither.rrr) * in_opacity;
+ return vec4(color, in_opacity);
}
"""
@@ -70,12 +75,15 @@ class TurbulenceNoiseShader(useFractal: Boolean = false) :
uv.x *= in_aspectRatio;
vec3 noiseP = vec3(uv + in_noiseMove.xy, in_noiseMove.z) * in_gridNum;
- float luma = abs(in_inverseLuma - simplex3d_fractal(noiseP)) * in_opacity;
+ // Bring it to [0, 1] range.
+ float luma = (simplex3d_fractal(noiseP) * in_inverseLuma) * 0.5 + 0.5;
+ luma = saturate(luma * in_lumaMatteBlendFactor + in_lumaMatteOverallBrightness)
+ * in_opacity;
vec3 mask = maskLuminosity(in_color.rgb, luma);
vec3 color = in_backgroundColor.rgb + mask * 0.6;
// Skip dithering.
- return vec4(color * in_color.a, in_color.a);
+ return vec4(color * in_opacity, in_opacity);
}
"""
@@ -125,6 +133,28 @@ class TurbulenceNoiseShader(useFractal: Boolean = false) :
}
/**
+ * Sets blend and brightness factors of the luma matte.
+ *
+ * @param lumaMatteBlendFactor increases or decreases the amount of variance in noise. Setting
+ * this a lower number removes variations. I.e. the turbulence noise will look more blended.
+ * Expected input range is [0, 1]. more dimmed.
+ * @param lumaMatteOverallBrightness adds the overall brightness of the turbulence noise.
+ * Expected input range is [0, 1].
+ *
+ * Example usage: You may want to apply a small number to [lumaMatteBlendFactor], such as 0.2,
+ * which makes the noise look softer. However it makes the overall noise look dim, so you want
+ * offset something like 0.3 for [lumaMatteOverallBrightness] to bring back its overall
+ * brightness.
+ */
+ fun setLumaMatteFactors(
+ lumaMatteBlendFactor: Float = 1f,
+ lumaMatteOverallBrightness: Float = 0f
+ ) {
+ setFloatUniform("in_lumaMatteBlendFactor", lumaMatteBlendFactor)
+ setFloatUniform("in_lumaMatteOverallBrightness", lumaMatteOverallBrightness)
+ }
+
+ /**
* Sets whether to inverse the luminosity of the noise.
*
* By default noise will be used as a luma matte as is. This means that you will see color in
@@ -132,7 +162,7 @@ class TurbulenceNoiseShader(useFractal: Boolean = false) :
* true.
*/
fun setInverseNoiseLuminosity(inverse: Boolean) {
- setFloatUniform("in_inverseLuma", if (inverse) 1f else 0f)
+ setFloatUniform("in_inverseLuma", if (inverse) -1f else 1f)
}
/** Current noise movements in x, y, and z axes. */
diff --git a/packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/turbulencenoise/TurbulenceNoiseView.kt b/packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/turbulencenoise/TurbulenceNoiseView.kt
index c3e84787d4fb..43d6504fce84 100644
--- a/packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/turbulencenoise/TurbulenceNoiseView.kt
+++ b/packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/turbulencenoise/TurbulenceNoiseView.kt
@@ -215,10 +215,12 @@ class TurbulenceNoiseView(context: Context?, attrs: AttributeSet?) : View(contex
noiseConfig = config
with(turbulenceNoiseShader) {
setGridCount(config.gridCount)
- setColor(ColorUtils.setAlphaComponent(config.color, config.opacity))
+ setColor(config.color)
setBackgroundColor(config.backgroundColor)
setSize(config.width, config.height)
setPixelDensity(config.pixelDensity)
+ setInverseNoiseLuminosity(inverse = false)
+ setLumaMatteFactors(config.lumaMatteBlendFactor, config.lumaMatteOverallBrightness)
}
paint.blendMode = config.blendMode
}
diff --git a/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaControlPanel.java b/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaControlPanel.java
index 516fbf5ca12c..14386c1c0fd6 100644
--- a/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaControlPanel.java
+++ b/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaControlPanel.java
@@ -76,7 +76,6 @@ import androidx.constraintlayout.widget.ConstraintSet;
import com.android.app.animation.Interpolators;
import com.android.internal.annotations.VisibleForTesting;
-import com.android.internal.graphics.ColorUtils;
import com.android.internal.jank.InteractionJankMonitor;
import com.android.internal.logging.InstanceId;
import com.android.internal.widget.CachingIconView;
@@ -1211,24 +1210,24 @@ public class MediaControlPanel {
private TurbulenceNoiseAnimationConfig createTurbulenceNoiseAnimation() {
return new TurbulenceNoiseAnimationConfig(
- TurbulenceNoiseAnimationConfig.DEFAULT_NOISE_GRID_COUNT,
+ /* gridCount= */ 2.14f,
TurbulenceNoiseAnimationConfig.DEFAULT_LUMINOSITY_MULTIPLIER,
- /* noiseMoveSpeedX= */ 0f,
+ /* noiseMoveSpeedX= */ 0.42f,
/* noiseMoveSpeedY= */ 0f,
TurbulenceNoiseAnimationConfig.DEFAULT_NOISE_SPEED_Z,
/* color= */ mColorSchemeTransition.getAccentPrimary().getCurrentColor(),
- // We want to add (BlendMode.PLUS) the turbulence noise on top of the album art.
- // Thus, set the background color with alpha 0.
- /* backgroundColor= */ ColorUtils.setAlphaComponent(Color.BLACK, 0),
- TurbulenceNoiseAnimationConfig.DEFAULT_OPACITY,
+ /* backgroundColor= */ Color.BLACK,
+ /* opacity= */ 51,
/* width= */ mMediaViewHolder.getMultiRippleView().getWidth(),
/* height= */ mMediaViewHolder.getMultiRippleView().getHeight(),
TurbulenceNoiseAnimationConfig.DEFAULT_MAX_DURATION_IN_MILLIS,
- /* easeInDuration= */ 2500f,
- /* easeOutDuration= */ 2500f,
+ /* easeInDuration= */ 1350f,
+ /* easeOutDuration= */ 1350f,
this.getContext().getResources().getDisplayMetrics().density,
- BlendMode.PLUS,
- /* onAnimationEnd= */ null
+ BlendMode.SCREEN,
+ /* onAnimationEnd= */ null,
+ /* lumaMatteBlendFactor= */ 0.26f,
+ /* lumaMatteOverallBrightness= */ 0.09f
);
}
private void clearButton(final ImageButton button) {