Texture Pegging

From SRB2 Wiki
(Redirected from Pegging)
Jump to navigation Jump to search
Sonic stands on the edge of a platform with a grass border. This border is a middle texture that is attached to the floor by checking the Lower Unpegged or Peg Midtexture flag on its linedef.
To do
Update for UDMF: Lower Unpegged no longer affects the middle texture there.

Texture pegging refers to the positioning of the textures on a sidedef. Specifically, pegging determines whether the textures are drawn from the bottom up or from the top down. The linedef flags Lower Unpegged, Upper Unpegged and Peg Midtexture are used to determine the pegging behavior.

Pegging is especially important for the middle texture. In SRB2, the middle texture is usually rendered as a "false wall", i.e. the player can pass through it. It is often used to add grass borders to the edges of sectors with a grass flat. To accomplish this, the middle texture must be attached to the sector's floor. However, by default the middle texture is attached to the ceiling. To attach it to the floor, the Lower Unpegged or Peg Midtexture flag (but not both) needs to be checked on the linedef.

Pegging behavior

Most linedefs are two-sided, which means they constitute a border between two sectors. Which textures are rendered and how they are rendered depends on the height differences between the ceilings and floors of the two sectors:

  • The upper texture is drawn as a solid wall between the two ceilings. By default, it attaches to the lower ceiling and is drawn from the bottom up. If the Upper Unpegged flag is checked, it attaches to the higher ceiling instead and is drawn from the top down.
  • The lower texture is drawn as a solid wall between the two floors. By default, it attaches to the higher floor and is drawn from the top down. If the Lower Unpegged flag is checked, it attaches to the lower floor instead and is drawn from the bottom up.
  • The middle texture is drawn as an intangible wall between the between the lower ceiling and the higher floor. By default, it attaches to the ceiling and is drawn from the top down. If the Lower Unpegged flag is checked, it attaches to the floor instead and is drawn from the bottom up. Checking the Peg Midtexture flag inverts this behavior: If it attached to the ceiling before, it will now attach to the floor, and vice versa. This makes it possible to unpeg the lower texture and still attach the middle texture to the ceiling, by checking both the Lower Unpegged and Peg Midtexture flags, or to attach the middle texture to the floor while leaving the lower texture attached to the higher floor, by checking only the Peg Midtexture flag.

For one-sided linedefs, there is only one bordering sector. Therefore, only the middle texture is drawn, as a solid wall between the ceiling and the floor. By default, it attaches to the ceiling and is drawn from the top down. If the Lower Unpegged or Peg Midtexture flag (but not both) is checked, it attaches to the floor instead and is drawn from the bottom up.

Most textures are drawn as solid walls because they constitute the borders between the level space and the outside. Because the outside needs to be concealed entirely from the player, the texture is tiled vertically until it fills the entire height of the wall. The pegging behavior only affects the vertical texture alignment: If the height of the wall is not a multiple of the height of the texture, the texture must be cut off either at the top or the bottom. If the texture is drawn from the top down, the bottom will be cut off. If the texture is drawn from the bottom up, the top will be cut off. Because the same effect can also be achieved with texture offsets, which also control horizontal alignment, pegging is rarely relevant for solid walls.

The middle texture of a two-sided linedef is different, however. Here, both the front and the back of the texture belong to the level space. Neither side must be blocked off or concealed from the player, so no wall is needed. Instead, the middle texture is mostly used for decorations and is thus intangible. By default, it is drawn only once and not tiled. This makes pegging relevant, since it is now important if the texture attaches to the ceiling or the floor. By default, it attaches to the ceiling and is drawn from the top down. This is useful for decorations that hang from the ceiling, such as vines or flags. For decorations that attach to the floor and should be drawn from the bottom up, such as grass borders, the Lower Unpegged or Peg Midtexture flag (but not both) needs to be checked.

Setting up middle textures

This section will teach how to set up middle textures, specifically grass borders like the ones seen in Greenflower Zone as well as vines hanging down from the ceiling.

First we will set up grass borders. Make a new map in Zone Builder and create a new sector. Select all of its linedefs and then right-click to bring up the "Edit Linedef" window.

In the "Flags" section, highlighted in red, are the two flags that control pegging behavior: Lower Unpegged and Upper Unpegged. To make a grass border that sticks out from the floor, you will need to check the Lower Unpegged flag. Now you need to set the correct textures. In most cases, middle textures will be visible from both sides, so select GFZGRASS as the middle texture on both the front side and the back side. If you go into 3D mode or test your map in-game, you should see that your sector is surrounded by grass borders like the sector to the left in the screenshot below.

To make hanging vines like in the sector to the right, simply leave the Lower Unpegged flag unchecked. Middle textures attach to the ceiling by default, which is what you want in this case. The vines in the screenshot use the texture JNGVIN1S. Overall, the sector's linedefs should be set up like this:

Middle textures on FOFs

Setting up middle textures such as grass borders for FOFs is slightly trickier. You can't use the middle texture of the FOF control sector, since that is used to display the walls of the FOF itself. Instead, you have to set the middle textures in the target sector. However, if you simply set the middle textures of the target sector's linedefs to GFZGRASS and then check Lower Unpegged, your sector will look like this:

The GFZGRASS texture will appear on the target sector's real floor, rather than on top of the FOF. To get the grass borders to attach to the FOF, you need to use a trick: Set the texture's Y offset to the top height of the FOF. That way, even though the grass borders won't actually be part of the FOF, they will be at just the right height to look like they are sticking out from the top of the FOF. In the screenshot, the FOF's top height is at 96, so if you set the Y offset on both sides of the sector's linedefs to 96, it should look like this:

A side effect of this method is that the target sector's lower texture will be shifted too, due to the Y offset. Another drawback is that if you can only place one grass border in the sector this way. If you want to have another grass border for the target sector's floor, you will have to set up the FOF's grass border differently: Linedef type 222 can be used to create an intangible FOF that shows only the sides. By placing an FOF like this on top of the other one and giving it the GFZGRASS texture, you can create a second grass border in the same sector. To place the grass border at the correct height, set the bottom of the grass border FOF to the same height as the top of the original FOF. GFZGRASS is 8 fracunits high, so the top of the FOF should be 8 fracunits higher than the bottom. The resulting arrangement should look like this:

Sample

Example file: ex_pegging.wad (MAP01)
How to use
  • You may load this file into your favorite map editor, such as Zone Builder. Select MAP01 as the map to load.
  • You may also load this file in the game:
    1. Save ex_pegging.wad into the addons folder of your SRB2 directory.
    2. Start SRB2, go to the Addons menu, and then select ex_pegging.wad.
    3. Start the game in Single Player mode.
    4. Press the Console button (~), and type in the command MAP MAP01 to access the example map.
  • When you load this file in the game, it replaces Greenflower Zone Act 1.