Floor Texture Alignment

Aligning textures can be a frustrating experience especially on floors
with moving textures such as conveyor belts or
water and slime canals. Although it is easy to control the direction that the player will move to when standing in the moving sector (angle of the
SectorEffector sprite) , the floor textures will sometimes move in a different
direction. Of course, the recommended directive in such a case is to change
the Firstwall of the sector and make it relatively aligned by using
the "R" key in 3D mode. Unfortunately, this alone does
not always cure the problem and the designer will often have to use the
"F" key, go back and forth between Build and Duke3D to
make sure that everything looks the way it should. This is a painstaking
process, particularly if you have a long chain of conveyers or a sinewy
river constructed from a large number of sectors. This is also the case
if you have rotated a bunch of sectors after adjusting their floor textures;
the sprites are automatically rotated but not the textures and you
have to start over. This tutorial is aimed at easing the process and aligning
these textures with 100% predictability and to eliminate the "back-and-forth"
hassle.
First, start off by making a simple rectangular
sector, insert two vertices on the top wall and draw another sector on
the inside of the first one. Place a SectorEffector sprite inside the
inner sector and give it a Lotag of 24 to create a
conveyer belt as shown in the picture on the right. Change the angle of
the sprite with the < or > key to make it point downwards. Go to
3D mode and raise the sector floor by a few clicks and change the floor
texture to tile #1156. It might not be aligned properly but leave
it for now. Change the texture of the top middle wall to a different texture
to make it easily identifiable.
Save your map and start the game with it. You will notice that when Duke
steps on the conveyer, he is moving in the right direction but the belt
may be moving in a direction either opposite or perpidicular to the desired
direction. The reason for this is that the movement or any object placed
on the conveyer belt depends only on the angle of the SectorEffector
sprite present in that sector. The orientation and direction
of the floor textures is an entirely different thing. In order to fully
understand their behavior, three basic notions have to be reviewed. Firstwall
, Relative Alignment and Texture Flipping . |
|

