1 #ifndef __DALI_TOOLKIT_SHADER_EFFECT_MOTION_BLUR_H__
2 #define __DALI_TOOLKIT_SHADER_EFFECT_MOTION_BLUR_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
24 #include <dali/dali.h>
26 namespace Dali DALI_IMPORT_API
34 * Class for motion blur shader that works on a per object basis. Objects will
35 * blur when they move, or if the camera moves. Can be applied to ImageActor or
40 * // Create shader used for doing motion blur\n
41 * MotionBlurEffect MotionBlurEffect = MotionBlurEffect::New();
43 * // set actor shader to the blur one\n
44 * Actor Actor = Actor::New( ... );\n
45 * Actor.SetShaderEffect( MotionBlurEffect );
48 class MotionBlurEffect : public ShaderEffect
54 * Create an uninitialized MotionBlurEffect; this can be initialized with MotionBlurEffect::New()
55 * Calling member functions with an uninitialized Dali::Object is not allowed.
62 virtual ~MotionBlurEffect();
65 * Create an initialized MotionBlurEffect
66 * The number of texture samples taken along the motion velocity vector of the
67 * actor, producing the blur, is set to a default of 8.
68 * @return A handle to a newly allocated Dali resource.
70 static MotionBlurEffect New();
73 * Create a MotionBlurEffect and attach it to the specified actor
74 * The number of texture samples taken along the motion velocity vector of the
75 * actor, producing the blur, is set to a default of 8.
76 * @return A handle to a newly allocated Dali resource.
78 static MotionBlurEffect Apply( Actor handle );
81 * Create an initialized MotionBlurEffect
82 * @param numBlurSamples The number of texture samples taken along the motion
83 * velocity vector of the actor, producing the blur. A higher number gives a
84 * smoother blur but costs more in terms of performance.
85 * @return A handle to a newly allocated Dali resource.
87 static MotionBlurEffect New( const unsigned int numBlurSamples );
90 * Set texcoord scale property. This scales the offset for texture samples
91 * along the motion velocity vector. A smaller value means the samples will
92 * be spaced closer, larger value further apart. User should use this to get
93 * the blur to look contiguous, i.e. the blur texels should not be too widely
94 * spread, with gaps in between. Default 0.125.
95 * @param texcoordScale The scaling factor that multiplies the motion velocity vector for texture lookups.
97 void SetTexcoordScale( float texcoordScale );
100 * Set geometry stretch factor property. This scales the amount the
101 * geometry stretches backwards along the motion velocity vector. A smaller
102 * value means the geometry stretches less, larger it stretches more. User
103 * should use this to get the blur to 'bleed' into areas outside the physical
104 * bounds of the actor. We need this as the blur is only applied inside the
105 * bounds of the actor, but you would expect motion blur trails where the
106 * actor was previously but is there no longer. Default 0.05.
107 * @param scalingFactor The scaling factor that extrudes the geometry backwards along the motion velocity vector.
109 void SetGeometryStretchFactor( float scalingFactor );
112 * Set speed scaling factor property. This takes the magnitude of the motion
113 * velocity vector and scales it to produce a value which is used to fade the
114 * blur in / out with the speed that the actor is moving. As the blur fades
115 * in, more of the blur is visible and less of the original actor, and vice
117 * This value is also used to control how much to fade the actor near the
118 * edges, based on the speed the actor is moving. When the actor is at rest
119 * this is not applied. Default 0.5.
120 * @param scalingFactor The scaling factor that controls the edge fade / blur fade of the actor.
122 void SetSpeedScalingFactor( float scalingFactor );
125 * Set the displacement from the centre of the actor that the actor will start
126 * to fade towards its edges. This is used to prevent an unsightly hard edge
127 * between the blurred actor and the scene. Depends on the values of the
128 * vertices in the vertex stream. When the actor is at rest this is not applied.
129 * Default 0.25, which is half way towards the edge for an ImageRenderer::QUAD.
130 * @param displacement The displacement from the centre of the actor that the actor will start to edge fade.
132 void SetObjectFadeStart( Vector2 displacement );
135 * Set the displacement from the centre of the actor that the actor will
136 * finish fading towards its edges. This is used to prevent an unsightly hard
137 * edge between the blurred actor and the scene. Depends on the values of the
138 * vertices in the vertex stream. When the actor is at rest this is not applied.
139 * Default 0.5, which is all the way towards the edge for an ImageRenderer::QUAD.
140 * @param displacement The displacement from the centre of the actor that the actor will finish edge fading.
142 void SetObjectFadeEnd( Vector2 displacement );
145 * Set a global scaler applied to the alpha of the actor. Used to make the
146 * blurred actor a bit more subtle (helps to hide discontinuities due to
147 * limited number of texture samples) and reveal a bit of the background
148 * behind it as it moves. When the actor is at rest this is not applied. Default 0.75.
149 * @param alphaScale The scaling factor which multiplies the alpha of each pixel of the actor.
151 void SetAlphaScale( float alphaScale );
154 * Set the number of texture samples to be taken. Increasing the number of
155 * samples provides better quality at the cost of performance.
156 * @param numSamples The number of texture samples to be taken. Default is 8.
158 void SetNumSamples( int numSamples );
161 * Get the name for the texcoord scale property. Useful for animation.
162 * @return A std::string containing the property name
164 const std::string& GetTexcoordScalePropertyName() const;
167 * Get the name for the geometry stretching property. Useful for animation.
168 * @return A std::string containing the property name
170 const std::string& GetGeometryStretchFactorPropertyName() const;
173 * Get the name for the speed scaling property. Useful for animation.
174 * @return A std::string containing the property name
176 const std::string& GetSpeedScalingFactorPropertyName() const;
179 * Get the name for the fade start property. Useful for animation.
180 * @return A std::string containing the property name
182 const std::string& GetObjectFadeStartPropertyName() const;
185 * Get the name for the fade end property. Useful for animation.
186 * @return A std::string containing the property name
188 const std::string& GetObjectFadeEndPropertyName() const;
191 * Get the name for the alpha scale property. Useful for animation.
192 * @return A std::string containing the property name
194 const std::string& GetAlphaScalePropertyName() const;
197 * Downcast an ShaderEffect handle to MotionBlurEffect handle. If handle points to a MotionBlurEffect object the
198 * downcast produces valid handle. If not the returned handle is left uninitialized.
199 * @param[in] handle to a ShaderEffect
200 * @return handle to a MotionBlurEffect object or an uninitialized handle
202 static MotionBlurEffect DownCast( ShaderEffect handle );
205 // Not intended for application developers
206 MotionBlurEffect( ShaderEffect handle );
213 #endif //#ifndef __DALI_TOOLKIT_SHADER_EFFECT_MOTION_BLUR_H__