Let CornerRadius / Borderline works on very small visual
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / graphics / shaders / image-visual-shader.frag
index 3694280..cb5e765 100644 (file)
@@ -9,6 +9,10 @@ INPUT mediump vec4 vCornerRadius;
 #endif
 
 uniform sampler2D sTexture;
+#ifdef IS_REQUIRED_YUV_TO_RGB
+uniform sampler2D sTextureU;
+uniform sampler2D sTextureV;
+#endif
 
 #ifdef IS_REQUIRED_ALPHA_MASKING
 uniform sampler2D sMaskTexture;
@@ -95,7 +99,8 @@ void calculatePotential()
 
 void setupMinMaxPotential()
 {
-  gPotentialRange = 1.0;
+  // Set soft anti-alias range at most 2% of visual size
+  gPotentialRange = min(1.0, max(vRectSize.x, vRectSize.y) * 0.02);
 
   gMaxOutlinePotential = gRadius + gPotentialRange;
   gMinOutlinePotential = gRadius - gPotentialRange;
@@ -138,7 +143,7 @@ lowp vec4 convertBorderlineColor(lowp vec4 textureColor)
     borderlineOpacity = smoothstep(gMinInlinePotential, gMaxInlinePotential, potential);
 
     // Muliply borderlineWidth to resolve very thin borderline
-    borderlineOpacity *= min(1.0, borderlineWidth);
+    borderlineOpacity *= min(1.0, borderlineWidth / gPotentialRange);
   }
 
   lowp vec3  borderlineColorRGB   = borderlineColor.rgb * uActorColor.rgb;
@@ -150,7 +155,7 @@ lowp vec4 convertBorderlineColor(lowp vec4 textureColor)
   // But if borderlineOpacity > 0.0 and borderlineColor.a == 0.0, we need to apply tCornerRadius.
   if(borderlineOpacity > 0.0 && borderlineColor.a * borderlineOpacity < 1.0)
   {
-    mediump float tCornerRadius = -gCenterPosition;
+    mediump float tCornerRadius = -gCenterPosition + gPotentialRange;
     mediump float MaxTexturelinePotential = tCornerRadius + gPotentialRange;
     mediump float MinTexturelinePotential = tCornerRadius - gPotentialRange;
     if(potential > MaxTexturelinePotential)
@@ -208,6 +213,20 @@ mediump float calculateCornerOpacity()
 }
 #endif
 
+#ifdef IS_REQUIRED_YUV_TO_RGB
+lowp vec3 ConvertYuvToRgb(mediump vec2 texCoord)
+{
+  lowp float y = texture(sTexture, texCoord).r;
+  lowp float u = texture(sTextureU, texCoord).r - 0.5;
+  lowp float v = texture(sTextureV, texCoord).r - 0.5;
+  lowp vec3 rgb;
+  rgb.r = y + (1.403 * v);
+  rgb.g = y - (0.344 * u) - (0.714 * v);
+  rgb.b = y + (1.770 * u);
+  return rgb;
+}
+#endif
+
 void main()
 {
 #ifdef ATLAS_DEFAULT_WARP
@@ -219,7 +238,11 @@ void main()
   mediump vec2 texCoord = vTexCoord;
 #endif
 
+#ifdef IS_REQUIRED_YUV_TO_RGB
+  lowp vec4 textureColor = vec4(ConvertYuvToRgb(texCoord), 1.0) * vec4( mixColor, 1.0 ) * uColor;
+#else
   lowp vec4 textureColor = TEXTURE( sTexture, texCoord ) * vec4( mixColor, 1.0 ) * uColor;
+#endif
 
 #ifdef IS_REQUIRED_ALPHA_MASKING
   mediump float maskAlpha = TEXTURE(sMaskTexture, vMaskTexCoord).a;