430832e703e35f5230c3890fa548e44ce325dcb6
[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/public-api/visuals/visual-properties.h>
26 #include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
27
28 namespace Dali
29 {
30 namespace Toolkit
31 {
32
33 void SetMotionBlurProperties( Actor& actor, unsigned int numBlurSamples )
34 {
35   actor.RegisterProperty("uBlurTexCoordScale", 0.125f);
36   actor.RegisterProperty("uGeometryStretchFactor", 0.05f);
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   actor.RegisterProperty("uNumSamples", static_cast<float>(numBlurSamples));
42   actor.RegisterProperty("uRecipNumSamples", 1.0f / static_cast<float>(numBlurSamples));
43   actor.RegisterProperty("uRecipNumSamplesMinusOne", 1.0f / static_cast<float>(numBlurSamples - 1.0f));
44   Property::Index uModelProperty = actor.RegisterProperty("uModelLastFrame", Matrix::IDENTITY);
45
46   Constraint constraint = Constraint::New<Matrix>(actor, uModelProperty, EqualToConstraint());
47   constraint.AddSource(Source(actor, Actor::Property::WORLD_MATRIX));
48   constraint.Apply();
49 }
50
51
52 Property::Map CreateMotionBlurEffect()
53 {
54   Property::Map map;
55
56   Property::Map customShader;
57   customShader[Visual::Shader::Property::VERTEX_SHADER]   = SHADER_MOTION_BLUR_EFFECT_VERT.data();
58   customShader[Visual::Shader::Property::FRAGMENT_SHADER] = SHADER_MOTION_BLUR_EFFECT_FRAG.data();
59
60   customShader[Visual::Shader::Property::SUBDIVIDE_GRID_X] = 10;
61   customShader[Visual::Shader::Property::SUBDIVIDE_GRID_Y] = 10;
62
63   customShader[Visual::Shader::Property::HINTS] = Shader::Hint::OUTPUT_IS_TRANSPARENT;
64
65   map[Toolkit::Visual::Property::SHADER] = customShader;
66   return map;
67 }
68
69 } // Toolkit
70 } // Dali