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

[css-masking-1] Mask on mask behavior #328

Open
dirkschulze opened this issue Dec 8, 2018 · 8 comments
Open

[css-masking-1] Mask on mask behavior #328

dirkschulze opened this issue Dec 8, 2018 · 8 comments

Comments

@dirkschulze
Copy link
Contributor

Moved from w3c/svgwg#608, opened by @RazrFalcon

https://www.w3.org/TR/css-masking-1/#the-mask

I'm trying to understand how a mask element with a mask attribute/property should be rendered.

I've made a simple example, but no matter what I do - it still renders the same in all applications. Looks like everyone is simply ignoring the mask property. Does no one support it or am I missing something?

<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg">

    <linearGradient id="lg1">
        <stop offset="0" stop-color="white" stop-opacity="0"/>
        <stop offset="1" stop-color="black"/>
    </linearGradient>

    <mask id="mask1">
        <rect id="rect1" x="40" y="40" width="120" height="120" fill="black"/>
    </mask>
    <mask id="mask2" mask="url(#mask1)" maskUnits="userSpaceOnUse" x="0" y="0" width="200" height="200">
        <rect id="rect1" x="20" y="20" width="160" height="160" fill="url(#lg1)"
              transform="rotate(90 100 100)"/>
    </mask>
    <rect id="rect2" x="20" y="20" width="160" height="160" fill="green" mask="url(#mask2)"/>

    <rect id="frame" x="1" y="1" width="198" height="198" fill="none" stroke="black"/>
</svg>

e-mask-26

@dirkschulze
Copy link
Contributor Author

dirkschulze commented Dec 8, 2018

I created a slightly modified example: https://codepen.io/krit/pen/PXoYNN

Edge does seem to support mask on mask but is the only browser that does. Firefox on Windows looks white btw.

@BigBadaboom
Copy link

Just a couple of comments on the above test cases.

There are a couple of gotchas here, that may be worth noting just to avoid others scratching their heads like I did for a while.

The first issue is fairly obvious. In the original SVG supplied by @RazrFalcon, the mask1 mask is a black square on black, so it is blank. Meaning that the correct rendering of the test case should be blank. Ie. librsvg is the only correct one here (albeit possibly accidentally).

The second issue relates to the gradient. It is interpolating from transparent white to black. This can cause problems if gradients aren't being interpolated and composited in the correct colour space. For example, Dirk's test case is blank on Firefox due to this. If we modify the gradient by adding a halfway step, the masked green square is now visible.

https://codepen.io/PaulLeBeau/pen/BvyBXZ

To avoid these issues causing confusion, it might be a good idea not to use that problematic gradient and instead use a more straightforward test case that more directly addresses the mask on mask issue.

<svg viewBox="0 0 200 200" width="200" height="200">

    <mask id="mask1">
        <circle id="rect1" cx="100" cy="100" r="50" fill="gray"/>
    </mask>
    <mask id="mask2" mask="url(#mask1)" maskUnits="userSpaceOnUse"
          x="0" y="0" width="200" height="200">
        <rect id="rect1" x="20" y="20" width="160" height="160" fill="white"/>
    </mask>
    <rect id="rect2" x="20" y="20" width="160" height="160" fill="green" mask="url(#mask2)"/>

    <rect id="frame" x="1" y="1" width="198" height="198" fill="none" stroke="black"/>
</svg>

https://codepen.io/PaulLeBeau/pen/RENwro

@RazrFalcon
Copy link

@BigBadaboom can you provide a PNG as a reference for the last example?

@BigBadaboom
Copy link

Sure. I should have done that anyway... :/

issue328

@RazrFalcon
Copy link

Yes. Looks like librsvg is the only one that supports it.

@dirkschulze
Copy link
Contributor Author

@RazrFalcon From the test of @BigBadaboom it seems like browsers do support mask on mask. (Thanks for catching the issue btw.) Can we close this issue now?

@BigBadaboom
Copy link

@dirkschulze No they don't all support it. I just tested Chrome, Firefox, Safari and Edge. The only one that rendered my test case correctly was Edge.

@dirkschulze
Copy link
Contributor Author

@BigBadaboom Argh, must have checked with the wrong test. Indeed, doesn't work on Chrome or Firefox. First mask still works, not the mask on the mask. Simply gets ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants