Creating Seamless Textures

 

This article should be read in conjunction with my article on photographing textures. I am assuming that you are familiar with your image editor of choice, as I won't be detailing every command or menu choice.

 

There are probably thousands of tutorials on the Internet about how to create seamless textures from photographs. Unfortunately most of them are too simplistic. There is far more to creating a usable seamless texture than merely using Photoshop's Offset filter and Clone tool.

 

First, we need good source material. If you have followed my advice in the article on photographing textures, you should have a pretty good base image to start with. Figure 1 shows the raw image that we'll be turning into a seamless texture. I'm making it 800 x 800 pixels, just to save on a bit of bandwidth, but you should use whatever size you feel is appropriate. If you want to use this texture, right click on Figure 1 and save it to your hard drive.

 

Figure 1


The first step is to apply an offset filter. Depending on your image editor, it will be hiding somewhere in your menus. In my version of Photoshop it's in Filter->Other->Offset. In the current version of GIMP, it's in Layer->Transform->Offset. We want the seams to appear in the middle of the image, so make sure you set the offset values to 400 (half the texture dimensions) if you're using this texture. Also make sure the Wrap Around option is selected. If you're using this texture, it should now look like Figure 2. Note that GIMP has a Make Seamless function in the Filters->Map menu. It seems to do a reasonable job but you have absolutely no control over it. Sometimes the blends don't look so good either. It also kills the contrast of the image. We want to be in control of how our textures look, so I would recommend avoiding it.

 

Figure 2


Here we see a problem that can ruin a seamless texture. There are colour and luminance differences across the image. We need to fix them. Undo the offset filter and duplicate the layer. With the top layer selected, invert the colour. In Photoshop it's Ctrl-i. In GIMP, it's Colours->Invert. Now the top layer looks like a colour negative. Apply a Gaussian Blur to the top layer. For an image this size, a blur value of 40 pixels is about right. Larger images will need more, smaller images less. The goal is to have any details blurred out. Figure 3 shows the inverted and blurred image.

 

Figure 3


Set the blending mode of the top layer to Soft Light at 100%. The colour and brightness shifts have been smoothed out. The top layer might be giving an unwanted tinge to the background layer. If so, select the top layer and turn its saturation all the way down. Note that some images will benefit from this step more than others, depending on the surface being photographed and how uniform the lighting was. It is worth doing with every image though, just to be sure. Next, flatten the image so we're back to one layer. The image is now more uniform, as seen in Figure 4, but lacks contrast. We need to fix this before we offset it and start painting out the seams. If we don't do it before offsetting the image, we can run into problems with non-matching colours on the edges.

 


Figure 4


Bring up the Histogram window in your image editor and have a look at it. It should look something like Figure 5. This is probably one of the least used tools in image editing. It shows the distribution of luminance values in the image, starting from the darkest pixels on the left and moving through the midtones to the brightest pixels on the right. The vertical axis shows the pixel count for each luminance value. We can see from Figure 5 that this texture is comprised mainly of midtones, which is why it looks a bit flat and dull. We'll fix that next.

 

Figure 5


Add a Levels Adjustment Layer, as in Figure 6.

 

Figure 6


 

Levels is one of the most useful digital imaging tools you'll ever use. Dragging the triangular sliders under the histogram will alter the brightness and contrast of the image. Dragging the right slider to the left will lighten the image, dragging the left slider to the right will darken it, and dragging the middle one makes overall brightness changes. Drag both left and right sliders inwards and the contrast increases. So, drag the left and right sliders inwards until you're happy with the amount of contrast in the image. This is really a matter of personal preference. Figure 7 shows where my sliders ended up, with the resultant change in brightness, contrast and colour saturation.


Figure 7

 

The colour is too rich for me, so I simply desaturated it a little. Figure 8 shows my final texture with the offset filter applied, before starting to use the Clone tool. Make sure to flatten all the layers before applying the offset filter. You should now have a flattened, offset image with the contrast you require.

 


Figure 8

 

Select the Clone tool and set its size to about 40 pixels, which is pretty much right for an image of this size. Start with a slightly soft brush, to avoid really hard edges on cloned areas. Depending on the subject matter, you may need to alter the brush softness. Select a source area for the brush, then move to a seam and start painting. Don't paint on the outer edges of the image or you'll create more seams. You'll need a smaller brush size to clone out the edges of the seams where they meet the edges of the image.

 

Although I said "start painting", you don't actually want to paint over the seams as such. Just running the brush down the image will surely get rid of the seams, but will most likely look odd, as you will be copying pixels virtually side by side, creating a pattern.

 

This is how I do it.

I select a source area, then use the Clone tool maybe four or five times around a particular spot. I then select another source area and repeat. On it goes until I finish that seam. You should also move across the seam with the Clone tool, extending it beyond just the few pixels the brush will cover. This helps the newly stamped areas to blend in better with the rest of the texture. Try to select source areas that are not too close to target areas. This helps to avoid creating patterns or areas near each other that look too similar.

 

It's actually harder to explain this process than to do it. Cloning is actually quite simple once you get the hang of it. Practice is the key. The important thing to remember is to select plenty of areas to clone in order to really hide those seams. Don't be afraid of cloning in whole new areas if that's what you feel the texture needs. Changing the brush size by a few pixels every now and then will also help to break things up. Figure 9 shows the result of about 10 minutes work with the Clone tool.

 

Figure 9


One thing to watch out for is any parts of the texture that stand out too much. If you wrap the texture onto an object, they can create repeating patterns that the eye will be drawn to. If you compare Figure 8 and 9, you can see I've cloned out that obvious white area near the centre top of the texture, in order to avoid this problem. It isn't always easy, but as usual, practice is the key.

 

Having done all this work, the final step is to sharpen the image, as you need to do with pretty much any digital photograph. Make sure to run the offset filter again before sharpening, to get the seams back to the edges of the image. In Photoshop, I go into Lab Colour mode, then select the Lightness channel and do the sharpening on it. The Lightness channel only holds luminance information, so any sharpening applied to the image will not affect the final colours. Once sharpening is applied in Lab mode, you go back to RGB mode. Some image editors will allow you to split the image into Hue, Saturation and Lightness channels. You then apply the sharpening to the Lightness channel and recombine the images to a new RGB image. If your image editor doesn't offer this functionality, it's not that much of a big deal.

 

The type of sharpening applied is always the Unsharp Mask filter, not simply the Sharpen command from the menu. Sharpen offers no control and can easily ruin all your work. Unsharp Mask has much more fine grained control and is the weapon of choice here. How much sharpening is required will vary from image to image and is a matter of trial and error. Just don't overdo it.

 

Figure 10 shows my final texture with sharpening applied and Figure 11 shows a simple render using it.

 


Figure 10

 


Figure 11