How do you make multiple "stacked" filters?

Discuss SVG code, accessible via the XML Editor.
abeall
Posts: 2
Joined: Sun Jun 06, 2010 1:50 pm

How do you make multiple "stacked" filters?

Postby abeall » Sun Jun 06, 2010 2:35 pm

Greetings.

Can anyone give me any pointers as to how you would do the following in SVG:

Given a path with a set fill/stroke, apply two conceptual filters to it: a red glow and a blue dropshadow.

I can make the two separately using a combination of fwGuassianBlur, feOffset, feColorMatrix, and feBlend, but I can't put the two together. At the moment I have:

Code: Select all

      <filter id="filter5" x="-100%" y="-100%" width="300%" height="300%">
         <!-- Glow -->
         <feColorMatrix result="matrixOut" in="SourceGraphic" type="matrix" values="0 0 0 0 1  0 0 0 0 0  0 0 0 0 0  0 0 0 1 0"/>
         <feGaussianBlur result="blurOut" in="matrixOut" stdDeviation="26"/>
         <feBlend in="SourceGraphic" in2="blurOut" mode="normal" result="blendOut"/>         
         <!-- Drop Shadow -->
         <feOffset result="offsetOut" in="blendOut" dx="10" dy="10"/>
         <feColorMatrix result="matrixOut" in="offsetOut" type="matrix" values="0 0 0 0 0  0 0 0 0 1  0 0 0 0 1  0 0 0 0.65 0"/>
         <feGaussianBlur result="blurOut" in="matrixOut" stdDeviation="8"/>
         <feBlend in="SourceGraphic" in2="blurOut" mode="normal"/>
      </filter>


I think the biggest hurdle is that I don't know how to colorize the shadow only. The second feColorMatrix in the drop shadow colorizes the entire object, since it was already blended together in blendOut.
Last edited by abeall on Tue Jun 08, 2010 2:33 am, edited 1 time in total.

User avatar
tomh
Posts: 218
Joined: Sat Feb 14, 2009 10:14 pm

Re: How do you make

Postby tomh » Mon Jun 07, 2010 8:06 am

Ok, I had to have a look at it in the inkscape effects editor: It helps a lot to have the connections visualised...

Here is what I have got.

Code: Select all

<filter id="filter2928" x="-100%" y="-100%" width="300%" height="300%" inkscape:label="Original">
  <!-- Glow -->
      <feColorMatrix result="matrixOut" in="SourceGraphic" type="matrix" values="0 0 0 0 1  0 0 0 0 0  0 0 0 0 0  0 0 0 1 0" />
      <feGaussianBlur result="blurOut" in="matrixOut" stdDeviation="26" />
      <feBlend in="SourceGraphic" in2="blurOut" mode="normal" result="Glow" />
  <!-- Drop Shadow -->
      <feOffset result="offsetOut" in="SourceGraphic" dx="26.21359223300972" dy="26.21359223300972" />
      <feColorMatrix result="matrixOut" in="offsetOut" type="matrix" values="0 0 0 0 0  0 0 0 0 1  0 0 0 0 1  0 0 0 0.65 0" />
      <feGaussianBlur result="shadow" in="matrixOut" stdDeviation="8"/>
  <!--The mixing -->
      <feBlend blend="normal"  in2="Glow" in="shadow" result="result1" />
    </filter>



The most important part is working out where to use the SourceGraphic input to start a new section of the filter, and then to use the blend to combine the two sections of the filter together.

Honestly though, Use the Inkscape filter to visualise the connections.

abeall
Posts: 2
Joined: Sun Jun 06, 2010 1:50 pm

Re: How do you make multiple "stacked" filters?

Postby abeall » Wed Jun 09, 2010 12:40 am

Hm, I think my previous reply got lost because I changed the title (had accidentally left it cut off as "How do you make"!) and it required the post to get re-approved I think. So, from memory:

Thanks for the help! So the trick is all about blending the right stuff. If I had more that 2 filters, I suppose I could use feMerge instead of feBlend. The only I'm still having a hard time wrapping my head around is how to make it stack... if I use feMerge to merge 3 filters after they have been rendered, and they are all rendered from the SourceGraphic, it isn't "stacked" like I would expect...

I can't seem to find the effects editor, where is that? Sounds like exactly what I need to experiment with.

Thanks!

vwanweb
Posts: 169
Joined: Sun Jun 06, 2010 1:48 pm

Re: How do you make multiple "stacked" filters?

Postby vwanweb » Sat Aug 07, 2010 8:51 am

After you apply the first filter, Group the object (even though it only one item), then apply the second filter.


Return to “SVG / XML Code”