[dali_2.0.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / shader-effects / motion-stretch-effect.cpp
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 // CLASS HEADER
18 #include <dali-toolkit/devel-api/shader-effects/motion-stretch-effect.h>
19
20 // EXTERNAL INCLUDES
21 #include <dali/public-api/actors/actor.h>
22 #include <dali/public-api/animation/constraints.h>
23 #include <dali/public-api/object/property-map.h>
24 #include <dali/public-api/rendering/shader.h>
25
26 // INTERNAL INCLUDES
27 #include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
28 #include <dali-toolkit/public-api/visuals/visual-properties.h>
29
30 namespace Dali
31 {
32 namespace Toolkit
33 {
34 void SetMotionStretchProperties(Actor& actor)
35 {
36   actor.RegisterProperty("uGeometryStretchFactor", 0.5f);
37   actor.RegisterProperty("uSpeedScalingFactor", 0.5f);
38   actor.RegisterProperty("uObjectFadeStart", Vector2(0.25f, 0.25f));
39   actor.RegisterProperty("uObjectFadeEnd", Vector2(0.5f, 0.5f));
40   actor.RegisterProperty("uAlphaScale", 0.75f);
41   Property::Index uModelProperty = actor.RegisterProperty("uModelLastFrame", Matrix::IDENTITY);
42
43   Constraint constraint = Constraint::New<Matrix>(actor, uModelProperty, EqualToConstraint());
44   constraint.AddSource(Source(actor, Actor::Property::WORLD_MATRIX));
45   constraint.Apply();
46 }
47
48 Property::Map CreateMotionStretchEffect()
49 {
50   Property::Map map;
51
52   Property::Map customShader;
53   customShader[Visual::Shader::Property::VERTEX_SHADER]   = SHADER_MOTION_STRETCH_EFFECT_VERT.data();
54   customShader[Visual::Shader::Property::FRAGMENT_SHADER] = SHADER_MOTION_STRETCH_EFFECT_FRAG.data();
55
56   customShader[Visual::Shader::Property::SUBDIVIDE_GRID_X] = 10;
57   customShader[Visual::Shader::Property::SUBDIVIDE_GRID_Y] = 10;
58
59   customShader[Visual::Shader::Property::HINTS] = Shader::Hint::OUTPUT_IS_TRANSPARENT;
60
61   map[Toolkit::Visual::Property::SHADER] = customShader;
62   return map;
63 }
64
65 } // namespace Toolkit
66 } // namespace Dali