/*
- * Copyright (c) 2014-2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016-2016 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
" }\n"
" ]\n"
" }\n"
- " },\n"
- " \"shaderEffects\": {\n"
- " \"Ripple2D\": {\n"
- " \"program\": {\n"
- " \"vertexPrefix\": \"\",\n"
- " \"vertex\": \"void main(void)\\n{\\n gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);\\n vTexCoord = aTexCoord;\\n}\\n\\n\",\n"
- " \"fragmentPrefix\": \"\",\n"
- " \"fragment\": \"precision mediump float;\\nuniform float uAmplitude; // 0.02; (< 1)\\nuniform float uTime;\\nvoid main()\\n{\\n highp vec2 textureSize = sTextureRect.zw - sTextureRect.xy;\\n highp vec2 pos = -1.0 + 2.0 * vTexCoord.st/textureSize;\\n highp float len = length(pos);\\n highp vec2 texCoord = vTexCoord.st/textureSize + pos/len * sin( len * 12.0 - uTime * 4.0 ) * uAmplitude; \\n gl_FragColor = texture2D(sTexture, texCoord) * uColor;\\n}\\n\\n\\n\",\n"
- " \"geometryType\": \"GEOMETRY_TYPE_IMAGE\"\n"
- " },\n"
- " \"geometryHints\": \"HINT_NONE\",\n"
- " \"gridDensity\": 0,\n"
- " \"loop\": true,\n"
- " \"uAmplitude\": 0.02,\n"
- " \"uTime\": 0.0\n"
- " }\n"
" }\n"
"}\n");
" }\n"
" ]\n"
" }\n"
- " },\n"
- " \"shaderEffects\": {\n"
- " \"Ripple2D\": {\n"
- " \"program\": {\n"
- " \"vertexPrefix\": \"\",\n"
- " \"vertex\": \"void main(void)\\n{\\n gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);\\n vTexCoord = aTexCoord;\\n}\\n\\n\",\n"
- " \"fragmentPrefix\": \"\",\n"
- " \"fragment\": \"precision mediump float;\\nuniform float uAmplitude; // 0.02; (< 1)\\nuniform float uTime;\\nvoid main()\\n{\\n highp vec2 textureSize = sTextureRect.zw - sTextureRect.xy;\\n highp vec2 pos = -1.0 + 2.0 * vTexCoord.st/textureSize;\\n highp float len = length(pos);\\n highp vec2 texCoord = vTexCoord.st/textureSize + pos/len * sin( len * 12.0 - uTime * 4.0 ) * uAmplitude; \\n gl_FragColor = texture2D(sTexture, texCoord) * uColor;\\n}\\n\\n\\n\",\n"
- " \"geometryType\": \"GEOMETRY_TYPE_IMAGE\"\n"
- " },\n"
- " \"geometryHints\": \"HINT_NONE\",\n"
- " \"gridDensity\": 0,\n"
- " \"loop\": true,\n"
- " \"uAmplitude\": 0.02,\n"
- " \"uTime\": 0.0\n"
- " }\n"
" }\n"
"}\n");
#include <dali-toolkit/dali-toolkit.h>
#include <dali-toolkit/devel-api/shader-effects/alpha-discard-effect.h>
-#include <dali-toolkit/devel-api/shader-effects/bendy-effect.h>
-#include <dali-toolkit/devel-api/shader-effects/blind-effect.h>
-#include <dali-toolkit/devel-api/shader-effects/bouncing-effect.h>
-#include <dali-toolkit/devel-api/shader-effects/carousel-effect.h>
-#include <dali-toolkit/devel-api/shader-effects/displacement-effect.h>
#include <dali-toolkit/devel-api/shader-effects/dissolve-effect.h>
-#include <dali-toolkit/devel-api/shader-effects/dissolve-local-effect.h>
#include <dali-toolkit/devel-api/shader-effects/distance-field-effect.h>
#include <dali-toolkit/devel-api/shader-effects/image-region-effect.h>
-#include <dali-toolkit/devel-api/shader-effects/iris-effect.h>
-#include <dali-toolkit/devel-api/shader-effects/mask-effect.h>
-#include <dali-toolkit/devel-api/shader-effects/mirror-effect.h>
#include <dali-toolkit/devel-api/shader-effects/motion-blur-effect.h>
#include <dali-toolkit/devel-api/shader-effects/motion-stretch-effect.h>
-#include <dali-toolkit/devel-api/shader-effects/overlay-effect.h>
-#include <dali-toolkit/devel-api/shader-effects/quadratic-bezier.h>
-#include <dali-toolkit/devel-api/shader-effects/ripple-effect.h>
-#include <dali-toolkit/devel-api/shader-effects/ripple2d-effect.h>
-#include <dali-toolkit/devel-api/shader-effects/shear-effect.h>
-#include <dali-toolkit/devel-api/shader-effects/soft-button-effect.h>
-#include <dali-toolkit/devel-api/shader-effects/spot-effect.h>
-#include <dali-toolkit/devel-api/shader-effects/square-dissolve-effect.h>
-#include <dali-toolkit/devel-api/shader-effects/swirl-effect.h>
using namespace Dali;
using namespace Dali::Toolkit;
END_TEST;
}
-int UtcDaliCreateBendyEffect(void)
-{
- ToolkitTestApplication application;
-
- ShaderEffect effect = Toolkit::CreateBendyEffect();
- DALI_TEST_CHECK( effect );
-
- END_TEST;
-}
-
-int UtcDaliCreateBlindEffect(void)
-{
- ToolkitTestApplication application;
-
- ShaderEffect effect = Toolkit::CreateBlindEffect();
- DALI_TEST_CHECK( effect );
-
- END_TEST;
-}
-
-int UtcDaliCreateBouncingEffect(void)
-{
- ToolkitTestApplication application;
-
- Vector4 color(1.0f,1.0f,1.0f,1.0f);
-
- ShaderEffect effect = Toolkit::CreateBouncingEffect(color);
- DALI_TEST_CHECK( effect );
-
- Property::Value value = effect.GetProperty( effect.GetPropertyIndex("uAssignedColor"));
- DALI_TEST_EQUALS( value.Get<Vector4>(), color, TEST_LOCATION );
-
- END_TEST;
-}
-
-int UtcDaliCreateCarouselEffect(void)
-{
- ToolkitTestApplication application;
-
- ShaderEffect effect = Toolkit::CreateCarouselEffect();
- DALI_TEST_CHECK( effect );
-
- END_TEST;
-}
-
-int UtcDaliCreateDisplacementEffectDisplaced(void)
-{
- ToolkitTestApplication application;
-
- ShaderEffect effect = Toolkit::CreateDisplacementEffect(Toolkit::DISPLACEMENT_EFFECT_DISPLACED);
- DALI_TEST_CHECK( effect );
-
- END_TEST;
-}
-
-int UtcDaliCreateDisplacementEffectFixed(void)
-{
- ToolkitTestApplication application;
-
- ShaderEffect effect = Toolkit::CreateDisplacementEffect(Toolkit::DISPLACEMENT_EFFECT_FIXED);
- DALI_TEST_CHECK( effect );
-
- END_TEST;
-}
-
int UtcDaliCreateDissolveEffect( bool highPrecision )
{
ToolkitTestApplication application;
return UtcDaliCreateDissolveEffect(false);
}
-int UtcDaliCreateDissolveLocalEffect(void)
-{
- ToolkitTestApplication application;
-
- ShaderEffect effect = Toolkit::CreateDissolveLocalEffect(0);
- DALI_TEST_CHECK( effect );
-
- END_TEST;
-}
-
int UtcDaliCreateDissolveEffect(void)
{
ToolkitTestApplication application;
END_TEST;
}
-int UtcDaliCreateIrisEffect(void)
-{
- ToolkitTestApplication application;
-
- ShaderEffect effect = Toolkit::CreateIrisEffect();
- DALI_TEST_CHECK( effect );
-
- END_TEST;
-}
-
-int UtcDaliCreateMaskEffect(void)
-{
- ToolkitTestApplication application;
-
- BufferImage image = CreateBufferImage();
- ShaderEffect effect = Toolkit::CreateMaskEffect(image);
- DALI_TEST_CHECK( effect );
-
- END_TEST;
-}
-
-int UtcDaliCreateMirrorEffect(void)
-{
- ToolkitTestApplication application;
-
- BufferImage image = CreateBufferImage();
- ShaderEffect effect = Toolkit::CreateMirrorEffect();
- DALI_TEST_CHECK( effect );
-
- END_TEST;
-}
-
int UtcDaliCreateMotionBlurEffect(void)
{
ToolkitTestApplication application;
END_TEST;
}
-
-int UtcDaliCreateOverlayEffect(void)
-{
- ToolkitTestApplication application;
-
- BufferImage image = CreateBufferImage();
- ShaderEffect effect = Toolkit::CreateOverlayEffect(image);
- DALI_TEST_CHECK( effect );
-
- END_TEST;
-}
-
-int UtcDaliCreateQuadraticBezier(void)
-{
- ToolkitTestApplication application;
-
- ShaderEffect effect = Toolkit::CreateQuadraticBezier(3,false);
- DALI_TEST_CHECK( effect );
-
- END_TEST;
-}
-
-int UtcDaliCreateQuadraticBezierFilled(void)
-{
- ToolkitTestApplication application;
-
- ShaderEffect effect = Toolkit::CreateQuadraticBezier(3,true);
- DALI_TEST_CHECK( effect );
-
- END_TEST;
-}
-
-int UtcDaliCreateRipple2DEffect(void)
-{
- ToolkitTestApplication application;
-
- ShaderEffect effect = Toolkit::CreateRipple2DEffect();
- DALI_TEST_CHECK( effect );
-
- END_TEST;
-}
-
-int UtcDaliCreateRippleEffect(void)
-{
- ToolkitTestApplication application;
-
- ShaderEffect effect = Toolkit::CreateRippleEffect();
- DALI_TEST_CHECK( effect );
-
- END_TEST;
-}
-
-int UtcDaliCreateShearEffect(void)
-{
- ToolkitTestApplication application;
-
- ShaderEffect effect = Toolkit::CreateShearEffect();
- DALI_TEST_CHECK( effect );
-
- END_TEST;
-}
-
-int UtcDaliSoftButtonEffectElliptical(void)
-{
- ToolkitTestApplication application;
-
- ShaderEffect effect = Toolkit::CreateSoftButtonEffect(Toolkit::SOFT_BUTTON_ELLIPTICAL);
- DALI_TEST_CHECK( effect );
-
- END_TEST;
-}
-
-int UtcDaliSoftButtonEffectRectangular(void)
-{
- ToolkitTestApplication application;
-
- ShaderEffect effect = Toolkit::CreateSoftButtonEffect(Toolkit::SOFT_BUTTON_RECTANGULAR);
- DALI_TEST_CHECK( effect );
-
- END_TEST;
-}
-
-int UtcDaliSoftButtonEffectFixed(void)
-{
- ToolkitTestApplication application;
-
- ShaderEffect effect = Toolkit::CreateSoftButtonEffect(Toolkit::SOFT_BUTTON_FIXED);
- DALI_TEST_CHECK( effect );
-
- END_TEST;
-}
-
-int UtcDaliCreateSpotEffect(void)
-{
- ToolkitTestApplication application;
-
- ShaderEffect effect = Toolkit::CreateSpotEffect();
- DALI_TEST_CHECK( effect );
-
- END_TEST;
-}
-
-int UtcDaliCreateSquareDissolveEffect(void)
-{
- ToolkitTestApplication application;
-
- ShaderEffect effect = Toolkit::CreateSquareDissolveEffect();
- DALI_TEST_CHECK( effect );
-
- END_TEST;
-}
-
-int UtcDaliSwirlEffect(void)
-{
- ToolkitTestApplication application;
-
- ShaderEffect effect = Toolkit::CreateSwirlEffect(false);
- DALI_TEST_CHECK( effect );
-
- END_TEST;
-}
-
-int UtcDaliSwirlEffectWrap(void)
-{
- ToolkitTestApplication application;
-
- ShaderEffect effect = Toolkit::CreateSwirlEffect(true);
- DALI_TEST_CHECK( effect );
-
- END_TEST;
-}
devel_api_shader_effects_header_files = \
$(devel_api_src_dir)/shader-effects/alpha-discard-effect.h \
- $(devel_api_src_dir)/shader-effects/bendy-effect.h \
- $(devel_api_src_dir)/shader-effects/blind-effect.h \
- $(devel_api_src_dir)/shader-effects/bouncing-effect.h \
- $(devel_api_src_dir)/shader-effects/carousel-effect.h \
- $(devel_api_src_dir)/shader-effects/displacement-effect.h \
$(devel_api_src_dir)/shader-effects/dissolve-effect.h \
- $(devel_api_src_dir)/shader-effects/dissolve-local-effect.h \
$(devel_api_src_dir)/shader-effects/distance-field-effect.h \
$(devel_api_src_dir)/shader-effects/image-region-effect.h \
- $(devel_api_src_dir)/shader-effects/iris-effect.h \
- $(devel_api_src_dir)/shader-effects/mask-effect.h \
- $(devel_api_src_dir)/shader-effects/mirror-effect.h \
$(devel_api_src_dir)/shader-effects/motion-blur-effect.h \
- $(devel_api_src_dir)/shader-effects/motion-stretch-effect.h \
- $(devel_api_src_dir)/shader-effects/overlay-effect.h \
- $(devel_api_src_dir)/shader-effects/quadratic-bezier.h \
- $(devel_api_src_dir)/shader-effects/ripple-effect.h \
- $(devel_api_src_dir)/shader-effects/ripple2d-effect.h \
- $(devel_api_src_dir)/shader-effects/shear-effect.h \
- $(devel_api_src_dir)/shader-effects/soft-button-effect.h \
- $(devel_api_src_dir)/shader-effects/spot-effect.h \
- $(devel_api_src_dir)/shader-effects/square-dissolve-effect.h \
- $(devel_api_src_dir)/shader-effects/swirl-effect.h
+ $(devel_api_src_dir)/shader-effects/motion-stretch-effect.h
devel_api_super_blur_view_header_files = \
$(devel_api_src_dir)/controls/super-blur-view/super-blur-view.h
* Property::Map alphaDiscardEffect = CreateAlphaDiscardEffect();
* actor.SetProperty( ImageView::Property::IMAGE, alphaDiscardEffect );
*
- * @return A handle to a newly allocated ShaderEffect.
+ * @return A property map of the required shaders.
*/
inline Property::Map CreateAlphaDiscardEffect()
{
+++ /dev/null
-#ifndef __DALI_TOOLKIT_SHADER_EFFECT_BENDY_H__
-#define __DALI_TOOLKIT_SHADER_EFFECT_BENDY_H__
-
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// EXTERNAL INCLUDES
-#include <dali/devel-api/shader-effects/shader-effect.h>
-
-namespace Dali
-{
-
-namespace Toolkit
-{
-
-/**
- * Creates a new Bendy effect
- *
- * BendyEffect is a custom shader effect to achieve bendy effects in Image actors
- *
- * Animatable/Constrainable uniforms:
- * "uCenter" - The center point of the bendy effect
- * "uDirection" - The direction of the bendy effect
- * "uRadius" - The radius of the bendy effect
- *
- * @return A handle to a newly allocated ShaderEffect.
- */
-inline ShaderEffect CreateBendyEffect()
-{
- // append the default version
- std::string vertextShader(
- "uniform mediump vec2 uCenter;\n"
- "uniform mediump vec2 uDirection;\n"
- "uniform mediump float uRadius;\n"
- "\n"
- "varying mediump float vShade;\n"
- "\n"
- "void main()\n"
- "{\n"
- " mediump float lighting = 0.25;\n"
- " mediump vec4 position = uModelView * vec4(aPosition, 1.0);\n"
- "\n"
- " mediump vec2 d = position.xy - uCenter;\n"
- " mediump float dist = max( 0.0, dot(d,uDirection) );\n"
- " mediump float radius = max(0.0, uRadius - dist * 0.01);\n"
- "\n"
- " mediump float cs = cos(dist / radius / 2.0);\n"
- " mediump float sn = sin(dist / radius / 2.0);\n"
- "\n"
- "position.xy = position.xy - uDirection * dist;\n"
- "\n"
- "position.xy += uDirection * sn * radius;\n"
- "position.z += (1.0 - cs) * radius;\n"
- "\n"
- "gl_Position = uProjection * position;\n"
- "\n"
- "vShade = 1.0 - abs(sn) * lighting;\n"
- "\n"
- "vTexCoord = mix( sTextureRect.xy, sTextureRect.zw, aTexCoord );\n"
- "}" );
-
- std::string fragmentShader(
- "varying mediump float vShade;\n"
- "\n"
- "void main()\n"
- "{\n"
- " gl_FragColor = texture2D(sTexture, vTexCoord) * uColor * vec4(vShade,vShade,vShade,1.0);\n"
- "}" );
-
- // Create the implementation, temporarily owned on stack,
- Dali::ShaderEffect shaderEffect = Dali::ShaderEffect::New(
- vertextShader,
- fragmentShader,
- ShaderEffect::GeometryHints( ShaderEffect::HINT_GRID | ShaderEffect::HINT_DEPTH_BUFFER ));
-
- shaderEffect.SetUniform( "uCenter", Vector2(0.0f, 0.0f), ShaderEffect::COORDINATE_TYPE_VIEWPORT_POSITION );
- shaderEffect.SetUniform( "uDirection", Vector2(0.0f, 0.0f), ShaderEffect::COORDINATE_TYPE_VIEWPORT_DIRECTION );
- shaderEffect.SetUniform( "uRadius", 0.0f );
-
-
- return shaderEffect;
-}
-
-} // namespace Toolkit
-
-} // namespace Dali
-
-#endif // __DALI_TOOLKIT_SHADER_EFFECT_BENDY_H__
+++ /dev/null
-#ifndef __DALI_TOOLKIT_SHADER_EFFECT_BLIND_H__
-#define __DALI_TOOLKIT_SHADER_EFFECT_BLIND_H__
-
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// EXTERNAL INCLUDES
-#include <dali/devel-api/shader-effects/shader-effect.h>
-
-namespace Dali
-{
-
-namespace Toolkit
-{
-
-/**
- * @brief BlindEffect is a custom shader effect to achieve blind effects in Image actors
- *
- * Animatable/Constrainable uniforms:
- * "uStep" - The step of the blind effect.
- *
- * @return A handle to a newly allocated ShaderEffect
- */
-
-inline ShaderEffect CreateBlindEffect()
-{
- std::string fragmentShader(
- "uniform mediump float uStep; \n"
- "void main() \n"
- "{ \n"
- " mediump vec4 alphaColor; \n"
- " mediump vec4 baseColor; \n"
- " baseColor = texture2D( sTexture, vTexCoord); \n"
- " alphaColor = vec4(0.1,0.1,0.1,1.0); \n"
- " lowp float index = 0.0; \n"
- " index = floor(vTexCoord.y/0.1); \n"
- " if((vTexCoord.y < (index * 0.1 + uStep * 0.005)) && (vTexCoord.y > index * 0.1))\n"
- " { \n"
- " gl_FragColor = alphaColor; \n"
- " } \n"
- " else \n"
- " { \n"
- " gl_FragColor = baseColor; \n"
- " } \n"
- " gl_FragColor*=uColor; \n"
- "} \n"
- );
-
- Dali::ShaderEffect shaderEffect = Dali::ShaderEffect::New(
- "",
- fragmentShader,
- ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING | ShaderEffect::HINT_GRID ));
-
- shaderEffect.SetUniform( "uStep", 0.0f );
-
- return shaderEffect;
-}
-
-} // namespace Toolkit
-
-} // namespace Dali
-
-#endif // __DALI_TOOLKIT_SHADER_EFFECT_BLIND_H__
+++ /dev/null
-#ifndef __DALI_TOOLKIT_SHADER_EFFECT_BOUNCING_H__
-#define __DALI_TOOLKIT_SHADER_EFFECT_BOUNCING_H__
-
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// EXTERNAL INCLUDES
-#include <dali/devel-api/shader-effects/shader-effect.h>
-
-namespace Dali
-{
-
-namespace Toolkit
-{
-
-/**
- * @brief Creates a new bouncing effect
- *
- * BouncingEffect is a custom overscroll effect with two waves appearing at two sides then moving towards center and overlapping.
- *
- * Usage Example:
- *
- * // Create the an imageActor, set shader effect, and add it to the stage
- * ImageActor imageActor = ImageActor::New( BufferImage::New( 1, 1 ) );
- * imageActor.SetSize(720.f,58.f);
- * Toolkit::ShaderEffect bouncingEffect = CreateBouncingEffect( Vector4(0.f,1.f,1.f,0.5f) );
- * imageActor.SetShaderEffect( bouncingEffect );
- * imageActor.SetParentOrigin( ParentOrigin::CENTER );
- * Stage::GetCurrent().Add( imageActor );
- *
- * // Start the animation
- * Animation animation = Animation::New(1.f);
- * animation.AnimateTo( Property( bouncingEffect,"uProgressRate" ),
- * 1.f, AlphaFunction::BOUNCE );
- * animation.Play();
- *
- * Animatable/Constrainable uniforms:
- * "uProgressRate" - The progress rate to the effect
- *
- * @param[in] color The color used on the bouncing stripe
- * @return A handle to a newly allocated ShaderEffect
- */
-
-inline ShaderEffect CreateBouncingEffect(const Vector4& color)
-{
- std::string fragmentShader = DALI_COMPOSE_SHADER(
- precision mediump float;\n
- uniform float uProgressRate;\n
- uniform vec4 uAssignedColor;\n
- void main()\n
- {\n
- float progressRate = abs(uProgressRate)*0.5;\n
- float amplitude = 0.15 - progressRate*0.15 ;\n
- float x1 = 7.5 * (vTexCoord.x - progressRate);\n
- float x2 = 7.5 * (vTexCoord.x - 1.0 + progressRate);\n
- float height1 = max(0.00001, 0.3 - amplitude * ( exp(x1) + exp(-x1) ) );\n
- float height2 = max(0.00001, 0.3 - amplitude * ( exp(x2) + exp(-x2) ) );\n
- float height3 = max(0.00001, 1.0 - 3.0 * amplitude * ( exp(x1*0.5) + exp(-x1*0.5) ) );\n
- float height4 = max(0.00001, 1.0 - 3.0 * amplitude * ( exp(x2*0.5) + exp(-x2*0.5) ) );\n
- vec4 fragColor = vec4(0.0);\n
- float y = vTexCoord.y/(height1+height2);\n
- float y2 = vTexCoord.y/max(height3,height4);\n
- float coef = max(height1,height2)*5.0/( 1.0+exp(y*12.0-6.0) );\n
- float alpha = pow( max(0.0,(1.0-y2))*(1.0-min(abs(x1),abs(x2))/5.0), 2.0);\n
- if( vTexCoord.y < 0.075 )\n
- {\n
- fragColor= mix(uAssignedColor, vec4(1.0), coef);\n
- fragColor += (vec4(1.0)-fragColor) * alpha;\n
- }\n
- else if (y2<1.0)\n
- {\n
- fragColor =vec4(1.0,1.0,1.0, alpha + (1.0-alpha)*coef);\n
- fragColor.rgb -= ( vec3(1.0)-uAssignedColor.rgb )*min(clamp(y*1.2-0.3, 0.0, 0.3),clamp(0.9-y*1.2,0.0,0.3));\n
- }\n
- fragColor.a *= 10.0*min(min(vTexCoord.x, 1.0-vTexCoord.x),0.1)*min(1.0, progressRate/0.2);\n
- gl_FragColor = fragColor;\n
- }
- );
-
- ShaderEffect shaderEffect;
- shaderEffect = ShaderEffect::New( "", fragmentShader,
- ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING ) );
-
- shaderEffect.SetUniform( "uAssignedColor", color );
- shaderEffect.SetUniform( "uProgressRate", 0.0f );
-
- return shaderEffect;
-}
-
-
-} // namespace Toolkit
-
-} // namespace Dali
-
-#endif // __DALI_TOOLKIT_SHADER_EFFECT_BOUNCING_H__
+++ /dev/null
-#ifndef __DALI_TOOLKIT_CAROUSEL_EFFECT_H__
-#define __DALI_TOOLKIT_CAROUSEL_EFFECT_H__
-
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// EXTERNAL INCLUDES
-#include <dali/devel-api/shader-effects/shader-effect.h>
-
-namespace Dali
-{
-
-namespace Toolkit
-{
-
-/**
- * @brief Creates a new Carousel effect
- *
- * CarouselEffect is a custom shader effect to achieve Carousel effects in actors
- *
- * A Carousel has a Radius property which can be +ve (appear as if viewing from the outside of
- * a cylinder/sphere)
- * or -ve (appear as if viewing from the inside of a cylinder/sphere).
- *
- * It can be a horizontal or vertical (cylindrical) or both (spherical). The AnglePerUnit
- * property provides this functionality as a Vector2.
- *
- * Finally, the carousel's center position can be specified as a Screen coordinate (top-left being
- * the origin).
- *
- * Animatable/Constrainable uniforms:
- * "uRadius" - The radius of the Carousel effect. A positive Radius will bend toward the camera,
- * while a negative Radius will bend away from the camera.
- * "uAnglePerUnit" - The angle deviation of Carousel in degrees per geometric unit for each axis
- For example if you wish for the horizontal angle deviation to vary from +/- 10
- degrees, then a Value of 20.0f / stageWidth for the X component should be specified.
- * "uCenter" - The center point of the carousel (in screen coordinates) this is where the peek of the carousel should appear.
- * Defaults value is top-left corner (0.0f, 0.0f).
- *
- * @return A handle to a newly allocated ShaderEffect
- */
-inline ShaderEffect CreateCarouselEffect()
-{
- // append the default version
- std::string vertexShader(
- "uniform float uRadius;\n"
- "uniform mediump vec2 uCenter;\n"
- "uniform mediump vec2 uAnglePerUnit;\n"
- "\n"
- "void main()\n"
- "{\n"
- " mediump vec4 world = uModelView * vec4(aPosition, 1.0);\n"
- " mediump vec2 d = (world.xy - uCenter) * uAnglePerUnit;\n"
- " mediump float a = length(d);\n"
- " mediump float cs = cos(radians(a));\n"
- " world.z -= cs * uRadius;\n"
- " gl_Position = uProjection * world;\n"
- " \n"
- " vTexCoord = mix( sTextureRect.xy, sTextureRect.zw, aTexCoord );\n"
- "}\n");
-
- ShaderEffect shaderEffect = ShaderEffect::New(
- vertexShader,
- "",
- ShaderEffect::GeometryHints( ShaderEffect::HINT_GRID | ShaderEffect::HINT_DEPTH_BUFFER ));
-
-
- shaderEffect.SetUniform( "uRadius", 0.0f );
- shaderEffect.SetUniform( "uCenter", Vector2( 0.0f, 0.0f ) );
- shaderEffect.SetUniform( "uAnglePerUnit", Vector2( 0.0f, 0.0f ) );
-
- return shaderEffect;
-}
-
-} // namespace Toolkit
-
-} // namespace Dali
-
-#endif // __DALI_TOOLKIT_CAROUSEL_EFFECT_H__
+++ /dev/null
-#ifndef __DALI_TOOLKIT_SHADER_EFFECT_DISPLACEMENT_H__
-#define __DALI_TOOLKIT_SHADER_EFFECT_DISPLACEMENT_H__
-
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// EXTERNAL INCLUDES
-#include <dali/devel-api/shader-effects/shader-effect.h>
-
-namespace Dali
-{
-
-namespace Toolkit
-{
-
-/**
- * @brief Creates a new displacement effect
- *
- * Two state displacement effect shader that works on a per object basis. By passing a height-normal map as an effect image, the user can create
- * various styles of buttons on an image actor. The shader requires two height-normal maps in one image, one for each state.
- *
- * The normals and height information for the two states of the button should be strictly specified in this format:
- * ______________
- * | State 0 |
- * | |
- * | | --> Unpressed button normals in rgb and height in a
- * | Map |
- * |______________|
- * | State 1 |
- * | |
- * | | --> Pressed button normals in rgb and height in a
- * | Map |
- * |______________|
- *
- * The RGB values should contain the surface normals and the alpha should contian the height map. For a better effect keep the highest point (alpha value) in
- * the combined map as 1.0 and the lowest posint as 0.0 and 0.5 for any region which doesn't need displacement.
- *
- * For the supplied Normal map the Y-Axis should be down, Meaning (0,0) is in the top left. As the shader inverts the Y axis for lighting calculation.
- *
- * Limitations: Can be applied to ImageActor only, And doesn't provide support for specular color.
- *
- * Usage example:-
- *
- * // Create shader used for doing soft button\n
- * ShaderEffect buttonEffect = CreateDisplacementEffect();
- * buttonEffect.SetEffectImage(Image::New( FANCY_BUTTON_HEIGHT_MAP_IMAGE_PATH ););
- *
- * // set shader to the soft button\n
- * ImageActor fancyButton = ImageActor::New( ... );\n
- * fancyButton.SetShaderEffect( buttonEffect );
- *
- * // animate a button push, using e.g. AlphaFunction::BOUNCE. With these values the button pushes in and out (animates to and fro between the two states)
- *
- *
- * Animation animation = Animation::New( ... );\n
- * animation.AnimateTo( Property(buttonEffect, "uState"), 1.0f, AlphaFunction::BOUNCE, ... );\n
- * animation.Play();\n
- *
- * Animatable/Constrainable uniforms:
- * "uLightDirection" - The light direction is used in the lighting calculation. The angle of incidence directly affects the amount of light reflected.
- * Default (0.0f, 0.7070168f, 0.7071068f), i.e angled at the surface from in front and above.
- * "uAmbientLightColor" - The ambient light is used in the lighting calculation. Care must be taken to not saturate the image by setting this value too high,
- * or the indentation will not look correct. Default 0.15.
- * "uDiffuseLightColor" - The diffuse light is used in the lighting calculation. Default is (1.0f, 1.0f, 1.0f).
- * "uLightMultiplier" - The ambient and diffuse lighting is multiplied by this factor. Since a diffuse light at an angle will cause the whole image to darken,
- * this property can be used to scale the image back up closer to the pixel values of the original diffuse texture. Care must be taken
- * to not saturate the image,or the indentation will not look correct. Default 1.0
- * "uState" - The shader can have a maximum of two end states 0 or 1, Animate between these two values to do the transitions
- * between states. Default 0.0
- * "uHightScale" - The height displacement is multiplied by this factor. Tweak this to get the required level of depth. Default 0.1
- * "uFixedNormal" - The Fixed normal will be used for the light calculation. Tweak this to get the required level of light.
- * Only applicable for the FIXED type shader and not for DISPLACED type
- *
- * @param type The type of the effect, can be either DISPLACED, or FIXED.
- * @return A handle to a newly allocated ShaderEffect
- *
- */
-
-typedef enum
-{
- DISPLACEMENT_EFFECT_DISPLACED = 0, /// Image gets displaced
- DISPLACEMENT_EFFECT_FIXED /// Image does not displace. Useful for matching lighting between areas that do not displace and those that do, e.g for backgrounds which are visible between buttons.
-}DisplacementEffectType;
-
-inline ShaderEffect CreateDisplacementEffect(DisplacementEffectType type)
-{
- std::string fragmentSourceFixed;
- fragmentSourceFixed = "precision mediump float;\n"
- "uniform vec3 uLightDirection;\n"
- "uniform vec3 uAmbientLightColor;\n"
- "uniform vec3 uDiffuseLightColor;\n"
- "uniform float uLightMultiplier;\n"
- "uniform float uState;\n"
- "uniform float uHightScale;\n"
- "uniform vec3 uFixedNormal;\n"
-
- "void main()\n"
- "{\n"
- " vec4 col = texture2D(sTexture, vTexCoord);\n"
- // calc lighting
- " float intensity = dot(uLightDirection, uFixedNormal);"
- " vec3 lighting = (intensity * uDiffuseLightColor) + uAmbientLightColor;\n"
- " lighting *= uLightMultiplier;\n"
- // output col = image * light
- " gl_FragColor = vec4(col.rgb * lighting * uColor.rgb, col.a * uColor.a);\n"
- "}\n";
-
-
-
- std::string fragmentSourceDisplaced(
- "precision mediump float;\n"
- "uniform vec3 uLightDirection;\n"
- "uniform vec3 uAmbientLightColor;\n"
- "uniform vec3 uDiffuseLightColor;\n"
- "uniform float uLightMultiplier;\n"
- "uniform float uState;\n"
- "uniform float uHightScale;\n"
- "void main()\n"
- "{\n"
- " highp vec4 displacementMap1 = texture2D(sEffect, vec2(vTexCoord.s, vTexCoord.t/2.0));\n"
- " highp vec4 displacementMap2 = texture2D(sEffect, vec2(vTexCoord.s, 0.5+vTexCoord.t/2.0));\n"
- " highp vec4 displacementMap = mix(displacementMap1, displacementMap2, uState);\n"
-
- " vec3 normalAdjusted = normalize(displacementMap.rgb*2.0-1.0);\n"
- " float height = uHightScale * (displacementMap.a*2.0 - 1.0);\n"
- " vec2 displacement = vec2(0.0);\n"
- " displacement += (vec2(0.5)-vTexCoord.st)*height;\n"
- " vec2 newCoord = vTexCoord.st + displacement.xy;\n"
-
- " vec4 col = texture2D(sTexture, newCoord);\n"
- // Y-Axis for the normal map is taken as in Y-Down format, So inverting it for GL
- " float intensity = dot(uLightDirection, vec3(1.0,-1.0, 1.0) * normalAdjusted);"
- " vec3 lighting = (intensity * uDiffuseLightColor) + uAmbientLightColor;\n"
- " lighting *= uLightMultiplier;\n"
- " vec3 color = col.rgb * lighting * uColor.rgb;\n"
- " gl_FragColor = vec4(color, col.a * uColor.a);\n"
- "}\n");
-
- //////////////////////////////////////
- // Create shader effect
- //
- //
-
- ShaderEffect shaderEffect;
- switch(type)
- {
- case DISPLACEMENT_EFFECT_DISPLACED:
- shaderEffect = ShaderEffect::New( "", fragmentSourceDisplaced);
- break;
-
- case DISPLACEMENT_EFFECT_FIXED:
- default:
- shaderEffect = ShaderEffect::New( "", fragmentSourceFixed);
- break;
- }
-
-
- //////////////////////////////////////
- // Register uniform properties
- //
- //
- // factors that scale the look, defaults
- shaderEffect.SetUniform("uLightDirection",Vector3(0.0, 0.7070168f, 0.7071068f));
- shaderEffect.SetUniform("uAmbientLightColor",Vector3(0.15f, 0.15f, 0.15f));
- shaderEffect.SetUniform("uDiffuseLightColor",Vector3(1.0f, 1.0f, 1.0f));
- shaderEffect.SetUniform("uLightMultiplier",1.0f);
- shaderEffect.SetUniform("uState",0.0f);
- shaderEffect.SetUniform("uHightScale",0.1f);
-
- if(type == DISPLACEMENT_EFFECT_FIXED)
- {
- shaderEffect.SetUniform("uFixedNormal",Vector3(0.0f, 0.0f, 1.0f) );
- }
-
- return shaderEffect;
-}
-
-}
-
-}
-
-#endif //#ifndef __DALI_TOOLKIT_SHADER_EFFECT_DISPLACEMENT_H__
+++ /dev/null
-#ifndef __DALI_TOOLKIT_SHADER_EFFECT_LOCAL_DISSOLVE_H__
-#define __DALI_TOOLKIT_SHADER_EFFECT_LOCAL_DISSOLVE_H__
-
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// EXTERNAL INCLUDES
-#include <dali/devel-api/shader-effects/shader-effect.h>
-#include <sstream>
-
-namespace Dali
-{
-
-namespace Toolkit
-{
-
-/**
- * @brief Create a new DissolveLocalEffect
- *
- * DissolveLocalEffect is a custom shader effect to achieve Dissolve effects in multiple small areas of Image actors
- *
- * Animatable/Constrainable uniforms:
- * "uTransparency"
- * "uCenter" - The center positions of each dimples
- * "uRadius" - The propagation radius of each dimple
- * "uPercentage" - The distortion applied to the effect texture. A value of zero means no distortion
- *
- * @param[in] numberOfDimples The number of dimples
- * @return A handle to a newly allocated ShaderEffect
- */
-inline ShaderEffect CreateDissolveLocalEffect( unsigned int numberOfDimples )
-{
- std::ostringstream vertexShaderStringStream;
- vertexShaderStringStream << "#define NUMBER_OF_DIMPLE "<< numberOfDimples << "\n";
- std::string vertexShader(
- "precision highp float;\n"
- "uniform vec2 uCenter[ NUMBER_OF_DIMPLE ];\n"
- "uniform float uRadius[ NUMBER_OF_DIMPLE ]; \n"
- "uniform float uPercentage[ NUMBER_OF_DIMPLE ]; \n"
- "varying float vPercentage;\n"
- "void main()\n"
- "{\n"
- " vec4 position = uModelView * vec4( aPosition, 1.0 );\n"
- " float percentage = 0.0;\n"
- " for( int i=0; i<NUMBER_OF_DIMPLE; ++i )\n"
- " {\n"
- " float distance = distance(uCenter[i], position.xy);\n"
- " percentage = max(percentage, uPercentage[i] * cos(clamp( distance/uRadius[i], 0.0, 1.0 )*1.57) );"
- " }\n"
- " vPercentage = clamp( percentage, 0.0, 1.0 );\n"
- " gl_Position = uProjection * position;\n"
- " vTexCoord = mix( sTextureRect.xy, sTextureRect.zw, aTexCoord );\n"
- "}\n");
- vertexShaderStringStream << vertexShader;
-
- std::string fragmentShader(
- "precision highp float;\n"
- "uniform float uTransparency;\n"
- "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 ); \n"
- " float offsetT = rand( vec2(vTexCoord.t*vPercentage, vTexCoord.s * vPercentage) ); \n"
- " vec2 lookupCoord = vTexCoord + vec2(offsetS, offsetT) * vPercentage; \n"
- " gl_FragColor = texture2D( sTexture, lookupCoord ) * uColor; \n"
- " gl_FragColor.a *= 1.0 - uTransparency*vPercentage; \n"
- "}\n");
-
- ShaderEffect shaderEffect = ShaderEffect::New(
- vertexShaderStringStream.str(), fragmentShader,
- ShaderEffect::GeometryHints( ShaderEffect::HINT_GRID | ShaderEffect::HINT_BLENDING ) );
-
- //Register uniform properties
- std::ostringstream oss;
- for( unsigned int i = 0; i < numberOfDimples; i++ )
- {
- oss.str("");
- oss<< "uCenter["<< i << "]";
- shaderEffect.SetUniform(oss.str(), Vector2(0.f,0.f));
-
- oss.str("");
- oss<< "uRadius["<< i << "]";
- shaderEffect.SetUniform(oss.str(), 0.f);
-
- oss.str("");
- oss<< "uPercentage["<< i << "]";
- shaderEffect.SetUniform( oss.str(), 0.f );
- }
-
- shaderEffect.SetProperty( ShaderEffect::Property::GRID_DENSITY, Dali::Property::Value(5.f) );
- shaderEffect.SetUniform( "uTransparency", 0.5f );
-
- return shaderEffect;
-}
-
-} // namespace Toolkit
-
-} // namespace Dali
-
-#endif // __DALI_TOOLKIT_SHADER_EFFECT_LOCAL_DISSOLVE_H__
* "uBottomRight" - The bottom-right corner of the image region. The coordinates are in percentage,
* (0,0) being the top-left and (1,1) the bottom right of the original image
*
- * @return A handle to a newly allocated ShaderEffect
+ * @return A property map of the required shader
*/
inline Property::Map CreateImageRegionEffect()
{
+++ /dev/null
-#ifndef __DALI_TOOLKIT_SHADER_EFFECT_IRIS_H__
-#define __DALI_TOOLKIT_SHADER_EFFECT_IRIS_H__
-
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// EXTERNAL INCLUDES
-#include <dali/devel-api/shader-effects/shader-effect.h>
-
-namespace Dali
-{
-
-namespace Toolkit
-{
-
-/**
- * @brief Creates a new IrisEffect
- *
- * IrisEffect is a custom shader effect to achieve iris effects in Image actors
- *
- * Animatable/Constrainable uniforms:
- *
- * "uRadius" - The radius of the iris effect in texture coordinate distance,
- * i.e. 0.0 (no circle) to 1.0 (complete circle), to > 1.0 (extending outside of texture).
- * @note For Atlas Textures results may be unpredictable.
- *
- * "uBlendFactor" - The blend factor of the iris effect. The lower the value, the larger the blending portion
- * (between Opaque & Transparent). Blending will account for 1 / blendFactor of the radius
- * of the texture.
- *
- * "uCenter" - The center point of the iris (in texture coordinates)
- *
- * @return A handle to a newly allocated ShaderEffect
- */
-inline ShaderEffect CreateIrisEffect()
-{
- // append the default version
- std::string vertexShader(
- "uniform mediump vec2 uCenter;\n"
- "varying mediump vec2 vRelativePosition;\n"
- "\n"
- "void main()\n"
- "{\n"
- " mediump vec4 world = uModelView * vec4(aPosition, 1.0);\n"
- " gl_Position = uProjection * world;\n"
- " \n"
- " vTexCoord = mix( sTextureRect.xy, sTextureRect.zw, aTexCoord );\n"
- " vRelativePosition = vTexCoord - uCenter;\n"
- "}\n");
-
- std::string fragmentShader(
- "uniform mediump float uRadius; \n"
- "uniform mediump float uBlendFactor; \n"
- "varying mediump vec2 vRelativePosition; \n"
- "void main() \n"
- "{ \n"
- " mediump float delta = (length(vRelativePosition) - uRadius); \n"
- " delta = clamp(0.0 - delta * uBlendFactor, 0.0, 1.0); \n"
- " gl_FragColor = texture2D(sTexture, vTexCoord) * uColor; \n"
- " gl_FragColor.a *= delta; \n"
- "} \n"
- );
-
- Dali::ShaderEffect shaderEffect = Dali::ShaderEffect::New(
- vertexShader,
- fragmentShader,
- ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING ));
-
- shaderEffect.SetUniform( "uRadius", 0.0f );
- shaderEffect.SetUniform( "uBlendFactor", 100.0f );
- shaderEffect.SetUniform( "uCenter", Vector2(0.5f, 0.5f) );
-
- return shaderEffect;
-}
-
-}
-}
-
-#endif
+++ /dev/null
-#ifndef __DALI_TOOLKIT_MASK_EFFECT_H__
-#define __DALI_TOOLKIT_MASK_EFFECT_H__
-
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// EXTERNAL INCLUDES
-#include <dali/public-api/images/image.h>
-#include <dali/devel-api/shader-effects/shader-effect.h>
-
-namespace Dali
-{
-
-namespace Toolkit
-{
-
-/**
- * @brief Creates a new MaskEffect
- *
- * MaskEffect is used to control which parts of an image are visible, using the alpha channel of a separate mask image.
- *
- * Typically mask images should be the same size as the main image being viewed, but this isn't essential.
- *
- * Usage example:
- *
- * ImageActor actor = ImageActor::New( Image( EXAMPLE_IMAGE_PATH ) );
- * ShaderEffect maskEffect = CreateMaskEffect( Image::New( MASK_IMAGE_PATH ) );
- * actor.SetShaderEffect( maskEffect );
- *
- * @param[in] maskImage The image to use as a mask
- * @return A handle to a newly allocated ShaderEffect
- */
-inline ShaderEffect CreateMaskEffect(Image maskImage)
-{
- const char* ALPHA_MASK_FRAGMENT_SHADER_SOURCE =
- "void main() \n"
- "{ \n"
- " highp vec4 mask = texture2D(sEffect, vTexCoord); \n"
- " gl_FragColor = texture2D(sTexture, vTexCoord) * uColor * vec4(1,1,1,mask.a); \n"
- "} \n";
-
- ShaderEffect shaderEffect = ShaderEffect::New(
- "", // Use default
- ALPHA_MASK_FRAGMENT_SHADER_SOURCE,
- ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING ) );
-
- shaderEffect.SetEffectImage( maskImage );
-
- return shaderEffect;
-}
-
-} // namespace Toolkit
-
-} // namespace Dali
-
-#endif // __DALI_TOOLKIT_MASK_EFFECT_H__
+++ /dev/null
-#ifndef __DALI_TOOLKIT_MIRROR_EFFECT_H__
-#define __DALI_TOOLKIT_MIRROR_EFFECT_H__
-
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// EXTERNAL INCLUDES
-#include <dali/devel-api/shader-effects/shader-effect.h>
-
-namespace Dali
-{
-
-namespace Toolkit
-{
-
-/**
- * @brief Creates a new MirrorEffect
- *
- * MirrorEffect is a custom shader effect to achieve square effects in Image actors
- *
- * Animatable/Constrainable uniforms:
- * "uDepth" - The depth of the mirror effect. Default value 0.5
- * "uAlpha" - The alpha of the mirror effect. Default value 1.0
- *
- * @return A handle to a newly allocated ShaderEffect
- */
-inline ShaderEffect CreateMirrorEffect()
-{
- std::string vertexShader(
- "void main() \n"
- "{ \n"
- " mediump vec3 pos = aPosition; \n"
- " pos.y = pos.y * 3.0; \n"
- " mediump vec4 world = uModelView * vec4(pos,1.0); \n"
- " gl_Position = uProjection * world; \n"
- " vTexCoord = mix( sTextureRect.xy, sTextureRect.zw, aTexCoord ); \n"
- "} \n" );
-
- std::string fragmentShader(
- "uniform mediump float uDepth; \n"
- "uniform mediump float uAlpha; \n"
- "void main() \n"
- "{ \n"
- " if(vTexCoord.y < 1.0 / 3.0) \n"
- " { \n"
- " gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); \n"
- " } \n"
- " else if(vTexCoord.y < 2.0 / 3.0) \n"
- " { \n"
- " gl_FragColor = texture2D(sTexture, vec2(vTexCoord.x, vTexCoord.y * 3.0 - 1.0)) * uColor; \n"
- " gl_FragColor.a *= uAlpha; \n"
- " } \n"
- " else \n"
- " { \n"
- " highp float darkness = 3.0 - vTexCoord.y * 3.0; \n"
- " darkness = (1.0 - 1.0 / uDepth + darkness * 1.0/ uDepth) * 0.65; \n"
- " highp vec4 color = texture2D(sTexture, vec2(vTexCoord.x, -vTexCoord.y *3.0 + 3.0)) * uColor; \n"
- " color.a *= uAlpha; \n"
- " gl_FragColor = color * vec4(darkness, darkness, darkness, darkness); \n"
- " } \n"
- "} \n" );
-
- Dali::ShaderEffect shaderEffect = Dali::ShaderEffect::New(
- vertexShader,
- fragmentShader,
- ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING ));
-
- shaderEffect.SetUniform("uAlpha", 1.0f);
- shaderEffect.SetUniform("uDepth", 0.5f);
-
- return shaderEffect;
-}
-
-
-} // namespace Toolkit
-
-} // namespace Dali
-
-#endif // __DALI_TOOLKIT_MIRROR_EFFECT_H__
+++ /dev/null
-#ifndef __DALI_TOOLKIT_OVERLAY_EFFECT_H__
-#define __DALI_TOOLKIT_OVERLAY_EFFECT_H__
-
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// EXTERNAL INCLUDES
-#include <dali/public-api/images/image.h>
-#include <dali/devel-api/shader-effects/shader-effect.h>
-
-namespace Dali
-{
-
-namespace Toolkit
-{
-
-/**
- * @brief Creates a new OverlayEffect
- *
- * OverlayEffect is used to apply an overlay image to the actor.
- * Typically overlay images should be the same size as the main image being viewed, but this isn't essential.
- *
- * Usage example:
- *
- * ImageActor actor = ImageActor::New( Image( EXAMPLE_IMAGE_PATH ) );
- * ShaderEffect overlayEffect = CreateOverlayEffect( Image::New( OVERLAY_IMAGE_PATH ) );
- * actor.SetShaderEffect( overlayEffect );
- *
- * @param[in] overlayImage The image to overlay on top of the actor
- * @return A handle to a newly allocated ShaderEffect
- */
-inline ShaderEffect CreateOverlayEffect(Image overlayImage)
-{
- // (Target > 0.5) * (1 - (1-2*(Target-0.5)) * (1-Blend)) + (Target <= 0.5) * ((2*Target) * Blend)
- const char* OVERLAY_FRAGMENT_SHADER_SOURCE =
- "void main()\n"
- "{\n"
- " lowp vec4 target = texture2D(sTexture, vTexCoord);\n"
- " lowp vec4 overlay = texture2D(sEffect, vTexCoord);\n"
- " if ( length( target.rgb ) > 0.5 )\n"
- " {\n"
- " gl_FragColor = vec4( mix( target.rgb, 1.0 - ( 1.0 - 2.0 * ( target.rgb - 0.5 ) ) * ( 1.0 - overlay.rgb ), overlay.a ), min( 1.0, target.a + overlay.a ) );\n"
- " }\n"
- " else\n"
- " {\n"
- " gl_FragColor = vec4( mix( target.rgb, 2.0 * target.rgb * overlay.rgb, overlay.a ), target.a + overlay.a );\n"
- " }\n"
- "}\n";
-
- ShaderEffect shaderEffect = ShaderEffect::New(
- "", // Use default
- OVERLAY_FRAGMENT_SHADER_SOURCE,
- ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING ) );
-
- shaderEffect.SetEffectImage( overlayImage );
-
- return shaderEffect;
-}
-
-} // namespace Toolkit
-
-} // namespace Dali
-
-#endif // __DALI_TOOLKIT_OVERLAY_EFFECT_H__
+++ /dev/null
-#ifndef __DALI_TOOLKIT_QUADRATIC_BEZIER_H__
-#define __DALI_TOOLKIT_QUADRATIC_BEZIER_H__
-
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// EXTERNAL INCLUDES
-#include <dali/devel-api/shader-effects/shader-effect.h>
-
-namespace Dali
-{
-
-namespace Toolkit
-{
-/**
- * @brief Creates a new QuadraticBezier shader effect
- *
- * QuadraticBezier is a custom shader to render quadratic bezier curves and bounded regions.
- *
- * Implementation based on the paper "Resolution Independent Curve Rendering using Programmable Graphics Hardware"
- * by Charles Loop and Jim Blinn.
- *
- * The coordinates of the control points is passed to the shader via uniforms.
- * aNormal attribute is used to pass the coefficients of each control point (xy coordinates) as well as the vertex ID (z coordinate).
- * A quadratic curve should have as normal for the first control point (0.0,0.0), (0.5,0.0) for the second and (1.0,1.0) for the third.
- * Triangles that do not contain curves should have coordinates (0.0,1.0) for each control point in order to be filled properly.
- *
- * Animatable/Constrainable uniforms:
- * "uPoint" - Position coordinates for the points in the curve
- * "uColor" - The color of the curve or bounded region
- * "uLineWidth" - The width of the path. Only for not filled curves
- *
- * @param[in] pointCount The maximum number of vertices
- * @param[in] filled Specify whether the the bounded region should be filled or not
- * @return A handle to a newly allocated ShaderEffect
- */
-inline ShaderEffect CreateQuadraticBezier(unsigned int pointCount, bool filled)
-{
- std::string vertexShader = DALI_COMPOSE_SHADER
- (
- uniform mediump vec3 uPoint[MAX_POINT_COUNT];\n
- varying highp vec2 vCoefficient;
- void main()\n
- {\n
- int vertexId = int(aNormal.z);\n
- gl_Position = uMvpMatrix * vec4(uPoint[vertexId], 1.0);\n
- vCoefficient = aNormal.xy;\n
- }\n
- );
-
- std::string fragmentShader;
-
- if( filled )
- {
- fragmentShader = DALI_COMPOSE_SHADER
- (
- varying highp vec2 vCoefficient;\n
-
- void main()\n
- {\n
- highp float C = (vCoefficient.x*vCoefficient.x-vCoefficient.y);\n
- highp float Cdx = dFdx(C);\n
- highp float Cdy = dFdy(C);\n
-
- highp float distance = float(C / sqrt(Cdx*Cdx + Cdy*Cdy));\n
-
- gl_FragColor = uColor;\n
- highp float alpha = 0.5 - distance;\n
- if( alpha < 0.0 )\n
- discard;\n
-
- gl_FragColor.w = alpha;\n
- }\n
- );
- }
- else
- {
- fragmentShader = DALI_COMPOSE_SHADER
- (
- varying highp vec2 vCoefficient;\n
- uniform lowp float uLineWidth;\n
-
- void main()\n
- {\n
- highp float C = (vCoefficient.x*vCoefficient.x-vCoefficient.y);\n
- highp float Cdx = dFdx(C);\n
- highp float Cdy = dFdy(C);\n
- highp float distance = abs(float(C / sqrt(Cdx*Cdx + Cdy*Cdy)));\n
- gl_FragColor = uColor*(uLineWidth-distance);\n
- }\n
- );
- }
-
- std::ostringstream vertexShaderPrefix;
- vertexShaderPrefix << "#define MAX_POINT_COUNT "<< pointCount << "\n";
-
- Dali::ShaderEffect shaderEffect = Dali::ShaderEffect::NewWithPrefix(
- vertexShaderPrefix.str(),vertexShader,
- "#extension GL_OES_standard_derivatives:enable\n", fragmentShader );
-
- //Set default uniform values
- shaderEffect.SetUniform( "uColor", Vector4(1.0f,1.0f,1.0f,1.0f) );
- if( !filled )
- {
- //Set default line widht to 1 pixel
- shaderEffect.SetUniform( "uLineWidth", 1.0f );
- }
-
- return shaderEffect;
-}
-
-} // namespace Toolkit
-
-} // namespace Dali
-
-#endif // __DALI_TOOLKIT_IMAGE_REGION_EFFECT_H__
+++ /dev/null
-#ifndef __DALI_TOOLKIT_SHADER_EFFECT_RIPPLE_H__
-#define __DALI_TOOLKIT_SHADER_EFFECT_RIPPLE_H__
-
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// EXTERNAL INCLUDES
-#include <dali/devel-api/shader-effects/shader-effect.h>
-
-namespace Dali
-{
-
-namespace Toolkit
-{
-
-/**
- * @brief Creates a new RippleEffect
- *
- * RippleEffect is a custom shader effect to achieve ripple effects on Image actors.
- *
- * Animatable/Constrainable uniforms:
- * "uAmplitude" - The amplitude of the effect
- * "uCenter" - The center point of the effect as screen coordinates
- * "uTime" - The time duration for the ripple
- *
- * @return A handle to a newly allocated ShaderEffect
- */
-inline ShaderEffect CreateRippleEffect()
-{
- std::string vertexShader(
- "precision mediump float;\n"
- "uniform mediump vec2 uCenter;\n"
- "uniform mediump float uTime;\n"
- "uniform mediump float uAmplitude;\n"
- "varying mediump float vLight;\n"
- "varying mediump float vShade;\n"
- "void main()\n"
- "{\n"
- "float lighting = uAmplitude * 0.02;\n"
- "float waveLength = uAmplitude * 0.0016;\n"
- "vec4 world = uModelView * vec4(aPosition, 1.0);\n"
- "vec2 d = vec2(world.x - uCenter.x, world.y - uCenter.y);\n"
- "float dist = length(d);\n"
- "float amplitude = cos(uTime - dist*waveLength);\n"
- "float slope = sin(uTime - dist*waveLength);\n"
- "world.z += amplitude * uAmplitude;\n"
- "gl_Position = uProjection * world;\n"
- "vec2 lightDirection = vec2(-0.707,0.707);\n"
- "float dot = 0.0;\n"
- "if(dist > 0.0)\n"
- "{\n"
- " dot = dot(normalize(d),lightDirection) * lighting;\n"
- "}\n"
- "vShade = 1.0 - (dot * slope);\n"
- "vLight = max(0.0, dot * -slope);\n"
- "vTexCoord = mix( sTextureRect.xy, sTextureRect.zw, aTexCoord );\n"
- "}" );
-
- // append the default version
- std::string imageFragmentShader(
- "precision mediump float;\n"
- "varying mediump float vLight;\n"
- "varying mediump float vShade;\n"
- "void main()\n"
- "{\n"
- " gl_FragColor = texture2D(sTexture, vTexCoord) * uColor * vec4(vShade,vShade,vShade,1.0) + vec4(vLight, vLight, vLight,0.0);\n"
- "}" );
-
-
- Dali::ShaderEffect shaderEffect = Dali::ShaderEffect::New(
- vertexShader, imageFragmentShader,
- ShaderEffect::GeometryHints(ShaderEffect::HINT_GRID) );
-
-
- shaderEffect.SetUniform( "uAmplitude", 0.0f );
- shaderEffect.SetUniform( "uCenter", Vector2(0.0f, 0.0f));
- shaderEffect.SetUniform( "uTime", 0.0f );
-
- return shaderEffect;
-}
-
-} // namespace Toolkit
-
-} // namespace Dali
-
-#endif // __DALI_TOOLKIT_SHADER_EFFECT_RIPPLE_H__
+++ /dev/null
-#ifndef __DALI_TOOLKIT_SHADER_EFFECT_RIPPLE2D_H__
-#define __DALI_TOOLKIT_SHADER_EFFECT_RIPPLE2D_H__
-
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// EXTERNAL INCLUDES
-#include <dali/devel-api/shader-effects/shader-effect.h>
-
-namespace Dali
-{
-
-namespace Toolkit
-{
-
-/**
- * @brief Creates a new Ripple2DEffect
- *
- * Ripple2DEffect is a custom shader effect to achieve 2d ripple effects on Image actors.
- *
- * Animatable/Constrainable uniforms:
- * "uTime" - The time duration for the 2d ripple
- * "uAmplitude" - The amplitude of the 2d ripple
- *
- * @return A handle to a newly allocated ShaderEffect
- */
-inline ShaderEffect CreateRipple2DEffect()
-{
- // append the default version
- std::string fragmentShader(
- "precision mediump float;\n"
- "uniform float uAmplitude;\n"
- "uniform float uTime;\n"
- "void main()\n"
- "{\n"
- " highp vec2 textureSize = sTextureRect.zw - sTextureRect.xy;\n"
- " highp vec2 pos = -1.0 + 2.0 * vTexCoord.st/textureSize;\n"
- " highp float len = length(pos);\n"
- " highp vec2 texCoord = vTexCoord.st/textureSize + pos/len * sin( len * 12.0 - uTime * 4.0 ) * uAmplitude;\n"
- " gl_FragColor = texture2D(sTexture, texCoord) * uColor;\n"
- "}" );
-
- Dali::ShaderEffect shaderEffect = Dali::ShaderEffect::New(
- "", fragmentShader,
- ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING | ShaderEffect::HINT_GRID ));
-
-
-
- shaderEffect.SetUniform( "uTextureSize", Vector2(0.0f, 0.0f) ); //@note: Is this needed?
- shaderEffect.SetUniform( "uAmplitude", 0.0f );
- shaderEffect.SetUniform( "uTime", 0.0f );
-
- return shaderEffect;
-}
-
-} // namespace Toolkit
-
-} // namespace Dali
-
-#endif // __DALI_TOOLKIT_SHADER_EFFECT_RIPPLE2D_H__
+++ /dev/null
-#ifndef __DALI_TOOLKIT_SHEAR_EFFECT_H__
-#define __DALI_TOOLKIT_SHEAR_EFFECT_H__
-
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// EXTERNAL INCLUDES
-#include <dali/devel-api/shader-effects/shader-effect.h>
-
-namespace Dali
-{
-
-namespace Toolkit
-{
-
-/**
- * @brief Creates a new ShearEffect
- *
- * ShearEffect is a custom shader effect to achieve shear effects in Image actors
- *
- * Animatable/Constrainable uniforms:
- * "uCenter" - The center point of the shear effect in screen coordinates
- * "uAngleXAxis" - The angle of the shear effect in the X axis
- * "uAngleYAxis" - The angle of the shear effect in the Y axis
- *
- * @return A handle to a newly allocated ShaderEffect
- */
-inline ShaderEffect CreateShearEffect()
-{
- // append the default version
- std::string vertexShader(
- "uniform mediump vec2 uCenter;\n"
- "uniform mediump float uAngleXAxis;\n"
- "uniform mediump float uAngleYAxis;\n"
- "\n"
- "void main()\n"
- "{\n"
- "mediump vec4 world = uModelView * vec4(aPosition, 1.0);\n"
- "\n"
- "world.x = world.x + tan(radians(uAngleXAxis)) * (world.y - uCenter.y * world.w);\n"
- "world.y = world.y + tan(radians(uAngleYAxis)) * (world.x - uCenter.x * world.w);\n"
- "\n"
- "gl_Position = uProjection * world;\n"
- "\n"
- "vTexCoord = mix( sTextureRect.xy, sTextureRect.zw, aTexCoord );\n"
- "}" );
-
- // Create the implementation, temporarily owned on stack,
- ShaderEffect shaderEffect = Dali::ShaderEffect::New(
- vertexShader,
- "",
- ShaderEffect::GeometryHints( ShaderEffect::HINT_GRID ));
-
-
- shaderEffect.SetUniform( "uCenter", Vector2(0.0f, 0.0f), ShaderEffect::COORDINATE_TYPE_VIEWPORT_POSITION );
- shaderEffect.SetUniform( "uAngleXAxis", 0.0f);
- shaderEffect.SetUniform( "uAngleYAxis", 0.0f);
-
- return shaderEffect;
-}
-
-} // namespace Toolkit
-
-} // namespace Dali
-
-#endif // __DALI_TOOLKIT_SHEAR_EFFECT_H__
+++ /dev/null
-#ifndef __DALI_TOOLKIT_SHADER_EFFECT_SOFT_BUTTON_H__
-#define __DALI_TOOLKIT_SHADER_EFFECT_SOFT_BUTTON_H__
-
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// EXTERNAL INCLUDES
-#include <dali/devel-api/shader-effects/shader-effect.h>
-
-namespace Dali
-{
-
-namespace Toolkit
-{
-
-/**
- * @brief Creates a new soft button shader effect
- *
- * Soft button shader effect works on a per object basis. Using animatable parameters user can create
- * effect of button pushing in / out. Can be applied to ImageActor only.
- *
- * Usage example:-
- *
- * // Create shader used for doing soft button\n
- * ShaderEffect softButtonEffect = CreateSoftButtonEffect();
- *
- * // set image actor shader to the soft button one\n
- * ImageActor imageActor = ImageActor::New( ... );\n
- * imageActor.SetShaderEffect( softButtonEffect );
- *
- * // animate a button push, using e.g. AlphaFunction::BOUNCE. With these values the button pushes in and pops out slightly at the end\n
- * Animation animation = Animation::New( ... );\n
- * animation.AnimateTo( Property(softButtonEffect, "uLightingIndentationAmount), 0.25f, AlphaFunction::BOUNCE, ... );\n
- * animation.AnimateTo( Property(softButtonEffect, "uLightingIndentationAmount"), -0.05f, AlphaFunction::BOUNCE, ... );\n
- * animation.AnimateTo( Property(softButtonEffect, "uTextureDistortAmount"), 0.25f, AlphaFunction::BOUNCE, ... );\n
- * animation.AnimateTo( Property(softButtonEffect, "uTextureDistortAmount"), -0.05f, AlphaFunction::BOUNCE, ... );\n
- * animation.Play();\n
- *
- * Animatable/Constrainable uniforms:
- *
- * "uLightingIndentationAmount" - This property changes the lighting, to make it look like the button is pushed in. User should animate
- * this in conjunction with texture distortion. Allowable values range from [-1..1], higher values give
- * more change in lighting. Default 0.0 (no lighting change).
- * "uTextureDistortAmount" - This property changes the distortion, to make it look like the button is pushed in. User should animate
- * this in conjunction with lighting indentation. Allowable values range from [-1..1) - note 1.0 is NOT
- * allowed - higher values give more distortion. Default 0.0 (no distortion).
- * "uAmbientLight" - The ambient light is used in the lighting calculation. Care must be taken to not saturate the image by
- * setting this value too high, or the indentation will not look correct. Default 0.15
- * "uDiffuseLight" - The diffuse light is used in the lighting calculation. Default is (0.0, 0.7070168, 0.7070168),
- * i.e. a light angled at the surface from in front and above. Note that you need to Normalize()
- * the Vector3 that you set with this property
- * "uLightMultiplier" - The ambient and diffuse lighting is multiplied by this factor. Since a diffuse light at an angle will
- * cause the whole image to darken, even outside the soft button indentation, this property can be used
- * to scale the image back up closer to the pixel values of the original diffuse texture. Care must be
- * taken to not saturate the image,or the indentation will not look correct. Default 1.2.
- * "uInsideCircleSizeScale" - The SoftButtonEffect consists of two shapes, one inside the other. The outside shape fits exactly to
- * the actor, touching its edges but completely contained. The inside shape size is given by a multiplier
- * of the outside shape size. For example a value of 0.5 means that the inside shape is half the size of
- * the outside one. Allowable values are in the range (0.0 - 1.0), note that 0.0 and 1.0 themselves are
- * not allowed. Default 0.75.
- * "uOutsideCircleDepth" - The SoftButtonEffect consists of two shapes, one inside the other. The depth of the indentation at the
- * transition between the inside and outside shapes is controlled by this property. The values lies in the
- * range [0.0 - 1.0]. A value of 0.0 means the outside shape has no depth (and is thus invisible), value of
- * 1.0 means the outside shape has maximum depth (and the inside shape is thus invisible). Default 0.05
- * "uEffectRegion" - The soft button effect is applied within the supplied rect region of the texture. Default values for this
- * is (0.0, 0.0, 1.0, 1.0) which is the entire image with 0,0 being the top left and 1.0, 1.0 being the bottom
- * right. If the image texture is split between multiple ImageActors then the developer should specify the pixel
- * area of the texture the effect should be applied with. Example, If the Image is split among two ImageActors
- * side by side, with the left one using left half of the texture and right one using the right half of the
- * texture then the pixel area value for the left ImageActor will be (0.0, 0.0, 0.5, 1.0) and the pixel area for
- * the right will be (0.5,0.0,1.0,1.0).
- * "uRectangleSizeScale" - This property can be used to set the mix between proportion of rectangle and proportion of ellipse - the
- * result is a rectangle with rounded corners. If the value is 0.0, the shape is an ellipse. If the value is
- * close to 1.0, the shape is close to a rectangle. The value lies in the range [0.0 - 1.0). Note that a value
- * of 1.0 is NOT allowed.Default 0.5.
- *
- * @param type The type of the soft button, can be either ELLIPTICAL, RECTANGULAR, or FIXED.
- * @return A handle to a newly allocated ShaderEffect
- */
-typedef enum
-{
- SOFT_BUTTON_ELLIPTICAL = 0, /// Button is elliptical
- SOFT_BUTTON_RECTANGULAR, /// Button is rectangular
- SOFT_BUTTON_FIXED /// Button does not indent (move). Useful for matching lighting between areas that do not indent (which can thus use a cheaper shader) and those that do indent.
-}SoftButtonEffectType;
-
-static void InverseConstraint( float& current, const PropertyInputContainer& inputs )
-{
- current = 1.0f / inputs[0]->GetFloat();
-}
-
-inline ShaderEffect CreateSoftButtonEffect(SoftButtonEffectType type)
-{
- std::string vertexSource;
- vertexSource = "precision mediump float;\n"
- "uniform vec3 uDiffuseLight;\n"
- "uniform float uAmbientLight;\n"
- "uniform float uLightMultiplier;\n"
- "uniform vec4 uEffectRegion;\n"
- "varying vec2 vCentredCoord;\n"
-
- "const vec3 norm = vec3(0.0, 0.0, 1.0);\n"
-
- "void main()\n"
- "{\n"
- " vTexCoord = mix( sTextureRect.xy, sTextureRect.zw, aTexCoord );\n"
- // Get the rect coords of the effect region in -1..1 range, i.e. circle centred around the center of the rect
- // Done in the vertex shader itself to make use of gl interpolation for varying.
- " vCentredCoord = vec2( ( (vTexCoord.x - uEffectRegion.x)/(uEffectRegion.z - uEffectRegion.x) * 2.0 - 1.0 ), ( (vTexCoord.y - uEffectRegion.y)/(uEffectRegion.w - uEffectRegion.y) * 2.0 - 1.0 ) );\n"
- " gl_Position = uMvpMatrix * vec4(aPosition, 1.0);\n"
- "}\n";
-
- std::string fragmentSourceFixed;
- fragmentSourceFixed = "precision mediump float;\n"
-
- "uniform vec3 uDiffuseLight;\n"
- "uniform float uAmbientLight;\n"
- "uniform float uLightMultiplier;\n"
- "varying vec2 vCentredCoord;\n"
-
- "const vec3 norm = vec3(0.0, 0.0, 1.0);\n"
-
- "void main()\n"
- "{\n"
- " vec4 col = texture2D(sTexture, vTexCoord);\n"
- // calc lighting
- " float lighting = (dot(uDiffuseLight, norm) + uAmbientLight) * uLightMultiplier;\n"
- // output col = image * light
- // use the lighting value for colors only
- " gl_FragColor = vec4(col.rgb * uColor.rgb * lighting, col.a * uColor.a);\n"
- "}\n";
-
- std::string fragmentSourceElliptical;
- fragmentSourceElliptical = "precision mediump float;\n"
-
- "uniform float uLightingIndentationAmount;\n"
- "uniform float uTextureDistortAmount;\n"
- "uniform vec3 uDiffuseLight;\n"
- "uniform float uAmbientLight;\n"
- "uniform float uLightMultiplier;\n"
- "uniform float uInsideCircleSizeScale;\n"
- "uniform float uRecipInsideCircleSizeScale;\n"
- "uniform float uOutsideCircleDepth;\n"
- "uniform vec4 uEffectRegion;\n"
- "varying vec2 vCentredCoord;\n"
-
- "const float PI = 3.1415927;\n"
-
- "void main()\n"
- "{\n"
- // Apply distortion only if the pixel is within the rect specified
- "if( (vTexCoord.x > uEffectRegion.x) && (vTexCoord.x < uEffectRegion.z) && (vTexCoord.y > uEffectRegion.y) && (vTexCoord.y < uEffectRegion.w) )\n"
- "{\n"
- " vec2 coord = vCentredCoord;\n"
-
- // find a coordinate representing distance from circle centre, such that we split into inside / outside circles that can have different gradients / normals
- " float realDistFromCentre = length(coord);\n"
- " realDistFromCentre = min(1.0, realDistFromCentre);\n" // clamp corners of square to vertical normal
- " float distFromCentre;\n"
- " if(realDistFromCentre <= uInsideCircleSizeScale)\n"
- " {\n"
- " distFromCentre = realDistFromCentre * uRecipInsideCircleSizeScale * (1.0 - uOutsideCircleDepth);\n" // inside circle indent, up to outline depth
- " }\n"
- " else \n"
- " {\n"
- " distFromCentre = mix(1.0 - uOutsideCircleDepth, 1.0, (realDistFromCentre - ( uInsideCircleSizeScale)) / (1.0 - uInsideCircleSizeScale));\n" // outside circle
- " }\n"
-
- // get coords in -PI..PI range, i.e. scale the circle for use by trig functions
- " coord *= PI;\n"
-
- // get a z value for the distorted surface in 0..1 range, using cos for a smooth curve (note, we ignore inside / outside circles since the difference isn't noticeable visually)
- " vec2 cosThetaCoord = (cos(coord) * 0.5) + 0.5;\n"
- " float z = cosThetaCoord.x * cosThetaCoord.y;\n"
-
- // get the normal for the distorted surface, using the fact that the derivative of cos is -sin, finding tangent vector from slope and then normal by cross product...
- " float sinThetaCoord = sin(distFromCentre*PI) * uLightingIndentationAmount;\n" // slope, so tangent vec is (1.0, -sin)
- // ...2D normal vector along distFromCentre vec is (sin, 1.0), convert to components in 3D.
- " vec3 norm = normalize(vec3(coord.x * sinThetaCoord, coord.y * sinThetaCoord, 1.0));\n"
-
- // form surface z and project texture onto it.
- " float indentAmount = 1.0 / (1.0 - (z * uTextureDistortAmount));\n"
- " vec2 distortedCoord = vCentredCoord * indentAmount;\n"
-
- // Convert the rect coordinates in -1 to 1 range back to the original coordinates
- " vec2 texCoord = vec2( ( (distortedCoord.x + 1.0)*(0.5) * (uEffectRegion.z - uEffectRegion.x) + uEffectRegion.x ), ( (distortedCoord.y + 1.0)*(0.5) * (uEffectRegion.w - uEffectRegion.y) + uEffectRegion.y ) ); \n"
- " vec4 col = texture2D(sTexture, texCoord);\n"
-
- // calc lighting
- " float lighting = (dot(uDiffuseLight, norm) + uAmbientLight) * uLightMultiplier;\n"
- " gl_FragColor = vec4(col.rgb * uColor.rgb * lighting, col.a * uColor.a);\n"
- "}\n"
- "else\n"
- "{\n"
- " vec4 col = texture2D(sTexture, vTexCoord);\n"
- " float lighting = (dot(uDiffuseLight, vec3(0.0, 0.0, 1.0)) + uAmbientLight) * uLightMultiplier;\n"
- " gl_FragColor = vec4(col.rgb * uColor.rgb * lighting, col.a * uColor.a);\n"
- "}\n"
- "}\n";
-
- std::string fragmentSourceRectangular;
- fragmentSourceRectangular = "precision mediump float;\n"
-
- "uniform float uLightingIndentationAmount;\n"
- "uniform float uTextureDistortAmount;\n"
- "uniform vec3 uDiffuseLight;\n"
- "uniform float uAmbientLight;\n"
- "uniform float uLightMultiplier;\n"
- "uniform float uInsideCircleSizeScale;\n"
- "uniform float uRecipInsideCircleSizeScale;\n"
- "uniform float uOutsideCircleDepth;\n"
- "uniform float uRectangleSizeScale;\n"
- "uniform vec4 uEffectRegion;\n"
- "varying vec2 vCentredCoord;\n"
-
- "const float PI = 3.1415927;\n"
-
- "void main()\n"
- "{\n"
- // Apply distortion only if the pixel is within the rect specified
- "if( (vTexCoord.x > uEffectRegion.x) && (vTexCoord.x < uEffectRegion.z) && (vTexCoord.y > uEffectRegion.y) && (vTexCoord.y < uEffectRegion.w) )\n"
- "{ \n"
- // get the rect coords to -1..1 range, i.e. circle centred around the center of the rect
- " vec2 centredCoord = vCentredCoord;\n"
- // clamp coords such that the circle is split into 4 pieces that lie in the corners of the actor. uRectangleScale is the distance along each axis from the centre
- // of the actor, e.g. 0.5 is half way along an axis from centre to actor edge.
- " vec2 clampedCoord;\n"
- " if(centredCoord.x > 0.0)\n"
- " {\n"
- " if(centredCoord.x < uRectangleSizeScale)\n"
- " {\n"
- // we are in a rectangular region along this axis, clamp coord to be same as centre pixel
- " clampedCoord.x = 0.0;\n"
- " }\n"
- " else\n"
- " {\n"
- // we are outside rectangular region along this axis, so we want curvature.
- " clampedCoord.x = smoothstep(0.0, 1.0, (centredCoord.x - uRectangleSizeScale) / (1.0 - uRectangleSizeScale));\n"
- " }\n"
- " }\n"
- " else\n"
- " {\n"
- " if(centredCoord.x > -uRectangleSizeScale)\n"
- " {\n"
- // we are in a rectangular region along this axis, clamp coord to be same as centre pixel
- " clampedCoord.x = 0.0;\n"
- " }\n"
- " else\n"
- " {\n"
- // we are outside rectangular region along this axis, so we want curvature.
- " clampedCoord.x = -smoothstep(0.0, 1.0, (centredCoord.x + uRectangleSizeScale) / (uRectangleSizeScale - 1.0));\n"
- " }\n"
- " }\n"
- " if(centredCoord.y > 0.0)\n"
- " {\n"
- " if(centredCoord.y < uRectangleSizeScale)\n"
- " {\n"
- // we are in a rectangular region along this axis, clamp coord to be same as centre pixel
- " clampedCoord.y = 0.0;\n"
- " }\n"
- " else\n"
- " {\n"
- // we are outside rectangular region along this axis, so we want curvature.
- " clampedCoord.y = smoothstep(0.0, 1.0, (centredCoord.y - uRectangleSizeScale) / (1.0 - uRectangleSizeScale));\n"
- " }\n"
- " }\n"
- " else\n"
- " {\n"
- " if(centredCoord.y > -uRectangleSizeScale)\n"
- " {\n"
- // we are in a rectangular region along this axis, clamp coord to be same as centre pixel
- " clampedCoord.y = 0.0;\n"
- " }\n"
- " else\n"
- " {\n"
- // we are outside rectangular region along this axis, so we want curvature.
- " clampedCoord.y = -smoothstep(0.0, 1.0, (centredCoord.y + uRectangleSizeScale) / (uRectangleSizeScale - 1.0));\n"
- " }\n"
- " }\n"
- // get coords in -PI..PI range, i.e. scale above circle for use by trig functions
- " vec2 thetaCoord = clampedCoord * PI;\n"
- // get a z value for the distorted surface in 0..1 range, using cos for a smooth curve (note, we ignore inside / outside circles since the difference isn't noticeable visually)
- " vec2 cosThetaCoord = (cos(thetaCoord) * 0.5) + 0.5;\n"
- " float z = cosThetaCoord.x * cosThetaCoord.y;\n"
- // find a coordinate representing distance from circle centre, such that we split into inside / outside circles that can have different gradients / normals
- " float realDistFromCentre = length(thetaCoord);\n"
- " realDistFromCentre = min(PI, realDistFromCentre);\n" // clamp corners of square to vertical normal
- " float distFromCentre;\n"
- " if(realDistFromCentre <= PI * uInsideCircleSizeScale)\n"
- " {\n"
- " distFromCentre = realDistFromCentre * uRecipInsideCircleSizeScale * (PI - (uOutsideCircleDepth * PI)) / PI;\n" // inside circle indent, up to outline depth
- " }\n"
- " else\n"
- " {\n"
- " distFromCentre = mix(PI - (uOutsideCircleDepth * PI), PI, (realDistFromCentre - ( PI * uInsideCircleSizeScale)) / (PI - (PI * uInsideCircleSizeScale)));\n" // outside circle
- " }\n"
- // get the normal for the distorted surface, using the fact that the derivative of cos is -sin, finding tangent vector from slope and then normal by cross product...
- " float sinThetaCoord = sin(distFromCentre) * uLightingIndentationAmount;\n" // slope, so tangent vec is (1.0, -sin)
- // ...2D normal vector along distFromCentre vec is (sin, 1.0), convert to components in 3D.
- " vec3 norm = normalize(vec3(thetaCoord.x * sinThetaCoord, thetaCoord.y * sinThetaCoord, 1.0));\n"
- // form surface z and project texture onto it.
- " float indentAmount = 1.0 / (1.0 - (z * uTextureDistortAmount));\n"
- " vec2 distortedCoord = centredCoord * indentAmount;\n"
- // Convert the rect coordinates in -1 to 1 range back to the original coordinates
- " vec2 texCoord = vec2( ( (distortedCoord.x + 1.0)/(2.0) * (uEffectRegion.z - uEffectRegion.x) + uEffectRegion.x ), ( (distortedCoord.y + 1.0)/(2.0) * (uEffectRegion.w - uEffectRegion.y) + uEffectRegion.y ) );\n"
- " vec4 col = texture2D(sTexture, texCoord);\n"
- // calc lighting
- " float lighting = (dot(uDiffuseLight, norm) + uAmbientLight) * uLightMultiplier;\n"
- // output col = image * light
- // use the lighting value for colors only
- " gl_FragColor = vec4(col.rgb * uColor.rgb * lighting, col.a * uColor.a);\n"
-
- "}\n"
- "else\n"
- "{\n"
- " vec4 col = texture2D(sTexture, vTexCoord);\n"
- " float lighting = (dot(uDiffuseLight, vec3(0.0, 0.0, 1.0)) + uAmbientLight) * uLightMultiplier;\n"
- " gl_FragColor = vec4(col.rgb * uColor.rgb * lighting, col.a * uColor.a);\n"
- "} \n"
- "}\n";
-
-
- //////////////////////////////////////
- // Create shader effectCreateSoftButtonEffect
- //
- //
-
- ShaderEffect shader;
- switch(type)
- {
- case SOFT_BUTTON_RECTANGULAR:
- shader = ShaderEffect::New( vertexSource, fragmentSourceRectangular, ShaderEffect::GeometryHints( ShaderEffect::HINT_NONE ));
- break;
-
- case SOFT_BUTTON_ELLIPTICAL:
- shader = ShaderEffect::New( vertexSource, fragmentSourceElliptical, ShaderEffect::GeometryHints( ShaderEffect::HINT_NONE ));
- break;
-
- case SOFT_BUTTON_FIXED:
- default:
- shader = ShaderEffect::New( vertexSource, fragmentSourceFixed, ShaderEffect::GeometryHints( ShaderEffect::HINT_NONE ));
- break;
- }
-
- //////////////////////////////////////
- // Register uniform properties
- //
- //
- static const float SOFT_BUTTON_LIGHTING_INDENTATION_AMOUNT_DEFAULT = 0.0f;
- static const float SOFT_BUTTON_TEXTURE_DISTORTION_AMOUNT_DEFAULT = 0.0f;
- static const float SOFT_BUTTON_AMBIENT_LIGHT_AMOUNT_DEFAULT = 0.15f;
- static const Vector3 SOFT_BUTTON_DIFFUSE_LIGHT_DEFAULT = Vector3(0.0f, 0.7070168f, 0.7071068f);
- static const float SOFT_BUTTON_LIGHTING_MULTIPLIER_DEFAULT = 1.2f;
- static const float SOFT_BUTTON_INSIDE_SHAPE_SIZE_SCALE_DEFAULT = 0.75f;
- static const float SOFT_BUTTON_OUTSIDE_SHAPE_DEPTH_DEFAULT = Math::PI * 0.05f;
- static const Vector4 SOFT_BUTTON_EFFECT_PIXEL_AREA_DEFAULT = Vector4(0.0f, 0.0f, 1.0f, 1.0f);
- static const float SOFT_BUTTON_RECTANGLE_SIZE_SCALE_DEFAULT = 0.5f;
-
- // factors that scale the look, defaults
- shader.SetUniform("uAmbientLight", SOFT_BUTTON_AMBIENT_LIGHT_AMOUNT_DEFAULT);
- shader.SetUniform("uDiffuseLight", SOFT_BUTTON_DIFFUSE_LIGHT_DEFAULT);
- shader.SetUniform("uLightMultiplier", SOFT_BUTTON_LIGHTING_MULTIPLIER_DEFAULT);
- if(SOFT_BUTTON_FIXED != type)
- {
- shader.SetUniform("uLightingIndentationAmount", SOFT_BUTTON_LIGHTING_INDENTATION_AMOUNT_DEFAULT);
- shader.SetUniform("uTextureDistortAmount", SOFT_BUTTON_TEXTURE_DISTORTION_AMOUNT_DEFAULT);
- shader.SetUniform("uInsideCircleSizeScale", SOFT_BUTTON_INSIDE_SHAPE_SIZE_SCALE_DEFAULT);
- shader.SetUniform("uRecipInsideCircleSizeScale", 1.0f / SOFT_BUTTON_INSIDE_SHAPE_SIZE_SCALE_DEFAULT);
- shader.SetUniform("uOutsideCircleDepth", SOFT_BUTTON_OUTSIDE_SHAPE_DEPTH_DEFAULT);
- shader.SetUniform("uEffectRegion", SOFT_BUTTON_EFFECT_PIXEL_AREA_DEFAULT);
- if(SOFT_BUTTON_RECTANGULAR == type)
- {
- shader.SetUniform("uRectangleSizeScale", SOFT_BUTTON_RECTANGLE_SIZE_SCALE_DEFAULT);
- }
-
- // precalc 1.0 / uInsideCircleSizeScale on CPU to save shader insns, using constraint to tie to the normal property
- Dali::Property::Index insideCircleSizeScalePropertyIndex = shader.GetPropertyIndex("uInsideCircleSizeScale");
- Dali::Property::Index recipInsideCircleSizeScalePropertyIndex = shader.GetPropertyIndex("uRecipInsideCircleSizeScale");
- Constraint constraint = Constraint::New<float>( shader, recipInsideCircleSizeScalePropertyIndex, InverseConstraint );
- constraint.AddSource( LocalSource(insideCircleSizeScalePropertyIndex) );
- constraint.Apply();
- }
-
- return shader;
-}
-
-}
-
-}
-
-#endif //#ifndef __DALI_TOOLKIT_SHADER_EFFECT_SOFT_BUTTON_H__
+++ /dev/null
-#ifndef __DALI_TOOLKIT_SHADER_EFFECT_SPOT_H__
-#define __DALI_TOOLKIT_SHADER_EFFECT_SPOT_H__
-
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// EXTERNAL INCLUDES
-#include <dali/devel-api/shader-effects/shader-effect.h>
-
-namespace Dali
-{
-
-namespace Toolkit
-{
-
-/**
- * @brief Creates a new SpotEffect
- *
- * SpotEffect is a custom shader effect to achieve spot effects on Image actors
- *
- * Animatable/Constrainable uniforms:
- * "uCenter" - The center of the spot. Default value (0.0,0.0)
- * "uRadius" - The radius of the spot. Default value 0.0
- *
- * @return A handle to a newly allocated ShaderEffect
- */
-inline ShaderEffect CreateSpotEffect()
-{
- // append the default version
- std::string vertexShader(
- "uniform mediump vec2 uCenter;\n"
- "uniform mediump float uRadius;\n"
- "varying mediump float vRange;\n"
- "\n"
- "void main()\n"
- "{\n"
- " mediump vec4 world = vec4(aPosition, 1.0);\n"
- " \n"
- " mediump vec2 d = vec2(world.xy - uCenter);\n"
- " mediump float dist = length(d);\n"
- " \n"
- " mediump float range = (uRadius - dist) / (uRadius);\n"
- " vRange = max(0.1, range);\n"
- " \n"
- " gl_Position = uMvpMatrix * world;\n"
- " vTexCoord = mix( sTextureRect.xy, sTextureRect.zw, aTexCoord );\n"
- "}");
-
- std::string fragmentShader(
- "varying mediump float vRange;\n"
- "\n"
- "void main()\n"
- "{\n"
- " gl_FragColor = texture2D(sTexture, vTexCoord) * vec4(vRange, vRange, vRange, 1.0) * uColor;\n"
- "}" );
-
- Dali::ShaderEffect shaderEffect = Dali::ShaderEffect::New(
- vertexShader, fragmentShader,
- ShaderEffect::GeometryHints( ShaderEffect::HINT_GRID ));
-
- shaderEffect.SetUniform( "uCenter", Vector2(0.0f, 0.0f) );
- shaderEffect.SetUniform( "uRadius", 0.0f );
-
- return shaderEffect;
-}
-
-} // namespace Toolkit
-
-} // namespace Dali
-
-#endif // __DALI_TOOLKIT_SHADER_EFFECT_SPOT_H__
+++ /dev/null
-#ifndef __DALI_TOOLKIT_SHADER_EFFECT_SQUARE_H__
-#define __DALI_TOOLKIT_SHADER_EFFECT_SQUARE_H__
-
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// EXTERNAL INCLUDES
-#include <dali/devel-api/shader-effects/shader-effect.h>
-
-namespace Dali
-{
-
-namespace Toolkit
-{
-
-/**
- * @brief Creates a new SquareDissolveEffect
- *
- * SquareDissolveEffect is a custom shader effect to achieve square effects in Image actors
- *
- * Animatable/Constrainable uniforms:
- * "uStep" - The step of the square effect
- * "uRows" - The rows of the square dissolve effect
- * "uColumns" - The columns of the square dissolve effect
- * "uTextureSize"- The texture size of the square dissolve
- *
- * @return A handle to a newly allocated ShaderEffect
- */
-inline ShaderEffect CreateSquareDissolveEffect()
-{
- // variable "uStep" range scope : [0.0, 1.0]
- std::string fragmentShader(
- "uniform mediump vec2 uTextureSize;\n"
- "uniform mediump float uStep;\n"
- "uniform mediump float uRows;\n"
- "uniform mediump float uColumns;\n"
- "void main()\n"
- "{\n"
- " mediump vec2 mosaicSize = vec2(1.0 / uRows, 1.0 / uColumns); \n"
- " mediump vec2 intXY = vec2(vTexCoord.x * uTextureSize.x, vTexCoord.y * uTextureSize.y); \n"
- " mediump vec2 XYMosaic = vec2(floor(intXY.x / mosaicSize.x) * mosaicSize.x, floor(intXY.y / mosaicSize.y) * mosaicSize.y); \n"
- " mediump vec2 UVMosaic = vec2(XYMosaic.x /uTextureSize.x, XYMosaic.y / uTextureSize.y); \n"
- " mediump vec4 noiseVec = texture2D(sEffect, UVMosaic); \n"
- " mediump float intensity = (noiseVec[0] + noiseVec[1] + noiseVec[2] + noiseVec[3]) / 4.0; \n"
- " if(intensity < uStep) \n"
- " gl_FragColor = vec4(0.1, 0.1, 0.1, 1.0); \n"
- " else \n"
- " gl_FragColor = texture2D(sTexture, vTexCoord); \n"
- " gl_FragColor *= uColor; \n"
- "} \n" );
-
- Dali::ShaderEffect shaderEffect = Dali::ShaderEffect::New(
- "",
- fragmentShader,
- ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING | ShaderEffect::HINT_GRID ));
-
- shaderEffect.SetUniform( "uTextureSize", Vector2(1.0f, 1.0f) );//COORDINATE_TYPE_DEFAULT
- shaderEffect.SetUniform( "uStep", 0.1f);
- shaderEffect.SetUniform( "uRows", 25.0f);
- shaderEffect.SetUniform( "uColumns", 25.0f);
-
- return shaderEffect;
-}
-
-} // namespace Toolkit
-
-} // namespace Dali
-
-#endif // __DALI_TOOLKIT_SHADER_EFFECT_SQUARE_H__
+++ /dev/null
-#ifndef __DALI_TOOLKIT_SHADER_EFFECT_SWIRL_H__
-#define __DALI_TOOLKIT_SHADER_EFFECT_SWIRL_H__
-
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// EXTERNAL INCLUDES
-#include <dali/devel-api/shader-effects/shader-effect.h>
-
-namespace Dali
-{
-
-namespace Toolkit
-{
-
-/**
- * @brief Creates a new SwirlEffect
- *
- * SwirlEffect is a custom shader effect to achieve swirl effects in Image actors.
- *
- * Animatable/Constrainable uniforms:
- * "uAngle" - The angle of the swirl
- * "uCenter" - The center of the swirl
- * "uRadius" - The radius of the swirl
- *
- * @param[in] warp True if the effect should warp
- * @return A handle to a newly allocated ShaderEffect
- */
-inline ShaderEffect CreateSwirlEffect( bool warp )
-{
- // append the default version
- std::string fragmentShader(
- "uniform mediump vec2 uTextureSize;\n"
- "uniform highp float uRadius;\n"
- "uniform highp float uAngle;\n"
- "uniform mediump vec2 uCenter;\n"
- "void main()\n"
- "{\n"
- " highp vec2 textureCenter = (sTextureRect.xy + sTextureRect.zw) * 0.5;\n"
- " textureCenter = vTexCoord.st - textureCenter;\n"
- " highp float distance = length(textureCenter);\n"
- " if (distance >= uRadius)\n"
- " discard;\n"
- " highp float percent = (uRadius - distance) / uRadius;\n"
- " highp float theta = percent * percent * uAngle * 4.0;\n"
- " highp float sinTheta = sin(theta);\n"
- " highp float cosTheta = cos(theta);\n" );
- // if warp, loose the sign from sin
- if( warp )
- {
- fragmentShader.append(
- " textureCenter = vec2( dot( textureCenter, vec2(cosTheta, sinTheta) ), "
- " dot( textureCenter, vec2(sinTheta, cosTheta) ) );\n" );
- }
- else
- {
- fragmentShader.append(
- " textureCenter = vec2( dot( textureCenter, vec2(cosTheta, -sinTheta) ), "
- " dot( textureCenter, vec2(sinTheta, cosTheta) ) );\n" );
- }
- fragmentShader.append(
- " textureCenter += uCenter;\n"
- " gl_FragColor = texture2D( sTexture, textureCenter ) * uColor;\n"
- "}" );
-
- Dali::ShaderEffect shaderEffect = Dali::ShaderEffect::New(
- "",
- fragmentShader,
- ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING | ShaderEffect::HINT_GRID ));
-
- shaderEffect.SetUniform( "uAngle", 0.0f );
- shaderEffect.SetUniform( "uCenter", Vector2(0.5f, 0.5f) );
- shaderEffect.SetUniform( "uRadius", 1.0f );
-
- return shaderEffect;
-}
-
-} // namespace Toolkit
-
-} // namespace Dali
-
-#endif // __DALI_TOOLKIT_SHADER_EFFECT_SWIRL_H__
// EXTERNAL INCLUDES
#include <dali/public-api/common/dali-vector.h>
-#include <dali/devel-api/shader-effects/shader-effect.h>
// INTERNAL INCLUDES
#include <dali-toolkit/public-api/controls/buttons/check-box-button.h>
+ [Equal To Constraint](@ref constraints-equal-to)
+ [Relative To Constraint](@ref constraints-relative-to)
+ [Multi-threading Notes](@ref animation-multi-threading-notes)
- + [Shader Animation](@ref animation-shader)
+ [Styling](@ref styling)
### Resources
+++ /dev/null
-/*! \page animation-shader Shader Effect Animation
- *
-
-The uniforms of a shader can be animated using the Animation::AnimateTo functions.
-
-For example, to animate the center point of the Bendy shader effect:
-@code
-Dali::Animation animation = Dali::Animation::New( 1.0f );
-//...
-Vector2 newPosition( 0.0f, 0.0f );
-animation.AnimateTo( Property(shaderEffect, shaderEffect.GetPositionPropertyName()), newPosition );
-@endcode
-
-To animate a uniform of a custom shader effect, the developer must use the name of the uniform:
-@code
-Dali::Animation animation = Dali::Animation::New( 1.0f );
-//...
-// Set the initial value for the uniform
-shaderEffect.SetUniform( "myUniform", -0.5f );
-//...
-// Animate the uniform to a value
-animation.AnimateTo( Property(shaderEffect, "myUniform"), 0.5f );
-@endcode
-
- *
- */
| Kind | Description | Start Index | End Index |
|:----------------------|:--------------------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------------------------:|:----------------------------------------------------------------------------------------------------------------------------------:|
-| Default | Properties defined within DALi Core, e.g. Dali::Actor, Dali::ShaderEffect default properties etc. | \link Dali::DEFAULT_OBJECT_PROPERTY_START_INDEX DEFAULT_OBJECT_PROPERTY_START_INDEX\endlink | \link Dali::DEFAULT_PROPERTY_MAX_COUNT DEFAULT_PROPERTY_MAX_COUNT\endlink (9999999) |
+| Default | Properties defined within DALi Core, e.g. Dali::Actor default properties etc. | \link Dali::DEFAULT_OBJECT_PROPERTY_START_INDEX DEFAULT_OBJECT_PROPERTY_START_INDEX\endlink | \link Dali::DEFAULT_PROPERTY_MAX_COUNT DEFAULT_PROPERTY_MAX_COUNT\endlink (9999999) |
| Registered | Properties registered using Dali::PropertyRegistration | \link Dali::PROPERTY_REGISTRATION_START_INDEX PROPERTY_REGISTRATION_START_INDEX\endlink (10000000) | \link Dali::PROPERTY_REGISTRATION_MAX_INDEX PROPERTY_REGISTRATION_MAX_INDEX\endlink (19999999) |
| Control | Property range reserved by Dali::Toolkit::Control | \link Dali::Toolkit::Control::CONTROL_PROPERTY_START_INDEX CONTROL_PROPERTY_START_INDEX\endlink (10000000) | \link Dali::Toolkit::Control::CONTROL_PROPERTY_END_INDEX CONTROL_PROPERTY_END_INDEX\endlink (10001000) |
| Derived Control | Property range for control deriving directly from Dali::Toolkit::Control | 10001001 | \link Dali::PROPERTY_REGISTRATION_MAX_INDEX PROPERTY_REGISTRATION_MAX_INDEX\endlink (19999999) |
dali.stage.add( imageView );
@endcode
-For a more detailed example see the ShaderEffect example in the JavaScript documentation.
-
<br>
<hr>
@section property-use-example-json Property use in JSON
on the attached renderer, and then on the attached shader object.
The actor property names and shader uniform names must not clash for the
-uniform to animate correctly. The convention in DALi is to prepend
-uniforms with 'u'.
+uniform to animate correctly.
+
+The actor needs to register the uniform properties as custom animatable
+properties.
~~~
- { \\
- "animations": \\ Animation library
- { \\
- "rotate": \\ An Animation named rotate
- { \\
- "duration": 10, \\
- "properties": \\ Properties changed in this animation
- [ \\
- {
- "actor":"image", \\ Actor found by name from the stage
- "property":"uTranslate", \\ Uniform name specified as if it is a
- \\ property of the object.
- "value":[10, 20],
- ...
- },
- ...
- ]
- },
- "shaderEffects":
- {
- "myshader1":
- {
- \\ Shader program with uniform
- "program": {...} \\ "uTranslate"
- }
- },
- "actors":
- [
- {
- "name": "image",
- "effect": "myshader1" \\ Actor using shader effect instance
- \\ "myshader1"
- }
- ]
+{
+ "animations":
+ {
+ "rotate": \\ An Animation named rotate
+ {
+ "properties": \\ Properties changed in this animation
+ [
+ {
+ "actor": "image", \\ Actor found by name from the stage
+ "property": "uTranslate", \\ Uniform name specified as if it is a property of the object
+ "value": [10, 20], \\ Target value of uniform
+ ...
+ }
+ ]
+ },
+ ...
+ },
+ "stage":
+ [
+ {
+ "type": "ImageView",
+ "name": "image", \\ Name of the actor
+ ...
+ "image":
+ {
+ ...
+ "shader": \\ ImageView has a shader property where we can set a custom shader
+ {
+ "vertexShader": "..." \\ Vertex shader with uniform "uTranslate"
+ }
+ },
+ "animatableProperties": \\ Custom properties that the actor needs to register
+ {
+ "uTranslate": [0, 0] \\ The name should match the uniform we want to animate
+ },
+ ...
},
+ ...
+ ]
+}
~~~
## Stage {#stage}
- **Templates** actor & control tree creation
- **Styles** used to style actor & control trees
- **Animations**
-- **Instances** of objects for path, shaderEffects, renderTasks, frameBuffers
+- **Instances** of objects for path, renderTasks, frameBuffers
- **Stage**. A list of actors / controls that can be added to the stage
- **Constants** (e.g. positions / colors, that can be references by other parts of the JSON file);
- **Actions**