Monday, March 25, 2013

Tiled Floor Tutorial using Inkscape and Gimp

Over on G+ I was asked how I created the tile floor I showed in my tile grunge tutorial. Here's the basic method I used, in what I hope is a useful format. First, here's what we're shooting for:
Let's begin, shall we?

First a little math. I'm going to do a 20'x20' tile pattern at 150dpi. That means my final image is 600x600. I don't really want to work in that scale in Inkscape though, because it uses a native 90dpi resolution, and we're going to be using SVG to export our work, which is a vector format. I've done a fair bit of testing and settled on using a 21px per five-foot square (4.2px per foot) scale in Inkscape. It Just Works (TM), trust me.

In this case we're going to create an 84x84px document in Inkscape, and set up two grids, one at 21x21px for our five-foot squares, and one at 4.2px for our one-foot grid. We're also going to turn on snap to grids, so our lines are easy to align. It's also useful to set up a layer specifically for our tiles. Here's the result:

Now, grab the Rectangle tool (F4), and lay a shape in one corner. Don't worry about line thickness or fill right now, though you'll want to set both to something visible so you don't miss spaces as you work. Lay a rectangle over the upper-left corner of the map. You'll want to cover the corner and allow the shape to extend outside your page. Remember that your small tiles are one-foot each, so use sizes that make sense for the effect you're trying to achieve!

Once you have a shape laid down, switch to the Select Tool (F1), highlight it and copy it. Paste this shape over each of the four corners, aligning it so it wraps north-south and east-west. Like so:

With the corners established, use the same technique to lay down tiles along all four edges, matching up the north-south and east-west edges. Note you can place tile edges on the image edge, as long as you do the same thing on both sides. You'll want to avoid runs of tiles with aligned edges as that will catch the eye when tiled out in your final map. Here's what I ended up with, which is adequate for demo purposes. I laid a white line around the image border so it was easier to see:
Now the fun part, fill in the rest! Use the same technique, but now you don't need to worry about aligning opposite sides. You'll want to avoid patterns or aligned edges as much as possible, and keep an eye on the spread of tile sizes you're using. I usually lay out a bunch of tiles in appropriate sizes along the outside of the image that I can cut/paste into place to ensure I'm using consistent sizes. Start by laying out a ring of larger tiles around the edges of your open space, then place smaller tiles to fill the voids. Remember that the tiles you're drawing are actually big honkin' sheets of rock, so use common sense when placing them.

Here's what I ended up with:
OK, that's our grout. It's time to move to Gimp. Before we go, we need to tweak our rectangles and prepare the image for saving so we get a useful result. First, Select All (CTRL-A) your rectangles, and set them to No Fill, Black Stroke, and .25px Stroke Width (yes, one-quarter px stroke). Hide any layers that contain any extra stuff in your image (like my white edge marker). Once that's all done, use Save As to save your image as an Inkscape SVG file. Time to switch to Gimp!

Step one in Gimp is to create our image. We want a 20'x20' image at 150dpi, and we're assuming five-feet per inch, so we need a 600px by 600px image. Use File / New (CTRL-N) and fill out Width and Height. Set 150dpi under advanced options. I usually fill the background layer with white so it's easier to see the grout lines. With our basic image in place time for some math! Recall we set our grid to 21px per five-foot square in Inkscape, but we're now working in 150px per five-foot square. Use File / Open as Layer and select your SVG grout file. This will bring up the Render Scalable Vector Graphics dialog. Lock the X and Y ratio fields together, and enter the magic number 7.1428 (150/21) in the fields. Set Resolution to 150 pixels/in. I don't care about the path information in this case, so leave Import paths unchecked. Note that setting the X/Y ratio auto-magically updates the Width and Height fields to 600x600. Hit OK.

Look familiar? Note that Gimp neatly sliced all the overflow off the edge of our SVG, leaving us with a ready to fill image. Our .25px grout lines are scaled up to nicely legible 2px lines. Rename this new layer Grout and lock it so we don't inadvertently fill it. Create a new transparent layer beneath it named Tiles, and save your work.

