summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Shan Huang <shanh@google.com> 2024-10-19 14:19:26 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2024-10-19 14:19:26 +0000
commit45c4fcbf863fcdbf07e5262ade2c3abe555e446c (patch)
tree052ddcc427eca2f516f639eaf5068865a0651989
parent4b75ad462fdf70c810de99127a3bc0797cc4dd3b (diff)
parenta63a89b6d9f6ecfef30ea6ee8772ba1da642feaa (diff)
Merge "Add TurbulenceNoiseShader.SIMPLEX_NOISE_SIMPLE." into main
-rw-r--r--packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/turbulencenoise/TurbulenceNoiseShader.kt36
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/surfaceeffects/turbulencenoise/TurbulenceNoiseShaderTest.kt14
2 files changed, 37 insertions, 13 deletions
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 025c8b9dce04..f426aa597a84 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
@@ -70,6 +70,19 @@ class TurbulenceNoiseShader(val baseType: Type = Type.SIMPLEX_NOISE) :
}
"""
+ private const val SIMPLEX_SIMPLE_SHADER =
+ """
+ vec4 main(vec2 p) {
+ vec2 uv = p / in_size.xy;
+ uv.x *= in_aspectRatio;
+
+ // Compute turbulence effect with the uv distorted with simplex noise.
+ vec3 noisePos = vec3(uv + in_noiseMove.xy, in_noiseMove.z) * in_gridNum;
+ float mixFactor = simplex3d(noisePos) * 0.5 + 0.5;
+ return mix(in_color, in_screenColor, mixFactor);
+ }
+ """
+
private const val FRACTAL_SHADER =
"""
vec4 main(vec2 p) {
@@ -155,6 +168,8 @@ class TurbulenceNoiseShader(val baseType: Type = Type.SIMPLEX_NOISE) :
return sparkleLayer;
}
"""
+ private const val SIMPLEX_NOISE_SIMPLE_SHADER =
+ ShaderUtilLibrary.SHADER_LIB + UNIFORMS + SIMPLEX_SIMPLE_SHADER
private const val SIMPLEX_NOISE_SHADER =
ShaderUtilLibrary.SHADER_LIB + UNIFORMS + COMMON_FUNCTIONS + SIMPLEX_SHADER
private const val FRACTAL_NOISE_SHADER =
@@ -163,17 +178,20 @@ class TurbulenceNoiseShader(val baseType: Type = Type.SIMPLEX_NOISE) :
ShaderUtilLibrary.SHADER_LIB + UNIFORMS + COMMON_FUNCTIONS + SIMPLEX_SPARKLE_SHADER
enum class Type {
- /** Effect with a simple color noise turbulence. */
+ /** Effect with a color noise turbulence with luma matte. */
SIMPLEX_NOISE,
+ /** Effect with a noise interpolating between foreground and background colors. */
+ SIMPLEX_NOISE_SIMPLE,
/** Effect with a simple color noise turbulence, with fractal. */
SIMPLEX_NOISE_FRACTAL,
/** Effect with color & sparkle turbulence with screen color layer. */
- SIMPLEX_NOISE_SPARKLE
+ SIMPLEX_NOISE_SPARKLE,
}
fun getShader(type: Type): String {
return when (type) {
Type.SIMPLEX_NOISE -> SIMPLEX_NOISE_SHADER
+ Type.SIMPLEX_NOISE_SIMPLE -> SIMPLEX_NOISE_SIMPLE_SHADER
Type.SIMPLEX_NOISE_FRACTAL -> FRACTAL_NOISE_SHADER
Type.SIMPLEX_NOISE_SPARKLE -> SPARKLE_NOISE_SHADER
}
@@ -206,15 +224,15 @@ class TurbulenceNoiseShader(val baseType: Type = Type.SIMPLEX_NOISE) :
setFloatUniform("in_pixelDensity", pixelDensity)
}
- /** Sets the noise color of the effect. Alpha is ignored. */
+ /**
+ * Sets the noise color of the effect. Alpha is ignored for all types except
+ * [Type.SIMPLEX_NOISE_SIMPLE].
+ */
fun setColor(color: Int) {
setColorUniform("in_color", color)
}
- /**
- * Sets the color that is used for blending on top of the background color/image. Only relevant
- * to [Type.SIMPLEX_NOISE_SPARKLE].
- */
+ /** Sets the color that is used for blending on top of the background color/image. */
fun setScreenColor(color: Int) {
setColorUniform("in_screenColor", color)
}
@@ -259,7 +277,7 @@ class TurbulenceNoiseShader(val baseType: Type = Type.SIMPLEX_NOISE) :
*/
fun setLumaMatteFactors(
lumaMatteBlendFactor: Float = 1f,
- lumaMatteOverallBrightness: Float = 0f
+ lumaMatteOverallBrightness: Float = 0f,
) {
setFloatUniform("in_lumaMatteBlendFactor", lumaMatteBlendFactor)
setFloatUniform("in_lumaMatteOverallBrightness", lumaMatteOverallBrightness)
@@ -279,8 +297,10 @@ class TurbulenceNoiseShader(val baseType: Type = Type.SIMPLEX_NOISE) :
/** Current noise movements in x, y, and z axes. */
var noiseOffsetX: Float = 0f
private set
+
var noiseOffsetY: Float = 0f
private set
+
var noiseOffsetZ: Float = 0f
private set
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/surfaceeffects/turbulencenoise/TurbulenceNoiseShaderTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/surfaceeffects/turbulencenoise/TurbulenceNoiseShaderTest.kt
index 286f01736497..dbe90a5b85a9 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/surfaceeffects/turbulencenoise/TurbulenceNoiseShaderTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/surfaceeffects/turbulencenoise/TurbulenceNoiseShaderTest.kt
@@ -20,6 +20,7 @@ import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.surfaceeffects.turbulencenoise.TurbulenceNoiseShader.Companion.Type.SIMPLEX_NOISE
import com.android.systemui.surfaceeffects.turbulencenoise.TurbulenceNoiseShader.Companion.Type.SIMPLEX_NOISE_FRACTAL
+import com.android.systemui.surfaceeffects.turbulencenoise.TurbulenceNoiseShader.Companion.Type.SIMPLEX_NOISE_SIMPLE
import com.android.systemui.surfaceeffects.turbulencenoise.TurbulenceNoiseShader.Companion.Type.SIMPLEX_NOISE_SPARKLE
import org.junit.Test
import org.junit.runner.RunWith
@@ -28,20 +29,23 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class TurbulenceNoiseShaderTest : SysuiTestCase() {
- private lateinit var turbulenceNoiseShader: TurbulenceNoiseShader
-
@Test
fun compilesSimplexNoise() {
- turbulenceNoiseShader = TurbulenceNoiseShader(baseType = SIMPLEX_NOISE)
+ TurbulenceNoiseShader(baseType = SIMPLEX_NOISE)
+ }
+
+ @Test
+ fun compilesSimplexSimpleNoise() {
+ TurbulenceNoiseShader(baseType = SIMPLEX_NOISE_SIMPLE)
}
@Test
fun compilesFractalNoise() {
- turbulenceNoiseShader = TurbulenceNoiseShader(baseType = SIMPLEX_NOISE_FRACTAL)
+ TurbulenceNoiseShader(baseType = SIMPLEX_NOISE_FRACTAL)
}
@Test
fun compilesSparkleNoise() {
- turbulenceNoiseShader = TurbulenceNoiseShader(baseType = SIMPLEX_NOISE_SPARKLE)
+ TurbulenceNoiseShader(baseType = SIMPLEX_NOISE_SPARKLE)
}
}