Palette

From SRB2 Wiki
Jump to: navigation, search
"COLORMAP" redirects here. For the colormap linedef special, see Linedef type 606.
ToDoIcon.png To do
Show the reader how to save pictures with the SRB2 palette. The WAD editor method is done, but we still need the graphics editor method.
SRB2's current palette, used for all flats, patches, sprites and other graphics.
The palette is the set of 256 colors that SRB2 can display. Instead of storing the color values directly, the data format used for all of SRB2's graphics stores the color index in the palette for each pixel. Because SRB2 will crash when trying to display a graphic that is not mapped to the palette, graphics that are stored in WAD files need to be converted from their native format to the Doom Graphics Format first (except for flats, which are stored in the Doom Flat Format). The textures for MD2 models, which are exclusive to OpenGL, are exempt from this.

Since Version 2.0, SRB2 has differed from the palette that is used in Doom, which means that graphics from earlier versions of SRB2 will have to be converted before they can be used in the current version. (See to the right for SRB2's current palette.)

The color cyan, which is present at index 247 in SRB2's palette, is commonly used to designate pixels that are meant to be transparent in the game. This convention was adopted by the Doom community because Doom's original palette included a redundant color at index 247 and because cyan contrasted well with Doom's primarily dark graphics. Some editors, such as XWE, automatically convert all pixels with index 247 to transparent pixels upon converting an image to the palette. However, because SRB2 actually features cyan in its palette at index 247, this may be undesirable for graphics that include actual cyan pixels. SLADE circumvents this issue by allowing the user to choose a different color to be converted to transparency.

Technical information

SRB2's default palette is stored in the PLAYPAL lump inside srb2.srb. Related to the palette is the COLORMAP lump, which controls how the colors fade in different light levels. It is possible to replace the palette by loading a WAD file that includes different PLAYPAL and COLORMAP lumps with a different palette. This palette will then overwrite the default one. Additionally, there is a level header option called Palette that allows the user to change the palette between levels.

PLAYPAL

The PLAYPAL lump located in srb2.srb stores 14 palettes, the first 5 of which have specific uses in SRB2, and the remainder of which are unused. All except the first are intended for use as flash palettes – i.e. temporary palettes that display in particular situations before returning to display the first palette again. For technical reasons, the OpenGL rendering mode does not directly use these flash palettes, but modifies the screen's display colors to simulate these – for this reason, custom palettes with different color tints will not appear as expected in OpenGL, as the simulated flash palettes' colors are pre-determined in SRB2's source code.

The constants for use in Lua and SOC are also given in the table below:

Palette number Palette name Description
0 none The default palette for SRB2.
1 PAL_WHITE SRB2's palette with a 75% white tint, of RGB(255,255,255). The flash palette used for Attraction Shields shorting out in water and Ideya Capture defeat.
2 PAL_MIXUP SRB2's palette with a 75% white tint, of RGB(255,255,255). The flash palette used for teleports and Teleport Monitors.
3 PAL_RECYCLE SRB2's palette with a 75% white tint, of RGB(255,255,255). The flash palette used for Recycler Monitors.
4 PAL_NUKE SRB2's palette tinted red. The flash palette used for Armageddon Shield explosions.

Note: This palette can be reproduced by tinting SRB2's palette 75% white as with the palettes above, but then changing the green/blue levels of all color indexes to 113.

5–13 n/a Unused palettes, all of SRB2's palette with a 75% white tint, of RGB(255,255,255), by default.

COLORMAP

SRB2's COLORMAP lump.

The COLORMAP lump stored in srb2.srb is a 256×34 graphic lump containing the default set of colormaps used by the game, storing colors in the same manner as flats (storing palette indexes rather than actual pixel colors). Each row in the graphic is a single colormap (an array of 256 palette indexes), which remaps each of the 256 colors from the palette to different indexes. The COLORMAP lump contains 34 different colormaps in total:

  • The first 32 colormaps (0–31) are used for the 32 different sector brightness levels that exist for the Software rendering mode; 0 is the brightest, and 31 is the darkest. These colormaps may also be used for walls, flats and sprites depending on the sectors they are located in and their distance from the camera. Walls additionally have their colormaps modified by what direction they are facing.
  • The remaining two colormaps (32 and 33) are leftovers from Doom and are unused by SRB2.

The first 32 colormaps correspond with the following sector brightness level ranges in Software, where 0 is complete darkness and 255 is maximum brightness:

Colormap # Brightness
0 248–255
1 240–247
2 232–239
3 224–231
4 216–223
5 208–215
6 200–207
7 192–199
Colormap # Brightness
8 184–191
9 176–183
10 168–175
11 160–167
12 152–159
13 144–151
14 136–143
15 128–135
Colormap # Brightness
16 120–127
17 112–119
18 104–111
19 96–103
20 88–95
21 80–87
22 72–79
23 64–71
Colormap # Brightness
24 56–63
25 48–55
26 40–47
27 32–39
28 24–31
29 16–23
30 8–15
31 0–7

PALxxxx and CLMxxxx

These lump names are reserved for custom level palettes (see Level header > Palette), and are identical in function to the PLAYPAL and COLORMAP lumps respectively. xxxx for these is a four-digit number between 0000 and 9999, and determines what palette set number they correspond with – PAL0000 and CLM0000 are reserved for when Palette in a level header is set to 1; PAL9999 and CLM9999 are reserved for when Palette is set to 10000. In general, the value of xxxx should be the intended value for Palette in a level header, minus one.

TRANS10–TRANS90

These lumps are SRB2's translucency maps for the Software rendering mode. These convert the colors of a graphic's pixels to other colors in SRB2's palette, depending on the translucency map being applied and what is being displayed behind them at the time – each row in a translucency map represents a possible palette color for the foreground, each column a possible palette color for the background, and the places a selected row and column meet give the resulting palette color used.

There are nine translucency maps in total, one for each of nine different levels of translucency:

Lump name Image (thumbnail) Description
TRANS10
TRANS10.png
10% translucency
TRANS20
TRANS20.png
20% translucency
TRANS30
TRANS30.png
30% translucency
TRANS40
TRANS40.png
40% translucency
TRANS50
TRANS50.png
50% translucency
Lump name Image (thumbnail) Description
TRANS60
TRANS60.png
60% translucency
TRANS70
TRANS70.png
70% translucency
TRANS80
TRANS80.png
80% translucency
TRANS90
TRANS90.png
90% translucency

Note that these lumps use the same graphics format as flats.

Setting up the palette

In order to use graphics in a WAD file, they have to be converted to Doom's graphics format first. By default, lump editors will convert graphics into Doom's palette, but SRB2's palette is different, this will mess up the graphics' colors. To convert images correctly, the lump editor needs to be directed to SRB2's palette.

SLADE

Unlike other WAD editors, SLADE already includes SRB2's palette in its native selection. To activate it, select "Sonic (SRB2)" in the "Palette" dropdown box in the toolbar. Additionally, if you select srb2.srb as your base resource (the SLADE article explains how to set this up), the "Existing/Global" palette option will also be SRB2's palette.

XWE

Whenever you open XWE, it uses whatever palette is used in its config. So what you need to do is tell XWE to use SRB2's palette, and from there on, every image you load in a WAD file will be displayed correctly. You can do this in three ways.

Using srb2.srb

The first way is to simply open srb2.srb and use the palette in there. The advantage is that you don't have to save anything, but the disadvantage is that you have to open srb2.srb every time you open XWE, which takes a while to load.

  • Open XWE and go to "View → Options".
  • Make sure the "Perform Clean Up on exit" option is unchecked. Otherwise, SRB2's IWAD will be corrupted and the game won't start anymore.
  • Opening srb2.srb is generally the easiest way to reach the palette lump. You may also want to export the lump and open it every time instead of opening srb2.srb, which takes a few seconds to load.
  • Choose the PLAYPAL lump located in srb2.srb. If you exported the lump as a file, then it'll be select by default, obviously.
  • Go to "Palette → Use current".
  • Close srb2.srb without closing XWE (File → Close).
  • Open the files with which you need to operate, and everything should be displayed properly. Obviously, it won't be right if you used an old version of SRB2's palette.

Saving the SRB2 palette in the XWE folder

The second way is to save SRB2's palette file in the XWE folder so that you can select it. The advantage of this is that you can convert graphics for v1.09.4 and earlier versions to the current version quite easily because you can switch between palettes quickly. The disadvantage is that if you want use SRB2's palette, you have to select it every time you open XWE.

  • Open XWE and go to "View → Options".
  • Make sure the "Perform Clean Up on exit" option is unchecked. Otherwise, SRB2's IWAD will be corrupted and the game won't start anymore.
  • Open srb2.srb and select the PLAYPAL lump.
  • Go to "Palette → Save As" and navigate to the PALETTES folder inside your XWE folder.
  • Save the file with a file name you can remember (SRB2v2.act, for example).
  • Now you can select the palette for an image by going to "Image → Select Palette" and choosing the palette you saved.

Changing XWE's IWAD

The third way is to simply change XWE's IWAD so that it will load SRB2's palette automatically. The advantage is that you don't have to set the palette every time you use XWE. The disadvantage is that if you switch to another palette, you can't switch back easily. You can prevent this by combining this with the previous option so you can select the palette from the Palette menu after changing back.

  • Find xwe.ini in your XWE folder and open it with a text editor like Notepad.
  • Go to "Edit → Find..." and search for "MainWAD".
  • The first time you see "MainWAD", change the text so that it points to srb2.srb, according to the following structure: MainWAD,C:\Folder\Folder with spaces\SRB2\,srb2.srb. Make sure to put the commas in the correct places.

Converting images from v1.09.4 to the current version

SLADE

  • Set the Base Resource to the current version's srb2.srb and the palette to "Existing/Global".
  • Open the file, select all lumps that you want to convert and right-click on one of them.
  • Select "Gfx → Convert to...".
  • In the window that should open now, select "Doom Gfx (Paletted)" as the format to convert to.
  • Select "Doom" as "Current Graphic" and "Existing/Global" as "Converted Graphic". Both pictures should now look the same.
  • Click "Convert All" to convert all selected graphics at once.

You can also select "Sonic (SRB2)" as "Converted Graphic", which allows you to convert images even when you have a different Base Resource and palette loaded.

XWE

First you must have the SRB2 palette in your XWE folder. (See Saving the SRB2 palette in the XWE folder). After you have done that, follow these steps:

  • Open the file that contains the image you want to convert.
  • If you have the current version's srb2.srb set as your IWAD, then go to "Images → Select Palette → doom" and click OK.
  • Go to "Entry → Save As" and export the images.
  • Go to "Images → Select Palette → SRB2v2" and click OK.
  • Go to "Entry → Load" and open the images that you saved. They will be automatically converted.

Creating custom palettes

Custom palettes may be wanted sometimes to change the appearance of graphics in SRB2, or to fit custom graphics being added in a custom modification. These can be made using SLADE's palette editing features:

  • To start off with SRB2's base palette, either the PLAYPAL lump from srb2.srb itself can be imported into the required WAD, or a new PLAYPAL lump can be generated by going to "Archive → New → PLAYPAL" and selecting "Sonic (SRB2)" from the dropdown box in the window that pops up (or "Existing/Global" if srb2.srb has been set as your base resource). Note that the latter method will only include the first of SRB2's palettes (see above for further information).
  • To modify specific colors in the palette, right click on them to bring up the window for modifying a color and apply the changes.
  • Other changes can be made to the whole of or part of the palette; the available options are:
    • "Colorize" – converts all palette colors to shades of a specific color
    • "Tint" – applies a tint of a specific color and amount to all palette colors
    • "Tweak" – adjusts Hue shift, Saturation and Luminosity settings
    • "Invert" – allows a selected range of the palette colors to be inverted
  • Further palettes can be created if needed, and can be switched between and such. Relevant options include:
    • "Generate Palettes" – will automatically generate the remaining palettes depending on the option selected (should be "Doom (14 Palettes)"). However, by default these will generate the relevant palettes modifications required for Doom rather than for SRB2; see above for how palettes should be colored in SRB2.
    • "Duplicate" – will automatically duplicate the currently selected palette in a new slot after all currently existing palettes.
    • "Pull Ahead" – will move the palette back a slot number. If the current palette is the first palette, the new slot given will be the last palette number.
    • "Push Back" – will move the palette forward a slot number. If the current palette is the last palette, the new slot given will be the first palette number.
    • "Remove" – will delete the currently selected palette and switch to viewing the next palette in the list.
    • "Remove Others" – will delete all palettes except the palette currently selected.
  • Options available after finishing the palette:
    • "Test Palette" – temporarily adds the palette to the list of selectable palettes for SLADE to display graphics with. The palette will be removed from the list when SLADE itself is closed.
    • "Add to Custom Palettes" – same as above, except the palette is permanently added to SLADE's palette list.
    • "Palette → Generate Colormaps" – automatically generates a COLORMAP lump for the selected palette lump.

See also