- // Dali fragmentSource prefix for reference:
- // precision highp float;
- // uniform sampler2D sTexture;
- // uniform sampler2D sEffect;
- // uniform vec4 uColor;
- // varying vec2 vTexCoord;
- std::string fragmentSource;
- fragmentSource =
- "precision mediump float;\n"
- "uniform vec2 uObjectFadeStart;\n"
- "uniform vec2 uObjectFadeEnd;\n"
- "uniform float uAlphaScale;\n"
- "uniform float uBlurTexCoordScale;\n"
- "uniform float uNumSamples;\n"
- "uniform float uRecipNumSamples;\n"
- "uniform float uRecipNumSamplesMinusOne;\n"
- // inputs
- "varying vec2 vModelSpaceCenterToPos;\n"
- "varying vec2 vScreenSpaceVelocityVector;\n"
- "varying float vSpeed;\n"
-
- "void main()\n"
- "{\n"
- // 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
- // the blurred object and the unblurred background. Use smoothstep also to hide any hard edges (discontinuities) in rate of change of this alpha gradient
- " vec2 centerToPixel = abs(vModelSpaceCenterToPos);\n"
- " vec2 fadeToEdges = smoothstep(0.0, 1.0, 1.0 - ((centerToPixel - uObjectFadeStart) / (uObjectFadeEnd - uObjectFadeStart)));\n"
- " float fadeToEdgesScale = fadeToEdges.x * fadeToEdges.y * uAlphaScale;\n" // apply global scaler
- " fadeToEdgesScale = mix(1.0, fadeToEdgesScale, vSpeed);\n" // fade proportional to speed, so opaque when at rest
-
- // scale velocity vector by user requirements
- " vec2 velocity = vScreenSpaceVelocityVector * uBlurTexCoordScale;\n"
-
- // standard actor texel
- " vec4 colActor = texture2D(sTexture, vTexCoord);\n"
-
- // blurred actor - gather texture samples from the actor texture in the direction of motion
- " vec4 col = colActor * uRecipNumSamples;\n"
- " for(float i = 1.0; i < uNumSamples; i += 1.0)\n"
- " {\n"
- " float t = i * uRecipNumSamplesMinusOne;\n"
- " col += texture2D(sTexture, vTexCoord + (velocity * t)) * uRecipNumSamples;\n"
- " }\n"
- " gl_FragColor = mix(colActor, col, vSpeed);\n" // lerp blurred and non-blurred actor based on speed of motion
- " gl_FragColor.a = colActor.a * fadeToEdgesScale;\n" // fade blurred actor to its edges based on speed of motion
- " gl_FragColor *= uColor;\n"
- "}\n";
-
- // NOTE: we must turn on alpha blending for the actor (HINT_BLENDING)
- ShaderEffect shader = ShaderEffect::New( vertexSource, fragmentSource,
- GEOMETRY_TYPE_IMAGE,
- ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING | ShaderEffect::HINT_GRID) );
-
- MotionBlurEffect handle( shader );
-
-
- //////////////////////////////////////
- // Register uniform properties
- //
- //
-
- // factors that scale the look, defaults
- handle.SetUniform( MOTION_BLUR_TEXCOORD_SCALE_PROPERTY_NAME, MOTION_BLUR_TEXCOORD_SCALE );
- handle.SetUniform( MOTION_BLUR_GEOM_STRETCH_SCALING_FACTOR_PROPERTY_NAME, MOTION_BLUR_GEOM_STRETCH_SCALING_FACTOR );
- handle.SetUniform( MOTION_BLUR_SPEED_SCALING_FACTOR_PROPERTY_NAME, MOTION_BLUR_SPEED_SCALING_FACTOR );
- handle.SetUniform( MOTION_BLUR_OBJECT_FADE_START_PROPERTY_NAME, MOTION_BLUR_OBJECT_FADE_START );
- handle.SetUniform( MOTION_BLUR_OBJECT_FADE_END_PROPERTY_NAME, MOTION_BLUR_OBJECT_FADE_END );
- handle.SetUniform( MOTION_BLUR_ALPHA_SCALE_PROPERTY_NAME, MOTION_BLUR_ALPHA_SCALE );
- handle.SetUniform( MOTION_BLUR_NUM_SAMPLES_NAME, static_cast<float>( MOTION_BLUR_NUM_SAMPLES ) );
- handle.SetUniform( MOTION_BLUR_RECIP_NUM_SAMPLES_NAME, 1.0f / static_cast<float>( MOTION_BLUR_NUM_SAMPLES ) );
- handle.SetUniform( MOTION_BLUR_RECIP_NUM_SAMPLES_MINUS_ONE_NAME, 1.0f / static_cast<float>( MOTION_BLUR_NUM_SAMPLES - 1.0f ) );
- handle.SetUniform( MOTION_BLUR_MODEL_LASTFRAME, Matrix::IDENTITY );
-
- return handle;