Graphics Reference
In-Depth Information
Artistic Effects
If you use a commercial image manipulation program such as Photoshop or a
general-distribution version such as GIMP, you will find a number of “artistic
filters” that you can use to make an image look more like a painting or as if any
of several other kinds of thing had been done to it. It is interesting to consider
how you might be able to create such artistic effects with a GLSL fragment
shader.
A general approach might be to select a region of several texels from the
image relative to the current texel, and apply some sort of process that results
in a single color value. For example, you might choose the texel in the region
that has the greatest luminance. In Figure 11.14 we have done that to create a
painting effect for the familiar cherry blossom figure of this chapter. The pro-
cess is fairly straightforward; we develop a full 5 × 5 texel rectangle R around
an individual pixel, as well as a 5 × 5 mask rectangle M whose values are sim-
ply zero or one. We then look at the luminance values of each texel in the set
RM and use the texel with the highest luminance value in the place of the
particular pixel. The code is rather long because, at this writing, GLSL does not
allow variables to be used as array indices, so we will not include it here. It is
available with the resources for the topic.
It is straightforward to choose which values are zero and which are one
in the mask, and changing the “shape” of the mask will change the effect of the
filter. You can use other criteria besides the maximum luminance to select the
color for the pixel. There is ample ground here for fruitful experimentation!
Figure 11.14. An image (left) with a painting-effect filter applied (right).
Search WWH ::




Custom Search