Merge "UTC Builder coverage" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / shader-effects / page-turn-effect-impl.cpp
1 /*
2  * Copyright (c) 2014 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
18 // CLASS HEADER
19 #include "page-turn-effect-impl.h"
20
21 // EXTERNAL HEADERS
22 #include <sstream>
23 #include <dali/public-api/animation/constraint.h>
24 #include <dali/public-api/common/stage.h>
25
26 namespace Dali
27 {
28
29 namespace Toolkit
30 {
31
32 namespace Internal
33 {
34
35 namespace
36 {
37 #define MAKE_STRING(A)#A
38
39 const std::string CURRENT_CENTER_PROPERTY_NAME("uCurrentCenter");
40 const std::string ORIGINAL_CENTER_PROPERTY_NAME("uOriginalCenter");
41 const std::string PAGE_SIZE_PROPERTY_NAME("uPageSize");
42 const std::string IS_TURNING_BACK_PROPERTY_NAME("uIsTurningBack");
43 const std::string SHADOW_WIDTH_PROPERTY_NAME("uShadowWidth");
44 const std::string SPINE_SHADOW_PARAMETER_PROPERTY_NAME("uSpineShadowParameter");
45
46 // fake shadow is used to enhance the effect, with its default maximum width to be pageSize * 0.15
47 const float DEFAULT_SHADOW_WIDTH(0.15f);
48
49 // the major&minor radius (in pixels) to form an ellipse shape
50 // the top-left quarter of this ellipse is used to calculate spine normal for simulating shadow
51 const Vector2 DEFAULT_SPINE_SHADOW_PARAMETER(50.0f, 20.0f);
52
53 // when the vanishing point is very far away(pageHeight*THRESHOLD), make it infinitely, in this case, the page bent horizontally
54 const float THRESHOLD(20.0);
55
56 void CommonParametersConstraint( Matrix& current, const PropertyInputContainer& inputs )
57 {
58   const Vector2& originalCenter = inputs[0]->GetVector2();
59   Vector2 currentCenter = inputs[1]->GetVector2();
60   const Vector2& pageSize = inputs[2]->GetVector2();
61
62   // calculate the curve direction and the vanishing point
63   // here, the vanishing point is the intersection of spine with the line passing through original center and vertical to curve direction
64   Vector2 curveDirection( currentCenter - originalCenter );
65   curveDirection.Normalize();
66   if( fabs(curveDirection.y) < 0.01f) // eliminate the possibility of division by zero in the next step
67   {
68     curveDirection.y = 0.01f;
69   }
70   float vanishingPointY = originalCenter.y + curveDirection.x * originalCenter.x / curveDirection.y;
71
72   float curveEndY, cosTheta ,sinTheta ,translateX, translateY;
73   // when the vanishing point is very far away, make it infinitely, in this case, the page bent horizontally
74   if( fabs(vanishingPointY-pageSize.y*0.5f) >= pageSize.y*THRESHOLD )
75   {
76     curveDirection = Vector2(-1.f,0.f);
77     currentCenter.y = originalCenter.y;
78
79     curveEndY = originalCenter.y;
80     cosTheta = 1.f;
81     sinTheta = 0.f;
82     translateX = currentCenter.x - originalCenter.x;
83     translateY = vanishingPointY;
84   }
85   else
86   {
87     curveEndY = currentCenter.y - curveDirection.y * (currentCenter.x/curveDirection.x) ;
88     Vector2 v1( currentCenter.x, currentCenter.y - vanishingPointY );
89     v1.Normalize();
90     Vector2 v2( originalCenter.x, originalCenter.y - vanishingPointY );
91     v2.Normalize();
92     cosTheta = v1.x*v2.x + v1.y*v2.y;
93     sinTheta = ( vanishingPointY > pageSize.y*0.5f ) ? sqrt(1.0-cosTheta*cosTheta) : -sqrt(1.0-cosTheta*cosTheta);
94     translateX = currentCenter.x - cosTheta*originalCenter.x - sinTheta*( originalCenter.y-vanishingPointY );
95     translateY = currentCenter.y + sinTheta*originalCenter.x - cosTheta*( originalCenter.y-vanishingPointY );
96   }
97
98   float originalLength = fabs(originalCenter.x/curveDirection.x);
99   float currentLength = fabs(currentCenter.x/curveDirection.x);
100   float curveHeight = 0.45f*sqrt(originalLength*originalLength - currentLength*currentLength);
101
102   float* parameterArray = current.AsFloat();
103   parameterArray[0] = cosTheta;
104   parameterArray[1] = -sinTheta;
105   parameterArray[2] = originalCenter.x;
106   parameterArray[3] = originalCenter.y;
107   parameterArray[4] = sinTheta;
108   parameterArray[5] = cosTheta;
109   parameterArray[6] = currentCenter.x;
110   parameterArray[7] = currentCenter.y;
111   parameterArray[8] = translateX;
112   parameterArray[9] = translateY;
113   parameterArray[10] = vanishingPointY;
114   parameterArray[11] = curveEndY;
115   parameterArray[12] = curveDirection.x;
116   parameterArray[13] = curveDirection.y;
117   parameterArray[14] = curveHeight;
118   parameterArray[15] = currentLength;
119 }
120
121 }//namespace
122
123 PageTurnEffect::PageTurnEffect()
124 : mOriginalCenterPropertyIndex(Property::INVALID_INDEX),
125   mCurrentCenterPropertyIndex(Property::INVALID_INDEX)
126 {
127 }
128
129 PageTurnEffect::~PageTurnEffect()
130 {
131 }
132
133 Toolkit::PageTurnEffect PageTurnEffect::CreateShaderEffect( bool enableBlending )
134 {
135   std::string vertexShader = MAKE_STRING(
136     /*
137      * The common parameters for all the vertices, calculate in CPU then pass into the shader as uniforms
138      *
139      *  first part of the page, (outside the the line passing through original center and vertical to curve direction)
140      * no Z change, only 2D rotation and translation
141      * ([0][0],[0][1],[1][0],[1][1]) mat2 rotateMatrix
142      * ([2][0],[2][1]) vec2 translationVector
143      *
144      * ([0][2],[0][3]) vec2 originalCenter: Typically the press down position of the Pan Gesture
145      * ([1][2],[1][3]) vec2 currentCenter: Typically the current position of the Pan Gesture
146      * ([3][0],[3][1]) vec2 curveDirection: The normalized vector pointing from original center to current center
147      * ([2][2]) float vanishingPointY: The Y coordinate of the intersection of the spine
148      *                                 and the line which goes through the original center and is vertical to the curveDirection
149      * ([2][3]) float curveEndY: The Y coordinate of intersection of the spine and the line through both original and current center
150      * ([3][2]) float curveHeight: The height of the interpolated hermite curve.
151      * ([3][3]) float currentLength: The length from the current center to the curveEnd.
152      */
153     precision mediump float;\n
154     uniform mat4 uCommonParameters;\n
155     \n
156     uniform vec2 uPageSize;\n
157     uniform float uIsTurningBack;\n
158     uniform float uShadowWidth;\n
159     varying vec3 vNormal;\n
160     varying vec4 vPosition;\n
161     varying float vEdgeShadow;\n
162     \n
163     void main()\n
164     {\n
165       vec4 position = vec4( aPosition.xy, 0.0, 1.0);\n
166       vec2 currentCenter = vec2( uCommonParameters[1][2], uCommonParameters[1][3]);\n
167       vec2 originalCenter = vec2( uCommonParameters[0][2], uCommonParameters[0][3]);\n
168       vec3 normal = vec3(0.0,0.0,1.0);\n
169       \n
170       if(currentCenter.x < originalCenter.x)\n
171       {\n
172         // change the coordinate origin from the center of the page to its top-left
173         position.xy += uPageSize * 0.5;\n
174         vec2 curveDirection = vec2( uCommonParameters[3]);\n
175         vec3 vanishingPoint = vec3(0.0, uCommonParameters[2][2], 0.0);\n
176         // first part of the page, (outside the the line passing through original center and vertical to curve direction)
177         //no Z change, only 2D rotation and translation
178         if( dot(curveDirection, position.xy - originalCenter) < 0.0 )
179         {\n
180           position.y -= vanishingPoint.y;\n
181           position.xy = mat2(uCommonParameters)*position.xy + vec2( uCommonParameters[2]);\n
182         }\n
183          // second part of the page, bent as a ruled surface
184         else\n
185         {\n
186           // calculate on the flat plane, between
187           // the first line passing through current vertex and vanishing point
188           // the second line passing through original center and current center
189           vec2 curveEnd = vec2( 0.0, uCommonParameters[2][3] );\n
190           vec2 curFlatDirection = vec2(0.0,1.0);\n
191           float lengthFromCurve = position.y - originalCenter.y;\n
192           float lengthOnCurve = position.x;\n
193           if(currentCenter.y != originalCenter.y)\n
194           {\n
195             curFlatDirection = normalize(position.xy - vanishingPoint.xy);\n
196             lengthFromCurve = (curveEnd.x*curveDirection.y-curveEnd.y*curveDirection.x-position.x*curveDirection.y+position.y*curveDirection.x)
197                             / (curFlatDirection.x*curveDirection.y-curFlatDirection.y*curveDirection.x);\n
198             lengthOnCurve = length(position.xy+lengthFromCurve*curFlatDirection-curveEnd);\n
199           }\n
200           \n
201           // define the control points of hermite curve, composed with two segments
202           // calulation is carried out on the 2D plane which is passing through both current and original center and vertical to the image plane
203           float currentLength = uCommonParameters[3][3];\n
204           float originalLength =  abs(originalCenter.x/curveDirection.x);\n
205           float height = uCommonParameters[3][2];\n
206           float percentage = currentLength/originalLength;\n
207           //vec2 SegmentOneControlPoint0 = vec2(0.0, 0.0);
208           vec2 SegmentOneControlPoint1 = vec2((0.65*percentage - 0.15)*originalLength, (0.8 + 0.2 * percentage)*height); \n
209           vec2 SegmentTwoControlPoint0 = SegmentOneControlPoint1;\n
210           vec2 SegmentTwoControlPoint1 = vec2(currentLength, 0.0); \n
211           vec2 SegmentOneTangentVector0 = SegmentOneControlPoint1;\n
212           vec2 SegmentOneTangentVector1 = vec2(0.5*originalLength,0.0);\n
213           vec2 SegmentTwoTangentVector0 = SegmentOneTangentVector1;\n
214           vec2 SegmentTwoTangentVector1 = SegmentOneTangentVector1;\n
215           \n
216           // calulate the corresponding curve point position and its tangent vector
217           // it is a linear mapping onto nonlinear curves, might cause some unwanted deformation
218           // but as there are no analytical method to calculate the curve length on arbitrary segment
219           // no efficient way to solve this nonlinear mapping, Numerical approximation would cost too much computation in shader
220           vec2 curvePoint2D;\n
221           vec2 tangent;\n
222           float t0 = lengthOnCurve / originalLength;\n
223           if(t0<=0.5)\n
224           {\n
225             float t = 2.0*t0;\n
226             float t_2 = t*t;\n
227             float t_3 = t*t_2;\n
228             curvePoint2D = (-2.0*t_3+3.0*t_2)*SegmentOneControlPoint1
229                          + (t_3-2.0*t_2+t)*SegmentOneTangentVector0 + (t_3-t_2)*SegmentOneTangentVector1;\n
230             tangent = (-6.0*t_2+6.0*t)*SegmentOneControlPoint1
231                     + (3.0*t_2-4.0*t+1.0)*SegmentOneTangentVector0 + (3.0*t_2-2.0*t)*SegmentOneTangentVector1;\n
232           }\n
233           else\n
234           {\n
235             float t = 2.0*t0-1.0;\n
236             float t_2 = t*t;\n
237             float t_3 = t*t_2;\n
238             curvePoint2D = (2.0*t_3-3.0*t_2+1.0)*SegmentTwoControlPoint0 + (-2.0*t_3+3.0*t_2)*SegmentTwoControlPoint1
239                          + (t_3-2.0*t_2+t)*SegmentTwoTangentVector0 + (t_3-t_2)*SegmentTwoTangentVector1;\n
240             tangent = (6.0*t_2-6.0*t)*SegmentTwoControlPoint0 + (-6.0*t_2+6.0*t)*SegmentTwoControlPoint1
241                     + (3.0*t_2-4.0*t+1.0)*SegmentTwoTangentVector0 + (3.0*t_2-2.0*t)*SegmentTwoTangentVector1;\n
242             // a trick to eliminate some optical illusion caused by the gradient matter of normal in per-fragment shading
243             // which is caused by linear interpolation of normal vs. nonlinear lighting
244             // will notice some artifact in the areas with dramatically normal changes, so compress the normal differences here
245             tangent.y *=  min(1.0, length(position.xyz - vanishingPoint) / uPageSize.y ); \n
246           }\n
247           vec3 curvePoint = vec3(curveEnd - curvePoint2D.x*curveDirection,max(0.0,curvePoint2D.y));\n
248           vec3 tangentVector = vec3(-tangent.x*curveDirection,tangent.y);\n
249           \n
250           // locate the new vertex position on the line passing through both vanishing point and the calculated curve point position
251           vec3 curLiftDirection = vec3(0.0,-1.0,0.0);\n
252           if(currentCenter.y != originalCenter.y)\n
253           {\n
254             curLiftDirection = normalize(curvePoint - vanishingPoint);\n
255             tangentVector *= (curveDirection.y > 0.0) ? -1.0 : 1.0;\n
256           // an heuristic adjustment here, to compensate the linear parameter mapping onto the nonlinear curve
257             float Y0 = position.y - curveDirection.y * (position.x/curveDirection.x); \n
258             float proportion;
259             float refLength;\n
260             if(abs(Y0-vanishingPoint.y) > abs(curveEnd.y-vanishingPoint.y)) \n
261             {\n
262               proportion = abs(curveEnd.y - Y0) / (abs(curveEnd.y-Y0)+abs(curveEnd.y - vanishingPoint.y)); \n
263               refLength = proportion*length(originalCenter-vanishingPoint.xy) / (proportion-1.0); \n
264             }\n
265             else\n
266             {\n
267               proportion = abs(curveEnd.y - Y0) / abs(curveEnd.y - vanishingPoint.y);\n
268               refLength = proportion*length(originalCenter-vanishingPoint.xy); \n
269             }\n
270             float Y1 = currentCenter.y - (normalize(currentCenter-vanishingPoint.xy)).y * refLength; \n
271             position.y = mix(Y0, Y1, t0); \n
272           }\n
273           position.xz = curvePoint.xz - lengthFromCurve*curLiftDirection.xz;\n
274           // calculate the normal vector, will be used for lighting
275           normal = cross(curLiftDirection, normalize(tangentVector));\n
276           // the signature of Z is decided by the page turning direction:
277           // from left to right(negative); from right to left (positive)
278           position.z *= -uIsTurningBack;\n
279           normal.xy *= -uIsTurningBack;\n
280         }\n
281         // change the coordinate origin from the top-left of the page to its center
282         position.xy -= uPageSize * 0.5; \n
283       }\n
284       position.z += aPosition.z;\n
285       gl_Position = uMvpMatrix * position;\n
286      // varying parameters for fragment shader
287       vTexCoord = aTexCoord;
288       vNormal = uNormalMatrix*normal;\n
289       vPosition = uModelView * position;\n
290   );
291
292   std::string vertexShaderWithFakedShadow = MAKE_STRING(
293       // display shadow, the fake shadow value is calculated according to the height and the distance from page edge
294       vTexCoord.x = (aTexCoord.x-sTextureRect.s) /( 1.0 - uShadowWidth ) + sTextureRect.s;\n
295       vTexCoord.y = ( aTexCoord.y-sTextureRect.t-0.5*uShadowWidth*(sTextureRect.q-sTextureRect.t) )/( 1.0 - uShadowWidth ) + sTextureRect.t;\n
296       float heightCoef = (1.0 + position.z*uIsTurningBack*3.0 / uPageSize.x) * 0.6;
297       vEdgeShadow = clamp(0.9 - heightCoef, 0.0, 0.9 ); \n
298       if( vTexCoord.y >= sTextureRect.q || vTexCoord.y <= sTextureRect.t || vTexCoord.x >= sTextureRect.p  )\n
299       {\n
300         float inversedShadowWidth = (1.0-uShadowWidth) / uShadowWidth ;\n
301         float alpha1 = (vTexCoord.x-sTextureRect.p) * inversedShadowWidth / (sTextureRect.p - sTextureRect.s);\n
302         inversedShadowWidth = 2.0 * inversedShadowWidth  / (sTextureRect.q - sTextureRect.t); \n
303         float alpha2 = (vTexCoord.y-sTextureRect.q) * inversedShadowWidth;\n
304         float alpha3 = (sTextureRect.t-vTexCoord.y) * inversedShadowWidth;\n
305         float alpha;\n
306         if(alpha1 > 0.0 && alpha2 > 0.0) alpha = sqrt(alpha2*alpha2+alpha1*alpha1)/sqrt(1.0 + max(alpha1,alpha2)*max(alpha1,alpha2));\n //bottom-right corner
307         else if(alpha1 > 0.0 && alpha3 > 0.0) alpha = sqrt(alpha3*alpha3+alpha1*alpha1)/sqrt(1.0+max(alpha1,alpha3)*max(alpha1,alpha3));\n //top-right corner
308         else alpha = max(alpha1,max(alpha2,alpha3)); \n
309         alpha = 0.9 - alpha*0.9;\n
310         vEdgeShadow = clamp(alpha - heightCoef, 0.0, 0.9 ); \n
311       }\n
312   );
313
314   std::string vertexShaderEnd("}");
315
316   std::string fragmentShaderPartOne = MAKE_STRING(
317     precision mediump float;\n
318     uniform vec2 uPageSize;\n
319     uniform vec2 uSpineShadowParameter;\n
320     varying vec3 vNormal;\n
321     varying vec4 vPosition;\n
322     varying float vEdgeShadow;\n
323     \n
324     void main()\n
325     {\n
326       // need to re-normalize the interpolated normal
327       vec3 normal = normalize(vNormal);\n
328       vec4 texel;\n
329       float spineShadowCoef = 1.0; \n
330    );
331
332   std::string fragmentShaderWithFakedShadow = MAKE_STRING(
333       if( vTexCoord.y > sTextureRect.q || vTexCoord.y < sTextureRect.t || vTexCoord.x > sTextureRect.p  )\n
334          texel = vec4(0.0,0.0,0.0,vEdgeShadow);
335       else \n
336   );
337
338   std::string fragmentShaderPartTwo = MAKE_STRING(
339       { \n
340         // display page content
341         // display back image of the page, flip the texture
342         if(  dot(vPosition.xyz, normal) > 0.0 ) texel = texture2D( sTexture, vec2( sTextureRect.p+sTextureRect.s-vTexCoord.x, vTexCoord.y ) );\n
343         // display front image of the page
344         else texel = texture2D( sTexture, vTexCoord );\n
345         // display book spine, a stripe of shadowed texture
346         float pixelPos = (vTexCoord.x-sTextureRect.s)*uPageSize.x; \n
347         if(pixelPos < uSpineShadowParameter.x) \n
348         {\n
349           float x = pixelPos - uSpineShadowParameter.x;\n
350           float y = sqrt( uSpineShadowParameter.x*uSpineShadowParameter.x - x*x);\n
351           spineShadowCoef = normalize( vec2( uSpineShadowParameter.y*x/uSpineShadowParameter.x, y ) ).y;\n
352         }\n
353       }\n
354     // calculate the lighting
355     // set the ambient color as vec3(0.4);
356       float lightColor = abs( normal.z ) * 0.6 + 0.4;\n
357       gl_FragColor = vec4( ( spineShadowCoef* lightColor)* texel.rgb , texel.a ) * uColor;\n
358     }
359   );
360
361   // Create the implementation, temporarily owned on stack,
362   Dali::ShaderEffect shaderEffectCustom;
363   std::ostringstream vertexShaderStringStream;
364   std::ostringstream fragmentShaderStringStream;
365   if( enableBlending )
366   {
367     vertexShaderStringStream<< vertexShader << vertexShaderWithFakedShadow << vertexShaderEnd;
368     fragmentShaderStringStream<< fragmentShaderPartOne << fragmentShaderWithFakedShadow << fragmentShaderPartTwo;
369     shaderEffectCustom = Dali::ShaderEffect::New( vertexShaderStringStream.str(), fragmentShaderStringStream.str(), GeometryType( GEOMETRY_TYPE_IMAGE ),
370             ShaderEffect::GeometryHints( ShaderEffect::HINT_GRID | ShaderEffect::HINT_DEPTH_BUFFER | ShaderEffect::HINT_BLENDING) );
371   }
372   else
373   {
374     vertexShaderStringStream<< vertexShader << vertexShaderEnd;
375     fragmentShaderStringStream<< fragmentShaderPartOne << fragmentShaderPartTwo;
376     shaderEffectCustom = Dali::ShaderEffect::New( vertexShaderStringStream.str(), fragmentShaderStringStream.str(), GeometryType( GEOMETRY_TYPE_IMAGE ),
377             ShaderEffect::GeometryHints( ShaderEffect::HINT_GRID | ShaderEffect::HINT_DEPTH_BUFFER ) );
378   }
379
380   PageTurnEffect* shaderImpl = new PageTurnEffect();
381   Dali::Toolkit::PageTurnEffect handle = Toolkit::PageTurnEffect( shaderEffectCustom, shaderImpl );
382
383   shaderImpl->Initialize( handle );
384
385   Vector2 defaultPageSize = Dali::Stage::GetCurrent().GetSize();
386   Matrix zeroMatrix(true);
387   handle.SetUniform( "uCommonParameters", zeroMatrix );
388   handle.SetUniform( PAGE_SIZE_PROPERTY_NAME, defaultPageSize/(1.f-DEFAULT_SHADOW_WIDTH) );
389   handle.SetUniform( SHADOW_WIDTH_PROPERTY_NAME, DEFAULT_SHADOW_WIDTH );
390   handle.SetUniform( SPINE_SHADOW_PARAMETER_PROPERTY_NAME, DEFAULT_SPINE_SHADOW_PARAMETER );
391
392   shaderImpl->mOriginalCenterPropertyIndex = handle.RegisterProperty( ORIGINAL_CENTER_PROPERTY_NAME, Vector2( defaultPageSize[0], defaultPageSize[1]*0.5f ) );
393   shaderImpl->mCurrentCenterPropertyIndex = handle.RegisterProperty( CURRENT_CENTER_PROPERTY_NAME, Vector2( defaultPageSize[0], defaultPageSize[1]*0.5f ) );
394
395   shaderImpl->ApplyInternalConstraint();
396
397   // setting isTurningBack to -1.0f here means turning page forward
398   handle.SetUniform( IS_TURNING_BACK_PROPERTY_NAME, -1.0f );
399
400   return handle;
401 }
402
403 void PageTurnEffect::SetPageSize(const Vector2& pageSize)
404 {
405   mShaderEffect.SetUniform(PAGE_SIZE_PROPERTY_NAME, pageSize);
406 }
407
408 void PageTurnEffect::SetOriginalCenter(const Vector2& originalCenter)
409 {
410   mShaderEffect.SetProperty( mOriginalCenterPropertyIndex, originalCenter );
411 }
412
413 void PageTurnEffect::SetCurrentCenter(const Vector2& currentCenter)
414 {
415   mShaderEffect.SetProperty( mCurrentCenterPropertyIndex, currentCenter );
416 }
417
418 void PageTurnEffect::SetIsTurningBack(bool isTurningBack)
419 {
420   float direction = isTurningBack ? 1.0f : -1.0f;
421   mShaderEffect.SetUniform(IS_TURNING_BACK_PROPERTY_NAME, direction);
422 }
423
424 void PageTurnEffect::SetShadowWidth(float shadowWidth)
425 {
426   mShaderEffect.SetUniform( SHADOW_WIDTH_PROPERTY_NAME, shadowWidth );
427 }
428
429 void PageTurnEffect::SetSpineShadowParameter(const Vector2& spineShadowParameter)
430 {
431   mShaderEffect.SetUniform( SPINE_SHADOW_PARAMETER_PROPERTY_NAME, spineShadowParameter);
432 }
433
434 void PageTurnEffect::ApplyInternalConstraint()
435 {
436   Constraint constraint = Constraint::New<Matrix>( mShaderEffect, mShaderEffect.GetPropertyIndex( "uCommonParameters" ), CommonParametersConstraint );
437   constraint.AddSource( LocalSource( mOriginalCenterPropertyIndex ) );
438   constraint.AddSource( LocalSource( mCurrentCenterPropertyIndex ) );
439   constraint.AddSource( LocalSource( mShaderEffect.GetPropertyIndex( PAGE_SIZE_PROPERTY_NAME ) ) );
440   constraint.Apply();
441 }
442
443 const std::string& PageTurnEffect::GetPageSizePropertyName() const
444 {
445   return PAGE_SIZE_PROPERTY_NAME;
446 }
447
448 const std::string& PageTurnEffect::GetOriginalCenterPropertyName() const
449 {
450   return ORIGINAL_CENTER_PROPERTY_NAME;
451 }
452
453 const std::string& PageTurnEffect::GetCurrentCenterPropertyName() const
454 {
455   return CURRENT_CENTER_PROPERTY_NAME;
456 }
457
458 void PageTurnEffect::Initialize( Dali::ShaderEffect shaderEffect )
459 {
460   // Save a reference to the shader handle
461   mShaderEffect = shaderEffect;
462 }
463
464 } // namespace Internal
465
466 } // namespace Toolkit
467
468 } // namespace Dali