Skip to content

Make the circle.frag Anti Aliasing continuous around 2px#183348

Closed
Hari-07 wants to merge 2 commits intoflutter:masterfrom
Hari-07:circle-frag-2px-bug
Closed

Make the circle.frag Anti Aliasing continuous around 2px#183348
Hari-07 wants to merge 2 commits intoflutter:masterfrom
Hari-07:circle-frag-2px-bug

Conversation

@Hari-07
Copy link
Contributor

@Hari-07 Hari-07 commented Mar 7, 2026

Currently Circle.frag has a hard limit of 2 pixels below which it gives full opacity to the ring

if (frag_info.stroked > 0.0 &&
      pixel_derivative_sdf * 2.0 >= frag_info.stroke_width) {
    sdf_distance = -frag_info.radius;
  }

So float alpha = 1.0 - smoothstep(-fade_width, 0.0, sdf_distance); was discontinuous at that border since sdf_distance jumped abruptly.

Fixes #183339

With this update fade width varies smoothly with stroke width, until 2px at which point both are equal, eliminating a discontinuity

Screen.Recording.2026-03-07.at.1.46.23.PM.mov

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

@github-actions github-actions bot added engine flutter/engine related. See also e: labels. e: impeller Impeller rendering backend issues and features requests labels Mar 7, 2026
@Hari-07 Hari-07 requested a review from gaaclarke March 7, 2026 08:09
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
}

TEST_P(AiksTest, DrawThinStrokedCircle) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test was copied from #183184 and should be removed before merging

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request aims to fix a visual discontinuity in the anti-aliasing of thin stroked circles by making the fade width dependent on the stroke width. A new playground test has been added for visual verification. My review identified a potential logic error in the shader where values with different units are compared, which could result in incorrect anti-aliasing under certain scaling conditions. Additionally, I found a minor issue in the new test case where an alpha slider has an incorrect range, limiting its usability.

ImGui::SliderFloat("Stroked Radius", &stroked_radius, 0, 500);
ImGui::SliderFloat("Stroked Width", &stroke_width, 0, 500);
ImGui::SliderFloat("Stroked Width Fine", &stroke_width_fine, 0, 5);
ImGui::SliderFloat("Stroked Alpha", &stroked_alpha, 0, 10.0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The stroked_alpha variable is initialized to 255.0f and used with DlColor::withAlpha(), which expects a value in the range [0, 255]. However, the slider for this variable has a range of [0, 10.0]. This will cause the alpha value to be clamped to 10 as soon as the slider is interacted with, making the circle nearly transparent and the control hard to use as intended. The slider range should be adjusted to match the expected alpha range.

Suggested change
ImGui::SliderFloat("Stroked Alpha", &stroked_alpha, 0, 10.0);
ImGui::SliderFloat("Stroked Alpha", &stroked_alpha, 0, 255.0);

Copy link
Member

@gaaclarke gaaclarke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking the time write this up. I'm still having some discussions with the team about what we want to do with #183184. That requires not just figuring out what we want to do for a fix but also what do we want to make cherry-picked into stable, etc.

@Hari-07 Hari-07 force-pushed the circle-frag-2px-bug branch from 26d986f to ceb8bf6 Compare March 12, 2026 05:16
@gaaclarke
Copy link
Member

Walley has addressed this issue in #183536

Thanks for the contribution, it's much appreciated. In this case Walley had a bit more background and we had some meetings around how to fix it so we let him address the root problem and a few others. Give that a shot if you want to verify it meets your requirements. I'll close this out in lieu of his.

@gaaclarke gaaclarke closed this Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

e: impeller Impeller rendering backend issues and features requests engine flutter/engine related. See also e: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stroked circle width jumps at 2

2 participants