Commit 396d6abe098c199fb715df1820caad8bf4fb97aa

Authored by David Steele
1 parent 7ee9a52a

Added animated uniforms to mesh example

Change-Id: Ie04949472ff608b4a83a34e511e352ce693af453
Showing 1 changed file with 52 additions and 3 deletions
examples/mesh/mesh-example.cpp
... ... @@ -36,6 +36,7 @@ attribute highp vec2 aTexCoord;
36 36 varying mediump vec2 vTexCoord;
37 37 uniform mediump mat4 uMvpMatrix;
38 38 uniform mediump vec3 uSize;
  39 +uniform lowp vec4 uFadeColor;
39 40  
40 41 void main()
41 42 {
... ... @@ -51,10 +52,11 @@ const char* FRAGMENT_SHADER = MAKE_SHADER(
51 52 varying mediump vec2 vTexCoord;
52 53 uniform lowp vec4 uColor;
53 54 uniform sampler2D sTexture;
  55 +uniform lowp vec4 uFadeColor;
54 56  
55 57 void main()
56 58 {
57   - gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;
  59 + gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor * uFadeColor;
58 60 }
59 61 );
60 62  
... ... @@ -101,7 +103,6 @@ public:
101 103 // Hide the indicator bar
102 104 application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE );
103 105  
104   -
105 106 mImage = ResourceImage::New( MATERIAL_SAMPLE );
106 107 mSampler = Sampler::New( mImage, "sTexture");
107 108 mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER );
... ... @@ -110,14 +111,60 @@ public:
110 111 mMaterial.AddSampler( mSampler );
111 112  
112 113 mGeometry = Geometry::New(); // Don't need to set a vertex buffer - it's a quad by default.
  114 +
113 115 mRenderer = Renderer::New( mGeometry, mMaterial );
114 116  
115 117 mMeshActor = Actor::New();
116 118 mMeshActor.AddRenderer( mRenderer );
117 119 mMeshActor.SetSize(400, 400);
118   - mMeshActor.SetParentOrigin( ParentOrigin::CENTER );
  120 +
  121 + Property::Index fadeColorIndex = mMeshActor.RegisterProperty( "fade-color", Color::GREEN );
  122 + mMeshActor.AddUniformMapping( fadeColorIndex, std::string("uFadeColor") );
  123 +
  124 + fadeColorIndex = mRenderer.RegisterProperty( "fade-color", Color::MAGENTA );
  125 + mRenderer.AddUniformMapping( fadeColorIndex, std::string("uFadeColor" ) );
  126 + mRenderer.SetDepthIndex(0);
  127 +
  128 + mMeshActor.SetParentOrigin( ParentOrigin::TOP_CENTER );
  129 + mMeshActor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
119 130 stage.Add( mMeshActor );
120 131  
  132 +
  133 + mRenderer2 = Renderer::New( mGeometry, mMaterial );
  134 +
  135 + mMeshActor2 = Actor::New();
  136 + mMeshActor2.AddRenderer( mRenderer2 );
  137 + mMeshActor2.SetSize(400, 400);
  138 +
  139 + mMeshActor2.RegisterProperty( "a-n-other-property", Color::GREEN );
  140 + Property::Index fadeColorIndex2 = mMeshActor2.RegisterProperty( "another-fade-color", Color::GREEN );
  141 + mMeshActor2.AddUniformMapping( fadeColorIndex2, std::string("uFadeColor") );
  142 +
  143 + mRenderer2.RegisterProperty( "a-n-other-property", Vector3::ZERO );
  144 + mRenderer2.RegisterProperty( "winning-formula", 8008.135f );
  145 + fadeColorIndex2 = mRenderer2.RegisterProperty( "another-fade-color", Color::GREEN );
  146 + mRenderer2.AddUniformMapping( fadeColorIndex2, std::string("uFadeColor" ) );
  147 + mRenderer2.SetDepthIndex(0);
  148 +
  149 + mMeshActor2.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
  150 + mMeshActor2.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
  151 + stage.Add( mMeshActor2 );
  152 +
  153 +
  154 + Animation animation = Animation::New(5);
  155 + KeyFrames keyFrames = KeyFrames::New();
  156 + keyFrames.Add(0.0f, Vector4::ZERO);
  157 + keyFrames.Add(1.0f, Vector4( 1.0f, 0.0f, 1.0f, 1.0f ));
  158 +
  159 + KeyFrames keyFrames2 = KeyFrames::New();
  160 + keyFrames2.Add(0.0f, Vector4::ZERO);
  161 + keyFrames2.Add(1.0f, Color::GREEN);
  162 +
  163 + animation.AnimateBetween( Property( mRenderer, fadeColorIndex ), keyFrames, AlphaFunctions::Sin );
  164 + animation.AnimateBetween( Property( mRenderer2, fadeColorIndex2 ), keyFrames2, AlphaFunctions::Sin2x );
  165 + animation.SetLooping(true);
  166 + animation.Play();
  167 +
121 168 stage.SetBackgroundColor(Vector4(0.0f, 0.2f, 0.2f, 1.0f));;
122 169 }
123 170  
... ... @@ -155,6 +202,8 @@ private:
155 202 Geometry mGeometry;
156 203 Renderer mRenderer;
157 204 Actor mMeshActor;
  205 + Renderer mRenderer2;
  206 + Actor mMeshActor2;
158 207 };
159 208  
160 209 void RunTest( Application& application )
... ...