highp float gPotentialRange = 0.0;
highp float gMaxOutlinePotential = 0.0;
highp float gMinOutlinePotential = 0.0;
+#ifdef IS_REQUIRED_BLUR
+#elif defined(IS_REQUIRED_BORDERLINE)
highp float gMaxInlinePotential = 0.0;
highp float gMinInlinePotential = 0.0;
+#endif
void calculateCornerRadius(highp vec4 cornerRadius, highp vec2 position)
{
);
#endif
}
-
-void calculatePosition(highp vec2 position, highp vec2 halfSizeOfRect, highp float currentBorderlineWidth)
+void calculateFragmentPosition(highp vec2 position, highp vec2 halfSizeOfRect)
{
gFragmentPosition = abs(position) - halfSizeOfRect;
+}
+
+void calculatePosition(highp float currentBorderlineWidth)
+{
gCenterPosition = -gRadius;
#ifdef IS_REQUIRED_BLUR
#elif defined(IS_REQUIRED_BORDERLINE)
gMinOutlinePotential = gRadius - gPotentialRange;
#ifdef IS_REQUIRED_BLUR
- gMaxInlinePotential = gMaxOutlinePotential;
- gMinInlinePotential = gMinOutlinePotential;
#elif defined(IS_REQUIRED_BORDERLINE)
gMaxInlinePotential = gMaxOutlinePotential - currentBorderlineWidth;
gMinInlinePotential = gMinOutlinePotential - currentBorderlineWidth;
#else
- gMaxInlinePotential = gMaxOutlinePotential;
- gMinInlinePotential = gMinOutlinePotential;
#endif
// reduce defect near edge of rounded corner.
- gMaxOutlinePotential += clamp(-min(gDiff.x, gDiff.y) / max(1.0, gRadius), 0.0, 1.0);
- gMinOutlinePotential += clamp(-min(gDiff.x, gDiff.y) / max(1.0, gRadius), 0.0, 1.0);
+ highp float heuristicEdgeCasePotential = clamp(-min(gDiff.x, gDiff.y) / max(1.0, gRadius), 0.0, gPotentialRange);
+ gMaxOutlinePotential += heuristicEdgeCasePotential;
+ gMinOutlinePotential += heuristicEdgeCasePotential;
}
void PreprocessPotential(highp vec4 cornerRadius, highp vec2 position, highp vec2 halfSizeOfRect, highp float currentBorderlineWidth)
{
calculateCornerRadius(cornerRadius, position);
- calculatePosition(position, halfSizeOfRect, currentBorderlineWidth);
+ calculateFragmentPosition(position, halfSizeOfRect);
+ calculatePosition(currentBorderlineWidth);
calculatePotential();
-
setupMinMaxPotential(currentBorderlineWidth);
}
#endif
#ifdef IS_REQUIRED_ROUNDED_CORNER
tempCornerRadius = vCornerRadius;
#endif
-#ifdef IS_REQUIRED_BLUR
-#elif defined(IS_REQUIRED_BORDERLINE)
- tempBorderlineWidth = borderlineWidth;
-#endif
- PreprocessPotential(tempCornerRadius, vPosition, vRectSize, tempBorderlineWidth);
+ calculateCornerRadius(tempCornerRadius, vPosition);
+ calculateFragmentPosition(vPosition, vRectSize);
#endif
#ifdef IS_REQUIRED_BLUR
-#elif defined(IS_REQUIRED_BORDERLINE)
- targetColor = convertBorderlineColor(targetColor);
-#endif
+ calculatePosition(tempBorderlineWidth);
+ calculatePotential();
+ setupMinMaxPotential(tempBorderlineWidth);
+
OUT_COLOR = targetColor;
-#ifdef IS_REQUIRED_BLUR
mediump float opacity = calculateBlurOpacity();
OUT_COLOR.a *= opacity;
-#elif defined(IS_REQUIRED_ROUNDED_CORNER)
- mediump float opacity = calculateCornerOpacity();
- OUT_COLOR.a *= opacity;
+#else
+#if defined(IS_REQUIRED_ROUNDED_CORNER) && !defined(IS_REQUIRED_BORDERLINE)
+ // skip rounded corner calculate for performance
+ if(gFragmentPosition.x + gFragmentPosition.y < -(gRadius + vAliasMargin) * 2.0)
+ {
+ // Do nothing.
+ OUT_COLOR = targetColor;
+ }
+ else
+#endif
+ {
+#if defined(IS_REQUIRED_ROUNDED_CORNER) || defined(IS_REQUIRED_BORDERLINE)
+#ifdef IS_REQUIRED_BORDERLINE
+ tempBorderlineWidth = borderlineWidth;
+#endif
+ calculatePosition(tempBorderlineWidth);
+ calculatePotential();
+ setupMinMaxPotential(tempBorderlineWidth);
+
+#ifdef IS_REQUIRED_BORDERLINE
+ targetColor = convertBorderlineColor(targetColor);
+#endif
+#endif
+
+ OUT_COLOR = targetColor;
+
+#ifdef IS_REQUIRED_ROUNDED_CORNER
+ mediump float opacity = calculateCornerOpacity();
+ OUT_COLOR.a *= opacity;
+#endif
+ }
#endif
#if defined(IS_REQUIRED_BLUR) || defined(IS_REQUIRED_ROUNDED_CORNER) || defined(IS_REQUIRED_BORDERLINE)
highp float gPotentialRange = 0.0;
highp float gMaxOutlinePotential = 0.0;
highp float gMinOutlinePotential = 0.0;
+#ifdef IS_REQUIRED_BORDERLINE
highp float gMaxInlinePotential = 0.0;
highp float gMinInlinePotential = 0.0;
+#endif
void calculateCornerRadius()
{
#endif
}
-void calculatePosition()
+void calculateFragmentPosition()
{
gFragmentPosition = abs(vPosition) - vRectSize;
+}
+
+void calculatePosition()
+{
gCenterPosition = -gRadius;
#ifdef IS_REQUIRED_BORDERLINE
gCenterPosition += borderlineWidth * (clamp(borderlineOffset, -1.0, 1.0) + 1.0) * 0.5;
#ifdef IS_REQUIRED_BORDERLINE
gMaxInlinePotential = gMaxOutlinePotential - borderlineWidth;
gMinInlinePotential = gMinOutlinePotential - borderlineWidth;
-#else
- gMaxInlinePotential = gMaxOutlinePotential;
- gMinInlinePotential = gMinOutlinePotential;
#endif
// reduce defect near edge of rounded corner.
- gMaxOutlinePotential += clamp(-min(gDiff.x, gDiff.y) / max(1.0, gRadius), 0.0, 1.0);
- gMinOutlinePotential += clamp(-min(gDiff.x, gDiff.y) / max(1.0, gRadius), 0.0, 1.0);
+ highp float heuristicEdgeCasePotential = clamp(-min(gDiff.x, gDiff.y) / max(1.0, gRadius), 0.0, gPotentialRange);
+ gMaxOutlinePotential += heuristicEdgeCasePotential;
+ gMinOutlinePotential += heuristicEdgeCasePotential;
}
-void PreprocessPotential()
-{
- calculateCornerRadius();
- calculatePosition();
- calculatePotential();
-
- setupMinMaxPotential();
-}
+//void PreprocessPotential()
+//{
+// calculateCornerRadius();
+// calculateFragmentPosition();
+// calculatePosition();
+// calculatePotential();
+// setupMinMaxPotential();
+//}
#endif
}
else
{
- PreprocessPotential();
+ calculateCornerRadius();
+ calculateFragmentPosition();
+#endif
+
+#if defined(IS_REQUIRED_ROUNDED_CORNER) && !defined(IS_REQUIRED_BORDERLINE)
+ // skip length and etc potential calculation for performance
+ if(gFragmentPosition.x + gFragmentPosition.y < -(gRadius + vAliasMargin) * 2.0)
+ {
+ // Do nothing.
+ OUT_COLOR = textureColor;
+ }
+ else
+#endif
+ {
+#if defined(IS_REQUIRED_ROUNDED_CORNER) || defined(IS_REQUIRED_BORDERLINE)
+ calculatePosition();
+ calculatePotential();
+ setupMinMaxPotential();
#endif
#ifdef IS_REQUIRED_BORDERLINE
- textureColor = convertBorderlineColor(textureColor);
+ textureColor = convertBorderlineColor(textureColor);
#endif
- OUT_COLOR = textureColor;
+ OUT_COLOR = textureColor;
#ifdef IS_REQUIRED_ROUNDED_CORNER
- mediump float opacity = calculateCornerOpacity();
- OUT_COLOR *= opacity;
+ mediump float opacity = calculateCornerOpacity();
+ OUT_COLOR *= opacity;
#endif
+ }
#if defined(IS_REQUIRED_ROUNDED_CORNER) || defined(IS_REQUIRED_BORDERLINE)
}
highp float gPotentialRange = 0.0;
highp float gMaxOutlinePotential = 0.0;
highp float gMinOutlinePotential = 0.0;
+#ifdef IS_REQUIRED_BORDERLINE
highp float gMaxInlinePotential = 0.0;
highp float gMinInlinePotential = 0.0;
+#endif
void calculateCornerRadius()
{
#endif
}
-void calculatePosition()
+void calculateFragmentPosition()
{
gFragmentPosition = abs(vPosition) - vRectSize;
+}
+
+void calculatePosition()
+{
gCenterPosition = -gRadius;
#ifdef IS_REQUIRED_BORDERLINE
gCenterPosition += borderlineWidth * (clamp(borderlineOffset, -1.0, 1.0) + 1.0) * 0.5;
#ifdef IS_REQUIRED_BORDERLINE
gMaxInlinePotential = gMaxOutlinePotential - borderlineWidth;
gMinInlinePotential = gMinOutlinePotential - borderlineWidth;
-#else
- gMaxInlinePotential = gMaxOutlinePotential;
- gMinInlinePotential = gMinOutlinePotential;
#endif
// reduce defect near edge of rounded corner.
- gMaxOutlinePotential += clamp(-min(gDiff.x, gDiff.y) / max(1.0, gRadius), 0.0, 1.0);
- gMinOutlinePotential += clamp(-min(gDiff.x, gDiff.y) / max(1.0, gRadius), 0.0, 1.0);
+ highp float heuristicEdgeCasePotential = clamp(-min(gDiff.x, gDiff.y) / max(1.0, gRadius), 0.0, gPotentialRange);
+ gMaxOutlinePotential += heuristicEdgeCasePotential;
+ gMinOutlinePotential += heuristicEdgeCasePotential;
}
-void PreprocessPotential()
-{
- calculateCornerRadius();
- calculatePosition();
- calculatePotential();
-
- setupMinMaxPotential();
-}
+//void PreprocessPotential()
+//{
+// calculateCornerRadius();
+// calculateFragmentPosition();
+// calculatePosition();
+// calculatePotential();
+// setupMinMaxPotential();
+//}
#endif
#ifdef IS_REQUIRED_BORDERLINE
else
#endif
{
- PreprocessPotential();
+ calculateCornerRadius();
+ calculateFragmentPosition();
+#endif
+
+#if defined(IS_REQUIRED_ROUNDED_CORNER) && !defined(IS_REQUIRED_BORDERLINE) && !defined(IS_REQUIRED_DEBUG_VISUAL_SHADER)
+ // skip rounded corner calculate for performance
+ if(gFragmentPosition.x + gFragmentPosition.y < -(gRadius + vAliasMargin) * 2.0)
+ {
+ // Do nothing.
+ OUT_COLOR = textureColor;
+ }
+ else
+#endif
+ {
+#if defined(IS_REQUIRED_DEBUG_VISUAL_SHADER) || defined(IS_REQUIRED_ROUNDED_CORNER) || defined(IS_REQUIRED_BORDERLINE)
+ calculatePosition();
+ calculatePotential();
+ setupMinMaxPotential();
#endif
#ifdef IS_REQUIRED_BORDERLINE
- textureColor = convertBorderlineColor(textureColor);
+ textureColor = convertBorderlineColor(textureColor);
#endif
- OUT_COLOR = textureColor;
+ OUT_COLOR = textureColor;
#ifdef IS_REQUIRED_ROUNDED_CORNER
- mediump float opacity = calculateCornerOpacity();
- OUT_COLOR.a *= opacity;
- OUT_COLOR.rgb *= mix(1.0, opacity, preMultipliedAlpha);
+ mediump float opacity = calculateCornerOpacity();
+ OUT_COLOR.a *= opacity;
+ OUT_COLOR.rgb *= mix(1.0, opacity, preMultipliedAlpha);
#endif
+ }
#if defined(IS_REQUIRED_DEBUG_VISUAL_SHADER) || defined(IS_REQUIRED_ROUNDED_CORNER) || defined(IS_REQUIRED_BORDERLINE)
}