Merge "Polish turbulence noise to be more cloudy and softer." into udc-dev am: 4c274db7ce

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/23532226

Change-Id: Id05b8e01ff0aecd2fa65210732e8993380493ee1
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Yein Jo
2023-06-02 23:59:58 +00:00
committed by Automerger Merge Worker
4 changed files with 65 additions and 20 deletions

View File

@@ -56,7 +56,19 @@ data class TurbulenceNoiseAnimationConfig(
val easeOutDuration: Float = DEFAULT_EASING_DURATION_IN_MILLIS, val easeOutDuration: Float = DEFAULT_EASING_DURATION_IN_MILLIS,
val pixelDensity: Float = 1f, val pixelDensity: Float = 1f,
val blendMode: BlendMode = DEFAULT_BLEND_MODE, 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 { companion object {
const val DEFAULT_MAX_DURATION_IN_MILLIS = 30_000f // Max 30 sec 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_NOISE_SPEED_Z = 0.3f
const val DEFAULT_OPACITY = 150 // full opacity is 255. const val DEFAULT_OPACITY = 150 // full opacity is 255.
const val DEFAULT_COLOR = Color.WHITE 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 const val DEFAULT_BACKGROUND_COLOR = Color.BLACK
val DEFAULT_BLEND_MODE = BlendMode.SRC_OVER val DEFAULT_BLEND_MODE = BlendMode.SRC_OVER
} }

View File

@@ -37,6 +37,8 @@ class TurbulenceNoiseShader(useFractal: Boolean = false) :
uniform float in_opacity; uniform float in_opacity;
uniform float in_pixelDensity; uniform float in_pixelDensity;
uniform float in_inverseLuma; uniform float in_inverseLuma;
uniform half in_lumaMatteBlendFactor;
uniform half in_lumaMatteOverallBrightness;
layout(color) uniform vec4 in_color; layout(color) uniform vec4 in_color;
layout(color) uniform vec4 in_backgroundColor; layout(color) uniform vec4 in_backgroundColor;
""" """
@@ -48,18 +50,21 @@ class TurbulenceNoiseShader(useFractal: Boolean = false) :
uv.x *= in_aspectRatio; uv.x *= in_aspectRatio;
vec3 noiseP = vec3(uv + in_noiseMove.xy, in_noiseMove.z) * in_gridNum; 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 mask = maskLuminosity(in_color.rgb, luma);
vec3 color = in_backgroundColor.rgb + mask * 0.6; 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. // shader here as we are in gamma space.
float dither = triangleNoise(p * in_pixelDensity) / 255.; 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 // 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. // multiply rgb with a to get the correct result.
color = (color + dither.rrr) * in_color.a; color = (color + dither.rrr) * in_opacity;
return vec4(color, in_color.a); return vec4(color, in_opacity);
} }
""" """
@@ -70,12 +75,15 @@ class TurbulenceNoiseShader(useFractal: Boolean = false) :
uv.x *= in_aspectRatio; uv.x *= in_aspectRatio;
vec3 noiseP = vec3(uv + in_noiseMove.xy, in_noiseMove.z) * in_gridNum; 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 mask = maskLuminosity(in_color.rgb, luma);
vec3 color = in_backgroundColor.rgb + mask * 0.6; vec3 color = in_backgroundColor.rgb + mask * 0.6;
// Skip dithering. // Skip dithering.
return vec4(color * in_color.a, in_color.a); return vec4(color * in_opacity, in_opacity);
} }
""" """
@@ -124,6 +132,28 @@ class TurbulenceNoiseShader(useFractal: Boolean = false) :
setFloatUniform("in_aspectRatio", width / max(height, 0.001f)) setFloatUniform("in_aspectRatio", width / max(height, 0.001f))
} }
/**
* 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. * Sets whether to inverse the luminosity of the noise.
* *
@@ -132,7 +162,7 @@ class TurbulenceNoiseShader(useFractal: Boolean = false) :
* true. * true.
*/ */
fun setInverseNoiseLuminosity(inverse: Boolean) { 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. */ /** Current noise movements in x, y, and z axes. */

View File

@@ -215,10 +215,12 @@ class TurbulenceNoiseView(context: Context?, attrs: AttributeSet?) : View(contex
noiseConfig = config noiseConfig = config
with(turbulenceNoiseShader) { with(turbulenceNoiseShader) {
setGridCount(config.gridCount) setGridCount(config.gridCount)
setColor(ColorUtils.setAlphaComponent(config.color, config.opacity)) setColor(config.color)
setBackgroundColor(config.backgroundColor) setBackgroundColor(config.backgroundColor)
setSize(config.width, config.height) setSize(config.width, config.height)
setPixelDensity(config.pixelDensity) setPixelDensity(config.pixelDensity)
setInverseNoiseLuminosity(inverse = false)
setLumaMatteFactors(config.lumaMatteBlendFactor, config.lumaMatteOverallBrightness)
} }
paint.blendMode = config.blendMode paint.blendMode = config.blendMode
} }

