4150ac83efc5c8cc1c91a784f187967ef1646fc8
[platform/core/uifw/dali-demo.git] / examples / refraction-effect / refraction-effect-example.cpp
1 /*
2  * Copyright (c) 2017 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 // EXTERNAL INCLUDES
19 #include <dali/dali.h>
20 #include <dali/public-api/rendering/renderer.h>
21 #include <dali-toolkit/dali-toolkit.h>
22 #include <dali-toolkit/devel-api/controls/buttons/button-devel.h>
23
24 #include <fstream>
25 #include <sstream>
26 #include <limits>
27
28 // INTERNAL INCLUDES
29 #include "shared/view.h"
30 #include "shared/utility.h"
31
32 using namespace Dali;
33
34 namespace
35 {
36 const char * const APPLICATION_TITLE( "Refraction Effect" );
37 const char * const TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" );
38 const char * const CHANGE_TEXTURE_ICON( DEMO_IMAGE_DIR "icon-change.png" );
39 const char * const CHANGE_TEXTURE_ICON_SELECTED( DEMO_IMAGE_DIR "icon-change-selected.png" );
40 const char * const CHANGE_MESH_ICON( DEMO_IMAGE_DIR "icon-replace.png" );
41 const char * const CHANGE_MESH_ICON_SELECTED( DEMO_IMAGE_DIR "icon-replace-selected.png" );
42
43 const char* MESH_FILES[] =
44 {
45  DEMO_MODEL_DIR "surface_pattern_v01.obj",
46  DEMO_MODEL_DIR "surface_pattern_v02.obj"
47 };
48 const unsigned int NUM_MESH_FILES( sizeof( MESH_FILES ) / sizeof( MESH_FILES[0] ) );
49
50 const char* TEXTURE_IMAGES[]=
51 {
52   DEMO_IMAGE_DIR "background-1.jpg",
53   DEMO_IMAGE_DIR "background-2.jpg",
54   DEMO_IMAGE_DIR "background-3.jpg",
55   DEMO_IMAGE_DIR "background-4.jpg"
56 };
57 const unsigned int NUM_TEXTURE_IMAGES( sizeof( TEXTURE_IMAGES ) / sizeof( TEXTURE_IMAGES[0] ) );
58
59 struct LightOffsetConstraint
60 {
61   LightOffsetConstraint( float radius )
62   : mRadius( radius )
63   {
64   }
65
66   void operator()( Vector2& current, const PropertyInputContainer& inputs )
67   {
68     float spinAngle = inputs[0]->GetFloat();
69     current.x = cos( spinAngle );
70     current.y = sin( spinAngle );
71
72     current *= mRadius;
73   }
74
75   float mRadius;
76 };
77
78 /**
79  * structure of the vertex in the mesh
80  */
81 struct Vertex
82 {
83   Vector3 position;
84   Vector3 normal;
85   Vector2 textureCoord;
86
87   Vertex()
88   {}
89
90   Vertex( const Vector3& position, const Vector3& normal, const Vector2& textureCoord )
91   : position( position ), normal( normal ), textureCoord( textureCoord )
92   {}
93 };
94
95 /************************************************************************************************
96  *** The shader source is used when the MeshActor is not touched***
97  ************************************************************************************************/
98 const char* VERTEX_SHADER_FLAT = DALI_COMPOSE_SHADER(
99 attribute mediump vec3    aPosition;\n
100 attribute mediump vec3    aNormal;\n
101 attribute highp   vec2    aTexCoord;\n
102 uniform   mediump mat4    uMvpMatrix;\n
103 varying   mediump vec2    vTexCoord;\n
104 void main()\n
105 {\n
106   gl_Position = uMvpMatrix * vec4( aPosition.xy, 0.0, 1.0 );\n
107   vTexCoord = aTexCoord.xy;\n
108 }\n
109 );
110
111 const char* FRAGMENT_SHADER_FLAT = DALI_COMPOSE_SHADER(
112 uniform lowp    vec4  uColor;\n
113 uniform sampler2D     sTexture;\n
114 varying mediump vec2  vTexCoord;\n
115 void main()\n
116 {\n
117   gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n
118 }\n
119 );
120
121 /************************************************************
122  ** Custom refraction effect shader***************************
123  ************************************************************/
124 const char* VERTEX_SHADER_REFRACTION = DALI_COMPOSE_SHADER(
125 attribute mediump vec3    aPosition;\n
126 attribute mediump vec3    aNormal;\n
127 attribute highp   vec2    aTexCoord;\n
128 uniform   mediump mat4    uMvpMatrix;\n
129 varying   mediump vec4    vVertex;\n
130 varying   mediump vec3    vNormal;\n
131 varying   mediump vec2    vTexCoord;\n
132 varying   mediump vec2    vTextureOffset;\n
133 void main()\n
134 {\n
135   gl_Position = uMvpMatrix * vec4( aPosition.xy, 0.0, 1.0 );\n
136   vTexCoord = aTexCoord.xy;\n
137
138   vNormal = aNormal;\n
139   vVertex = vec4( aPosition, 1.0 );\n
140   float length = max(0.01, length(aNormal.xy)) * 40.0;\n
141   vTextureOffset = aNormal.xy / length;\n
142 }\n
143 );
144
145 const char* FRAGMENT_SHADER_REFRACTION = DALI_COMPOSE_SHADER(
146 precision mediump float;\n
147 uniform   mediump float  uEffectStrength;\n
148 uniform   mediump vec3   uLightPosition;\n
149 uniform   mediump vec2   uLightXYOffset;\n
150 uniform   mediump vec2   uLightSpinOffset;\n
151 uniform   mediump float  uLightIntensity;\n
152 uniform   lowp    vec4   uColor;\n
153 uniform   sampler2D      sTexture;\n
154 varying   mediump vec4   vVertex;\n
155 varying   mediump vec3   vNormal;\n
156 varying   mediump vec2   vTexCoord;\n
157 varying   mediump vec2   vTextureOffset;\n
158
159 vec3 rgb2hsl(vec3 rgb)\n
160 {\n
161   float epsilon = 1.0e-10;\n
162   vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n
163   vec4 P = mix(vec4(rgb.bg, K.wz), vec4(rgb.gb, K.xy), step(rgb.b, rgb.g));\n
164   vec4 Q = mix(vec4(P.xyw, rgb.r), vec4(rgb.r, P.yzx), step(P.x, rgb.r));\n
165   \n
166   // RGB -> HCV
167   float value = Q.x;\n
168   float chroma = Q.x - min(Q.w, Q.y);\n
169   float hue = abs(Q.z + (Q.w-Q.y) / (6.0*chroma+epsilon));\n
170   // HCV -> HSL
171   float lightness = value - chroma*0.5;\n
172   return vec3( hue, chroma/max( 1.0-abs(lightness*2.0-1.0), 1.0e-1 ), lightness );\n
173 }\n
174
175 vec3 hsl2rgb( vec3 hsl )\n
176 {\n
177   // pure hue->RGB
178   vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n
179   vec3 p = abs(fract(hsl.xxx + K.xyz) * 6.0 - K.www);\n
180   vec3 RGB = clamp(p - K.xxx, 0.0, 1.0);\n
181   \n
182   float chroma = ( 1.0 - abs( hsl.z*2.0-1.0 ) ) * hsl.y;\n
183   return ( RGB - 0.5 ) * chroma + hsl.z;\n
184 }\n
185
186 void main()\n
187 {\n
188   vec3 normal = normalize( vNormal);\n
189
190   vec3 lightPosition = uLightPosition + vec3(uLightXYOffset+uLightSpinOffset, 0.0);\n
191   mediump vec3 vecToLight = normalize( (lightPosition - vVertex.xyz) * 0.01 );\n
192   mediump float spotEffect = pow( max(0.05, vecToLight.z ) - 0.05, 8.0);\n
193
194   spotEffect = spotEffect * uEffectStrength;\n
195   mediump float lightDiffuse = ( ( dot( vecToLight, normal )-0.75 ) *uLightIntensity  ) * spotEffect;\n
196
197   lowp vec4 color = texture2D( sTexture, vTexCoord + vTextureOffset * spotEffect );\n
198   vec3 lightedColor =  hsl2rgb( rgb2hsl(color.rgb) + vec3(0.0,0.0,lightDiffuse) );\n
199
200   gl_FragColor = vec4( lightedColor, color.a ) * uColor;\n
201 }\n
202 );
203
204 } // namespace
205
206
207 /*************************************************/
208 /*Demo using RefractionEffect*****************/
209 /*************************************************/
210 class RefractionEffectExample : public ConnectionTracker
211 {
212 public:
213   RefractionEffectExample( Application &application )
214   : mApplication( application ),
215     mContent(),
216     mTextureSet(),
217     mGeometry(),
218     mRenderer(),
219     mMeshActor(),
220     mShaderFlat(),
221     mShaderRefraction(),
222     mLightAnimation(),
223     mStrenghAnimation(),
224     mLightXYOffsetIndex( Property::INVALID_INDEX ),
225     mSpinAngleIndex( Property::INVALID_INDEX ),
226     mLightIntensityIndex( Property::INVALID_INDEX ),
227     mEffectStrengthIndex( Property::INVALID_INDEX ),
228     mChangeTextureButton(),
229     mChangeMeshButton(),
230     mCurrentTextureId( 1 ),
231     mCurrentMeshId( 0 )
232   {
233     // Connect to the Application's Init signal
234     application.InitSignal().Connect(this, &RefractionEffectExample::Create);
235   }
236
237   ~RefractionEffectExample()
238   {
239   }
240
241 private:
242
243   // The Init signal is received once (only) during the Application lifetime
244   void Create(Application& application)
245   {
246     Stage stage = Stage::GetCurrent();
247     Vector2 stageSize = stage.GetSize();
248
249     stage.KeyEventSignal().Connect(this, &RefractionEffectExample::OnKeyEvent);
250
251     // Creates a default view with a default tool bar.
252     // The view is added to the stage.
253     Toolkit::ToolBar toolBar;
254     Toolkit::Control    view;
255     mContent = DemoHelper::CreateView( application,
256         view,
257         toolBar,
258         "",
259         TOOLBAR_IMAGE,
260         APPLICATION_TITLE );
261
262     // Add a button to change background. (right of toolbar)
263     mChangeTextureButton = Toolkit::PushButton::New();
264     mChangeTextureButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, CHANGE_TEXTURE_ICON );
265     mChangeTextureButton.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, CHANGE_TEXTURE_ICON_SELECTED );
266     mChangeTextureButton.ClickedSignal().Connect( this, &RefractionEffectExample::OnChangeTexture );
267     toolBar.AddControl( mChangeTextureButton,
268                         DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage,
269                         Toolkit::Alignment::HorizontalRight,
270                         DemoHelper::DEFAULT_MODE_SWITCH_PADDING  );
271     // Add a button to change mesh pattern. ( left of bar )
272     mChangeMeshButton = Toolkit::PushButton::New();
273     mChangeMeshButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, CHANGE_MESH_ICON );
274     mChangeMeshButton.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, CHANGE_MESH_ICON_SELECTED );
275     mChangeMeshButton.ClickedSignal().Connect( this, &RefractionEffectExample::OnChangeMesh );
276     toolBar.AddControl( mChangeMeshButton,
277                         DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage,
278                         Toolkit::Alignment::HorizontalLeft,
279                         DemoHelper::DEFAULT_MODE_SWITCH_PADDING  );
280
281
282
283     // shader used when the screen is not touched, render a flat surface
284     mShaderFlat = Shader::New( VERTEX_SHADER_FLAT, FRAGMENT_SHADER_FLAT );
285     mGeometry = CreateGeometry( MESH_FILES[mCurrentMeshId] );
286
287     Texture texture = DemoHelper::LoadStageFillingTexture( TEXTURE_IMAGES[mCurrentTextureId] );
288     mTextureSet = TextureSet::New();
289     mTextureSet.SetTexture( 0u, texture );
290
291     mRenderer = Renderer::New( mGeometry, mShaderFlat );
292     mRenderer.SetTextures( mTextureSet );
293
294     mMeshActor = Actor::New();
295     mMeshActor.AddRenderer( mRenderer );
296     mMeshActor.SetSize( stageSize );
297     mMeshActor.SetParentOrigin(ParentOrigin::CENTER);
298     mContent.Add( mMeshActor );
299
300     // Connect the callback to the touch signal on the mesh actor
301     mContent.TouchSignal().Connect( this, &RefractionEffectExample::OnTouch );
302
303     // shader used when the finger is touching the screen. render refraction effect
304     mShaderRefraction = Shader::New( VERTEX_SHADER_REFRACTION, FRAGMENT_SHADER_REFRACTION );
305
306     // register uniforms
307     mLightXYOffsetIndex = mMeshActor.RegisterProperty( "uLightXYOffset", Vector2::ZERO );
308
309     mLightIntensityIndex = mMeshActor.RegisterProperty( "uLightIntensity", 2.5f );
310
311     mEffectStrengthIndex = mMeshActor.RegisterProperty( "uEffectStrength",  0.f );
312
313     Vector3 lightPosition( -stageSize.x*0.5f, -stageSize.y*0.5f, stageSize.x*0.5f ); // top_left
314     mMeshActor.RegisterProperty( "uLightPosition", lightPosition );
315
316     Property::Index lightSpinOffsetIndex = mMeshActor.RegisterProperty( "uLightSpinOffset", Vector2::ZERO );
317
318     mSpinAngleIndex = mMeshActor.RegisterProperty("uSpinAngle", 0.f );
319     Constraint constraint = Constraint::New<Vector2>( mMeshActor, lightSpinOffsetIndex, LightOffsetConstraint(stageSize.x*0.1f) );
320     constraint.AddSource( LocalSource(mSpinAngleIndex) );
321     constraint.Apply();
322
323     // the animation which spin the light around the finger touch position
324     mLightAnimation = Animation::New(2.f);
325     mLightAnimation.AnimateTo( Property( mMeshActor, mSpinAngleIndex ), Math::PI*2.f );
326     mLightAnimation.SetLooping( true );
327     mLightAnimation.Pause();
328   }
329
330   void SetLightXYOffset( const Vector2& offset )
331   {
332     mMeshActor.SetProperty( mLightXYOffsetIndex,  offset );
333   }
334
335   /**
336    * Create a mesh actor with different geometry to replace the current one
337    */
338   bool OnChangeMesh( Toolkit::Button button  )
339   {
340     mCurrentMeshId = ( mCurrentMeshId + 1 ) % NUM_MESH_FILES;
341     mGeometry = CreateGeometry( MESH_FILES[mCurrentMeshId] );
342     mRenderer.SetGeometry( mGeometry );
343
344     return true;
345   }
346
347   bool OnChangeTexture( Toolkit::Button button )
348   {
349     mCurrentTextureId = ( mCurrentTextureId + 1 ) % NUM_TEXTURE_IMAGES;
350     Texture texture = DemoHelper::LoadStageFillingTexture( TEXTURE_IMAGES[mCurrentTextureId] );
351     mTextureSet.SetTexture( 0u, texture );
352     return true;
353   }
354
355   bool OnTouch( Actor actor, const TouchData& event )
356   {
357     switch( event.GetState( 0 ) )
358     {
359       case PointState::DOWN:
360       {
361         mRenderer.SetShader( mShaderRefraction );
362
363         SetLightXYOffset( event.GetScreenPosition( 0 ) );
364
365         mLightAnimation.Play();
366
367         if( mStrenghAnimation )
368         {
369           mStrenghAnimation.Clear();
370         }
371
372         mStrenghAnimation= Animation::New(0.5f);
373         mStrenghAnimation.AnimateTo( Property( mMeshActor, mEffectStrengthIndex ), 1.f );
374         mStrenghAnimation.Play();
375
376         break;
377       }
378       case PointState::MOTION:
379       {
380         // make the light position following the finger movement
381         SetLightXYOffset( event.GetScreenPosition( 0 ) );
382         break;
383       }
384       case PointState::UP:
385       case PointState::LEAVE:
386       case PointState::INTERRUPTED:
387       {
388         mLightAnimation.Pause();
389
390         if( mStrenghAnimation )
391         {
392           mStrenghAnimation.Clear();
393         }
394         mStrenghAnimation = Animation::New(0.5f);
395         mStrenghAnimation.AnimateTo( Property( mMeshActor, mEffectStrengthIndex ), 0.f );
396         mStrenghAnimation.FinishedSignal().Connect( this, &RefractionEffectExample::OnTouchFinished );
397         mStrenghAnimation.Play();
398         break;
399       }
400       case PointState::STATIONARY:
401       {
402         break;
403       }
404     }
405
406     return true;
407   }
408
409   void OnTouchFinished( Animation& source )
410   {
411     mRenderer.SetShader( mShaderFlat );
412     SetLightXYOffset( Vector2::ZERO );
413   }
414
415   Geometry CreateGeometry(const std::string& objFileName)
416   {
417     std::vector<Vector3> vertexPositions;
418     Vector<unsigned int> faceIndices;
419     Vector<float> boundingBox;
420     // read the vertice and faces from the .obj file, and record the bounding box
421     ReadObjFile( objFileName, boundingBox, vertexPositions, faceIndices );
422
423     std::vector<Vector2> textureCoordinates;
424     // align the mesh, scale it to fit the screen size, and calculate the texture coordinate for each vertex
425     ShapeResizeAndTexureCoordinateCalculation( boundingBox, vertexPositions, textureCoordinates );
426
427     // re-organize the mesh, the vertices are duplicated, each vertex only belongs to one triangle.
428     // Without sharing vertex between triangle, so we can manipulate the texture offset on each triangle conveniently.
429     std::vector<Vertex> vertices;
430
431     std::size_t size = faceIndices.Size();
432     vertices.reserve( size );
433
434     for( std::size_t i=0; i<size; i=i+3 )
435     {
436       Vector3 edge1 = vertexPositions[ faceIndices[i+2] ] - vertexPositions[ faceIndices[i] ];
437       Vector3 edge2 = vertexPositions[ faceIndices[i+1] ] - vertexPositions[ faceIndices[i] ];
438       Vector3 normal = edge1.Cross(edge2);
439       normal.Normalize();
440
441       // make sure all the faces are front-facing
442       if( normal.z > 0 )
443       {
444         vertices.push_back( Vertex( vertexPositions[ faceIndices[i] ], normal, textureCoordinates[ faceIndices[i] ] ) );
445         vertices.push_back( Vertex( vertexPositions[ faceIndices[i+1] ], normal, textureCoordinates[ faceIndices[i+1] ] ) );
446         vertices.push_back( Vertex( vertexPositions[ faceIndices[i+2] ], normal, textureCoordinates[ faceIndices[i+2] ] ) );
447       }
448       else
449       {
450         normal *= -1.f;
451         vertices.push_back( Vertex( vertexPositions[ faceIndices[i] ], normal, textureCoordinates[ faceIndices[i] ] ) );
452         vertices.push_back( Vertex( vertexPositions[ faceIndices[i+2] ], normal, textureCoordinates[ faceIndices[i+2] ] ) );
453         vertices.push_back( Vertex( vertexPositions[ faceIndices[i+1] ], normal, textureCoordinates[ faceIndices[i+1] ] ) );
454       }
455     }
456
457     Property::Map vertexFormat;
458     vertexFormat["aPosition"] = Property::VECTOR3;
459     vertexFormat["aNormal"] = Property::VECTOR3;
460     vertexFormat["aTexCoord"] = Property::VECTOR2;
461     PropertyBuffer surfaceVertices = PropertyBuffer::New( vertexFormat );
462     surfaceVertices.SetData( &vertices[0], vertices.size() );
463
464     Geometry surface = Geometry::New();
465     surface.AddVertexBuffer( surfaceVertices );
466
467     return surface;
468   }
469
470   void ReadObjFile( const std::string& objFileName,
471       Vector<float>& boundingBox,
472       std::vector<Vector3>& vertexPositions,
473       Vector<unsigned int>& faceIndices)
474   {
475     std::ifstream ifs( objFileName.c_str(), std::ios::in );
476
477     boundingBox.Resize( 6 );
478     boundingBox[0]=boundingBox[2]=boundingBox[4] = std::numeric_limits<float>::max();
479     boundingBox[1]=boundingBox[3]=boundingBox[5] = -std::numeric_limits<float>::max();
480
481     std::string line;
482     while( std::getline( ifs, line ) )
483     {
484       if( line[0] == 'v' && std::isspace(line[1]))  // vertex
485       {
486         std::istringstream iss(line.substr(2), std::istringstream::in);
487         unsigned int i = 0;
488         Vector3 vertex;
489         while( iss >> vertex[i++] && i < 3);
490         if( vertex.x < boundingBox[0] )  boundingBox[0] = vertex.x;
491         if( vertex.x > boundingBox[1] )  boundingBox[1] = vertex.x;
492         if( vertex.y < boundingBox[2] )  boundingBox[2] = vertex.y;
493         if( vertex.y > boundingBox[3] )  boundingBox[3] = vertex.y;
494         if( vertex.z < boundingBox[4] )  boundingBox[4] = vertex.z;
495         if( vertex.z > boundingBox[5] )  boundingBox[5] = vertex.z;
496         vertexPositions.push_back( vertex );
497       }
498       else if( line[0] == 'f' ) //face
499       {
500         unsigned int numOfInt = 3;
501         while( true )
502         {
503           std::size_t found  = line.find('/');
504           if( found == std::string::npos )
505           {
506             break;
507           }
508           line[found] = ' ';
509           numOfInt++;
510         }
511
512         std::istringstream iss(line.substr(2), std::istringstream::in);
513         unsigned int indices[ numOfInt ];
514         unsigned int i=0;
515         while( iss >> indices[i++] && i < numOfInt);
516         unsigned int step = (i+1) / 3;
517         faceIndices.PushBack( indices[0]-1 );
518         faceIndices.PushBack( indices[step]-1 );
519         faceIndices.PushBack( indices[2*step]-1 );
520       }
521     }
522
523     ifs.close();
524   }
525
526   void ShapeResizeAndTexureCoordinateCalculation( const Vector<float>& boundingBox,
527       std::vector<Vector3>& vertexPositions,
528       std::vector<Vector2>& textureCoordinates)
529   {
530     Vector3 bBoxSize( boundingBox[1] - boundingBox[0], boundingBox[3] - boundingBox[2], boundingBox[5] - boundingBox[4]);
531     Vector3 bBoxMinCorner( boundingBox[0], boundingBox[2], boundingBox[4] );
532
533     Vector2 stageSize = Stage::GetCurrent().GetSize();
534     Vector3 scale( stageSize.x / bBoxSize.x, stageSize.y / bBoxSize.y, 1.f );
535     scale.z = (scale.x + scale.y)/2.f;
536
537     textureCoordinates.reserve(vertexPositions.size());
538
539     for( std::vector<Vector3>::iterator iter = vertexPositions.begin(); iter != vertexPositions.end(); iter++ )
540     {
541       Vector3 newPosition(  (*iter) - bBoxMinCorner ) ;
542
543      textureCoordinates.push_back( Vector2( newPosition.x / bBoxSize.x, newPosition.y / bBoxSize.y ) );
544
545       newPosition -= bBoxSize * 0.5f;
546       (*iter) = newPosition * scale;
547     }
548   }
549
550   /**
551    * Main key event handler
552    */
553   void OnKeyEvent(const KeyEvent& event)
554   {
555     if(event.state == KeyEvent::Down)
556     {
557       if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) )
558       {
559         mApplication.Quit();
560       }
561     }
562   }
563
564 private:
565
566   Application&   mApplication;
567   Layer          mContent;
568   TextureSet     mTextureSet;
569   Geometry       mGeometry;
570   Renderer       mRenderer;
571   Actor          mMeshActor;
572
573   Shader         mShaderFlat;
574   Shader         mShaderRefraction;
575
576   Animation      mLightAnimation;
577   Animation      mStrenghAnimation;
578
579   Property::Index mLightXYOffsetIndex;
580   Property::Index mSpinAngleIndex;
581   Property::Index mLightIntensityIndex;
582   Property::Index mEffectStrengthIndex;
583
584   Toolkit::PushButton        mChangeTextureButton;
585   Toolkit::PushButton        mChangeMeshButton;
586   unsigned int               mCurrentTextureId;
587   unsigned int               mCurrentMeshId;
588 };
589
590 /*****************************************************************************/
591
592 static void
593 RunTest(Application& app)
594 {
595   RefractionEffectExample theApp(app);
596   app.MainLoop();
597 }
598
599 /*****************************************************************************/
600
601 int DALI_EXPORT_API main(int argc, char **argv)
602 {
603   Application app = Application::New(&argc, &argv, DEMO_THEME_PATH);
604
605   RunTest(app);
606
607   return 0;
608 }