SVG滤镜在Chrome和Firefox中看起来非常不同。

huangapple go评论65阅读模式
英文:

SVG filter looks very different in Chrome vs Firefox

问题

I have created an example here:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

&lt;svg viewBox=&quot;0 0 800 200&quot;&gt;
  &lt;defs&gt;
    &lt;filter id=&quot;cloth&quot;&gt;
      &lt;feTurbulence  seed=&quot;399&quot; type=&quot;fractalNoise&quot; baseFrequency=&quot;10.797&quot; id=&quot;weave&quot;/&gt;
      &lt;feColorMatrix type=&quot;saturate&quot; values=&quot;0&quot;/&gt;
      &lt;feComposite   operator=&quot;arithmetic&quot; k3=&quot;4&quot;/&gt;
      &lt;feComposite   operator=&quot;in&quot; in2=&quot;SourceGraphic&quot;    result=&quot;rComp1&quot;/&gt;
      &lt;feColorMatrix type=&quot;luminanceToAlpha&quot;              result=&quot;rColor1&quot;/&gt;
      &lt;feDiffuseLighting surfaceScale=&quot;-10&quot; diffuseConstant=&quot;0.5&quot;&gt;
        &lt;feDistantLight azimuth=&quot;225&quot; elevation=&quot;20&quot;/&gt;
      &lt;/feDiffuseLighting&gt;
      &lt;feComposite   operator=&quot;arithmetic&quot;   in2=&quot;rComp1&quot; k1=&quot;1&quot; k2=&quot;1&quot; k3=&quot;1&quot;/&gt;
      &lt;feBlend       mode=&quot;multiply&quot;         in =&quot;rColor1&quot;/&gt;
      &lt;feComposite   operator=&quot;arithmetic&quot;                       k2=&quot;1.2&quot;/&gt;
      &lt;feComposite   operator=&quot;in&quot;           in2=&quot;rComp1&quot; result=&quot;rComp2&quot;/&gt;
      &lt;feColorMatrix type=&quot;luminanceToAlpha&quot; in =&quot;rComp2&quot; result=&quot;rColor2&quot;/&gt;
      &lt;feDiffuseLighting surfaceScale=&quot;-10&quot; diffuseConstant=&quot;0.5&quot; id=&quot;surfaceScale&quot;&gt;
        &lt;feDistantLight azimuth=&quot;225&quot; elevation=&quot;20&quot;/&gt;
      &lt;/feDiffuseLighting&gt;
      &lt;feComposite   operator=&quot;arithmetic&quot;   in2=&quot;rComp2&quot; k1=&quot;1&quot; k2=&quot;1&quot; k3=&quot;2&quot; id=&quot;dye&quot;/&gt;
      &lt;feBlend       mode=&quot;multiply&quot;         in =&quot;rColor2&quot;/&gt;
      &lt;feComposite   operator=&quot;arithmetic&quot;                       k2=&quot;1.2&quot;/&gt;
      &lt;feComposite   operator=&quot;in&quot;           in2=&quot;rComp2&quot;/&gt;
    &lt;/filter&gt;
  &lt;/defs&gt;
  &lt;rect width=&quot;800&quot; height=&quot;200&quot; filter=&quot;url(#cloth)&quot;/&gt;
&lt;/svg&gt;

<!-- end snippet -->

Open it in Chrome and Firefox, and the results are quite different. I'm wondering if there is a formula to make them the same, like "multiply the k2 attribute in the feComposite elements by 1.8", something systematic. If not, then at least some suggestions as to how to get it to look like it does on Chrome on Firefox (I use Chrome as my primary dev browser, so that's where I designed the filter).

Unfortunately, it's a big filter, so there are a lot of attributes to fiddle with.

英文:

I have created an example here:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

