Seamless Texture Tutorial

From GameStudio Wiki

Revision as of 09:10, 6 May 2006; view current revision
←Older revision | Newer revision→
Jump to: navigation, search

creating seamless textures with the gimp

this tutorial describes how to create seamless textures from photographs with the GIMP 2.0 (and newer versions). the windows installer for the GIMP can be downloaded from http://gimp.org/windows/. make sure you install the GTK+ toolkit first.

Image:gimp003bw.jpg
  • start the GIMP and open the photograph you want to use as source for your texture (a great website with free high resolution photographs which are well suited as source for textures is http://www.mayang.com).
  • use the crop tool (knife icon in the toolbar) to select a square region in the image. textures should use power of two sizes. it's possible to specify the size of the selection in the dialog box of the crop tool or you can scale the image afterwards (image -> scale image...).

before:

Image:gimp018nv.jpg

after:

Image:gimp024bz.jpg

  • one way of making textures seamless in GIMP is using the <make seamless> filter (filters -> map -> make seamless). this filter automatically cross-fades the borders of the image. for some kinds of textures (like the grass texture on the example screenshots) the results of this method may look good enough, in many cases the blends look too artificial though.
  • bupaje shared a very useful trick: "The option you mention of the automatic "make seamless" doesn't work well for all patterns as you said but one 'trick' I have used it for occasionally is to generate a seamless tile, use the freehand selection tool to select a sort of 'picture frame' and feather then you can lay this as a layer on top of the textures. I'm not at home or I could send an example but to clarify if you have a dirt picture, use 'make seamless' then cut out the tiling 'frame' you can create several different variations of your dirt tile 'center' and as long as you use the same 'frame' they will tile with each other. I don't use that technique often with handdrawn stuff but with photos it can be useful to say cut several tiles out of one large dirt photo, give them a shared 'frame' and end up with 5-6 variations that can then be tiled together."

Image:gimp038uo.jpg

  • to get rid of the border seams manually, the seams have to be made visible first. this can be done with layer -> transform -> offset... -> offset by (x/2),(y/2).

Image:gimp048go.jpg

  • the clone tool is suited for retouching the seams. adjust its opacity and select a proper brush (if none of the predefined brushes fits your needs you can create your own ones with the brush editor). with ctrl+left click the source location of the cloning can be set. with the left mouse button you can draw. once no seam is visible anymore, offset the image again to check if you didn't accidentally create additional seams with the clone tool.

using a high-pass filter

sometimes a texture tiles perfectly well at the edges but annoying repeating patterns are visible if the texture is tiled many times over because of low frequency detail (areas of different brightness) in the image. with a high-pass filter it's possible to filter out these low frequencies. there is no high-pass filter in the GIMP but the fact that a gaussian blur basically is a low-pass filter can be exploited.

high-pass filtering can be achieved with the following steps:

  1. duplicate the layer
  2. apply a gaussian blur
  3. invert the layer
  4. desaturate the layer (the high-pass filter should only affect luminosity)
  5. set layer blending mode to overlay
  6. merge down the layer

the GIMP has very powerful scripting abilities which can be used to automate this task.

(
define (high-pass image drawable radius)
  (gimp-image-undo-group-start image)
  (set! new-layer (car (gimp-layer-copy drawable 0)))
  (gimp-drawable-set-name new-layer "temporary layer")
  (gimp-image-add-layer image new-layer 0)
  (gimp-displays-flush)
  (plug-in-gauss-iir 1 image new-layer radius 1 1)
  (gimp-invert new-layer)
  (gimp-desaturate new-layer)
  (gimp-layer-set-mode new-layer 5)
  (gimp-image-merge-down image new-layer 0)
  (gimp-image-undo-group-end image)
  (gimp-displays-flush)
)

(
script-fu-register
  "high-pass"
  "<Image>/Script-Fu/High Pass..."
  "a high-pass filter..."
  "ventilator"
  "ventilator"
  "2004-04-12"
  "RGB*"
  SF-IMAGE "image" 0
  SF-DRAWABLE "layer" 0
  SF-ADJUSTMENT "radius" '(50 1 1000 1 10 0 1)
)
  • save this scheme script as <high-pass.scm> and copy it to <your install path>/GIMP-2.0/share/gimp/2.0/scripts. (scheme is a weird language. i'd prefer python but i didn't get python scripting to work with GIMP 2.0 for windows so i had to examine scheme a little! :)
  • after a new script has been added to this directory you have to execute Xtns -> Script-Fu -> Refresh Scripts.

before:

Image:gimp051hj.jpg

after:

Image:gimp060oz.jpg

  • the high-pass filter is now located under Script-Fu in the image's menu bar or right click menu. you will have to experiment with the radius a little until the right frequencies get filtered out. use undo if the try wasn't successful. for the example on the left i used a radius of 25. (ideally you should use the high-pass filter before the procedure with the offset. if you use it afterwards you should check if it didn't create some slight seams at the borders.)

before:

Image:gimp071nu.jpg

after:

Image:gimp089cv.jpg

  • the high-pass filter got applied two times with the radius set to 150 to filter out the brightness differences of the photograph.