Merge "New shader parameters" into sc-dev
This commit is contained in:
@@ -40,9 +40,9 @@ import java.util.function.Consumer;
|
|||||||
public final class RippleAnimationSession {
|
public final class RippleAnimationSession {
|
||||||
private static final String TAG = "RippleAnimationSession";
|
private static final String TAG = "RippleAnimationSession";
|
||||||
private static final int ENTER_ANIM_DURATION = 450;
|
private static final int ENTER_ANIM_DURATION = 450;
|
||||||
private static final int EXIT_ANIM_DURATION = 225;
|
private static final int EXIT_ANIM_DURATION = 375;
|
||||||
private static final long NOISE_ANIMATION_DURATION = 7000;
|
private static final long NOISE_ANIMATION_DURATION = 7000;
|
||||||
private static final long MAX_NOISE_PHASE = NOISE_ANIMATION_DURATION / 120;
|
private static final long MAX_NOISE_PHASE = NOISE_ANIMATION_DURATION / 214;
|
||||||
private static final TimeInterpolator LINEAR_INTERPOLATOR = new LinearInterpolator();
|
private static final TimeInterpolator LINEAR_INTERPOLATOR = new LinearInterpolator();
|
||||||
private static final Interpolator FAST_OUT_SLOW_IN =
|
private static final Interpolator FAST_OUT_SLOW_IN =
|
||||||
new PathInterpolator(0.4f, 0f, 0.2f, 1f);
|
new PathInterpolator(0.4f, 0f, 0.2f, 1f);
|
||||||
@@ -61,12 +61,12 @@ public final class RippleAnimationSession {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NonNull RippleAnimationSession enter(Canvas canvas) {
|
@NonNull RippleAnimationSession enter(Canvas canvas) {
|
||||||
|
mStartTime = AnimationUtils.currentAnimationTimeMillis();
|
||||||
if (isHwAccelerated(canvas)) {
|
if (isHwAccelerated(canvas)) {
|
||||||
enterHardware((RecordingCanvas) canvas);
|
enterHardware((RecordingCanvas) canvas);
|
||||||
} else {
|
} else {
|
||||||
enterSoftware();
|
enterSoftware();
|
||||||
}
|
}
|
||||||
mStartTime = AnimationUtils.currentAnimationTimeMillis();
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,7 +160,8 @@ public final class RippleAnimationSession {
|
|||||||
RenderNodeAnimator expand =
|
RenderNodeAnimator expand =
|
||||||
new RenderNodeAnimator(props.getProgress(), .5f);
|
new RenderNodeAnimator(props.getProgress(), .5f);
|
||||||
expand.setTarget(canvas);
|
expand.setTarget(canvas);
|
||||||
RenderNodeAnimator loop = new RenderNodeAnimator(props.getNoisePhase(), MAX_NOISE_PHASE);
|
RenderNodeAnimator loop = new RenderNodeAnimator(props.getNoisePhase(),
|
||||||
|
mStartTime + MAX_NOISE_PHASE);
|
||||||
loop.setTarget(canvas);
|
loop.setTarget(canvas);
|
||||||
startAnimation(expand, loop);
|
startAnimation(expand, loop);
|
||||||
}
|
}
|
||||||
@@ -190,7 +191,7 @@ public final class RippleAnimationSession {
|
|||||||
notifyUpdate();
|
notifyUpdate();
|
||||||
mProperties.getShader().setProgress((float) expand.getAnimatedValue());
|
mProperties.getShader().setProgress((float) expand.getAnimatedValue());
|
||||||
});
|
});
|
||||||
ValueAnimator loop = ValueAnimator.ofFloat(0f, MAX_NOISE_PHASE);
|
ValueAnimator loop = ValueAnimator.ofFloat(mStartTime, mStartTime + MAX_NOISE_PHASE);
|
||||||
loop.addUpdateListener(updatedAnimation -> {
|
loop.addUpdateListener(updatedAnimation -> {
|
||||||
notifyUpdate();
|
notifyUpdate();
|
||||||
mProperties.getShader().setNoisePhase((float) loop.getAnimatedValue());
|
mProperties.getShader().setNoisePhase((float) loop.getAnimatedValue());
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ import android.graphics.Rect;
|
|||||||
import android.graphics.Shader;
|
import android.graphics.Shader;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
import android.view.animation.AnimationUtils;
|
||||||
import android.view.animation.LinearInterpolator;
|
import android.view.animation.LinearInterpolator;
|
||||||
|
|
||||||
import com.android.internal.R;
|
import com.android.internal.R;
|
||||||
@@ -151,7 +152,7 @@ public class RippleDrawable extends LayerDrawable {
|
|||||||
/** The maximum number of ripples supported. */
|
/** The maximum number of ripples supported. */
|
||||||
private static final int MAX_RIPPLES = 10;
|
private static final int MAX_RIPPLES = 10;
|
||||||
private static final LinearInterpolator LINEAR_INTERPOLATOR = new LinearInterpolator();
|
private static final LinearInterpolator LINEAR_INTERPOLATOR = new LinearInterpolator();
|
||||||
private static final int DEFAULT_EFFECT_COLOR = 0x80ffffff;
|
private static final int DEFAULT_EFFECT_COLOR = 0x8dffffff;
|
||||||
/** Temporary flag for teamfood. **/
|
/** Temporary flag for teamfood. **/
|
||||||
private static final boolean FORCE_PATTERNED_STYLE = true;
|
private static final boolean FORCE_PATTERNED_STYLE = true;
|
||||||
|
|
||||||
@@ -970,15 +971,16 @@ public class RippleDrawable extends LayerDrawable {
|
|||||||
? mState.mColor.getColorForState(getState(), Color.BLACK)
|
? mState.mColor.getColorForState(getState(), Color.BLACK)
|
||||||
: mMaskColorFilter.getColor());
|
: mMaskColorFilter.getColor());
|
||||||
final int effectColor = mState.mEffectColor.getColorForState(getState(), Color.MAGENTA);
|
final int effectColor = mState.mEffectColor.getColorForState(getState(), Color.MAGENTA);
|
||||||
|
final float noisePhase = AnimationUtils.currentAnimationTimeMillis();
|
||||||
shader.setColor(color, effectColor);
|
shader.setColor(color, effectColor);
|
||||||
shader.setOrigin(cx, cy);
|
shader.setOrigin(cx, cy);
|
||||||
shader.setTouch(x, y);
|
shader.setTouch(x, y);
|
||||||
shader.setResolution(w, h, mState.mDensity);
|
shader.setResolution(w, h, mState.mDensity);
|
||||||
shader.setNoisePhase(0);
|
shader.setNoisePhase(noisePhase);
|
||||||
shader.setRadius(radius);
|
shader.setRadius(radius);
|
||||||
shader.setProgress(.0f);
|
shader.setProgress(.0f);
|
||||||
properties = new RippleAnimationSession.AnimationProperties<>(
|
properties = new RippleAnimationSession.AnimationProperties<>(
|
||||||
cx, cy, radius, 0f, p, 0f, color, shader);
|
cx, cy, radius, noisePhase, p, 0f, color, shader);
|
||||||
if (mMaskShader == null) {
|
if (mMaskShader == null) {
|
||||||
shader.setShader(null);
|
shader.setShader(null);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ final class RippleShader extends RuntimeShader {
|
|||||||
+ " float s = 0.0;\n"
|
+ " float s = 0.0;\n"
|
||||||
+ " for (float i = 0; i < 4; i += 1) {\n"
|
+ " for (float i = 0; i < 4; i += 1) {\n"
|
||||||
+ " float l = i * 0.1;\n"
|
+ " float l = i * 0.1;\n"
|
||||||
+ " float h = l + 0.025;\n"
|
+ " float h = l + 0.05;\n"
|
||||||
+ " float o = sin(PI * (t + 0.35 * i));\n"
|
+ " float o = sin(PI * (t + 0.35 * i));\n"
|
||||||
+ " s += threshold(n + o, l, h);\n"
|
+ " s += threshold(n + o, l, h);\n"
|
||||||
+ " }\n"
|
+ " }\n"
|
||||||
@@ -70,7 +70,7 @@ final class RippleShader extends RuntimeShader {
|
|||||||
+ " return 1. - smoothstep(1. - blurHalf, 1. + blurHalf, d / radius);\n"
|
+ " return 1. - smoothstep(1. - blurHalf, 1. + blurHalf, d / radius);\n"
|
||||||
+ "}\n"
|
+ "}\n"
|
||||||
+ "float softRing(vec2 uv, vec2 xy, float radius, float progress, float blur) {\n"
|
+ "float softRing(vec2 uv, vec2 xy, float radius, float progress, float blur) {\n"
|
||||||
+ " float thickness = 0.3 * radius;\n"
|
+ " float thickness = 0.05 * radius;\n"
|
||||||
+ " float currentRadius = radius * progress;\n"
|
+ " float currentRadius = radius * progress;\n"
|
||||||
+ " float circle_outer = softCircle(uv, xy, currentRadius + thickness, blur);\n"
|
+ " float circle_outer = softCircle(uv, xy, currentRadius + thickness, blur);\n"
|
||||||
+ " float circle_inner = softCircle(uv, xy, max(currentRadius - thickness, 0.), "
|
+ " float circle_inner = softCircle(uv, xy, max(currentRadius - thickness, 0.), "
|
||||||
@@ -93,7 +93,7 @@ final class RippleShader extends RuntimeShader {
|
|||||||
+ " return softCircle(coord, vec2(normal_radius), radius, radius * 50.0);\n"
|
+ " return softCircle(coord, vec2(normal_radius), radius, radius * 50.0);\n"
|
||||||
+ "}\n"
|
+ "}\n"
|
||||||
+ "float turbulence(vec2 uv, float t) {\n"
|
+ "float turbulence(vec2 uv, float t) {\n"
|
||||||
+ " const vec2 scale = vec2(1.5);\n"
|
+ " const vec2 scale = vec2(0.8);\n"
|
||||||
+ " uv = uv * scale;\n"
|
+ " uv = uv * scale;\n"
|
||||||
+ " float g1 = circle_grid(scale, uv, t, in_tCircle1, in_tRotation1, 0.17);\n"
|
+ " float g1 = circle_grid(scale, uv, t, in_tCircle1, in_tRotation1, 0.17);\n"
|
||||||
+ " float g2 = circle_grid(scale, uv, t, in_tCircle2, in_tRotation2, 0.2);\n"
|
+ " float g2 = circle_grid(scale, uv, t, in_tCircle2, in_tRotation2, 0.2);\n"
|
||||||
@@ -102,12 +102,12 @@ final class RippleShader extends RuntimeShader {
|
|||||||
+ " return saturate(0.45 + 0.8 * v);\n"
|
+ " return saturate(0.45 + 0.8 * v);\n"
|
||||||
+ "}\n";
|
+ "}\n";
|
||||||
private static final String SHADER_MAIN = "vec4 main(vec2 p) {\n"
|
private static final String SHADER_MAIN = "vec4 main(vec2 p) {\n"
|
||||||
+ " float fadeIn = subProgress(0., 0.1, in_progress);\n"
|
+ " float fadeIn = subProgress(0., 0.13, in_progress);\n"
|
||||||
+ " float scaleIn = subProgress(0., 0.45, in_progress);\n"
|
+ " float scaleIn = subProgress(0., 1.0, in_progress);\n"
|
||||||
+ " float fadeOutNoise = subProgress(0.5, 0.95, in_progress);\n"
|
+ " float fadeOutNoise = subProgress(0.4, 0.5, in_progress);\n"
|
||||||
+ " float fadeOutRipple = subProgress(0.5, 1., in_progress);\n"
|
+ " float fadeOutRipple = subProgress(0.4, 1., in_progress);\n"
|
||||||
+ " vec2 center = mix(in_touch, in_origin, scaleIn);\n"
|
+ " vec2 center = mix(in_touch, in_origin, saturate(in_progress * 2.0));\n"
|
||||||
+ " float ring = softRing(p, center, in_maxRadius, scaleIn, 0.45);\n"
|
+ " float ring = softRing(p, center, in_maxRadius, scaleIn, 1.);\n"
|
||||||
+ " float alpha = min(fadeIn, 1. - fadeOutNoise);\n"
|
+ " float alpha = min(fadeIn, 1. - fadeOutNoise);\n"
|
||||||
+ " vec2 uv = p * in_resolutionScale;\n"
|
+ " vec2 uv = p * in_resolutionScale;\n"
|
||||||
+ " vec2 densityUv = uv - mod(uv, in_noiseScale);\n"
|
+ " vec2 densityUv = uv - mod(uv, in_noiseScale);\n"
|
||||||
@@ -115,7 +115,7 @@ final class RippleShader extends RuntimeShader {
|
|||||||
+ " float sparkleAlpha = sparkles(densityUv, in_noisePhase) * ring * alpha "
|
+ " float sparkleAlpha = sparkles(densityUv, in_noisePhase) * ring * alpha "
|
||||||
+ "* turbulence;\n"
|
+ "* turbulence;\n"
|
||||||
+ " float fade = min(fadeIn, 1. - fadeOutRipple);\n"
|
+ " float fade = min(fadeIn, 1. - fadeOutRipple);\n"
|
||||||
+ " float waveAlpha = softCircle(p, center, in_maxRadius * scaleIn, 0.2) * fade "
|
+ " float waveAlpha = softCircle(p, center, in_maxRadius * scaleIn, 1.) * fade "
|
||||||
+ "* in_color.a;\n"
|
+ "* in_color.a;\n"
|
||||||
+ " vec4 waveColor = vec4(in_color.rgb * waveAlpha, waveAlpha);\n"
|
+ " vec4 waveColor = vec4(in_color.rgb * waveAlpha, waveAlpha);\n"
|
||||||
+ " vec4 sparkleColor = vec4(in_sparkleColor.rgb * in_sparkleColor.a, "
|
+ " vec4 sparkleColor = vec4(in_sparkleColor.rgb * in_sparkleColor.a, "
|
||||||
@@ -139,7 +139,7 @@ final class RippleShader extends RuntimeShader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setRadius(float radius) {
|
public void setRadius(float radius) {
|
||||||
setUniform("in_maxRadius", radius);
|
setUniform("in_maxRadius", radius * 2.3f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOrigin(float x, float y) {
|
public void setOrigin(float x, float y) {
|
||||||
@@ -205,7 +205,7 @@ final class RippleShader extends RuntimeShader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setResolution(float w, float h, int density) {
|
public void setResolution(float w, float h, int density) {
|
||||||
final float densityScale = density * DisplayMetrics.DENSITY_DEFAULT_SCALE;
|
final float densityScale = density * DisplayMetrics.DENSITY_DEFAULT_SCALE * 0.8f;
|
||||||
setUniform("in_resolutionScale", new float[] {1f / w, 1f / h});
|
setUniform("in_resolutionScale", new float[] {1f / w, 1f / h});
|
||||||
setUniform("in_noiseScale", new float[] {densityScale / w, densityScale / h});
|
setUniform("in_noiseScale", new float[] {densityScale / w, densityScale / h});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user