   // it between the limits accepted by `mix`.
   float colorMix = min(max(distanceFromMixLine / pixelsPerFragment, -0.5), 0.5) + 0.5;
   return mix(vHorizontalColor, vVerticalColor, colorMix);
+}
+
+float alpha_for_solid_border(float distance_from_ref,
+                             float inner_radius,
+                             float outer_radius,
+                             float pixels_per_fragment) {
+  // We want to start anti-aliasing one pixel in from the border.
+  float nudge = 1 * pixels_per_fragment;
+  inner_radius += nudge;
+  outer_radius -= nudge;
+
+  if ((distance_from_ref < outer_radius && distance_from_ref > inner_radius)) {
+    return 1.0;
+  }
+
+  float distance_from_border = max(distance_from_ref - outer_radius,
+                                   inner_radius - distance_from_ref);
+
+  // Move the distance back into pixels.
+  distance_from_border /= pixels_per_fragment;
+
+  // Apply a more gradual fade out to transparent.
+  distance_from_border -= 0.5;
+
+  return smoothstep(1.0, 0, distance_from_border);
+}
+
+float alpha_for_solid_border_corner(vec2 local_pos,
+                                    float inner_radius,
+                                    float outer_radius,
+                                    float pixels_per_fragment) {
+  float distance_from_ref = distance(vRefPoint, local_pos);
+  return alpha_for_solid_border(distance_from_ref, inner_radius, outer_radius, pixels_per_fragment);
 }
 
 #ifdef WR_FEATURE_TRANSFORM

            draw_solid_border(vDistanceFromMixLine, local_pos);
            break;
        case BORDER_STYLE_DOUBLE:
            discard_pixels_in_rounded_borders(local_pos);
            draw_double_border();
            break;
        default:
            discard;

  return mix(white, circleColor, circleColor.a);
}

vec4 draw_double_edge(float pos, float len, float pixelsPerFragment) {
  float total_border_width = len;
  float one_third_width = total_border_width / 3.0;

  // Contribution of the outer border segment.
  float alpha = alpha_for_solid_border(pos,
                                       total_border_width - one_third_width,
                                       total_border_width,
                                       pixelsPerFragment);

  // Contribution of the inner border segment.
  alpha += alpha_for_solid_border(pos, 0, one_third_width, pixelsPerFragment);
  return get_fragment_color(vDistanceFromMixLine, pixelsPerFragment) * vec4(1, 1, 1, alpha);
}

vec4 draw_double_edge_vertical(float pixelsPerFragment) {
  // Get our position within this specific segment
  float position = vLocalPos.x - vLocalRect.x;
  return draw_double_edge(position, vLocalRect.z, pixelsPerFragment);
}

vec4 draw_double_edge_horizontal(float pixelsPerFragment) {
  // Get our position within this specific segment
  float position = vLocalPos.y - vLocalRect.y;
  return draw_double_edge(position, vLocalRect.w, pixelsPerFragment);
}

vec4 draw_double_edge_corner_with_radius(float pixelsPerFragment) {
  float total_border_width = vRadii.x - vRadii.z;
  float one_third_width = total_border_width / 3.0;

  // Contribution of the outer border segment.
  float alpha = alpha_for_solid_border_corner(vLocalPos,
                                              vRadii.x - one_third_width,
                                              vRadii.x,
                                              pixelsPerFragment);

  // Contribution of the inner border segment.
  alpha += alpha_for_solid_border_corner(vLocalPos,
                                         vRadii.z,
                                         vRadii.z + one_third_width,
                                         pixelsPerFragment);
  return get_fragment_color(vDistanceFromMixLine, pixelsPerFragment) * vec4(1, 1, 1, alpha);
}

vec4 draw_double_edge_corner(float pixelsPerFragment) {
  if (vRadii.x > 0) {
    return draw_double_edge_corner_with_radius(pixelsPerFragment);
  }

  bool is_vertical = (vBorderPart == PST_TOP_LEFT) ? vDistanceFromMixLine < 0 :
                                                     vDistanceFromMixLine >= 0;
  if (is_vertical) {
    return draw_double_edge_vertical(pixelsPerFragment);
  } else {
    return draw_double_edge_horizontal(pixelsPerFragment);
  }
}

