Merge branch 'devel/master' into devel/graphics
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / shader-effects / motion-blur-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-blur-effect.h>
19
20 // EXTERNAL INCLUDES
21 #include <dali/public-api/animation/constraints.h>
22 #include <dali/public-api/rendering/shader.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
26 #include <dali-toolkit/public-api/visuals/visual-properties.h>
27
28 namespace Dali
29 {
30 namespace Toolkit
31 {
32 void SetMotionBlurProperties(Actor& actor, unsigned int numBlurSamples)
33 {
34   actor.RegisterProperty("uBlurTexCoordScale", 0.125f);
35   actor.RegisterProperty("uGeometryStretchFactor", 0.05f);
36   actor.RegisterProperty("uSpeedScalingFactor", 0.5f);
37   actor.RegisterProperty("uObjectFadeStart", Vector2(0.25f, 0.25f));
38   actor.RegisterProperty("uObjectFadeEnd", Vector2(0.5f, 0.5f));
39   actor.RegisterProperty("uAlphaScale", 0.75f);
40   actor.RegisterProperty("uNumSamples", static_cast<float>(numBlurSamples));
41   actor.RegisterProperty("uRecipNumSamples", 1.0f / static_cast<float>(numBlurSamples));
42   actor.RegisterProperty("uRecipNumSamplesMinusOne", 1.0f / static_cast<float>(numBlurSamples - 1.0f));
43   Property::Index uModelProperty = actor.RegisterProperty("uModelLastFrame", Matrix::IDENTITY);
44
45   Constraint constraint = Constraint::New<Matrix>(actor, uModelProperty, EqualToConstraint());
46   constraint.AddSource(Source(actor, Actor::Property::WORLD_MATRIX));
47   constraint.Apply();
48 }
49
50 Property::Map CreateMotionBlurEffect()
51 {
52   Property::Map map;
53
54   Property::Map customShader;
55   customShader[Visual::Shader::Property::VERTEX_SHADER]   = SHADER_MOTION_BLUR_EFFECT_VERT.data();
56   customShader[Visual::Shader::Property::FRAGMENT_SHADER] = SHADER_MOTION_BLUR_EFFECT_FRAG.data();
57
58   customShader[Visual::Shader::Property::SUBDIVIDE_GRID_X] = 10;
59   customShader[Visual::Shader::Property::SUBDIVIDE_GRID_Y] = 10;
60
61   customShader[Visual::Shader::Property::HINTS] = Shader::Hint::OUTPUT_IS_TRANSPARENT;
62
63   map[Toolkit::Visual::Property::SHADER] = customShader;
64   return map;
65 }
66
67 } // namespace Toolkit
68 } // namespace Dali