============================================================ A Step-by-Step Tutorial For Converting Sprites to Night-Time By Andrew350 ============================================================ Before we get started... ------------------------ Please note this is in no way a must-follow tutorial; there are probably many ways to acheive similar results. This guide only outlines the basics of what I did to get you started. I am assuming you already have an 8bpp spritesheet ready to go and are using GIMP 2 as your tool of choice. Other programs will be different, but the same principles should apply. To keep track of which files are which, within my main gfx/ folder I then create two more folders called 8bpp and 32bpp. The game still requires 8bpp 'fallback' sprites, so the original spritesheets go in the 8bpp folder, while our new 32bpp files will go into the 32bpp folder. Within the 32bpp folder are also another two folders named 'masks' and 'gimp_files', but we'll get into that later. For now copy the 8bpp spritesheet into the 32bpp folder and lets get started. ========================================== STEP 1: Convert the spritesheet into 32bpp ========================================== Convert image to RGB (Image -> Mode -> RGB) and add an alpha channel (right click in the Layers dialog and select 'Add Alpha Channel') Now pick the select-by-color tool and deselect the 'Antialiasing' and 'Select transparent areas' checkboxes, and set the 'Threshold' slider to 0.0 (this makes sure you are only selecting the exact colors you are picking, not all similar ones) With this tool, select the pure white and transparent blue colors in the image and delete them. This should leave you with only the actual sprites on a 'transparent' background. Congratulations, you have now made your sprites 32bpp! ================================== STEP 2: Add some layers (optional) ================================== Depending on what the sprites are, I add up to three new layers; from top to bottom: Lights - Custom (usually hand-drawn) lighting effects Action Colors - Special TTD colors like Fire Cycle, Flashing Red/Yellow, etc. CC/Recolor - Company Color 1 + 2, bridge/building/custom recolorings, etc. [Base Image] Each of these 'features' will be treated differently, so I found it easieast to separate them into individual layers to make editing (and re-editing later) easier. If your sprites do not contain any of these features, there is no need to make any separate layers, only add what you will need. In this case you can also skip to the last part of the tutorial, since everything else here is about editing these layers. I would still recommend reading everything though if you are unfamiliar with the process, as you might learn something helpful along the way. ======================================================= STEP 3.1: Let's do Company Colors! (and other recolors) ======================================================= With the select-by-color tool still active, select all shades of Company Color blue (CC1) on the base image layer. Also, if activated in your NewGRF, select all shades of CC2 green, and any other unique colors used for recolor purposes (including any custom recolor sprites for cargoes, etc) TIP: If you're unsure what shades of color are which in your image, open the Palettes dialog (Windows -> Dockable Dialogs -> Palettes) and select the TTD palette used in the original image (hopefully you already have them saved at this point). This will open a separate window where you can select each color directly from the palette based on its index number (shown in the lower left). Similarly, using the color picker tool on the image itself will highlight that color in the palette window, allowing you to locate a specific range of colors. This can also be useful for the later steps as well. Color indexes of note for this step (using the DOS palette): 198-205 CC1 80-87 CC2 (if activated) 70-79 Bridge/Building recolor (used only in some select TTD sprites) 128-135 Typically used for windows (may be useful for lighting effects?) Now that all your recolor pixels are selected, copy them (Ctrl-C) and then select the CC/Recolor layer and paste them (Ctrl-V) in the same spot. You now have an exact copy of the recolor pixels in a separate layer on top of the original sprites. ======================================= STEP 3.2: Desaturate the Recolor Pixels ======================================= In order to keep these recolor sprites from becoming over-saturated in game, it is necessary to desaturate their color to some neutral grays. The appropriate colors will be re-applied later by a separate mask file. With the CC/Recolor layer active, navigate to Colors -> Desaturate, select 'Average' and click OK. This will effectively turn this layer into a grayscale version of the recolor pixels. Note that this is only one way to achieve this goal. Selecting other modes of desaturation, or even replacing all pixels with one shade of gray will also work, with different results; this is just the way I found easiest and with good results, other options may work better for you. It might be a good idea to save your file here before we continue. Make sure to select 'Save As' and save it as an .xcf file; keeping the same name is a good idea. I like to keep these 'source' files saved separately in the 'gimp_files' folder I mentioned at the beginning, but this is of course optional. ========================================== STEP 4.1: Let's start making the mask file ========================================== Now that we have desaturated the recolor pixels in our 32bpp file, we need to make a new 'mask' file which will tell the game where and how to apply these special colors. Only areas that are painted in the mask file will be affected, if you don't paint anything in the mask file, OpenTTD will not know where to apply the recolors! To make things simple, start off by making a new image the same dimensions as the base 32bpp image. Unlike our 32bpp image, this one is going to be indexed in a TTD palette (Image -> Mode -> Indexed - Select 'Use custom palette' -> Select a TTD palette -> Uncheck 'remove unused colors' -> Convert). Now we need to copy all of the recolor pixels from our base image into our new mask file, and make sure to place them in exactly the same spot!. If you need help lining them up, you can always create a temporary layer with the full base image underneath, and use the layer visibility toggle to see when they are aligned (just be sure to remove this layer at the end). Be mindful of where you place your mask sprites; if they overlap a part of the base image which is not prepared properly, it may result in some odd recoloring effects! =============================================== STEP 4.2: Choose the right shade for recoloring =============================================== Now that all of our recolor pixels have been aligned properly in our new mask file, we want to recolor each range into one single shade each. Again using the select-by-color tool, select all shades of ONE of the recolor ranges. Now switch to the bucket-fill tool and select 'Fill whole selection' and make sure opacity is set to 100.0. Select the color from the palette you wish to use and fill the selection. Note that this obviously must be done individually for each recolor range, i.e. all shades of CC1 need to be filled with a shade of CC1, CC2 should be filled with CC2, etc. Depending on how you desaturated your sprites in the base file, you may need to choose a darker or lighter shade for the mask to achieve a good result. Somewhere in the middle of the range is usually best, for example I use index 202 in the DOS palette for CC1 when using my methods above. "What's the point of this?" The reason we do this is because in our base image we desaturated the colors, but the texturing was left in place. So by masking over these areas with a single color, it will retain the same texture while allowing us to make the mask file much simpler (as opposed to trying to do the texturing here in a separate file). Retaining the texturing in both files tends to result in an over-contrast between light and dark, so I don't recommend it, but of course you are welcome to try it. Do whatever looks best! You may go ahead and save this file now if you want to, but do keep it open, we will still need it! This file doesn't need to be saved as an .xcf, you can just choose 'Export As' to save as a .png file. I like to save my mask files in a separate folder named 'masks' as mentioned earlier, and I make sure to save it with the same name as the base image, but with '-mask' appended to it for clarity. Again, my formatting is purely optional, but for a big set with lots of sprites, it will help maintain your sanity, especially when it comes time for coding! Congratulations, you are done with the recolor sprites! Now onto the Action Colors. ======================================================== STEP 5: Dealing with the animated pixels (Action Colors) ======================================================== Going back to our 32bpp image, with the base layer active, we must select all of the pixels which OpenTTD uses for palette animation. Color indexes of note for this step (using the DOS palette): 227-231 Block Cycle (used in toyland, ?) 232-238 Fire Cycle 239-240 Flashing Red 241-244 Flashing Yellow 245-254 Water Cycle Just like the recolor pixels, these must now be copied and pasted into the Action Colors layer in the same location, with the exception of the Block Cycle and Water Cycle colors, which should be left out of this step. The reason we don't separate the Block and Water Cycle colors here is because these are (normally) not meant to act as 'lights', and therefore should remain dark (this will make more sense later). With the Action Colors layer active, re-select all the animated colors. Now pick the bucket fill tool and select a color from the palette, preferably somewhere in the mid-gray range (I use index 10), and fill the selection. "What does this do?" Because these action colors are meant to act as "lights" in the game, we need to separate them into another layer so they won't be darkened later. By painting them in a neutral gray color in this file, it will allow the animated pixels to retain their natural color in-game, without becoming over-exposed. Applying other colors here than gray may cause some discoloration to these pixels; in some cases such as the Yellow Cycle this can even cause these animations to change color completely, which is generally not desired. The reason we don't paint over the Block and Water Cycle colors is because they seem to work just fine without it. But your tastes may differ, do what looks best! Now we need to do what we did with the recolor sprites and add the action colors to our mask file. With the base layer active (make sure you're on the right layer!) select ALL of the action colors (INCLUDING the Block and Water Cycle colors this time!) and once again copy and paste them into our mask file in the same position. This time we do not need to do any recoloring; these colors must stay as they are. Now that we have all of our masks in place, fill the background of your mask file with the transparent blue color (index 0 in the palette). That's it, we are now done with the action colors! We are also done with the mask file, so you may save it (make sure to use 'Export' or 'Overwrite' to save as .png). ========================== STEP 6: Add some lighting! ========================== The final step towards finishing up the graphics is to give them 'lights'. How and where you choose to put lights on your graphics is completely up to you, but I would strongly suggest to keep them on a separate 'Lights' layer. You may choose to emulate the simplistic style I have gone for or choose to go for something more realistic. One tip I would like to point out though: make sure you know where your masks are! Drawing lights on a part of the sprite which is masked will give noticeably odd results, so keep an eye out for things like company colors, especially when drawing headlights on vehicles and such. You may have to slightly adjust the masks to accomodate the lighting, so keeping the mask file open while you're drawing lights can be a big help. =========================== STEP 7: Let There be Night! =========================== Before we begin the final step, save your 32bpp file one last time in its .xcf format; once we apply darkness DO NOT save over it again, we will instead be exporting it to its final .png format. For this step, first we are going to merge the CC/Recolor layer down to the base layer (right click the layer -> select 'Merge Down'). We want to do this to make the next part easier. Now, select the bucket fill tool and select pure black, and set opacity to 65.0. This is the level of darkness applied to NightGFX; you may change it according to preference. With the base layer active, fill over the image, then using the select-by-color tool select the background and delete it. And you're done!! If you've done everything correctly you should now have darkened sprites on a fully transparent background, with all recolors darkened and gray, action colors gray but not darkened, and your custom lights lit up on top of it all. Good! Now, it's VERY important like I said at the beginning of this step to make sure you EXPORT the image as a .png; DO NOT use 'Save' and save over your .xcf! You want to keep that file as it is before you merge layers and apply the darkness, or else you will have a much harder time changing things later. Trust me, I know! If you can find an easy, clean way of including the darkness in your sprites without having to marge layers, then that's even better. I just found it easier to leave that part out of the source file, and just apply it before exporting. Anyway, that's it! Now you can repeat all the steps above for the rest of your spritesheets! ================== STEP 8: Celebrate! ================== Congratulations, you're all done!...with the graphics anyway. Now you must go into your code and add alternative_sprites blocks for all of your new 32bpp sprites, but first, take a break, you deserve it! Hopefully this guide was helpful for you, and if you have any questions or suggestions don't hesitate to contact me (Andrew350) on tt-forums or post in the NightGFX release topic. Good luck, I can't wait to see what kinds of things you create!