Firstwall
Basics
- The firstwall of a sector is the first one to be drawn when drawing
a new sector from scratch provided that it is drawn in
a clockwise fashion.
- If drawn counter-clockwise, the first wall of the sector will
be the one opposite to the first line that was drawn at least in the case
of a rectangular sector.
- If an adjoining sector is created using one wall from an existing sector,
the firstwall of the new sector will be the first one-sided wall to be
drawn when going clockwise and the last one-sided wall to be drawn when
going counter-clockwise.
- The wall with the lowest wall number of any given sector is always
the firstwall of that sector.
- Walls inside a sector are numbered in ascending order clockwise from
the firstwall (lowest number).
Which is which?
- To find out the number of a wall, hold the mouse pointer close to the
line so it blinks and hit the "Alt-TAB" key in 2D mode
to display the line attributes. See example below.
| Wall 34 |
| X-coordinate : 3328 |
Flags (hex) : 0 |
nextsector : -1 |
| Y-coordinate : -13568 |
Shade : 0 |
nextwall : -1 |
| Point2 : 35 |
Pal : 0 |
Extra : -1 |
| Sector : 4 |
(X,Y) repeat : 12, 8 |
Wall length : 96 |
| Tags : 0, 0 |
(X,Y) pan : 15, 36 |
Pixel height : 76 |
| ( 0x0 ), ( 0x0 ) |
Tile number : 355 |
| Overtile number : 0 |
- The wall number is then displayed in the top left corner of the attributes
window in the bottom part of the Build screen.
- Red lines actually carry two walls: one on either side of the line
so make sure the cursor rests on the inside of the sector close
to the line while hitting the "Alt-TAB" key.
- If a nearby sprite also blinks when you hit the "Alt-TAB"
key, Build will give the priority to the sprite and display
the spite attributes instead. Zooming out far enough
to make the sprite boxes disappear helps to grab only the line.
- The firstwall of a sector can be determined at any time by aiming the
cursor anywhere inside this sector and hitting the "TAB"
key in 2D mode. This will then display the sector attributes and
the sector firstwall number is displayed in the second row of the leftmost
column in the bottom part of the Build screen as shown in the example below.
| Sector 4 |
Ceilings : |
Floors : |
| Firstwall : 34 |
Flags (hex) : 24 |
Flags (hex) : 40 |
| Numberofwalls : 1 |
(X,Y) pan : 15, 36 |
(X,Y) pan : 0, 0 |
| Firstsprite : 1 |
Shade byte : 7 |
Shade byte : 7 |
| Tags : 0, 0 |
Z-coordinate : -7168 |
Z-coordinate : 12288 |
| ( 0x0 ), ( 0x0 ) |
Tile number : 355 |
Tile number : 1156 |
| Extra : -1 |
Ceiling heinum : 4096 |
Floor heinum : -4096 |
| Visibility : 32 |
Palookup number : 0 |
Palookup number : 0 |
| Pixel height : 76 |
How can I change the firstwall of the sector?
As such, the firstwall number of a sector cannot be altered
unless the sector is either split or joined. But, you can change the
wall number assignments by hitting the "Alt-F" key while
pointing at a wall in 3D mode. This causes all the walls of a sector to
swap numbers in a round-robin fashion as shown below. The net effect
is that you can actually choose which wall will be the firstwall of the
sector.
Relative Alignment
What it means
- When a new sector is drawn, the floor texture is always aligned relatively to the map grid by default.
- In the case of a sector with the firstwall drawn orthogonally to the grid, the texture will be either parrallel or perpidicular to the firstwall of that sector depending on which wall was drawn first (see example above). In this case, using relative alignment makes no difference regarding texture alignment and movement control other than the resulting Floor Hex flags in the sector attributes (more on this later).
- If the firstwall of a sector made from any number of walls is drawn at an angle in relation with the map grid and the designer wants to use this particular wall as a reference for floor texture alignment and movement control, Relative Alignment must be used by hitting the "R" key while aiming at the floor with the mouse cursor in 3D mode.
- In most cases, the use of relative alignment alone is not sufficient to impart the desired orientation to a fixed floor texture and the direction of a moving one. Texture flipping is also required, there are 8 possible orientations when using the "F"
key (more on this later).
- Even though it might not be necessary in some cases to relatively align the floor texture to the firstwall of your sector, it is nevertheless good practice in case you decide later to move the walls around or rotate a sector in which the textures must remain aligned. You will still have to use texture flipping though.
Texture Flipping
How it works
- Texture flipping controls two aspects of moving floor textures : orientation of the tile itself and the direction in which this tile will scroll while in the game. For each tile orientation, there are two possible directions of movement. This is why there are 8 possible settings (4 x 2).
- Symmetrical tiles such as tile #1156
which is almost always used for conveyer belts are hard to align because they look the same when flipped twice giving the map designer the false impression that there are only four possible orientations. Worse, it's impossible to rely on texture oriententation when using random pattern tiles such as water or slime.
- Despite this fact, the tiles that lend themselves best to moving floors are the ones mentionned above. Tiles which have a horizontal line pattern in the tile palette cannot be resolved. Their orientation will always be perpendicular to their movement. They can be used but will not look right.
- Flipping the texture twice after trying the map in the game does not always make the conveyer belt or the river move in the right direction right away and often, several "back-and-forth" cycles are required before the desired effect is attained. Fortunately, there is a better way and this is where the Floor hex Flags in the sector attributes come into play.
Floor hex flags
The Floor Hex Flags is a 16 bit register in which the first 7 bits (Bit 0 - Bit 6) are used by Build to convey information on the floor of a given sector. The remaining bits are reserved and not documented in the Build Docs. As the name implies, its value is in hexadecimal form and is displayed in the second row of the third column in the sector attributes screen. By reading the value of this flag, it is possible to determine the status of floor parameters like parallaxing, slope and smooshiness as well as relative alignment and direction of floor displacement without having to start the game.
Don't worry if you don't understand binary or hexadecimal, tables with the hexadecimal flag values and their corresponding texture orientation and displacement are provided below. Use these tables as a reference when you want to coordinate the floor textures and their direction of displacement in your maps. Of course, these flag values are valid provided that your floor is neither sloped, parallaxed or smooshed. If you want to apply these features to the same floors, I suggest that you do it last. Alternately, if you are familiar with binary and hex, you can use the binary table at the end of this tutorial to figure out the hex codes that will result from a combination of all the features you wish to implement. This might be useful in the event that you are reworking a existing map and have rotated many sectors
Table 1
| Direction of floor displacement with corresponding hex flags when using Relative Alignment |
 |
 |
 |
 |
| Floor Hex Flag = 40 |
Floor Hex Flag = 64 |
Floor Hex Flag = 70 |
Floor Hex Flag = 54 |
 |
 |
 |
 |
