Apply PreMultipliedAlpha on BorderlineColor
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / graphics / shaders / motion-stretch-effect.frag
1 precision mediump float;
2
3 uniform sampler2D sTexture;
4 uniform vec4 uColor;
5
6 uniform vec2 uObjectFadeStart;
7 uniform vec2 uObjectFadeEnd;
8 uniform float uAlphaScale;
9
10 // inputs
11 varying vec2 vModelSpaceCenterToPos;
12 varying vec2 vScreenSpaceVelocityVector;
13 varying float vSpeed;
14 varying vec2 vTexCoord;
15
16 void main()
17 {
18   // calculate an alpha value that will fade the object towards its extremities, we need this to avoid an unsightly hard edge between color values of
19   // the stretched object and the background. Use smoothstep also to hide any hard edges (discontinuities) in rate of change of this alpha gradient
20   vec2 centerToPixel = abs( vModelSpaceCenterToPos );
21   vec2 fadeToEdges = smoothstep(0.0, 1.0, 1.0 - ((centerToPixel - uObjectFadeStart) / (uObjectFadeEnd - uObjectFadeStart)));
22   float fadeToEdgesScale = fadeToEdges.x * fadeToEdges.y * uAlphaScale; // apply global scaler
23   fadeToEdgesScale = mix(1.0, fadeToEdgesScale, vSpeed);                // fade proportional to speed, so opaque when at rest
24
25   // standard actor texel
26   vec4 colActor = texture2D(sTexture, vTexCoord);
27   gl_FragColor = colActor;
28   gl_FragColor.a *= fadeToEdgesScale; // fade actor to its edges based on speed of motion
29   gl_FragColor *= uColor;
30 }