• Welcome to SC4 Devotion Forum Archives.

How to create smooth curved transit textures with GIMP

Started by memo, September 26, 2012, 01:53:51 PM

Previous topic - Next topic

0 Members and 3 Guests are viewing this topic.

memo

In this tutorial, we will learn how to create smooth transit textures for wide-radius curves using GIMP, by the example of the S-curve for TLA-3. If I had known this back in 2006, the textures of my very first puzzle piece (and the very first wide-radius curve, by the way), the 45 degree rail curve, would have been much nicer and smoother. Click here for a view at the former pixelated textures. I created those by copy-&-pasting a partly rotated sample texture. This is not what we are going to do.




So let us get started. First of all, if you do not already have it, you will need to install GIMP. It is freely distributed, so there is nothing to be said against it. You can get it here.

Additionally, we will need a straight orthogonal texture of TLA-3 or any other texture you want to use that is 128 x 128 pixels in size. You can export it from the NWM files. We are going to use this texture:


Throughout this tutorial, the unit tiles shall denote a length of 128 pixels, since this is the size of a texture used in zoom level 5 in SimCity 4.

What we essentially want to do, is to use the Polar Coordinates Distortion Filter of GIMP in order to radially bend the straight TLA-3 texture. So at first, we will check the functionality of this filter.

(Update: There is a script now to automate this procedure (see below), so you do not need to handle all the details.)




Firstly, we rotate the Image by 90 degrees in order that it runs horizontally (if not already). Also, please check the texture is symmetrical, that is it continuously aligns with flipped versions of the same texture. Otherwise, you will encounter glitches later in the game. I am highlighting this because, while the continuous alignment is true for NWM textures, it is not for the original Maxis road texture.

In order to tile multiple textures next to each other, we select
  • Filters > Map > Tile : width = 512, height = 128.

We turn on the grid (representing the grid of the game) by going to
  • Image > Configure Grid : width = 128, height = 128
and
  • View > Show Grid.

Now we select
  • Image > Canvas Size : width = 512, height = 512
and
  • Layer > Layer to Image Size.

What we have now should look like this:


To try out the Polar Coordinates Filter, we hit
  • Filters > Distorts > Polar Coordinates
with these settings:


We will get this:


Looking closely at this, you will notice two things. Firstly, the road has only half the width (0.5 tiles) it should have. We will circumvent this the next time by doubling the image in size before applying the filter. Secondly, the image gets stretched by a considerable amount when mapped along the circle (Look at the center stripes!). To circumvent this, we will scale our image in the opposite direction before applying the filter.




Having assured ourself the Polar Coordinates Filter indeed is what we want to use, we can now get to the actual work. Remember we want to create an S-curve. We want the textures to cover exactly 2x4 tiles and they have to be symmetrical to the central point. We will create it out of two segments of a circle.

At first, we have to find out the radius to use for these circles. For this, we have to do some calculations, with the kind help of Pythagoras.



Let r denote the radius of the texture's (imaginary) center line (blue). As you can see in the image, we get the equation
  • r² = (r - 0.5)² + 2².
Either enter this at WolframAlpha or simply solve the equation (which in fact is a linear equation only) for r. We get
  • r = 4.25 tiles.
Let R be the outer radius (including transparancy). Usually this is R = r + .5 for one-tile networks and R = r + 1 for two-tile networks. So in this case, it is R = 4.75 tiles. Think of R this way: The circle we will end up with will have a grid size of 2R x 2R.

(Update: You can either continue here, or you make use of the script attached to this post and skip the next steps up to the next horizontal line.)

Next, we need to calculate our scaling factor to outweigh the stretching as explained above. So let
  • s := r * 2*π / R = 4.25 * 2*π / 4.75 = 5.62.

Instead of scaling down the image horizontally, we will scale it up by this factor vertically, so as not to loose any horizontal information. So let
  • t := s*128 pixels = 720 pixels
be the new image height.

