-inline ShaderEffect CreateDissolveEffect(bool useHighPrecision = true)
-{
- std::string prefixHighPrecision( "precision highp float;\n");
- std::string prefixMediumPrecision( "precision mediump float;\n" );
- std::string vertexShader(
- "uniform float uPercentage;\n"
- "uniform vec3 uSaddleParam;\n"
- "uniform vec2 uTranslation;\n"
- "uniform vec2 uRotation; \n"
- "uniform float uToNext;\n"
- "varying float vPercentage;\n"
- "void main()\n"
- "{\n"
- "gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);\n"
- "vTexCoord = aTexCoord;\n"
- //Calculate the distortion value given the dissolve central line
- "vec2 texCoor = vec2( (aTexCoord.s - sTextureRect.s ) / (sTextureRect.p - sTextureRect.s), (aTexCoord.t- sTextureRect.t)/(sTextureRect.q - sTextureRect.t) ); \n"
- "vec2 value = texCoor + uTranslation; \n"
- "mat2 rotateMatrix = mat2( uRotation.s, uRotation.t, -uRotation.t, uRotation.s ); \n"
- "value = rotateMatrix * value; \n"
- "if(uToNext == 1.0) \n"
- " value.s = uSaddleParam[2] + value.s; \n"
- "float delay = value.t*value.t / uSaddleParam[0] - value.s*value.s/uSaddleParam[1];\n"
- "vPercentage = clamp( uPercentage*2.0 - 0.5*sin(delay*1.571) - 0.5, 0.0, 1.0 ); \n"
- "}\n");
- std::string fragmentShader(
- "varying float vPercentage;\n"
- "float rand(vec2 co) \n"
- "{\n"
- " return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); \n"
- "}\n"
- "void main()\n"
- "{\n"
- //Calculate the randomness
- "float offsetS = rand( vTexCoord * vPercentage ) * (sTextureRect.p - sTextureRect.s) - vTexCoord.s + sTextureRect.s; \n"
- "float offsetT = rand( vec2(vTexCoord.t*vPercentage, vTexCoord.s * vPercentage) ) * (sTextureRect.q - sTextureRect.t) - vTexCoord.t + sTextureRect.t; \n"
- "vec2 lookupCoord = vTexCoord + vec2(offsetS, offsetT) * vPercentage; \n"
- "gl_FragColor = texture2D( sTexture, lookupCoord ) * uColor; \n"
- "gl_FragColor.a *= 1.0 - vPercentage; \n"
- "}" );
-
- // Create the implementation, temporarily owned on stack,
- Dali::ShaderEffect shaderEffect;
- if( useHighPrecision )
- {
- shaderEffect = Dali::ShaderEffect::New(
- prefixHighPrecision+vertexShader, prefixHighPrecision + fragmentShader,
- ShaderEffect::GeometryHints( ShaderEffect::HINT_GRID | ShaderEffect::HINT_BLENDING ) );
- }
- else
- {
- shaderEffect = Dali::ShaderEffect::New(
- prefixMediumPrecision+vertexShader, prefixMediumPrecision + fragmentShader,
- ShaderEffect::GeometryHints( ShaderEffect::HINT_GRID | ShaderEffect::HINT_BLENDING ) );
- }
-
- shaderEffect.SetUniform( "uPercentage", 0.0f );
- shaderEffect.SetProperty( ShaderEffect::Property::GRID_DENSITY, Dali::Property::Value(50.0f) );
-
- DissolveEffectSetCentralLine( shaderEffect, Vector2(1.0f,0.5f), Vector2(-1.0f, 0.0f) );
-
- return shaderEffect;
-
-}