4d088d1ed1ce6c0df1ad1c0deed3f9992cee3c8f
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / bloom-view / bloom-view-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 "bloom-view-impl.h"
20
21 // EXTERNAL INCLUDES
22 #include <sstream>
23 #include <iomanip>
24 #include <dali/public-api/animation/constraint.h>
25 #include <dali/public-api/animation/constraints.h>
26 #include <dali/public-api/common/stage.h>
27 #include <dali/public-api/object/property-map.h>
28 #include <dali/public-api/object/type-registry.h>
29 #include <dali/devel-api/object/type-registry-helper.h>
30 #include <dali/public-api/render-tasks/render-task-list.h>
31 #include <dali/devel-api/rendering/renderer.h>
32
33 // INTERNAL INCLUDES
34 #include <dali-toolkit/public-api/controls/gaussian-blur-view/gaussian-blur-view.h>
35 #include <dali-toolkit/devel-api/controls/bloom-view/bloom-view.h>
36 #include "../gaussian-blur-view/gaussian-blur-view-impl.h"
37
38 namespace Dali
39 {
40
41 namespace Toolkit
42 {
43
44 namespace Internal
45 {
46
47 namespace
48 {
49
50 using namespace Dali;
51
52 BaseHandle Create()
53 {
54   return Toolkit::BloomView::New();
55 }
56
57 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::BloomView, Toolkit::Control, Create )
58 DALI_TYPE_REGISTRATION_END()
59
60 // default parameters
61 const float BLOOM_THRESHOLD_DEFAULT = 0.25f;
62 const float BLOOM_BLUR_STRENGTH_DEFAULT = 1.0f;
63 const float BLOOM_INTENSITY_DEFAULT = 1.0f;
64 const float IMAGE_INTENSITY_DEFAULT = 1.0f;
65 const float BLOOM_SATURATION_DEFAULT = 1.0f;
66 const float IMAGE_SATURATION_DEFAULT = 1.0f;
67
68 // gaussian blur
69 const unsigned int BLOOM_GAUSSIAN_BLUR_VIEW_DEFAULT_NUM_SAMPLES = 5;
70 const float BLOOM_GAUSSIAN_BLUR_VIEW_DEFAULT_BLUR_BELL_CURVE_WIDTH = 1.5f;
71 const Pixel::Format BLOOM_GAUSSIAN_BLUR_VIEW_DEFAULT_RENDER_TARGET_PIXEL_FORMAT = Pixel::RGBA8888;
72 const float BLOOM_GAUSSIAN_BLUR_VIEW_DEFAULT_BLUR_FADE_IN = 1.0f;                                       // default, fully blurred
73 const float BLOOM_GAUSSIAN_BLUR_VIEW_DEFAULT_DOWNSAMPLE_WIDTH_SCALE = 0.5f;
74 const float BLOOM_GAUSSIAN_BLUR_VIEW_DEFAULT_DOWNSAMPLE_HEIGHT_SCALE = 0.5f;
75
76 const float ARBITRARY_FIELD_OF_VIEW = Math::PI / 4.0f;
77
78 const char* const BLOOM_BLUR_STRENGTH_PROPERTY_NAME = "BlurStrengthProperty";
79 const char* const BLOOM_THRESHOLD_PROPERTY_NAME = "uBloomThreshold";
80 const char* const RECIP_ONE_MINUS_BLOOM_THRESHOLD_PROPERTY_NAME = "uRecipOneMinusBloomThreshold";
81 const char* const BLOOM_INTENSITY_PROPERTY_NAME = "uBloomIntensity";
82 const char* const BLOOM_SATURATION_PROPERTY_NAME = "uBloomSaturation";
83 const char* const IMAGE_INTENSITY_PROPERTY_NAME = "uImageIntensity";
84 const char* const IMAGE_SATURATION_PROPERTY_NAME = "uImageSaturation";
85
86 const char* const EFFECT_IMAGE_NAME( "sEffect" );
87
88 ///////////////////////////////////////////////////////
89 //
90 // Bloom shaders
91 //
92
93 const char* const BLOOM_EXTRACT_FRAGMENT_SOURCE =
94   "varying mediump vec2 vTexCoord;\n"
95   "uniform sampler2D sTexture;\n"
96   "uniform lowp vec4 uColor;\n"
97   "uniform mediump float uBloomThreshold;\n"
98   "uniform mediump float uRecipOneMinusBloomThreshold;\n"
99   "void main()\n"
100   "{\n"
101   "  mediump vec4 col;\n"
102   "  col = texture2D(sTexture, vTexCoord);\n"
103   "  col = (col - uBloomThreshold) * uRecipOneMinusBloomThreshold;\n" // remove intensities lower than the thresold and remap intensities above the threshold to [0..1]
104   "  gl_FragColor = clamp(col, 0.0, 1.0);\n"
105   "}\n";
106
107 const char* const COMPOSITE_FRAGMENT_SOURCE =
108   "precision mediump float;\n"
109   "varying mediump vec2 vTexCoord;\n"
110   "uniform sampler2D sTexture;\n"
111   "uniform sampler2D sEffect;\n"
112   "uniform lowp vec4 uColor;\n"
113   "uniform float uBloomIntensity;\n"
114   "uniform float uImageIntensity;\n"
115   "uniform float uBloomSaturation;\n"
116   "uniform float uImageSaturation;\n"
117
118   "vec4 ChangeSaturation(vec4 col, float sat)\n"
119   "{\n"
120   "  float grey = dot(col.rgb, vec3(0.3, 0.6, 0.1));\n"
121   "  return mix(vec4(grey, grey, grey, 1.0), col, sat);\n"
122   "}\n"
123
124   "void main()\n"
125   "{\n"
126   "  mediump vec4 image;\n"
127   "  mediump vec4 bloom;\n"
128   "  image = texture2D(sTexture, vTexCoord);\n"
129   "  bloom = texture2D(sEffect, vTexCoord);\n"
130   "  image = ChangeSaturation(image, uImageSaturation) * uImageIntensity;\n"
131   "  bloom = ChangeSaturation(bloom, uBloomSaturation) * uBloomIntensity;\n"
132   "  image *= 1.0 - clamp(bloom, 0.0, 1.0);\n" // darken base where bloom is strong, to prevent excessive burn-out of result
133   "  gl_FragColor = image + bloom;\n"
134   "}\n";
135
136 } // namespace
137
138
139
140 BloomView::BloomView()
141   : Control( ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) )
142   , mBlurNumSamples(BLOOM_GAUSSIAN_BLUR_VIEW_DEFAULT_NUM_SAMPLES)
143   , mBlurBellCurveWidth(BLOOM_GAUSSIAN_BLUR_VIEW_DEFAULT_BLUR_BELL_CURVE_WIDTH)
144   , mPixelFormat(BLOOM_GAUSSIAN_BLUR_VIEW_DEFAULT_RENDER_TARGET_PIXEL_FORMAT)
145   , mDownsampleWidthScale(BLOOM_GAUSSIAN_BLUR_VIEW_DEFAULT_DOWNSAMPLE_WIDTH_SCALE)
146   , mDownsampleHeightScale(BLOOM_GAUSSIAN_BLUR_VIEW_DEFAULT_DOWNSAMPLE_HEIGHT_SCALE)
147   , mDownsampledWidth( 0.0f )
148   , mDownsampledHeight( 0.0f )
149   , mTargetSize(Vector2::ZERO)
150   , mLastSize(Vector2::ZERO)
151   , mChildrenRoot(Actor::New())
152   , mInternalRoot(Actor::New() )
153   , mBloomThresholdPropertyIndex(Property::INVALID_INDEX)
154   , mBlurStrengthPropertyIndex(Property::INVALID_INDEX)
155   , mBloomIntensityPropertyIndex(Property::INVALID_INDEX)
156   , mBloomSaturationPropertyIndex(Property::INVALID_INDEX)
157   , mImageIntensityPropertyIndex(Property::INVALID_INDEX)
158   , mImageSaturationPropertyIndex(Property::INVALID_INDEX)
159   , mActivated( false )
160 {
161 }
162
163 BloomView::BloomView( const unsigned int blurNumSamples, const float blurBellCurveWidth, const Pixel::Format renderTargetPixelFormat,
164                                     const float downsampleWidthScale, const float downsampleHeightScale)
165   : Control( ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) )
166   , mBlurNumSamples(blurNumSamples)
167   , mBlurBellCurveWidth(blurBellCurveWidth)
168   , mPixelFormat(renderTargetPixelFormat)
169   , mDownsampleWidthScale(downsampleWidthScale)
170   , mDownsampleHeightScale(downsampleHeightScale)
171   , mDownsampledWidth( 0.0f )
172   , mDownsampledHeight( 0.0f )
173   , mTargetSize(Vector2::ZERO)
174   , mLastSize(Vector2::ZERO)
175   , mChildrenRoot(Actor::New())
176   , mInternalRoot(Actor::New())
177   , mBloomThresholdPropertyIndex(Property::INVALID_INDEX)
178   , mBlurStrengthPropertyIndex(Property::INVALID_INDEX)
179   , mBloomIntensityPropertyIndex(Property::INVALID_INDEX)
180   , mBloomSaturationPropertyIndex(Property::INVALID_INDEX)
181   , mImageIntensityPropertyIndex(Property::INVALID_INDEX)
182   , mImageSaturationPropertyIndex(Property::INVALID_INDEX)
183   , mActivated( false )
184 {
185 }
186
187 BloomView::~BloomView()
188 {
189 }
190
191 Toolkit::BloomView BloomView::New()
192 {
193   BloomView* impl = new BloomView();
194
195   Dali::Toolkit::BloomView handle = Dali::Toolkit::BloomView( *impl );
196
197   // Second-phase init of the implementation
198   // This can only be done after the CustomActor connection has been made...
199   impl->Initialize();
200
201   return handle;
202 }
203
204 Toolkit::BloomView BloomView::New(const unsigned int blurNumSamples, const float blurBellCurveWidth, const Pixel::Format renderTargetPixelFormat,
205                                                 const float downsampleWidthScale, const float downsampleHeightScale)
206 {
207   BloomView* impl = new BloomView( blurNumSamples, blurBellCurveWidth, renderTargetPixelFormat, downsampleWidthScale, downsampleHeightScale);
208
209   Dali::Toolkit::BloomView handle = Dali::Toolkit::BloomView( *impl );
210
211   // Second-phase init of the implementation
212   // This can only be done after the CustomActor connection has been made...
213   impl->Initialize();
214
215   return handle;
216 }
217
218 ///////////////////////////////////////////////////////////
219 //
220 // Private methods
221 //
222
223 void BloomView::OnInitialize()
224 {
225   // root actor to parent all user added actors, needed to allow us to set that subtree as exclusive for our child render task
226   mChildrenRoot.SetParentOrigin( ParentOrigin::CENTER );
227   mInternalRoot.SetParentOrigin( ParentOrigin::CENTER );
228
229   //////////////////////////////////////////////////////
230   // Create actors
231
232   // Create an ImageActor for rendering from the scene texture to the bloom texture
233   mBloomExtractImageActor = Toolkit::ImageView::New();
234   mBloomExtractImageActor.SetParentOrigin( ParentOrigin::CENTER );
235
236   // Create shader used for extracting the bright parts of an image
237   Property::Map customShader;
238   customShader[ "fragmentShader" ] = BLOOM_EXTRACT_FRAGMENT_SOURCE;
239   Property::Map rendererMap;
240   rendererMap.Insert( "rendererType", "image" );
241   rendererMap.Insert( "shader", customShader );
242   mBloomExtractImageActor.SetProperty( Toolkit::ImageView::Property::IMAGE, rendererMap );
243
244   // Create an ImageActor for compositing the result (scene and bloom textures) to output
245   mCompositeImageActor = Toolkit::ImageView::New();
246   mCompositeImageActor.SetParentOrigin( ParentOrigin::CENTER );
247
248   // Create shader used to composite bloom and original image to output render target
249   customShader[ "fragmentShader" ] = COMPOSITE_FRAGMENT_SOURCE;
250   rendererMap[ "shader" ] = customShader;
251   mCompositeImageActor.SetProperty( Toolkit::ImageView::Property::IMAGE, rendererMap );
252
253   // Create an ImageActor for holding final result, i.e. the blurred image. This will get rendered to screen later, via default / user render task
254   mTargetImageActor = Toolkit::ImageView::New();
255   mTargetImageActor.SetParentOrigin( ParentOrigin::CENTER );
256
257   // Create the Gaussian Blur object + render tasks
258   // Note that we use mBloomExtractTarget as the source image and also re-use this as the gaussian blur final render target. This saves the gaussian blur code from creating it
259   // render targets etc internally, so we make better use of resources
260   // Note, this also internally creates the render tasks used by the Gaussian blur, this must occur after the bloom extraction and before the compositing
261   mGaussianBlurView = Dali::Toolkit::GaussianBlurView::New(mBlurNumSamples, mBlurBellCurveWidth, mPixelFormat, mDownsampleWidthScale, mDownsampleHeightScale, true);
262   mGaussianBlurView.SetParentOrigin( ParentOrigin::CENTER );
263
264
265   //////////////////////////////////////////////////////
266   // Create cameras for the renders corresponding to the (potentially downsampled) render targets' size
267   mRenderDownsampledCamera = CameraActor::New();
268   mRenderDownsampledCamera.SetParentOrigin(ParentOrigin::CENTER);
269   mRenderDownsampledCamera.SetInvertYAxis( true );
270
271   mRenderFullSizeCamera = CameraActor::New();
272   mRenderFullSizeCamera.SetParentOrigin(ParentOrigin::CENTER);
273   mRenderFullSizeCamera.SetInvertYAxis( true );
274
275
276   ////////////////////////////////
277   // Connect to actor tree
278   Self().Add( mChildrenRoot );
279   Self().Add( mInternalRoot );
280   mInternalRoot.Add( mBloomExtractImageActor );
281   mInternalRoot.Add( mGaussianBlurView );
282   mInternalRoot.Add( mCompositeImageActor );
283   mInternalRoot.Add( mTargetImageActor );
284   mInternalRoot.Add( mRenderDownsampledCamera );
285   mInternalRoot.Add( mRenderFullSizeCamera );
286
287   // bind properties for / set shader constants to defaults
288   SetupProperties();
289 }
290
291 void BloomView::OnSizeSet(const Vector3& targetSize)
292 {
293   mTargetSize = Vector2(targetSize);
294   mChildrenRoot.SetSize(targetSize);
295   mCompositeImageActor.SetSize(targetSize);
296   mTargetImageActor.SetSize(targetSize);
297
298   // Children render camera must move when GaussianBlurView object is
299   // resized. This is since we cannot change render target size - so we need
300   // to remap the child actors' rendering accordingly so they still exactly
301   // fill the render target. Note that this means the effective resolution of
302   // the child render changes as the GaussianBlurView object changes size,
303   // this is the trade off for not being able to modify render target size
304   // Change camera z position based on GaussianBlurView actor height
305   float cameraPosConstraintScale = 0.5f / tanf(ARBITRARY_FIELD_OF_VIEW * 0.5f);
306   mRenderFullSizeCamera.SetZ( mTargetSize.height * cameraPosConstraintScale);
307
308   // if we have already activated the blur, need to update render target sizes now to reflect the new size of this actor
309   if(mActivated)
310   {
311     Deactivate();
312     Activate();
313   }
314 }
315
316 void BloomView::OnControlChildAdd( Actor& child )
317 {
318   if( child != mChildrenRoot && child != mInternalRoot)
319   {
320     mChildrenRoot.Add( child );
321   }
322 }
323
324 void BloomView::OnControlChildRemove( Actor& child )
325 {
326   mChildrenRoot.Remove( child );
327 }
328
329 void BloomView::AllocateResources()
330 {
331   // size of render targets etc is based on the size of this actor, ignoring z
332   if(mTargetSize != mLastSize || !mActivated)
333   {
334     mLastSize = mTargetSize;
335
336     // get size of downsampled render targets
337     mDownsampledWidth = mTargetSize.width * mDownsampleWidthScale;
338     mDownsampledHeight = mTargetSize.height * mDownsampleHeightScale;
339
340
341     //////////////////////////////////////////////////////
342     // Create cameras
343
344     // Create and place a camera for the renders corresponding to the (potentially downsampled) render targets' size
345     mRenderDownsampledCamera.SetFieldOfView(ARBITRARY_FIELD_OF_VIEW);
346     // TODO: how do we pick a reasonable value for near clip? Needs to relate to normal camera the user renders with, but we don't have a handle on it
347     mRenderDownsampledCamera.SetNearClippingPlane(1.0f);
348     mRenderDownsampledCamera.SetAspectRatio(mDownsampledWidth / mDownsampledHeight);
349     mRenderDownsampledCamera.SetType(Dali::Camera::FREE_LOOK); // camera orientation based solely on actor
350
351     mRenderDownsampledCamera.SetPosition(0.0f, 0.0f, ((mDownsampledHeight * 0.5f) / tanf(ARBITRARY_FIELD_OF_VIEW * 0.5f)));
352
353     // Create and place a camera for the children render, corresponding to its render target size
354     mRenderFullSizeCamera.SetFieldOfView(ARBITRARY_FIELD_OF_VIEW);
355     // TODO: how do we pick a reasonable value for near clip? Needs to relate to normal camera the user renders with, but we don't have a handle on it
356     mRenderFullSizeCamera.SetNearClippingPlane(1.0f);
357     mRenderFullSizeCamera.SetAspectRatio(mTargetSize.width / mTargetSize.height);
358     mRenderFullSizeCamera.SetType(Dali::Camera::FREE_LOOK); // camera orientation based solely on actor
359
360     float cameraPosConstraintScale = 0.5f / tanf(ARBITRARY_FIELD_OF_VIEW * 0.5f);
361     mRenderFullSizeCamera.SetPosition(0.0f, 0.0f, mTargetSize.height * cameraPosConstraintScale);
362
363     //////////////////////////////////////////////////////
364     // Pass size change onto GaussianBlurView, so it matches
365     mGaussianBlurView.SetSize(mTargetSize);
366     GetImpl(mGaussianBlurView).AllocateResources();
367
368
369     //////////////////////////////////////////////////////
370     // Create render targets
371
372     // create off screen buffer of new size to render our child actors to
373     mRenderTargetForRenderingChildren = FrameBufferImage::New( mTargetSize.width, mTargetSize.height, mPixelFormat, Dali::Image::UNUSED );
374     mBloomExtractTarget = FrameBufferImage::New( mDownsampledWidth, mDownsampledHeight, mPixelFormat, Dali::Image::UNUSED );
375     FrameBufferImage mBlurExtractTarget = FrameBufferImage::New( mDownsampledWidth, mDownsampledHeight, mPixelFormat, Dali::Image::UNUSED );
376     mOutputRenderTarget = FrameBufferImage::New( mTargetSize.width, mTargetSize.height, mPixelFormat, Dali::Image::UNUSED);
377
378
379     //////////////////////////////////////////////////////
380     // Point actors and render tasks at new render targets
381
382     mBloomExtractImageActor.SetImage( mRenderTargetForRenderingChildren );
383     mBloomExtractImageActor.SetSize(mDownsampledWidth, mDownsampledHeight); // size needs to match render target
384
385     // set GaussianBlurView to blur our extracted bloom
386     mGaussianBlurView.SetUserImageAndOutputRenderTarget(mBloomExtractTarget, mBlurExtractTarget);
387
388     // use the completed blur in the first buffer and composite with the original child actors render
389     mCompositeImageActor.SetImage( mRenderTargetForRenderingChildren );
390     Material material = mCompositeImageActor.GetRendererAt(0).GetMaterial();
391     int textureIndex = material.GetTextureIndex( EFFECT_IMAGE_NAME );
392     if( textureIndex == -1 )
393     {
394       material.AddTexture( mBlurExtractTarget, EFFECT_IMAGE_NAME );
395     }
396     else
397     {
398       material.SetTextureImage( textureIndex, mBlurExtractTarget );
399     }
400
401     // set up target actor for rendering result, i.e. the blurred image
402     mTargetImageActor.SetImage(mOutputRenderTarget);
403   }
404 }
405
406 void BloomView::CreateRenderTasks()
407 {
408   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
409
410   // create render task to render our child actors to offscreen buffer
411   mRenderChildrenTask = taskList.CreateTask();
412   mRenderChildrenTask.SetSourceActor( mChildrenRoot );
413   mRenderChildrenTask.SetExclusive(true);
414   mRenderChildrenTask.SetInputEnabled( false );
415   mRenderChildrenTask.SetClearEnabled( true );
416   mRenderChildrenTask.SetCameraActor(mRenderFullSizeCamera); // use camera that covers render target exactly
417   mRenderChildrenTask.SetTargetFrameBuffer( mRenderTargetForRenderingChildren );
418
419   // Extract the bright part of the image and render to a new buffer. Downsampling also occurs at this stage to save pixel fill, if it is set up.
420   mBloomExtractTask = taskList.CreateTask();
421   mBloomExtractTask.SetSourceActor( mBloomExtractImageActor );
422   mBloomExtractTask.SetExclusive(true);
423   mBloomExtractTask.SetInputEnabled( false );
424   mBloomExtractTask.SetClearEnabled( true );
425   mBloomExtractTask.SetCameraActor(mRenderDownsampledCamera);
426   mBloomExtractTask.SetTargetFrameBuffer( mBloomExtractTarget );
427
428   // GaussianBlurView tasks must be created here, so they are executed in the correct order with respect to BloomView tasks
429   GetImpl(mGaussianBlurView).CreateRenderTasks();
430
431   // Use an image actor displaying the children render and composite it with the blurred bloom buffer, targeting the output
432   mCompositeTask = taskList.CreateTask();
433   mCompositeTask.SetSourceActor( mCompositeImageActor );
434   mCompositeTask.SetExclusive(true);
435   mCompositeTask.SetInputEnabled( false );
436   mCompositeTask.SetClearEnabled( true );
437   mCompositeTask.SetCameraActor(mRenderFullSizeCamera);
438   mCompositeTask.SetTargetFrameBuffer( mOutputRenderTarget );
439 }
440
441 void BloomView::RemoveRenderTasks()
442 {
443   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
444
445   taskList.RemoveTask(mRenderChildrenTask);
446   taskList.RemoveTask(mBloomExtractTask);
447
448   GetImpl(mGaussianBlurView).RemoveRenderTasks();
449
450   taskList.RemoveTask(mCompositeTask);
451 }
452
453 void BloomView::Activate()
454 {
455   // make sure resources are allocated and start the render tasks processing
456   AllocateResources();
457   CreateRenderTasks();
458   mActivated = true;
459 }
460
461 void BloomView::Deactivate()
462 {
463   // stop render tasks processing
464   // Note: render target resources are automatically freed since we set the Image::Unused flag
465   RemoveRenderTasks();
466   mRenderTargetForRenderingChildren.Reset();
467   mBloomExtractTarget.Reset();
468   mOutputRenderTarget.Reset();
469   mActivated = false;
470 }
471
472 /**
473  * RecipOneMinusConstraint
474  *
475  * f(current, property) = property
476  */
477 struct RecipOneMinusConstraint
478 {
479   RecipOneMinusConstraint(){}
480
481   void operator()( float& current, const PropertyInputContainer& inputs )
482   {
483     current = 1.0f / ( 1.0f - inputs[0]->GetFloat() );
484   }
485 };
486
487 // create properties and constraints to tie internal shader etc settings to BloomView object. User can therefore animate / set them via BloomView object without knowing about
488 // internal implementation classes
489 void BloomView::SetupProperties()
490 {
491   CustomActor self = Self();
492
493
494   ///////////////////////////////////////////
495   // bloom threshold
496
497   // set defaults, makes sure properties are registered with shader
498   mBloomExtractImageActor.RegisterProperty( BLOOM_THRESHOLD_PROPERTY_NAME, BLOOM_THRESHOLD_DEFAULT );
499   mBloomExtractImageActor.RegisterProperty( RECIP_ONE_MINUS_BLOOM_THRESHOLD_PROPERTY_NAME, 1.0f / (1.0f - BLOOM_THRESHOLD_DEFAULT) );
500
501   // Register a property that the user can control to change the bloom threshold
502   mBloomThresholdPropertyIndex = self.RegisterProperty(BLOOM_THRESHOLD_PROPERTY_NAME, BLOOM_THRESHOLD_DEFAULT);
503   Property::Index shaderBloomThresholdPropertyIndex = mBloomExtractImageActor.GetPropertyIndex(BLOOM_THRESHOLD_PROPERTY_NAME);
504   Constraint bloomThresholdConstraint = Constraint::New<float>( mBloomExtractImageActor, shaderBloomThresholdPropertyIndex, EqualToConstraint());
505   bloomThresholdConstraint.AddSource( Source(self, mBloomThresholdPropertyIndex) );
506   bloomThresholdConstraint.Apply();
507
508   // precalc 1.0 / (1.0 - threshold) on CPU to save shader insns, using constraint to tie to the normal threshold property
509   Property::Index shaderRecipOneMinusBloomThresholdPropertyIndex = mBloomExtractImageActor.GetPropertyIndex(RECIP_ONE_MINUS_BLOOM_THRESHOLD_PROPERTY_NAME);
510   Constraint thresholdConstraint = Constraint::New<float>( mBloomExtractImageActor, shaderRecipOneMinusBloomThresholdPropertyIndex, RecipOneMinusConstraint());
511   thresholdConstraint.AddSource( LocalSource(shaderBloomThresholdPropertyIndex) );
512   thresholdConstraint.Apply();
513
514
515   ////////////////////////////////////////////
516   // bloom strength
517
518   // Register a property that the user can control to fade the blur in / out via internal GaussianBlurView object
519   mBlurStrengthPropertyIndex = self.RegisterProperty(BLOOM_BLUR_STRENGTH_PROPERTY_NAME, BLOOM_BLUR_STRENGTH_DEFAULT);
520   Constraint blurStrengthConstraint = Constraint::New<float>( mGaussianBlurView, mGaussianBlurView.GetBlurStrengthPropertyIndex(), EqualToConstraint());
521   blurStrengthConstraint.AddSource( Source(self, mBlurStrengthPropertyIndex) );
522   blurStrengthConstraint.Apply();
523
524
525   ////////////////////////////////////////////
526   // bloom intensity
527
528   // Register a property that the user can control to fade the bloom intensity via internally hidden shader
529   mBloomIntensityPropertyIndex = self.RegisterProperty(BLOOM_INTENSITY_PROPERTY_NAME, BLOOM_INTENSITY_DEFAULT);
530   mCompositeImageActor.RegisterProperty( BLOOM_INTENSITY_PROPERTY_NAME, BLOOM_INTENSITY_DEFAULT );
531   Property::Index shaderBloomIntensityPropertyIndex = mCompositeImageActor.GetPropertyIndex(BLOOM_INTENSITY_PROPERTY_NAME);
532   Constraint bloomIntensityConstraint = Constraint::New<float>( mCompositeImageActor, shaderBloomIntensityPropertyIndex, EqualToConstraint());
533   bloomIntensityConstraint.AddSource( Source(self, mBloomIntensityPropertyIndex) );
534   bloomIntensityConstraint.Apply();
535
536
537   ////////////////////////////////////////////
538   // bloom saturation
539
540   // Register a property that the user can control to fade the bloom saturation via internally hidden shader
541   mBloomSaturationPropertyIndex = self.RegisterProperty(BLOOM_SATURATION_PROPERTY_NAME, BLOOM_SATURATION_DEFAULT);
542   mCompositeImageActor.RegisterProperty( BLOOM_SATURATION_PROPERTY_NAME, BLOOM_SATURATION_DEFAULT );
543   Property::Index shaderBloomSaturationPropertyIndex = mCompositeImageActor.GetPropertyIndex(BLOOM_SATURATION_PROPERTY_NAME);
544   Constraint bloomSaturationConstraint = Constraint::New<float>( mCompositeImageActor, shaderBloomSaturationPropertyIndex, EqualToConstraint());
545   bloomSaturationConstraint.AddSource( Source(self, mBloomSaturationPropertyIndex) );
546   bloomSaturationConstraint.Apply();
547
548
549   ////////////////////////////////////////////
550   // image intensity
551
552   // Register a property that the user can control to fade the image intensity via internally hidden shader
553   mImageIntensityPropertyIndex = self.RegisterProperty(IMAGE_INTENSITY_PROPERTY_NAME, IMAGE_INTENSITY_DEFAULT);
554   mCompositeImageActor.RegisterProperty( IMAGE_INTENSITY_PROPERTY_NAME, IMAGE_INTENSITY_DEFAULT );
555   Property::Index shaderImageIntensityPropertyIndex = mCompositeImageActor.GetPropertyIndex(IMAGE_INTENSITY_PROPERTY_NAME);
556   Constraint imageIntensityConstraint = Constraint::New<float>( mCompositeImageActor, shaderImageIntensityPropertyIndex, EqualToConstraint());
557   imageIntensityConstraint.AddSource( Source(self, mImageIntensityPropertyIndex) );
558   imageIntensityConstraint.Apply();
559
560
561   ////////////////////////////////////////////
562   // image saturation
563
564   // Register a property that the user can control to fade the image saturation via internally hidden shader
565   mImageSaturationPropertyIndex = self.RegisterProperty(IMAGE_SATURATION_PROPERTY_NAME, IMAGE_SATURATION_DEFAULT);
566   mCompositeImageActor.RegisterProperty( IMAGE_SATURATION_PROPERTY_NAME, IMAGE_SATURATION_DEFAULT );
567   Property::Index shaderImageSaturationPropertyIndex = mCompositeImageActor.GetPropertyIndex(IMAGE_SATURATION_PROPERTY_NAME);
568   Constraint imageSaturationConstraint = Constraint::New<float>( mCompositeImageActor, shaderImageSaturationPropertyIndex, EqualToConstraint());
569   imageSaturationConstraint.AddSource( Source(self, mImageSaturationPropertyIndex) );
570   imageSaturationConstraint.Apply();
571 }
572
573 } // namespace Internal
574
575 } // namespace Toolkit
576
577 } // namespace Dali