We scale the image by selecting
  • Image > Scale Image : width = 128, height = t = 720 pixels.



Our image now looks like this:


Next, we select
  • Image > Canvas Size : width = 128, height = t*R = 3420 pixels
and
  • Layer > Layer to Image Size.
and
  • Filters > Map > Tile : width = 3420, height = 3420 (to a square).

We now have this:


It looks similar to what we had already in our first try, except we took steps to circumvent the aforementioned issues. So we are prepared for the radial bending now. We select
  • Filters > Distorts > Polar Coordinates



and scale it back to the previously calculated size 2R x 2R:
  • Image > Scale Image : width = height = 2*R = 1216 pixels.

Since the mapping is started at the top going clockwise, we will want to cut the image to the top-right quarter by halfing the canvas size by
  • Image > Canvas Size : width = height = 608 pixels, Offset: x = -608, y = 0
like this:


Additionally, we select
  • Layer > Layer to Image Size.

We have this now.




The (imaginary) center line crosses exactly the center of the 2x4-tiles S-curve piece, which is what we wanted. However, looking closely at the picture, you will notice the stripes will not align properly in the middle part if we put together the S-curve.




We have several different options to proceed. Either,
  • we do nothing, which is okay, but considering the amount of work already invested in creating nice textures, this would be somehow unfortunate;
  • or we play around a little bit with the scaling factor s;
  • or we modify the original texture to circumvent this problem;
  • or we do some more precise calculations to get matching stripes.

I decided to go for the latter. For this, we calculate the total number of stripes (thinking of one stripe as 64 pixels) on the whole circle. The circumference is
  • R * t = 4.75 * 720 pixels = 3420 pixels.
So there are 3420/64 = 53.4375 stripes in total.

Let
  • b := arctan(2 / (r-.5)) / (2π)
be the arc length of the segment coloured in blue in one of the above pictures.

Thus, the blue segment has b * 53.4375 = 4.167 stripes on it. Since we want it to have 4.5 stripes exactly (you could use 4 stripes as well), let
  • s2 := s * 4.5/4.167
be the new scaling factor. Thus,
  • t2 := s2 * 128 = s * 128 * 4.5 / 4.167 = 777.095 ≈ 776.
(I rounded it down to a number divisible by four because four is the smallest integer which multiplied by R makes an integer.)

Finally, we have to repeat what we have done before, with s2 and t2 instead of s and t.

If you are using the script, enter 4.5/4.167 = 1.08 as scaling factor.

We will end up with this:


You can see that the stripes will align. It is a cakewalk now to create the actual S-curve textures that will look like this:




Update: There is a script now to automate this long procedure which is attached to this post. Install it to "C:\Program Files\GIMP 2\share\gimp\2.0\scripts",  if you are using the Windows release, or to "~/Library/GIMP/2.8/scripts" for the Mac release. You will find the script at
  • Filter > Radial Bending.

Use the previously calculated radii as parameters, that is 4.25 as central radius and 4.75 as outer radius in our example. For the scaling factor adjustments enter "desired number of stripes / actual number of stripes". In our example, this is "4.5 / 4.167 = 1.08".

vortext

OH YES! Thank you so, so, so much!  &apls &apls  &apls

I've been wrestling with wide curves for quite a while, copy-paste indeed and even tried modelling in BAT with no luck at all and frankly, I was about to give up. .   :(

So this is seriously awesome. Gonna try this out as soon as possible! Thanks once more!  :thumbsup:
time flies like a bird
fruit flies like a banana

art128

Gold tutorial that will be useful to many of us.   &apls
I'll take a quiet life... A handshake of carbon monoxide.

Props & Texture Catalog

Tarkus

Wow, this is an absolutely phenomenal tutorial!  :o :thumbsup:  I'm definitely going to be giving this a go.

I should also add, there's a handy script for GIMP for slicing images into 128x128 squares for import--ATG Split and Join Images, which you can pick up here.  Just install it to your C:\Program Files\GIMP 2\share\gimp\2.0\scripts folder, and you can access it from Filters > ATG on the menu.