&lt;svg viewBox=&quot;0 0 800 200&quot;&gt;
  &lt;defs&gt;
    &lt;filter id=&quot;cloth&quot;&gt;
      &lt;feTurbulence  seed=&quot;399&quot; type=&quot;fractalNoise&quot; baseFrequency=&quot;10.797&quot; id=&quot;weave&quot;/&gt;
      &lt;feColorMatrix type=&quot;saturate&quot; values=&quot;0&quot;/&gt;
      &lt;feComposite   operator=&quot;arithmetic&quot; k3=&quot;4&quot;/&gt;
      &lt;feComposite   operator=&quot;in&quot; in2=&quot;SourceGraphic&quot;    result=&quot;rComp1&quot;/&gt;
      &lt;feColorMatrix type=&quot;luminanceToAlpha&quot;              result=&quot;rColor1&quot;/&gt;
      &lt;feDiffuseLighting surfaceScale=&quot;-10&quot; diffuseConstant=&quot;0.5&quot;&gt;
        &lt;feDistantLight azimuth=&quot;225&quot; elevation=&quot;20&quot;/&gt;
      &lt;/feDiffuseLighting&gt;
      &lt;feComposite   operator=&quot;arithmetic&quot;   in2=&quot;rComp1&quot; k1=&quot;1&quot; k2=&quot;1&quot; k3=&quot;1&quot;/&gt;
      &lt;feBlend       mode=&quot;multiply&quot;         in =&quot;rColor1&quot;/&gt;
      &lt;feComposite   operator=&quot;arithmetic&quot;                       k2=&quot;1.2&quot;/&gt;
      &lt;feComposite   operator=&quot;in&quot;           in2=&quot;rComp1&quot; result=&quot;rComp2&quot;/&gt;
      &lt;feColorMatrix type=&quot;luminanceToAlpha&quot; in =&quot;rComp2&quot; result=&quot;rColor2&quot;/&gt;
      &lt;feDiffuseLighting surfaceScale=&quot;-10&quot; diffuseConstant=&quot;0.5&quot; id=&quot;surfaceScale&quot;&gt;
        &lt;feDistantLight azimuth=&quot;225&quot; elevation=&quot;20&quot;/&gt;
      &lt;/feDiffuseLighting&gt;
      &lt;feComposite   operator=&quot;arithmetic&quot;   in2=&quot;rComp2&quot; k1=&quot;1&quot; k2=&quot;1&quot; k3=&quot;2&quot; id=&quot;dye&quot;/&gt;
      &lt;feBlend       mode=&quot;multiply&quot;         in =&quot;rColor2&quot;/&gt;
      &lt;feComposite   operator=&quot;arithmetic&quot;                       k2=&quot;1.2&quot;/&gt;
      &lt;feComposite   operator=&quot;in&quot;           in2=&quot;rComp2&quot;/&gt;
    &lt;/filter&gt;
  &lt;/defs&gt;
  &lt;rect width=&quot;800&quot; height=&quot;200&quot; filter=&quot;url(#cloth)&quot;/&gt;
&lt;/svg&gt;

<!-- end snippet -->

Open it in Chrome and Firefox and the results are quite different. I'm wondering if there is a formula to make them the same, like "multiply the k2 attribute in the feComposite elements by 1.8", something systematic. If not, then at least some suggestions as to how to get it to look like it does on Chrome on Firefox (I use Chrome as my primary dev browser, so that's where I designed the filter).

Unfortunately it's a big filter, so there are a lot of attributes to fiddle with.

答案1

得分: 1

似乎 Chrome 在线性 RGB 色彩空间中的 feDiffuseLighting 实现不正确(至少在 Windows 上)。如果您在滤镜元素中添加 "color-interpolation-filters="sRGB"",它将切换到 sRGB 色彩空间,从而在各个浏览器中获得一致的结果。

(值得一提的是,这个滤镜比必要的复杂得多 - 当 baseFrequency 如此高时,无需使用光照效果 - 您应该能够通过一个或两个 feColorMatrixes 完成您想要的一切。)

英文:

It looks like Chrome's implementation of feDiffuseLighting in the linearRGB color-space is not correct (on Windows at least). If you add "color-interpolation-filters="sRGB" to your filter element, it will switch you to the sRGB color space and give you consistent results cross browser.

(FWIW - this filter is far more complex than it needs to be - there's no need to use lighting effects when the baseFrequency is this high - you should be able to do everything you want with one or two feColorMatrixes.)

huangapple
  • 本文由 发表于 2023年5月21日 04:37:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76297264.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定