2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <dali-toolkit/devel-api/shader-effects/motion-blur-effect.h>
21 #include <dali/public-api/animation/constraints.h>
22 #include <dali/public-api/rendering/shader.h>
25 #include <dali-toolkit/public-api/visuals/visual-properties.h>
26 #include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
33 void SetMotionBlurProperties( Actor& actor, unsigned int numBlurSamples )
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);
46 Constraint constraint = Constraint::New<Matrix>(actor, uModelProperty, EqualToConstraint());
47 constraint.AddSource(Source(actor, Actor::Property::WORLD_MATRIX));
52 Property::Map CreateMotionBlurEffect()
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();
60 customShader[Visual::Shader::Property::SUBDIVIDE_GRID_X] = 10;
61 customShader[Visual::Shader::Property::SUBDIVIDE_GRID_Y] = 10;
63 customShader[Visual::Shader::Property::HINTS] = Shader::Hint::OUTPUT_IS_TRANSPARENT;
65 map[Toolkit::Visual::Property::SHADER] = customShader;