-Alex

Swordmaster

The GIMP is awesome, but people who are able to use it well are even more awesome! Bookmarked for further reference.

Cheers
Willy

memo

Thanks for the script, Alex. It is very helpful, indeed. :thumbsup:

So I wanted to learn scripting and went ahead by writing a script doing all the hard work which is attached to this post to the main post. You will find it at Filter > Radial Bending, just have to enter the radii and you are done. You can replicate the tutorial's images with a scaling factor of 4.5/4.167 = 1.08.

I have updated the tutorial accordingly.

Tarkus

You're most welcome, and thank you for your script--I'm floored at how quick it is.  S-Curves have always been the trickiest wide-radius curves to put together for me before, and now, it's an amazingly simple job. :thumbsup:

-Alex

ivo_su

Oh really memo this tutorial is great and I just minutes, I was able to do this with the texture of the OWR-3. Do not look perfect, but the important thing is that it is quick and easy. Can you show how to proceed with broader networks (two or three tiles networks)


Haljackey

Oh very cool Ivo! And Memo, your tutorial is awesome!

memo

Quote from: ivo_su on September 27, 2012, 05:37:51 PM
Can you show how to proceed with broader networks (two or three tiles networks)

Since two-tile networks' textures basically consist of two 128x128 textures, you have two possibilities of doing it. On the one hand, you can create two circles, one for each texture, with the radii differing by exactly one tile. This works exactly as described in the tutorial.
On the other hand, you can take the 128x256 image for the radial bending as well. It would be this one for the avenue:


This way the inner lanes will have the same number of stripes as the outer lanes. Make sure that the outer radius R is one tile more than the central radius r. So if you are using the script, enter r = 6 and R = 7 for example, and you will get this:


Tarkus

Some preliminary results from my experimentation with this:



That entailed creating two circles and splicing them together.

-Alex

vortext

#11
Since we're sharing experimental results. .




It's not the right size yet but it works fine for stone brick as well.  ()stsfd()

btw, did I already mention this is frigging awesome?!  :thumbsup:
time flies like a bird
fruit flies like a banana

ivo_su

#12
Today I worked on , and I managed to create this   semi -circle of OWR-3, it is not a problem for me to create Path file, for this piece. But anyway what do you think


MandelSoft

Well, to my opinion, the lines are way too long. Try to reduce the length by a half
Lurk mode: ACTIVE

Shadow Assassin

This makes a great alternative to using the BAT to create the textures, and overall means less work, though the BAT would be better for creating more complex setups (such as for FAR). Otherwise, this makes it easy to do S-curves and 45/90 deg curves... worth it, for sure.
New Horizons Productions
Berethor ♦ beskhu3epnm ♦ blade2k5 ♦ dedgren ♦ dmscopio ♦ Ennedi
emilin ♦ Heblem ♦ jplumbley ♦ moganite ♦ M4346 ♦ papab2000
Shadow Assassin ♦ Tarkus ♦ wouanagaine
See my uploads on the LEX!

art128

Ivo_su:



Small details, I know you have them in sight. ;)
I'll take a quiet life... A handshake of carbon monoxide.

Props & Texture Catalog

ivo_su

My friend Ioan (io_bg) help me to fix this image




Now I think is better

MandelSoft

Lurk mode: ACTIVE

Haljackey

Quote from: MandelSoft on October 13, 2012, 06:08:01 AM
The lines are still way too long...

Regardless, that is some beautiful work ivo_su. Keep it up!  :thumbsup:

jdenm8

#19
Delete what you've done so far. Seriously, it's so wide of the mark it's unrecoverable.

Download the script attached to the bottom of the Top Post, drop it in:
.../GIMP 2/share/gimp/2.0/scripts

And start again.

I was able to make this in ten seconds:


"We're making SimCity, not some dopey casual game." -Ocean Quigley