<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>266295</bug_id>
          
          <creation_ts>2023-12-12 10:49:36 -0800</creation_ts>
          <short_desc>Viewport-dependant weird tiling/ gaps when applying SVG filters</short_desc>
          <delta_ts>2026-01-04 11:43:04 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>SVG</component>
          <version>Other</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=136482</see_also>
    
    <see_also>https://bugs.webkit.org/show_bug.cgi?id=151995</see_also>
    
    <see_also>https://bugs.webkit.org/show_bug.cgi?id=279290</see_also>
    
    <see_also>https://bugs.webkit.org/show_bug.cgi?id=279293</see_also>
    
    <see_also>https://bugs.webkit.org/show_bug.cgi?id=270567</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>BrowserCompat, InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          <dependson>279290</dependson>
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Ana Tudor">ana.tudor.lhnh</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>karlcow</cc>
    
    <cc>maggotfish</cc>
    
    <cc>sabouhallawa</cc>
    
    <cc>simon.fraser</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>zimmermann</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1999034</commentid>
    <comment_count>0</comment_count>
    <who name="Ana Tudor">ana.tudor.lhnh</who>
    <bug_when>2023-12-12 10:49:36 -0800</bug_when>
    <thetext>I came across this while trying to achieve sliced text effects. By sliced text effects, I mean things like:

* https://www.pinterest.com/pin/57139489011897480/

* https://www.pinterest.com/pin/outside-lands-creative-paper-typography-by-owen-gildersleeve--508695720422079050/

* https://www.pinterest.com/pin/582794008042826341/

The first one is a plain horizontal slicing effect, which I would have thought is pretty straightforward.

We create a displacement map that&apos;s `100%` red in the top half, `0%` red in the bottom half and `50%` transparent everywhere and use it for the slicing effect.

```
svg(width=&apos;0&apos; height=&apos;0&apos;)
	filter#f(primitiveUnits=&apos;objectBoundingBox&apos;
	         x=&apos;0&apos; y=&apos;0&apos; width=&apos;100%&apos; height=&apos;100%&apos;)
		feFlood(result=&apos;back&apos;)
		feFlood(height=&apos;.5&apos; flood-color=&apos;red&apos;)
		feComposite(in2=&apos;back&apos;)
		feComponentTransfer: feFuncA(type=&apos;discrete&apos; tableValues=&apos;.5&apos;)
		feDisplacementMap(scale=&apos;.04&apos; in=&apos;SourceGraphic&apos; xChannelSelector=&apos;R&apos;)
```

This seems to work fine regardless of any other factors in both Chrome and Firefox.

However, it has weird gaps and tiling in Safari (tested via Epiphany) and these depend on the viewport, though from a certain viewport size down, everything seems to look fine.

Live demo https://codepen.io/thebabydino/pen/qBgweEw?editors=1100

Recording of the problem on viewport resize https://twitter.com/anatudor/status/1734633884212400389

Even weirder, the full demo with shadows does not seem to exhibit the same tiling problem https://codepen.io/thebabydino/pen/xxMyvPp

If I remove the shadow from the demo, yes, we still get the tiling and the gaps. But once the sliced &amp; offset text is composited with the shadow, the gaps &amp; tiling issue disappears.

---

For diagonal effects, my first thought was create a displacement map as a `feImage` that uses an SVG element as the source. We cannot use a link to an image, as this doesn&apos;t work in Chrome and it&apos;s probably never going to work for security reasons (and it applies to data URIs as well).

```
svg(width=&apos;100%&apos; height=&apos;100%&apos;)
	filter#f
		feImage(xlink:href=&apos;#i&apos;)
		
	defs
		g#i
			rect(width=&apos;100%&apos; height=&apos;100%&apos; fill=&apos;red&apos;)
			line(x1=&apos;-50%&apos; x2=&apos;150%&apos; 
			     transform=&apos;rotate(45)&apos; 
			     stroke=&apos;blue&apos; stroke-width=&apos;300%&apos; stroke-dasharray=&apos;15%&apos;)
```