For the next steps you'll need a texture to use as a pattern for the tile fill. There are plenty of stone textures around, and the Gimp site tells you how to add patterns, so I'm going to assume you can handle that. Because of the way Gimp does pattern fill (starting at the upper left corner of the current selection), it's useful to create four copies of the base pattern by doing a series of 90 degree rotations of the base pattern. We're not really worried about using seamless patterns, since all we care about is making each tile seamless. Here's the general process:

  • Select Grout layer.
  • Use Fuzzy Select (U, hold SHIFT to add to selection) on the empty space of a random selection of tiles. Be sure Select transparent areas is on and Sample merged is off. Two things to keep in mind: You'll want to leave unselected tiles between your selections, and you'll want to select both sides of any tile that crosses the edges of your image at the same time to have the same general grain in the texture. They won't be seamless yet, but we fix that later.
  • Once you have a collection of tiles picked out, use Select / Grow Selection to add 1px to the selection. You should end up with a bunch of selected rectangles extending 1px into the grout. If you have tiles that are touching, they'll merge. That's OK.
  • Select the Tiles layer.
  • Select one of your four stone patterns from the Patterns window.
  • Use Edit / Fill with pattern (CTRL-;) to fill the selected area with stone. Voila! Stone tiles. Here's what mine looks like after the first pass using a fairly ugly stone texture:

Note that the corners are all filled, as are all the selected edge pieces that cross over the border. Also note the big tile on the east edge that is not matched up with fill on the other side. That tile ends on the edge of the image, so the far side is a set of new tiles.

Repeat this procedure several times, using a different pattern from your set of tiles each time. With practice you can do this in four passes, one for each rotation of the pattern. The end result is a completely filled set of tiles, each with a different piece of the pattern. We're done!

Not quite. Because we matched our edge tiles when we filled them they have the same grain, but they're not guaranteed to be seamless (unless your original texture width is identical to your image size). We need to fix that. Here's how:

  • With the Grout and Tiles layer showing (as above), use Layer / New from Visible to create a new layer and name it something useful. I'll call it Final. Select this layer.
  • Use Layer / Transform / Offset (SHIFT-CTRL-O) to open the Offset dialog. Set Edge Behavior to Wrap around, and hit the Offset by x/2, y/2 button. Hit the Offset button.

Oh noes! Your carefully laid out image has been destroyed! Not really. If you were careful with the grout the only problem you have to fix is a vertical and a horizontal issue cutting the center of your image. This is pretty easy to fix with the Clone tool. Time to zoom in and do some tweaking. Here's what I'm starting with:
Here's how to fix it:
Pick a decent sized soft brush from the toolbox. I use the standard Hardness 25 brush set to Size 15.
Activate Clone (C), and use CTRL to pick a source. In the case above, I'm going to use the two tiles just below the line and blur things out from down to up. This takes a bit of practice and care (so you don't mangle things with grout lines). Here's what mine looked like after I fixed it:
You can get very fussy about this step, but I tend to be a little sloppy. These tiles end up being small, and if you drop a layer of grunge over them, little imperfections go away. If you find yourself getting lost in your image, set up a pair of 50% guides to show you where the flaw lines are.

Once you've fixed all the lines, you're ready to save your work. Simply File / Export as a pattern (.pat) and save it to your patterns directory. You'll need to refresh your pattern listings or restart Gimp to have it show up in the Pattern listings.

A couple tricks and warnings:
  • You'll probably want to dirty up your grout lines before you use the image in your maps. I generally tweak the color, add some noise, and adjust levels for final output.
  • Instead of doing the seamless fix above, you can cut/paste filled, properly-sized tiles along the edges of your image, repeating the same tile in the crossover spaces, which guarantees a seamless pattern.
  • Use the same Grout  layer to set up multiple Tiles layers with different textures in the same image. This gives you an entire collection of tiled floors.
  • You can also do the seam fixes on each Tiles layer, then redo the offset to restore the original image.
  • Be sure you keep your Offsetting consistent! It's best to lay out all your tile layers, do grunge layer(s) over the entire thing, then fix your seams.
  • If you want to use multiple textured tile floors in one map, create a full-sized layer for each color tile, fill the entire layer with your chosen tile, then use layer masks to cut through the appropriate areas. Doing this means all your tiles line up correctly, allowing you to do things like this by simply cutting through a layer mask:

OK, I think that's about it. Hope you find this useful. If you're looking for some textures to start with, check out Seamless Pixels on Blogger.

Edit: And here's another example of using multiple colors of tiles in a single image. In this case the hall / chamber tiles change over, but you have to think in tiles, so using masks I cut the various floor layers to show the right tile. As you can see this technique isn't perfect: there should be several tiles involved in the cuts around the walls, but I think it lends a nice sense of imperfection to the floors, something you see in older buildings.
And if I really wanted to be anal-retentive I could make up some individual tiles to layer in and break things up completely correctly. :D

No comments:

Post a Comment

Note: all comments are moderated to block spammers. Please be polite.