Inkscape: SVG Filter Effects

Exclusive offer: get 50% off this eBook here
Inkscape 0.48 Illustrator's Cookbook

Inkscape 0.48 Illustrator's Cookbook — Save 50%

109 recipes to create scalable vector graphics with Inkscape

$26.99    $13.50
by Mihaela Jurković Rigel Di Scala | April 2011 | Open Source

Get exclusive offers on Open Source Graphic Application and Library books through out this month. For more information click here.

Inkscape is frequently mentioned, and lauded, as one of the best examples of open-source software available today. It is a mature, feature-full and flexible product, thanks to a very dedicated developer community. The latest version, 0.48, adds new tools, such as the Airbrush (which many have longed for), and advanced path editing, among many other additions and improvements.

In this article by Mihaela Jurković and Rigel Di Scala, authors of Inkscape 0.48 Illustrator's Cookbook, we will cover:

  • Blurring
  • Creating irregular edges using filters
  • Using lighting effects
  • Creating a red wax seal
  • Creating a brushed steel effect
  • Creating a water surface effect
  • Filtering all objects in a layer
  • Creating your own filter from scratch

 

Inkscape 0.48 Illustrator's Cookbook

Inkscape 0.48 Illustrator's Cookbook

109 recipes to create scalable vector graphics with Inkscape

        Read more about this book      

(For more resources on this subject, see here.)

Introduction

Solid color and gradient vector objects can only get us so far when trying to create realistic shading and other complex effects. SVG filters give us the ability to achieve such effects on vector objects by combining various filter primitives.

Inkscape comes with a many different preset filters (all listed under the Filters menu) we can use straight away, although a few tweaks might be necessary to produce the intended result. This article will show us how to make those tweaks on some of the filters, and in the final recipe we will create our very own filter.

Due to the large number of filters available, trying to find the one closest to our needs using a trial and error process can be time consuming. To compare all the filter outcomes on the same object you can open the filters.svg file that comes with your Inkscape installation in the share/examples folder. When testing filters, be sure to use objects having strokes, gradient fills, and transparency as specimens, as some filters produce varying results depending on the object's attributes.

Filter rendering is quite CPU intensive and once they stack up they can reduce the Canvas update rate, so you might want to disable them temporarily by selecting the Menu | View | Display Mode | No filters mode, if you need to concentrate on another part of the drawing. To remove all filters from an object, select it and choose Menu | Filters | Remove Filters.

Blurring

The blur effect is versatile and has many possible applications in the realm of vector graphics. It is frequently used to enhance depth perception in a drawing, and to make certain elements stand out. It has its own section in the Inkscape menu (Menu | Filters | Blurs), where you will find several filter presets with descriptive names, such as "Apparition" and "Noisy". These presets combine different effects to produce a particular blur, and can be modified using the Filter Editor.

This recipe will show us how to use the Gaussian Blur filter and introduce us to some basic filters related options.

How to do it...

