[dali_2.1.31] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / graphics / shaders / text-visual-shader.frag
1 INPUT mediump vec2 vTexCoord;
2 uniform sampler2D sTexture;
3 #ifdef IS_REQUIRED_STYLE
4 uniform sampler2D sStyle;
5 #endif
6 #ifdef IS_REQUIRED_OVERLAY
7 uniform sampler2D sOverlayStyle;
8 #endif
9 #ifdef IS_REQUIRED_MULTI_COLOR
10 #elif defined(IS_REQUIRED_EMOJI)
11 // Single color with emoji.
12 uniform sampler2D sMask;
13 uniform lowp float uHasMultipleTextColors;
14 #endif
15 uniform lowp vec4 uTextColorAnimatable;
16 uniform lowp vec4 uColor;
17 uniform lowp vec3 mixColor;
18
19 void main()
20 {
21 #ifdef IS_REQUIRED_STYLE
22   mediump vec4 styleTexture = TEXTURE( sStyle, vTexCoord );
23 #endif
24
25 #ifdef IS_REQUIRED_OVERLAY
26   mediump vec4 overlayStyleTexture = TEXTURE( sOverlayStyle, vTexCoord );
27 #endif
28
29 #if defined(IS_REQUIRED_MULTI_COLOR) || defined(IS_REQUIRED_EMOJI)
30   // Multiple color or use emoji.
31   mediump vec4 textColor = TEXTURE(sTexture, vTexCoord);
32
33 #ifdef IS_REQUIRED_MULTI_COLOR
34 #elif defined(IS_REQUIRED_EMOJI)
35   // Single color with emoji.
36   mediump float maskTexture = TEXTURE(sMask, vTexCoord).r;
37
38   // Set the color of non-transparent pixel in text to what it is animated to.
39   // Markup text with multiple text colors are not animated (but can be supported later on if required).
40   // Emoji color are not animated.
41   mediump float vstep = step( 0.0001, textColor.a );
42   textColor.rgb = mix(textColor.rgb, uTextColorAnimatable.rgb, vstep * maskTexture * (1.0 - uHasMultipleTextColors));
43 #endif
44 #else
45   // Single color without emoji.
46   mediump float textTexture = TEXTURE(sTexture, vTexCoord).r;
47   mediump vec4 textColor = uTextColorAnimatable * textTexture;
48 #endif
49
50   // Draw the text as overlay above the style
51   OUT_COLOR = uColor * vec4(mixColor, 1.0) * (
52 #ifdef IS_REQUIRED_OVERLAY
53                    (
54 #endif
55                      textColor
56 #ifdef IS_REQUIRED_STYLE
57                      + styleTexture * (1.0 - textColor.a)
58 #endif
59 #ifdef IS_REQUIRED_OVERLAY
60                    ) * (1.0 - overlayStyleTexture.a) + overlayStyleTexture
61 #endif
62                  );
63 }