Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: What is the process used to colour tilesets?  (Read 6397 times)

ButterflySammy

  • Escaped Lunatic
    • View Profile
What is the process used to colour tilesets?
« on: October 10, 2013, 06:55:48 am »

If I wanted to take a tileset and render it outside of Dwarf Fortress - what would be the process and what files would I need?
Logged

Vabalokis

  • Bay Watcher
  • Urist McKneeGrow
    • View Profile
Re: What is the process used to colour tilesets?
« Reply #1 on: October 10, 2013, 06:28:36 pm »

you think you will be given source code on rendering? lel
Logged

ButterflySammy

  • Escaped Lunatic
    • View Profile
Re: What is the process used to colour tilesets?
« Reply #2 on: October 11, 2013, 03:39:30 am »

you think you will be given source code on rendering? lel

Someone woke up with a hangover and an overweight elf this morning.

Course not.

Just a plain English description of what users believe happen to the image files before they are displayed on the screen so I can use it to make something that is compatible with Quickfort that isn't a spreadsheet.
Logged

Taffer

  • Bay Watcher
    • View Profile
Re: What is the process used to colour tilesets?
« Reply #3 on: October 11, 2013, 08:08:21 am »

Doesn't seem like you're having a lot of luck finding an answer, here or on Reddit. This Dwarf Fortress wiki page may contain the answer you seek. It is for the 40d version, but my own experiments in tileset colouring seemed to corroborate its veracity for the newer versions. (Some tilesets, like CLA, use a solid black overlay as a bit of trickery to enable different tiles to display when inverted, but it falls down when using a colour scheme with a non-black background, as I could never reproduce the results with Tocky's colours.)

If this isn't satisfactory, then the best person for this question would be Baughn, as they know more about the graphics rendering than even Toady, but seeing as Baughn is AWOL you should try a Future of the Fortress post or private message this fellow. I hope you find the detailed answer that you seek!
« Last Edit: October 11, 2013, 09:02:09 am by Taffer »
Logged

ButterflySammy

  • Escaped Lunatic
    • View Profile
Re: What is the process used to colour tilesets?
« Reply #4 on: October 13, 2013, 02:34:20 pm »

Sorry I didn't see this earlier, I don't check the forum as often as Reddit as with Reddit I have a phone app to amuse myself when I am away from my PC.

When you said:

Quote
Doesn't seem like you're having a lot of luck finding an answer

You forgot to account for your own answer!

From the wiki:

Quote
When the game draws a tile, it will select a foreground color, a background color, and a tile based on the item being drawn. The background color will be used in place of magenta (Hex code #FF00FF or RGB 255 0 255). All other colors in the tile will be treated as a mask against the foreground color. Pure white (#FFFFFF) will always show the foreground color, while light grey (#CCCCCC) will be a slightly darker version of the foreground color, and dark grey (#888888) will be a dark version of the foreground color. Black (#000000) will always be black. It is impossible to use different shades of the background color.

This is exactly what I needed! Thanks!

It even contains the maths  - I'm fairly sure just from reading this, having played the game and seen the originals before they were rendered that this is exactly what it does! I think no one copied it from 40d wiki page, that's all.

I can write code from this!

Edit: Looking at the most recent Phoebus file it isn't entirely up to date, but I know what it is doing different.

So - the biggest change it appears from Pheobus is colours other than grey.

When I look at the original image http://dwarffortresswiki.org/images/f/f1/Phoebus_16x16.png for example, the off/on levers - they contain green and red. Clearly they want to stay!

So I added a new rule - colours will be used as a mask except grey, white and black.

White will use the foreground colour instead of a mask.

A colour is "grey" when red, green and blue are equal - this should use the mask formula you linked to. After test processing the Pheobus file, what looked to me to be "grey" remained in a few spots - upon checking, it was #2b2c2b - the rgb values were slightly different but it was clearly supposed to be grey not a colour given contex.

I updated my definition of equal to be a little more tollerant - after playing with the Phoebus file, the value difference in hex values that should be taken as a colour is 62 which would be fine, except setting the tollerence that high also got the green of the leaves.

Black is the background color. I left it black - for most things it is a black outline so it worked for the demo.

When red, green and blue do not match, that is a "colour" should remain unchanged when processed. So they green of the "on" state stays green.




Using those rules,  I was able to re-process the image into red #ff0000, green #00ff00 and blue #0000ff versions.

Red - http://i.imgur.com/x3bwvtB.png
Green - http://i.imgur.com/CCAo4Np.png
Blue - http://i.imgur.com/2fSStRP.png


Obviously these are not realistic foreground colours for all the elements but since the process works, it is a case of getting each foreground colour from the config files (not too difficult) - the tolerence value may also need tweaking on a per element basis.

There are a few interesting exceptions - Strawberry bushes have the following set in the raws - [SHRUB_COLOR:2:4:1] - which is bright green foreground, dark green background.

The Alpha layer (which I've just preserved for now) actually servers as the background colour and allows berries to be coloured separately.

The colors.txt file defines what exactly "Red" and "Green" are for those particular tilesets, that shouldn't be too hard to get hold of either.

So - Thanks! I created working code from your post!


I could play with the berry trees a little more(and I probably will eventually) but I don't see a huge need since I only wanted different coloured backgrounds that roughly mimicked in game materials so that people could use a tool that actually looks like Dwarf Fortress to create structures and import them into Quickfort.

Now that I definitely can colour tilesets outside of Dwarf Fortress... on to finding a Tileset with a license that will let me use it or someone who has made one I can convince.

Thanks again!

Edit 2: Couldn't resist screwing around - also got the bushes to show berries in the background colour - http://i.imgur.com/3wAIEwG.png

Obviously, in game the whole tilesheet isn't recoloured like this all the objects are different colour combinations, etc.
« Last Edit: October 13, 2013, 06:16:51 pm by ButterflySammy »
Logged

Taffer

  • Bay Watcher
    • View Profile
Re: What is the process used to colour tilesets?
« Reply #5 on: October 14, 2013, 12:38:40 pm »

Sorry I didn't see this earlier, I don't check the forum as often as Reddit as with Reddit I have a phone app to amuse myself when I am away from my PC.

When you said:

Quote
Doesn't seem like you're having a lot of luck finding an answer

You forgot to account for your own answer!
...[snip]

You're welcome. Glad I could help. I'm looking forward to seeing your utility! For future reference, this is the section for tileset/graphic set releases, rather than questions.
Logged