Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect box-shadow rendering when the blur of adjacent rounded corners overlaps #2180

Closed
mstange opened this issue Dec 6, 2017 · 1 comment
Closed

Comments

@mstange
Copy link
Contributor

@mstange mstange commented Dec 6, 2017

https://bugzilla.mozilla.org/show_bug.cgi?id=1423692

Testcase

Actual vs expected results:
screen shot 2017-12-06 at 2 23 46 pm

---
root:
  items:
    - type: stacking-context
      bounds: [0, 0, 1000, 1000]
      items:
        - type: box-shadow
          bounds: [ 50, 10, 200, 80 ]
          color: black
          clip-mode: outset
          offset: 0 150
          blur-radius: 20
          border-radius:
            top-left: [100, 40]
            top-right: [0, 0]
            bottom-left: [100, 40]
            bottom-right: [0, 0]
@mstange
Copy link
Contributor Author

@mstange mstange commented Dec 9, 2017

I thought about this problem some more and came to a surprising conclusion: Blurring corners separately and combining them afterwards into the whole blurred box works fine at all sizes, even if the box is so small that the blur from one corner extends into the blur from another corner! In the overlapping part, the correct blurred result can be computed from the individually-blurred corners like this:

float shadow_alpha(pos) {
  return sample_from_one_blurred_corner(pos)
          + sample_from_the_other_blurred_corner(pos)
          - sample_from_the_repeated_middle_part(pos);
}

Proof via picture:
blur-arithmetic

This is even true more generically:
blur-arithmetic-with-pictures

It looks like this works because of the distributive property of discrete 2d convolutions.

glennw pushed a commit to glennw/webrender that referenced this issue Dec 15, 2017
glennw pushed a commit to glennw/webrender that referenced this issue Dec 15, 2017
bors-servo added a commit that referenced this issue Dec 18, 2017
Fix box shadows when the shadow rect is smaller than the nine-patch.

Fixes #2180.
Fixes #2179.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/webrender/2229)
<!-- Reviewable:end -->
GuanWen-Chen added a commit to GuanWen-Chen/webrender that referenced this issue Jan 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.