update bubble-emitter to use new mesh
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / bubble-effect / color-adjuster.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_COLOR_ADJUSTER_H_
2 #define __DALI_TOOLKIT_INTERNAL_COLOR_ADJUSTER_H_
3
4 /*
5  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20 #include <dali/public-api/math/vector3.h>
21 #include <dali/public-api/shader-effects/shader-effect.h>
22
23 namespace Dali
24 {
25
26 namespace Toolkit
27 {
28
29 namespace Internal
30 {
31
32 /**
33 * Creates a new ColorAdjuster effect.
34 * ColorAdjuster is a custom shader effect to adjust the image color in HSV space.
35 * @param[in] hsvDelta The color difference to apply to the HSV channel.
36 * @param[in] ignoreAlpha If true, the result color will be opaque even though source has alpha value
37 * @return A handle to a newly allocated Dali resource.
38 */
39 inline ShaderEffect CreateColorAdjuster( const Vector3& hsvDelta, bool ignoreAlpha = false )
40 {
41   std::string fragmentShader = DALI_COMPOSE_SHADER(
42     precision highp float;\n
43     uniform vec3 uHSVDelta;\n
44     uniform float uIgnoreAlpha;\n
45     float rand(vec2 co) \n
46     {\n
47       return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); \n}
48     \n
49     vec3 rgb2hsv(vec3 c)\n
50     {\n
51       vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n
52       vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n
53       vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n
54       \n
55       float d = q.x - min(q.w, q.y);\n
56       float e = 1.0e-10;\n
57       return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n
58     }\n
59     vec3 hsv2rgb(vec3 c)\n
60     {\n
61       vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n
62       vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n
63       return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n
64     }\n
65     void main() {\n
66       vec4 color = texture2D(sTexture, vTexCoord); \n
67       vec3 hsvColor = rgb2hsv( color.rgb );\n
68       // modify the hsv Value
69       hsvColor += uHSVDelta * rand(vTexCoord); \n
70       // if the new vale exceeds one, then decrease it
71       hsvColor -= max(hsvColor*2.0 - vec3(2.0), 0.0);\n
72       // if the new vale drops below zero, then increase it
73       hsvColor -= min(hsvColor*2.0, 0.0);\n
74       color.rgb = hsv2rgb( hsvColor ); \n
75       // uIgnoreAlpha decide the result alpha will be 1.0 or source's alpha
76       color.a += uIgnoreAlpha;\n
77       gl_FragColor = color; \n
78     }\n
79   );
80
81   ShaderEffect shaderEffect = ShaderEffect::New("", fragmentShader);
82   shaderEffect.SetUniform( "uHSVDelta", hsvDelta );
83   shaderEffect.SetUniform( "uIgnoreAlpha", ignoreAlpha?1.0f:0.0f );
84
85   return shaderEffect;
86 }
87
88 } // namespace Internal
89
90 } // namespace Toolkit
91
92 } // namespace Dali
93
94 #endif /* __DALI_TOOLKIT_INTERNAL_COLOR_ADJUSTER_H_ */