1 precision mediump float;
3 uniform sampler2D sTexture;
6 uniform vec2 uObjectFadeStart;
7 uniform vec2 uObjectFadeEnd;
8 uniform float uAlphaScale;
11 varying vec2 vModelSpaceCenterToPos;
12 varying vec2 vScreenSpaceVelocityVector;
14 varying vec2 vTexCoord;
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
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;