Surface and Content flags of Sin SWL textures - Part I
by Eutectic


1. Introduction

The purpose of this tutorial is to establish the relationship between the surface/content properties of SWL textures in Sin and the value of the HEX registers that are used to set those in Sinview. This is mostly useful for people who want either to convert existing textures from another format (WAD, WAL or WAD3) to SWL or make new textures from scratch. And for this purpose, Sinview can be a very useful tool.

In order to do this, you will need SinEd, Sinview1.2b, Wally and a paint program such as PaintShop Pro or Adobe Photoshop. For converting textures from another format or creating new ones, PCX Run Length Encoding Version 5 is the format of choice since Wally can export textures to that format and Sinview can read them and convert them to SWL.

First, let's open SinEd, load and select a texture and look at the texture properties displayed in the surface inspector:




Next, let's take a look at the SWL texture properties displayed in Sinview when you use it to browse the same texture:



Now if you compare the properties displayed in one and the other, you will notice that all the fields and their values in Sinview's texture view have a direct equivalent to the fields displayed in SinEd's surface inspector except for the 4th to 7th fields: Flags, Contents, Value and Direct.

The Value and Direct fields are beyond the scope of this tutorial, what we're really interested in here are fields 4 and 5, Flags and Contents, outlined in red below:




So what are they and what use can we make of them? Well, they are basically 32 bit binary registers and their value must be set in hexadecimal. Each of the bits in Flags register can pre-set a surf flag or surface type for a texture and each of the bits in the Contents register can set a content flag for that texture.

Confused? Don't worry, this is a lot simpler than it sounds. Let's take a look at the first one and see how it works.


2. Surface Properties

Simply put, the value you give to the Flags field in Sinview will determine what default surface properties your texture will have when you select it and open the surface inspector in SinEd as can be seen outlined in red in the images below:


Sinview
SETS THESE
SinEd


3. How the Flags register works


Flags 0x00000000

The register always starts with 0x followed by 8 digits. The 0x part can't be changed but any of the following 8 digits can be set to any hexadecimal value from 0 to F (0 to 15 in decimal) so each of these digits contain 4 bits (a nibble). Each individual bit, when set to 1, sets a surface type or checks a surf flag for the texture. If the bit is 0, the surf flag is of course, not checked. Since there are 8 of those 4-bit digits, that's 32 bits total.

Still confused? Ok, let's just display the register vertically so we can break it down into small pieces to show you what I mean:


0 This part is reserved (do not use)
x
0 This digit contains 4 flag bits
0 This digit contains 4 flag bits
0 This digit contains 4 flag bits
0 This digit contains 4 flag bits
0 This digit contains 4 flag bits
0 This digit contains 4 flag bits
0 This digit contains 4 flag bits
0 This digit contains 4 flag bits


Ok, so what do each of these slices of 4-bit or nibbles do? Well let's break them down individually to show what each one does:


0 This part is reserved (do not use)
x
0 Bit 3 : 80000000
Bit 2 : surfbit3
Bit 1 : surfbit2
Bit 0 : surfbit1
0 Bit 3 : surfbit0
Bit 2 : nomerge
Bit 1 : translate
Bit 0 : rndtime
0 Bit 3 : animate
Bit 2 : random
Bit 1 : envmap
Bit 0 : add-blend
0 Bit 3 : normal
Bit 2 : weak
Bit 1 : damage
Bit 0 : HW-only
0 Bit 3 : usecolor
Bit 2 : console
Bit 1 : mirror
Bit 0 : prelit
0 Bit 3 : ricochet
Bit 2 : wavy
Bit 1 : skip
Bit 0 : hint
0 Bit 3 : nodraw
Bit 2 : conveyor
Bit 1 : nofilter
Bit 0 : non-lit
0 Bit 3 : warp
Bit 2 : sky
Bit 1 : masked
Bit 0 : light


Fine, so how do how you figure out the hexadecimal value to give to each of the nibbles when you want a surf flag or a combination of surf flags to be set? Well each of the bits have a value depending on which one is set:


0 This part is reserved (do not use)
x
0 Bit 3 : when set is worth 8
Bit 2 : when set is worth 4
Bit 1 : when set is worth 2
Bit 0 : when set is worth 1
0 Bit 3 : when set is worth 8
Bit 2 : when set is worth 4
Bit 1 : when set is worth 2
Bit 0 : when set is worth 1


Although only the first 2 nibbles are displayed above, it's the same for all 8 of them. So let's say you made a brand new texture and you want to have the normal, damage, prelit and light flags preset on your texture. Well, you would figure out the value this way:


Bit 3 of the 4th nibble has to be set. Value: 8
Bit 1 of the 4th nibble has to be set. Value: 2
Bit 0 of the 5th nibble has to be set. Value: 1
Bit 0 of the 8th nibble has to be set. Value: 1


So now all you have to do is add the values for each nibble and assign the result to the register:

0 This part is reserved (do not use) 0
x x
0 No bits set (value 0) 0
0 No bits set (value 0) 0
0 No bits set (value 0) 0
0 Bit 3 : normal (set, value 8)
Bit 1 : damage (set, value 2)
Total: A
0 Bit 0 : prelit (set, value 1) Total: 1
0 No bits set (value 0) 0
0 No bits set (value 0) 0
0 Bit 0 : light (set, value 1) Total: 1


In the above example, the total for the 4th nibble is 10 but in hexadecimal, this is expressed with the letter A. If you're not familiar with hexadecimal, don't worry, you don't really have to be to use this. All you have to know is that in hex, the numbers 0 to 9 are the same and that:


10 = A
11 = B
12 = C
13 = D
14 = E
15 = F

And the largest value you can have in any nibble is 15 (8 + 4 + 2 + 1).

So if you set the value of the Flags field to 0x000A1001 for your texture in Sinview and hit the Save .SWL button, the next time you load your texture in SinED, select it and call the surface inspector, it will have the normal, damage, prelit and light surf flags set by default.

Now that you're familiar with the basics of figuring out the value of your Flags register to set the surf flags of your textures, we can now move along to Part II of this tutorial in which I will describe how to use the surfbit0 - surfbit3 bits to set the Surface Type of your Sin textures.

Part II