The following steps will demonstrate how to use Blurs:

  1. Select the Ellipse tool (F5 or E) and create an ellipse inside the page area. Set its fill to Lime (#00FF00), stroke to Green (#008000), and stroke width to 32.
  2. Open the Fill and Stroke dialog (Shift + Ctrl + F) and increase the blur to 7 using the Blur: slider. Notice how the edges of the ellipse (outside edge and the one between the fill and the stroke) get more and more blurred, and how the object bounding box is now larger.
  3. Open the Filter Editor by going to Filters | Filter Editor.... Notice that there is one filter listed in the Filter list. This is the blur filter applied to the ellipse, and under Effect there is one filter primitive, namely Gaussian Blur.

    Sometimes the filter selection in the Filter list isn't updated automatically, to refresh it simply deselect the object (Esc) and select it again.

  4. Under the Effect parameters tab make sure that the Link under Standard Deviation: is pressed and move the top slider to the right until you reach 25. Notice how the blur of the ellipse changes as the slider is moved, and also notice how the Blur: slider in the Fill and Stroke dialog changes with it (it will end up on 12.5). The object bounding box changes too.
  5. Press the Link button to unlink the X from the Y standard deviation slider and change the second (Y) slider to 0 to only blur the object in the X direction.
  6. Select the Filter General Settings tab and change the X box of the Coordinates: to 0.2 and the Y to 0.25. Set X box of the Dimensions: to 0.6 and the Y box to 0.5. Notice how the object gets clipped as we change the settings.

    Inkscape: SVG Filter Effects

How it works...

We can apply the Blur filter to the currently selected object by using the slider in the Fill and Stroke dialog (Blend can also be applied to layers). If we want to apply blurring through the Filter Editor we can use the Simple blur that can be accessed from the menu, under the Filters | ABCs category.

The Blur: slider is actually the standard deviation property of the blur although the scale is doubled. Changing one automatically updates the value of the other.

If we want to apply a more complex blurring effect we have to open the Filter Editor and unlink the X and Y standard deviation options.

The size of the filter region is a common setting to all filters and is defined by the Dimensions parameters in the Filter General Settings tab found in the Filter Editor. It is obvious from our blur example how the filter region needs to be larger than the original object size to avoid clipping at the original bounding box edges and get the expected result. A predefined, finite region is necessary because the standard deviation function is calculated using an infinite plane, which is both impractical and unnecessary in this context.

A more "natural selection"
Selecting filtered objects using the rubber-band selection is a hit-and-miss affair because the bounding boxes are usually larger compared to the unfiltered state. Another way of selecting can be very helpful in that case. First empty your selection in case you have anything selected (Esc), hold Alt, and start dragging over the objects you want selected. A red line appears when we start dragging and all objects it touches are selected. The selection must be empty otherwise Alt triggers the movement of the selection. The Shift key can also come in handy to add any objects we missed.

Using the Blur: slider in the Fill and Stroke dialog adjusts the filter region automatically so the object isn't clipped at any side. If we want to change the region manually we can do so through the Filter Editor.

Having only one filter primitive inside the filter structure makes it the simplest filter we'll encounter. More complex filters consist of more than one filter primitive and those primitives are usually of different types.

There's more...

Many different blur presets are present in the Blurs section, such as Motion blur, horizontal and Motion blur, vertical, which we learned how to do manually. Using the presets can be a bit quicker but they always apply the same amount of blurring so if it doesn't turn out to be the right amount you will need to adjust that manually.

A lot of filters from other categories also use the Gaussian Blur filter primitive as part of their structure and although most of them can't be labeled as blur effects some could easily be listed under the Blurs category. Examples are the Feather filter under the ABCs category, Soft colors under the Color category that produces the well-known Ortoneffect, used in photo manipulation to produce hazy, dreamlike landscapes, Soft focus lens under Image effects, and Fuzzy Glow under Shadows and Glows.

Creating irregular edges using filters

In this recipe we will create a sheet of paper with burnt edges, using the Roughen and Blur content filters.

How to do it...

The following steps will demonstrate how to create burnt paper edges:

  1. Select the Rectangle tool (F4 or R) and create a 400x500 px rectangle. Set its fill to #fff7d5ff, stroke to #2b1100, and stroke width to 16.
  2. Apply the Roughen filter by going to Filters | ABCs | Roughen. Notice how all the edges (outside edge and the one between the fill and the stroke) turned irregular.
  3. Now all that's left is to blur the edge between the fill and the stroke, which can be done by going to Filters | Blurs | Blur content.
  4. Change the stroke width to 8.
  5. Open Filter Editor, select the Turbulence primitive from the Effect list, change the Type: to Fractal Noise, and change the Base Frequency: to 0.025.
  6. Select the Displacement Map primitive from the Effect list and change the Scale: slider to 30. We now have our burnt sheet of paper.

    Inkscape: SVG Filter Effects

How it works...

Applying Roughen and Blur content brings us close to our goal but some tweaks to the filters are necessary. Since no clipping occurs when applying Roughen or Blur content we had to compensate by halving the stroke in this recipe.

The Turbulence filter primitive is used when our object has a property that is chaotic and random up to a point. It is often used when creating realistic textures. There are two types of Turbulence primitive filters and it can be hard sometimes to predict which one is better for our current case and it's the same with a lot of settings. Try experimenting with the different options available before settling on one.

As you can guess from the name, the Displacement Map shifts parts of the object from their positions. Although this description is overly simplified we can deduce why its Scale: slide changes the object edges to be more or less irregular.

The amount of blurring we got using the Blur content filter seems to be right for our example. Else, we would be able to tweak the amount in the Gaussian Blur primitive.

There's more...

Roughen isn't the only filter that can be used to create irregular edges, but it proved itself as a good choice for the burnt paper edges look we expected to achieve. Most of the other filter presets that make the object edges irregular can be found under Distort, Protrusions, and Textures.

Inkscape 0.48 Illustrator's Cookbook 109 recipes to create scalable vector graphics with Inkscape
Published: April 2011
eBook Price: $26.99
Book Price: $44.99
See more
Select your format and quantity:
        Read more about this book      

(For more resources on this subject, see here.)

Using lighting effects

Lighting effects can make a flat object, such as a label, acquire the three dimensional look of a button through the use of highlights and shadows. Inkscape comes with Diffuse light and Specular light filters that create soft light sources, such as those produced by rays of sunlight shining on a wall, or reflected light sources.

This recipe will show us how we can use those filters to give our viewer an illusion of three dimensions.

How to do it...

The following steps will demonstrate how to use lighting effects:

  1. Select the Star tool (Shift + F9 or *) and create a star with four corners. Set Spoke ratio: to 0.477 and Rounded: to 0.14. Set its fill to a color you like (we used #0066FF in the picture) and remove the stroke. Stamp it three times (Space) to get four stars in total.
  2. Select one star and apply the Diffuse light filter to it by going to Filters | ABCs | Diffuse light. Notice how the object appears to be three dimensional, being lit by a distant light source coming from the upper-left corner.
  3. Select the second star and apply the Specular light filter to it by going to Filters | ABCs | Specular light. Notice that the highlight appear to be reflected from the object.
  4. Select the third star and apply the Combined lighting filter to it by going to Filters | Bevels | Combined lighting. Notice how our star now has a more realistic 3D look.
  5. Select the fourth star and apply the Combined lighting filter again, like we did in Step 4.
  6. Open the Filter Editor. Notice that the filter applied to the fourth star is active. Select the first Gaussian Blur primitive by clicking on it and increase the Standard Deviation: to 16.
  7. Select the Diffuse Lighting primitive by clicking on it and change the Surface Scale: to 30 on the Effect parameters tab. Notice how the object looks less flat.
  8. Select the Specular Lighting primitive by clicking on it and change the Exponent: to 40 and Elevation to 66.
  9. Select the second Gaussian Blur primitive by clicking on it and increase the Standard Deviation: to 10. Notice how the highlight now appears to be reflected from an object that is more plump.

    Inkscape: SVG Filter Effects

How it works...

If you take a look at the structure of the Diffuse light and Specular light filters and compare it to the Combined lighting filter, you'll see that the Combined lighting is simply diffuse and specular light filters applied to an object at the same time. There are some minor differences in the filter settings and they are visible in our examples. Which filter you use is completely up to the case you're working on, although using Combined lighting might be a quicker and simpler way of reaching a more complete 3D look.

Tweaking the settings of the Combined lighting filter enabled us to make the object appear more plump. You probably noticed that the settings for diffuse and specular primitives only differ in Exponent: option which is present only in Specular lighting and makes the object appear more shiny.

However, to get the look we wanted we also had to tweak the Gaussian Blur primitives that feed into the diffuse and specular primitives. Here we can see how filter primitives work together. Most often they do their bit and pass the result to the next primitive. Understanding of the inner workings of filter primitives helps to guess which options and which primitives to tweak to achieve a certain result, although we can often get by with the trial and error method. If you are curious about what's going on "behind the scenes", refer to the SVG filters working draft.

Notice that we didn't have to touch the Composite primitives. They are there simply because of the nature of the lighting filters. Lighting filters are applied to the whole filter region, shading them completely. But our intention is to confine the shading to the object edges and Composite primitives enable us to do just that. The last Composite primitive applied to an independent effect (such as diffuse or specular lighting) always uses the Source Graphic as one of its inputs limiting the output inside the object edges.

We had to apply the Combined lighting filter independently to the last two stars because if we duplicated the star, the duplicate would inherit the filter and we wouldn't be able to edit the filters applied to them independently. This means that we can share filters between objects, we can create a filter on one object and apply it to another by enabling it in the Filter list when the object is selected, or simply use Paste Style.

There's more...

There is an option of Diffuse Lighting and Specular Lighting primitives that can add even more complexity into the lighting effects, and that is Light Source. We can choose between Distant Light, Point Light, and Spot Light as our light sources. All of the light sources come with options that set their location with respect to the object they are shining on.

Distant Light emits parallel rays of light. Azimuth controls the direction of where the light is coming from with regards to the canvas plane covering 360 degrees, and the Elevation controls how high the light source is above or below the object.

Point Light can be set in space using the usual X, Y, and Z coordinates, shining rays of light in all directions from that location, which are obviously not parallel.

Spot Light is like a Point Light, only it doesn't shine in all directions but covers a limited area on the object's surface. Specular Exponent and Cone Angle are codependent and they control how large the area is and how concentrated it appears to be.

The lighting filters we used in this recipe are the base ones. There are a number of other filters that achieve different 3D effects. You can find most of them under Bevels and Shadows and Glows filters.

Creating a red wax seal

In this recipe we will apply what we've learned so far about the filters by creating a red wax seal with the help of lighting filters.

The drawing will consist of three objects: the stamp area, the stamp sign, and the remaining wax surrounding the stamp area. Each object will be filtered independently to achieve a realistic look and adjust the filter settings to a particular object size.

How to do it...

The following steps will demonstrate how to create a wax seal:

  1. Select the Ellipse tool (F5 or E) and create a 250 px wide circle inside the page area. Set its fill to a dark shade of red, such as #D40000, and remove the stroke. This will be the wax stamp area.
  2. Apply the Inner Shadow filter to the circle by going to Filters | Shadows and Glows | Inner Shadow.
  3. Select the Pencil tool (F6 or P) and create a wavy outline (using the Freehand line setting and shape set to None) around the circle where you want the wax edge to be. Set its fill to the same shade of red (#D40000) and remove the stroke. This is the spilled wax object.
  4. Select the circle behind the object (hold Alt and click to select under) and duplicate the circle (Ctrl + D). Add the spilled wax object to the selection and go to Path | Difference (Ctrl + -).
  5. Apply the Combined lighting filter to the outer wax object by going to Filters | Bevels | Combined lighting.
  6. Select the circle and make it slightly bigger so the background doesn't shine through at the edges where the circle meets the wax object. Hold Shift to scale from the circle center and Ctrl to maintain the ratio.
  7. Open the inkscape.logo.svg file that comes with your Inkscape installation under the share/clipart folder and copy the logo into the wax seal document centering it over the stamp area. The Inkscape logo will be our stamp sign.
  8. Ungroup the logo (Shift + Ctrl + G). Combine the white objects into one (Ctrl + K), then add the black mountain/ink into the selection and go to Path | Difference (Ctrl + -) to get a single path to serve as the stamp sign.
  9. Apply the Combined lighting filter to the logo path by going to Filters | Bevels | Combined lighting. Now set the fill color of the logo to the same shade of red we used previously (#D40000).

What we have now does resemble a wax stamp but we need to do some tweaking to make it more realistic and finish the drawing. We'll edit each object's filter one by one and adjust them so they together form a meaningful drawing.

The outside wax should look plumper so we'll adjust that object and also the Inset filter of the stamp area because together they form the 3D illusion of the wax surrounding the stamp area.

The Inkscape logo should have more defined edges so it's more believable that it was created using a stamp. The following steps add fine touches to the stamp:

  1. Open the Filter Editor by going to Filters | Filter Editor...
  2. Select the spilled wax object, choose the first Gaussian Blur primitive, and increase its Standard Deviation: to 20.
  3. Select the Diffuse Lighting primitive and set Surface Scale: to 20, Constant: to 0.9, and Elevation to 50. The object should now look a bit plumper.
  4. Select the second Gaussian Blur primitive and increase its Standard Deviation: to 12.
  5. Select the Specular Lighting primitive and set Surface Scale: to 20, Constant: to 1.3, Exponent: to 40, and Elevation to 50.
  6. Select the circle (stamp area), in the Effect area. Select Gaussian Blur and set its Standard Deviation: to 8.
  7. Select the Offset primitive and change both deltas to 8.
  8. Select the Flood primitive and change the Flood Color: to #2E0000 (very dark brown). This will soften the shadow.
  9. Select the Inkscape logo path and in the first Gaussian Blur primitive change Standard Deviation: to 3.
  10. Select Diffuse Lighting primitive and set Surface Scale: to 5, Constant: to 0.9, and Elevation to 50.
  11. Select the second Gaussian Blur primitive and set its Standard Deviation: to 3.
  12. Select the Specular Lighting primitive and set Surface Scale: to 4, Constant: to 1.3, Exponent: to 40, and Elevation to 50.

Although we tweaked the filters to get the desired 3D effect, it still seems like something's missing. It's hard to avoid shadows in the real world, and that seems to be missing from our drawing. We can see where the light is coming from but there are some shadows missing that should be there. Also the outer wax object surface isn't smooth as a result of the filters we applied, we can fix it with some blurring. The following steps add the finishing touches to our wax stamp:

  1. Add the Drop Shadow filter to the Inkscape logo by going to Filters | Shadows and Glows | Drop Shadow... and set the Blur radius, px to 3, Opacity, % to 50, and both offsets to 1.
  2. Select the outer wax object and add the Drop Shadow filter, and set the Blur radius, px to 7, Opacity, % to 70, and both offsets to 3. We now have our wax seal!

    Inkscape: SVG Filter Effects

How it works...

Cutting out a hole in the outer wax object ensured we got correct highlights. If we hadn't done that the filter would be applied to the object as if it's a piece of material without indentations and we wouldn't get the highlights in the bottom-right of the object. This example also shows us we can edit the paths after a filter has been applied and the filter will automatically adjust to the new shape.

Both Diffuse light and Specular light start with the Gaussian Blur primitive. The output from that Gaussian Blur is used by the lighting primitives and it changes the object's appearance to more or less flat. This is the first step in changing the object "size".

Lighting primitive settings take some experimentation before you can predict their outcome, but it's well worth the effort. The object size also has some effect on the final result. If you apply the same filter to two object of different sizes the outcome won't be scaled. To achieve the same effect on an object of a different size the filter settings need to be adjusted.

There's more...

You probably noticed artifacts on the outer wax surface. They sometimes happen with lighting filters due to limited resolution on the bump map used in those filters. To remove them we can add another Gaussian Blur filter primitive to the Effect list of that object and apply enough blurring to make the artifacts go away. After that we need to clip the object to its original edges using clipping or another Composite filter primitive with the second in attribute set to Source Graphic and the Operator: to In.

This workaround doesn't help with specular light through because blurring destroys the effect.

Creating a brushed steel effect

In this recipe we will modify the Film grain filter to resemble brushed steel, a texture that is often used as panel textures for websites and interfaces of operating systems, such as Mac OS X and Enlightenment DR16 for Linux and BSD.

How to do it...

The following steps will demonstrate how to create a brushed steel effect:

  1. Select the Rectangle tool (F4 or R) and create a 600x300 px rectangle. Set its fill to 20% Gray and remove the stroke.
  2. Apply the Film grain filter by going to Filters | Image effects | Film grain.
  3. Open the Filter Editor by going to Filters | Filter Editor.... The Film grain filter and the Turbulence primitive will be selected.
  4. Under the Effect parameters tab, click on the Link button to unlink the X and Y Base Frequency: setting.
  5. Move the X slider of the Base Frequency: almost all the way to the left. Keep an eye on the drawing and stop when the pattern looks acceptable (0.005 in my case).
  6. Select the Composite primitive and change the K1: attribute to 0.3, K2: to 0.7, K3: to 0.15, and K4: to 0.05. We have our brushed steel texture!

    Inkscape: SVG Filter Effects

How it works...

When trying to create a new texture from an existing filter the first important step is to choose the most convenient filter to start from. A brushed steel effect is very often created using a noise texture as the starting point, so Film grain seemed perfect for the job.

The Turbulence primitive has a very convenient option to set a different Base Frequency: value for the X and Y directions. That is how we achieved the "stretched" look.

Changing the Composite K arithmetic values helped us get the color right. Playing with different value combinations can get us to the desired result. For best results, don't move far away from 0 in any direction. Hovering over the sliders gives us tooltips that describe what each attribute does so, if you're mathematically inclined, try reading them and see if you can predict the outcome of various value combinations—you'll probably find out that drawing is more fun!

We didn't have to change the Color Matrix primitive because the settings from the Film grain suited us perfectly for the steel gray look. Try changing the saturation Value(s): option to 1 and see a nice rainbow effect through our steel.

Inkscape 0.48 Illustrator's Cookbook 109 recipes to create scalable vector graphics with Inkscape
Published: April 2011
eBook Price: $26.99
Book Price: $44.99
See more
Select your format and quantity:
        Read more about this book      

(For more resources on this subject, see here.)

Creating a water surface effect

In this recipe we will create a filter the mimics a water surface using the 3D wood filter. It might be surprising to use something that has "wood" in its name to create something completely different! There are filters with "liquid" in their names that can be used to achieve similar effect, but this recipe will show us that lateral thinking while searching for the "right" filter can be very beneficial; by being imaginative we can solve a problem in an innovative way.

How to do it...

The following step will demonstrate how to create a water surface effect:

  1. Select the Rectangle tool (F4 or R) and create a 600x300 px rectangle. Set its fill to a shade of blue, like #0044AA, and remove the stroke.
  2. Apply the 3D wood filter by going to Filters | Materials | 3D wood.
  3. Open the Filter Editor. The 3D wood filter and the Gaussian Blur primitive will be selected.
  4. We immediately notice that the wood grooves are too fine to represent water ripples so we adjust the Turbulence-Base Frequency: sliders to 0.006 and 0.04 to get "bigger" ripples.
  5. The Octaves: option also brings in too much detail so we reduce it to 2.
  6. Our "ripples" still don't look realistic, as they are too blurry. This is due to the first Composite primitive being set to show the Source Graphic inside the area defined by the Gaussian Blur primitive. To correct this we composite the Source Graphic with the Turbulence primitive by clicking on the lower arrow on the Composite primitive and dragging it to the right and up until it reaches the arrow or the bottom line of the Turbulence primitive.
  7. The Displacement MapScale: option affects how "disturbed" our water surface is. Any value between 50 and 100 can do, and I went with 80.
  8. The Flood primitive introduces a beige color for the original wood effect. Replace it with white (#FFFFFF) and notice we now have the light reflections form the ripples.
  9. The set of primitives near the bottom of the list consisting of Gaussian Blur, Specular Lighting, and the two Composite primitives that follow, only affect the object edge to create the 3D effect. We can bypass them by making the Convolve Matrix primitive feed from higher up in the list: click on the Convolve Matrix arrow and drag to the right and up until you reach the Composite that is above the Gaussian Blur.
  10. Go back to the Turbulence primitive and take a look at what the effect looks like when Type: is set to Turbulence—it's still a water surface, but maybe rain is making it ripple more.
  11. Duplicate the object and move it away. Remove the filter by going to Filters | Remove Filters.
  12. For comparison, apply the Shaken liquid filter by going to Filters | Textures | Shaken liquid and set the Turbulence primitive Base Frequency: to 0.016 and 0.052. We now have three different water surface filters to choose from.

    Inkscape: SVG Filter Effects

There's more...

The set of primitives we bypassed can be removed completely from the Effect list, but we left them in there just in case we change our minds and want to create a 3D plate with a water effect on it. Filter primitives can be removed by right-clicking on them and choosing Remove.

Using a different shade of blue or green and adjusting the saturation changes the scene atmosphere from night to day or the type of water (sea, lake, pool). Since we set the Flood to white we don't have to adjust the highlight color. It is enough to simply change the fill color of the object.

The possibilities offered by combining primitives are endless. Once you start playing with them you will be inspired to create new combinations and experiment with different settings. You can find more interesting texture filters under the Bumps, Materials, Overlays, and Texture categories.

Filtering all objects in a layer

A blending filter primitive can be applied to a layer by using the Layers dialog and selecting a Blend mode. There's a catch however: you can only choose one from a predefined list.

There is a way though to apply a complex filter to a whole layer manually. This method was first invented by the Inkscape forum user kelan (http://www.inkscapeforum.com) and expanded by Ivan Loulette. It involves playing some dirty tricks with the XML editor, but the results are quite effective.

This recipe will guide us through that method of adding a filter to all objects in a layer.

How to do it...

The following steps will demonstrate how to use a filter on all the objects in a layer:

  1. In a new document open the Layers dialog (Shift + Ctrl + L) and create a new layer. Name it "Filtered".
  2. Select the Rectangle tool (F4 or R) and create a rectangle. Set its fill to #0044AA and remove the stroke.
  3. Apply the 3D mother of pearl filter by going to Filters | Materials | 3D mother of pearl.
  4. Open the XML editor (Shift + Ctrl + X), expand the svg:defs element, and select the svg:filter element inside it.
  5. In the right-hand pane find the id attribute, select it by clicking on it and copy its value from the bottom area. It will be of the form "filter1234".
  6. Select the svg:g element in the left-hand pane that has inkscape:label set to "Filtered".
  7. Add a style attribute by writing "style" into the field next to the Set button, writing "filter:url(#filter1234)" into the text area box at the bottom (where the number 1234 is the number we copied from the filter id), and pressing the Set button. Our Filtered layer now has the 3D mother of pearl filter applied.
  8. Close the XML editor and notice our rectangle now has the filter applied to it twice, once as an object and the second time because it's in the layer where that filter is applied. Go to Filters | Remove Filters to remove the "object" filter, so only the one from the layer stays.
  9. Select the Star tool (Shift + F9 or *) and create a star in the Filtered layer. The 3D mother of pearl will be automatically applied to it, as will any object we create in that layer.

How it works...

Filters and their settings are kept in svg:defs elements along with any gradient or pattern information too. Every such resource from svg:defs has a unique ID called the id attribute. To apply a filter or some other resource to an object, a reference to the filter we want to use is added inside the object's style attribute.

What we did here is reference a filter from a layer instead from an object in a layer. This isn't surprising if we remember that the Inkscape layers are nothing more than SVG group elements with a bit of special "Inkscape sauce" (there are no layers in the SVG specifications).

Maybe in some future versions of Inkscape, this method will be accessible through a graphical interface so it will be easier to apply it.

Creating your own filter from scratch

If modifying a preset filter seems like too much work we can create a filter from scratch, which we will do in this recipe trying to achieve a "Nebula" effect.

How to do it...

The following steps will demonstrate how to create your own filter:

  1. Open the Filter Editor by going to Filters | Filter Editor...
  2. Press the New button. Notice a new filter is created in the Effect list without any primitives.
  3. Click on the filter name and rename it to "My Filter".
  4. Beneath the Effect pane there is a widget to add a new primitive to the current filter. Select Gaussian Blur from the drop-down list and press the Add Effect: button.
  5. Change the Standard Deviation: in the Effect parameters tab to 10.
  6. Now select Turbulence from the drop-down list and press the Add Effect: button. Set Type: to Fractal Noise, Base Frequency: to 0.008, and Octaves: to 5.
  7. Select Displacement Map from the drop-down list and press Add Effect: button. Set the Scale: slider to 100.
  8. Select Composite from the drop-down list and press the Add Effect: button. Click on the top arrow and drag it to the right and up until it reaches the arrow or the bottom line of the Turbulence primitive.
  9. Select Turbulence from the drop-down list and press the Add Effect: button. Set Type: to Turbulence, Base Frequency: to 0.015, and Octaves: to 1.
  10. Select Composite from the drop-down list and press the Add Effect: button. Click on the bottom arrow and drag it to the right and up until it reaches the arrow or the bottom line of the first Composite primitive.
  11. Open the XML editor (Shift + Ctrl + X), expand the svg:defs element, and select the svg:filter element inside it.
  12. Add a color-interpolation-filters attribute by writing "color-interpolationfilters" into the field next to the Set button, writing "sRGB" in the text area box at the bottom, and pressing the Set button. Our filter is done.

    Inkscape: SVG Filter Effects

How it works...

As we could see from the example, it's very easy to create new filters and change their structure. The tricky part is to understand the primitives so we know which one to pick next and how to set it up. Studying the structure of the preset filters can help us understand the concept better and gain some experience.

Our "Nebula" example could certainly be improved. Can you think of any suggestions which may improve the picture and make it similar to those awe-inspiring astronomical pictures taken by observatories and satellites?

In the end we added a special attribute to our filter using the XML editor. This attribute is only necessary if you plan to display your drawing in a SVG renderer other than Inkscape because Inkscape doesn't use the standard SVG color space (linearRGB) with filters. This only needs to be done on filters we create from scratch, as the preset ones already have that attribute.

Summary

In this article we experimented with SVG filter effects, taking vector graphics to a new level of sophistication, and created our own filter from scratch.


Further resources on this subject:


About the Author :


Mihaela Jurković

Mihaela Jurković is the owner of a small Croatian web development shop. Drupal, Inkscape and linux are the most common words in her open source dictionary. In addition to being a friendly ghost on the Inkscape forum she also enjoys photography, hiking, TED talks and lolcats.

Rigel Di Scala

Rigel discovered computer graphics on a Commodore VIC-20 as young child. Before going insane trying to render artistic landscapes using only the limited character set of his primitive 8-bit computer, he upgraded to a CBM Amiga 500 and started creating his first bitmaps with Dan Silva's Deluxe Paint II.

During his college years he started working part-time as a Web developer and consultant for several institutions and companies, and later as a system administrator, journalist and editor in the computer games industry.

Today he works as a Web application developer for an IT company based in Milan. He promotes and uses open-source technology exclusively in his projects. Inkscape is his tool of choice for developing vector graphics.

In his free time, he likes to freeclimb, skydive and read Reddit.

Books From Packt


Inkscape 0.48 Essentials for Web Designers
Inkscape 0.48 Essentials for Web Designers

GIMP 2.6 cookbook
GIMP 2.6 cookbook

Python 2.6 Graphics Cookbook
Python 2.6 Graphics Cookbook

Blender 2.5 Character Animation Cookbook: RAW
Blender 2.5 Character Animation Cookbook: RAW

Scribus 1.3.5: Beginner's Guide
Scribus 1.3.5: Beginner's Guide

OGRE 3D 1.7 Beginner's Guide
OGRE 3D 1.7 Beginner's Guide

OpenSceneGraph 3.0: Beginner's Guide
OpenSceneGraph 3.0: Beginner's Guide

Blender 3D 2.49 Architecture, Buildings, and Scenery
Blender 3D 2.49 Architecture, Buildings, and Scenery


Your rating: None Average: 5 (1 vote)

Post new comment

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
n
z
h
X
B
G
Enter the code without spaces and pay attention to upper/lower case.
Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software