`feImage` with a reference to another SVG element doesn&apos;t work in Firefox, only with a link to an image or data URI - a 15 year old bug with no signal of getting fixed any time soon.

So this tactic should only create diagonal stripes in Chrome and Safari and... it almost does, just that it&apos;s buggy. In Chrome it only works after triggering a viewport resize and in Safari, we get the exact same tiling problem.

Live demo https://codepen.io/thebabydino/pen/VwgNqpv?editors=1100

Screenshots from multiple systems in the replies https://twitter.com/anatudor/status/1734563149578404038

An attempt at the actual effect, it would actually work in Safari if it wasn&apos;t for the tiling problem! At certain viewport sizes, it actually looks like it works!

https://codepen.io/thebabydino/pen/JjxZxod?editors=1000

---

My second thought when it came to diagonal effects was to use the `SourceGraphic` as its own displacement map. This does not work at all in Firefox, it&apos;s buggy in a really weird way in Chrome and exhibits the exact same weird gaps and tiling problem in Safari.

```
svg(width=&apos;0&apos; height=&apos;0&apos;)
	filter#f
		feDisplacementMap(scale=&apos;80&apos; 
		                  xChannelSelector=&apos;R&apos; yChannelSelector=&apos;B&apos;)
```

Live demo https://codepen.io/thebabydino/pen/KKJrKJj

Lots of screnshots and recordings from multiple devices in the replies https://twitter.com/anatudor/status/1734479534458589200 - some reports say Safari on iOS works fine, though I wonder whether that&apos;s not related to the smaller viewport size?

Trying this with text instead of a rectangle looks even worse https://codepen.io/thebabydino/pen/eYxPqjR?editors=1100</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1999046</commentid>
    <comment_count>1</comment_count>
    <who name="Nikolas Zimmermann">zimmermann</who>
    <bug_when>2023-12-12 11:39:52 -0800</bug_when>
    <thetext>Thanks a lot Ana, nice testcases.

@Said, do you eventually have some time to check those issues?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1999367</commentid>
    <comment_count>2</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2023-12-13 12:44:36 -0800</bug_when>
    <thetext>&lt;rdar://problem/119627691&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1999368</commentid>
    <comment_count>3</comment_count>
    <who name="Simon Fraser (smfr)">simon.fraser</who>
    <bug_when>2023-12-13 12:44:54 -0800</bug_when>
    <thetext>Possibly related to bug 151995.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2058292</commentid>
    <comment_count>4</comment_count>
    <who name="Simon Fraser (smfr)">simon.fraser</who>
    <bug_when>2024-09-06 14:27:36 -0700</bug_when>
    <thetext>Part of the issue here is that SVGFEDisplacementMapElement doesn&apos;t implement `outsets()`.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2058316</commentid>
    <comment_count>5</comment_count>
    <who name="Simon Fraser (smfr)">simon.fraser</who>
    <bug_when>2024-09-06 16:34:37 -0700</bug_when>
    <thetext>I will fix one subset of the issues via bug 279290.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2058324</commentid>
    <comment_count>6</comment_count>
    <who name="Simon Fraser (smfr)">simon.fraser</who>
    <bug_when>2024-09-06 16:54:07 -0700</bug_when>
    <thetext>I filed bug 279293 on https://codepen.io/thebabydino/pen/qBgweEw because WebKit slices in a different location.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2058330</commentid>
    <comment_count>7</comment_count>
    <who name="Simon Fraser (smfr)">simon.fraser</who>
    <bug_when>2024-09-06 17:09:18 -0700</bug_when>
    <thetext>I think with bug 279290 fixed, the only remaining issue is that https://codepen.io/thebabydino/pen/VwgNqpv remains blank.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2169134</commentid>
    <comment_count>8</comment_count>
    <who name="Simon Fraser (smfr)">simon.fraser</who>
    <bug_when>2026-01-04 11:43:04 -0800</bug_when>
    <thetext>I filed bug 304911 about https://codepen.io/thebabydino/pen/VwgNqpv not rendering</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>