Wall wiggle bug



In the Doom engine, the wall wiggle bug, also known as the wobbly line bug, is a graphical glitch most often apparent when a player is positioned in such a way that a two-sided linedef passes almost directly through the center of the player. Due to the nature of the glitch, it is generally observed when the player is standing at the boundary between two sectors with different heights, such that there is a ledge visible above or beneath the player. The glitch results in the line demarcating the ledge appearing to "wiggle" back and forth in a distracting and unrealistic manner as the player moves.

While the glitch has been present since the original release of Doom, it was not widely noticed until the advent of high-resolution source ports, due to the unusual aspect that the glitch actually becomes more severe as the engine's resolution increases.

Technical
The bug arises from the following code in the R_ScaleFromGlobalAngle function:

To summarize, the Doom engine calculates how far the line is from the player's point of view at each visible end of the line, and uses this to determine the scaling factor that should be applied to the line at each end. In the case where the line passes extremely closely to the center of the player, this means that the scaling factor for the line would be extremely large at one end, because the player's viewpoint is infinitesimally close to the line.



The engine, however, defines a maximum value for the line's scaling as 64*FRACUNIT. This limit is implemented because the engine must use fixed-point arithmetic to determine the final amount to scale a linedef texture, and an extremely large scaling factor would overflow the limit of the variable type used.

In practice, this means that a line that passes almost directly under or over the player will appear to bend away from the player. This is exacerbated by the fact that the Doom engine using precalculated tables for the sine and cosine values used to calculate the scaling factor, and near the edge cases where the engine is attempting to divide by a precalculated value extremely close to zero, the coarse nature of the tables can result in a very large multiplicative value that can instantaneously shift by a large amount.

Most source ports which have implemented high resolutions have not implemented any measures to address this bug, and continue to use the same fixed-point arithmetic to determine linedef scaling factors; because the ports generally increase the detailshift and projection values in the process of implementing higher resolutions, the result is that the scaling factor reaches its limit at even less oblique angles, and the wall wiggle becomes more common and more noticeable.

Workarounds have been developed to limit the severity of wall wiggle within the original engine framework, but because the bug is related to the fundamental workings of the Doom engine's renderer, it cannot be eliminated without a significant rewrite of the rendering code.

ZDoom is known to have fixed this error in its software renderer, and all hardware-accelerated source ports eliminate the bug by default.