+
+ // NOTE : gradient-visual is always preMultiplied.
+ borderlineColorAlpha *= borderlineOpacity;
+ borderlineColorRGB *= borderlineOpacity;
+ // We use pre-multiplied color to reduce operations.
+ // In here, textureColor and borderlineColorRGB is pre-multiplied color now.
+
+ // Manual blend operation with premultiplied colors.
+ // Final alpha = borderlineColorAlpha + (1.0 - borderlineColorAlpha) * textureColor.a.
+ // (Final rgb * alpha) = borderlineColorRGB + (1.0 - borderlineColorAlpha) * textureColor.rgb
+ // If preMultipliedAlpha == 1.0, just return vec4(rgb*alpha, alpha)
+ // Else, return vec4((rgb*alpha) / alpha, alpha)
+
+ lowp float finalAlpha = mix(textureColor.a, 1.0, borderlineColorAlpha);
+ lowp vec3 finalMultipliedRGB = borderlineColorRGB + (1.0 - borderlineColorAlpha) * textureColor.rgb;
+ return vec4(finalMultipliedRGB, finalAlpha);