XML technologies / SVG / Filters, transformations and gradients / Using and combining filters and lighting effectively / Filters and masks / The feBlend filter

(Excerpt from “Das Einsteigerseminar SVG — Webgrafiken mit XML” by Helma Spona)

The <feBlend> filter blends two objects in several ways. Its attributes are listed below, alongside the universal attributes.

Two formulas calculate the result: one for pixel opacity, one for color. The opacity qr always uses this formula:

qr = 1-(1-qa)*(1-qb)

Here, qa is the first image pixel’s opacity, and qb the second’s. Depending on the attribute mode, different formulas calculate color, as shown in the table:

Table: Settings of feBlend’s mode parameter.

Setting of mode

Formula

normal

cr = (1-qa)*cb+ca

multiply

cr = (1-qa)*cb+(1-qb)*ca+ca*cb

screen

cr = cb+ca-ca*cb

darken

cr = Min((1-qa)*cb+ca, (1-qb)*ca+cb)

lighten

cr = Max((1-qa)*cb+ca, (1-qb)*ca+cb)

Here, cr is the resulting color; ca is the first image pixel’s color, and cb the second’s color. The previous explanation applies to qb and qa.

Note:
This effect is useful only for objects with transparency. Fully opaque objects look no different from ordinary overlapping elements.

First add transparency to make the effect visible, for example setting the text’s property fill-opacity to 0.5. You also need two objects to blend. Shift the text a few pixels with the filter element <feOffset>.

<defs>
  <filter id="Blend">
    <feOffset dx="-3" dy="-3" in="SourceGraphic" result="rText"/>
    <feBlend mode="darken" in="SourceGraphic" in2="rText" />
  </filter>
  ...
</defs>
...
<g transform="translate(120,20)">
  <desc>Der Text mit Rechteck</desc>
  <rect x="0" y="0" width="150" height="75" style="fill:red;stroke:black;stroke-width:1"/>
  <text id="iText" x="20" y="55" style="filter:url(#Blend);fill-opacity:0.5; font-family:'Arial Black';font-size:46;stroke:black;fill:yellow">SVG</text>
</g>

The following figure shows three settings of the mode attribute: on the left mode="normal", in the middle mode="darken", and on the right mode="lighten".

Three variants of the feBlend effect

Figure: Three variants of the feBlend effect.

   

 

 

 

back to top