Skip to content

Comments

fix: CPU AA rasterizer quality improvements (#95)#127

Merged
kolkov merged 3 commits intomainfrom
fix/aa-quality-95
Feb 24, 2026
Merged

fix: CPU AA rasterizer quality improvements (#95)#127
kolkov merged 3 commits intomainfrom
fix/aa-quality-95

Conversation

@kolkov
Copy link
Contributor

@kolkov kolkov commented Feb 24, 2026

Summary

  • AdvanceX drift fix — scanline-to-scanline AdvanceX() accumulated floating-point error, causing edges to expand toward the bottom of shapes. Replaced with direct per-scanline X computation.
  • coverageToRuns maxValue fix — merged adjacent alpha runs used sum instead of max, causing vertex pixels to get incorrect partial coverage.
  • 4 regression tests for vertex pixel accuracy
  • Update wgpu v0.16.13, gogpu v0.20.4

Closes #95

AdvanceX() advanced line.X by one sub-pixel step per pixel scanline,
but computeSegmentCoverage already computes positions analytically via
lineTopX = x + dx*(lineTopY - firstY). The accumulated drift caused
progressive edge position error (slope * N / aaScale per scanline),
making triangle edges visibly expand toward the bottom.
coverageToRuns used AlphaRuns.Add() which sets maxValue=255 for middle
pixels in merged runs. When two adjacent pixels had identical partial
coverage (e.g. 44% at triangle vertices), the second pixel got 100%
instead of 44%. Fixed by using AddWithCoverage(maxValue=currentAlpha).

Added 4 regression tests:
- TestVertexCoverage_PartialAlpha: vertex pixels get correct partial alpha
- TestEdgePosition_NoDrift: edges don't expand over distance
- TestCoverageToRuns_MergedRunAlpha: merged runs preserve alpha
- TestInteriorPixels_FullCoverage: interior pixels still get 100%
@codecov
Copy link

codecov bot commented Feb 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@kolkov kolkov merged commit fc6f80a into main Feb 24, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pattern result is strange

1 participant