View File

@@ -76,7 +76,6 @@ import androidx.constraintlayout.widget.ConstraintSet;
import com.android.app.animation.Interpolators; import com.android.app.animation.Interpolators;
import com.android.internal.annotations.VisibleForTesting; import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.graphics.ColorUtils;
import com.android.internal.jank.InteractionJankMonitor; import com.android.internal.jank.InteractionJankMonitor;
import com.android.internal.logging.InstanceId; import com.android.internal.logging.InstanceId;
import com.android.internal.widget.CachingIconView; import com.android.internal.widget.CachingIconView;
@@ -1211,24 +1210,24 @@ public class MediaControlPanel {
private TurbulenceNoiseAnimationConfig createTurbulenceNoiseAnimation() { private TurbulenceNoiseAnimationConfig createTurbulenceNoiseAnimation() {
return new TurbulenceNoiseAnimationConfig( return new TurbulenceNoiseAnimationConfig(
TurbulenceNoiseAnimationConfig.DEFAULT_NOISE_GRID_COUNT, /* gridCount= */ 2.14f,
TurbulenceNoiseAnimationConfig.DEFAULT_LUMINOSITY_MULTIPLIER, TurbulenceNoiseAnimationConfig.DEFAULT_LUMINOSITY_MULTIPLIER,
/* noiseMoveSpeedX= */ 0f, /* noiseMoveSpeedX= */ 0.42f,
/* noiseMoveSpeedY= */ 0f, /* noiseMoveSpeedY= */ 0f,
TurbulenceNoiseAnimationConfig.DEFAULT_NOISE_SPEED_Z, TurbulenceNoiseAnimationConfig.DEFAULT_NOISE_SPEED_Z,
/* color= */ mColorSchemeTransition.getAccentPrimary().getCurrentColor(), /* color= */ mColorSchemeTransition.getAccentPrimary().getCurrentColor(),
// We want to add (BlendMode.PLUS) the turbulence noise on top of the album art. /* backgroundColor= */ Color.BLACK,
// Thus, set the background color with alpha 0. /* opacity= */ 51,
/* backgroundColor= */ ColorUtils.setAlphaComponent(Color.BLACK, 0),
TurbulenceNoiseAnimationConfig.DEFAULT_OPACITY,
/* width= */ mMediaViewHolder.getMultiRippleView().getWidth(), /* width= */ mMediaViewHolder.getMultiRippleView().getWidth(),
/* height= */ mMediaViewHolder.getMultiRippleView().getHeight(), /* height= */ mMediaViewHolder.getMultiRippleView().getHeight(),
TurbulenceNoiseAnimationConfig.DEFAULT_MAX_DURATION_IN_MILLIS, TurbulenceNoiseAnimationConfig.DEFAULT_MAX_DURATION_IN_MILLIS,
/* easeInDuration= */ 2500f, /* easeInDuration= */ 1350f,
/* easeOutDuration= */ 2500f, /* easeOutDuration= */ 1350f,
this.getContext().getResources().getDisplayMetrics().density, this.getContext().getResources().getDisplayMetrics().density,
BlendMode.PLUS, BlendMode.SCREEN,
/* onAnimationEnd= */ null /* onAnimationEnd= */ null,
/* lumaMatteBlendFactor= */ 0.26f,
/* lumaMatteOverallBrightness= */ 0.09f
); );
} }
private void clearButton(final ImageButton button) { private void clearButton(final ImageButton button) {