| Floor Hex Flag = 50 |
Floor Hex Flag = 74 |
Floor Hex Flag = 60 |
Floor Hex Flag = 44 |
Table 2
| Direction of floor displacement with corresponding hex flags without Relative Alignment |
 |
 |
 |
 |
| Floor Hex Flag = 0 |
Floor Hex Flag = 24 |
Floor Hex Flag = 30 |
Floor Hex Flag = 14 |
 |
 |
 |
 |
| Floor Hex Flag = 10 |
Floor Hex Flag = 34 |
Floor Hex Flag = 20 |
Floor Hex Flag = 4 |
How to use the tables
- Choose the wall you want to be the firstwall of the sector with the "Alt-F" key in 3D mode. Sometimes, the floor of the sector might have to be temporarily raised or lowered to be able to point at it. Remember, red lines have two walls, make sure you aim the cursor at the right one.
- At this point, it's up to you to decide if you need to use relative alignment or not. If you do, hit the "R" key, go back to 2D mode and refer to the values in Table 1. Otherwise, go straight to 2D mode and refer to the values in Table 2.
- Display the sector attributes by hitting the "TAB" key and note the value of the Floor hex flags. All the values in the tables are shown in their sequential order. When the last value is reached, another press of the "F" key will take the hex flags back to its first value.
- So, if for example you chose to use relative alignment and the Floor hex flags in the sector attributes is at 74 and you want the floor to move towards the right side of the room when facing the firstwall, you need to change the hex flags to a value of 70. To do this, go to 3D mode and hit the "F" key 5 times while pointing at the floor. Go back to 2D mode and hit the "TAB" key again to check if the hex flags is right and you're done.
For the technically inclined
Here is a binary table describing the role of each of the bits in the floor hex flags register and two more to show the relation between the hex value and the binary value of the register for those who are bent on fine-tuning their floor properties.
Floor Hex Flags register bit assignment
| BIT No. |
B15 - B7 |
B6 |
B5 |
B4 |
B3 |
B2 |
B1 |
B0 |
| FUNCTION |
Reserved |
Relative
Alignment |
Y-Flip |
X-Flip |
Smoosh
Tile |
Swap
X & Y |
Sloped
Floor |
Parallaxing |
| MODE |
N/A |
1 = ON
0 = OFF |
1 = ON
0 = OFF |
1 = ON
0 = OFF |
1 = ON
0 = OFF |
1 = ON
0 = OFF |
1 = ON
0 = OFF |
1 = ON
0 = OFF |
BUILD
COMMAND |
N/A |
R |
F |
E |
F |
[ , ] , / |
P |
| BINARY |
HEX |
| B6 |
B5 |
B4 |
B3 |
B2 |
B1 |
B0 |
|
| 1 |
0 |
0 |
0 |
0 |
0 |
0 |
40 |
| 1 |
1 |
0 |
0 |
1 |
0 |
0 |
64 |
| 1 |
1 |
1 |
0 |
0 |
0 |
0 |
70 |
| 1 |
0 |
1 |
0 |
1 |
0 |
0 |
54 |
| 1 |
0 |
1 |
0 |
0 |
0 |
0 |
50 |
| 1 |
1 |
1 |
0 |
1 |
0 |
0 |
74 |
| 1 |
1 |
0 |
0 |
0 |
0 |
0 |
60 |
| 1 |
0 |
0 |
0 |
1 |
0 |
0 |
44 |
|
| BINARY |
HEX |
| B6 |
B5 |
B4 |
B3 |
B2 |
B1 |
B0 |
|
| 0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
| 0 |
1 |
0 |
0 |
1 |
0 |
0 |
24 |
| 0 |
1 |
1 |
0 |
0 |
0 |
0 |
30 |
| 0 |
0 |
1 |
0 |
1 |
0 |
0 |
14 |
| 0 |
0 |
1 |
0 |
0 |
0 |
0 |
10 |
| 0 |
1 |
1 |
0 |
1 |
0 |
0 |
34 |
| 0 |
1 |
0 |
0 |
0 |
0 |
0 |
20 |
| 0 |
0 |
0 |
0 |
1 |
0 |
0 |
4 |
|
| With Relative Alignment |
Without Relative Alignment |
|
Page written by : |
|
| Duke Nukem 3D is copyright
©1996 |
|
, All Rights reserved. |
THIS PAGE IS NOT MADE BY OR SUPPORTED BY 3D REALMS