Merge "Fix resource ready state" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / graphics / shaders / motion-blur-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 uniform float uBlurTexCoordScale;
10 uniform float uNumSamples;
11 uniform float uRecipNumSamples;
12 uniform float uRecipNumSamplesMinusOne;
13
14 // inputs
15 varying vec2 vModelSpaceCenterToPos;
16 varying vec2 vScreenSpaceVelocityVector;
17 varying float vSpeed;
18 varying vec2 vTexCoord;
19
20 void main()
21 {
22   // 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
23   // the blurred object and the unblurred background. Use smoothstep also to hide any hard edges (discontinuities) in rate of change of this alpha gradient
24   vec2 centerToPixel = abs(vModelSpaceCenterToPos);
25   vec2 fadeToEdges = smoothstep(0.0, 1.0, 1.0 - ((centerToPixel - uObjectFadeStart) / (uObjectFadeEnd - uObjectFadeStart)));
26   float fadeToEdgesScale = fadeToEdges.x * fadeToEdges.y * uAlphaScale; // apply global scaler
27   fadeToEdgesScale = mix(1.0, fadeToEdgesScale, vSpeed);// fade proportional to speed, so opaque when at rest
28
29   // scale velocity vector by user requirements
30   vec2 velocity = vScreenSpaceVelocityVector * uBlurTexCoordScale;
31
32   // standard actor texel
33   vec4 colActor = texture2D(sTexture, vTexCoord);
34
35   // blurred actor - gather texture samples from the actor texture in the direction of motion
36   vec4 col = colActor * uRecipNumSamples;
37   for(float i = 1.0; i < uNumSamples; i += 1.0)
38   {
39     float t = i * uRecipNumSamplesMinusOne;
40     col += texture2D(sTexture, vTexCoord + (velocity * t)) * uRecipNumSamples;
41   }
42   gl_FragColor = mix(colActor, col, vSpeed); // lerp blurred and non-blurred actor based on speed of motion
43   gl_FragColor.a = fadeToEdgesScale;//colActor.a * fadeToEdgesScale; // fade blurred actor to its edges based on speed of motion
44   gl_FragColor *= uColor;
45 }