Difference between revisions of "Fake contrast"

From DoomWiki.org

[checked revision][checked revision]
m (+wl Wolf 3D; dispose of obsolete tt tags; use syntaxhighlight for code)
Line 3: Line 3:
 
'''Fake contrast''' is a feature of the original [[vanilla Doom]] engine, which consists in making walls oriented parallel to the East-West axis brighter, while walls parallel to the North-South axis are darker. The aim of fake contrast is to help accentuate the angles in the map's geometry, because with the simple lighting system of the Doom engine (ambient omnidirectional light, no shadows) and the low-resolution paletted textures, the angles could seem flat in rooms.
 
'''Fake contrast''' is a feature of the original [[vanilla Doom]] engine, which consists in making walls oriented parallel to the East-West axis brighter, while walls parallel to the North-South axis are darker. The aim of fake contrast is to help accentuate the angles in the map's geometry, because with the simple lighting system of the Doom engine (ambient omnidirectional light, no shadows) and the low-resolution paletted textures, the angles could seem flat in rooms.
  
The system, however, is not perfect. It only works for orthogonal geometry, even though getting free of the orthogonality constraint present in older raycaster engines (such as Wolfenstein 3D) was one of the main points of the Doom engine. The relatively steep difference detracts from it as well, and has even been perceived as a bug.
+
The system, however, is not perfect. It only works for orthogonal geometry, even though getting free of the orthogonality constraint present in older raycaster engines (such as [[Wolfenstein 3-D]]) was one of the main points of the Doom engine. The relatively steep difference detracts from it as well, and has even been perceived as a bug.
  
 
[[Doomsday]] and [[ZDoom]] feature options to completely disable fake contrast or to make it gradually change with wall orientation.
 
[[Doomsday]] and [[ZDoom]] feature options to completely disable fake contrast or to make it gradually change with wall orientation.
Line 9: Line 9:
 
== Technical details ==
 
== Technical details ==
  
In vanilla, it corresponds to a part of the functions <tt>R_RenderMaskedSegRange()</tt> and <tt>R_StoreWallRange()</tt> in r_segs.c, specifically code segments like this:
+
In vanilla, it corresponds to a part of the functions {{c|R_RenderMaskedSegRange}} and {{c|R_StoreWallRange}} in r_segs.c, specifically code segments like this:
<pre>   // Calculate light table.
+
<syntaxhighlight lang="C">
 +
    // Calculate light table.
 
     // Use different light tables
 
     // Use different light tables
 
     //  for horizontal / vertical / diagonal. Diagonal?
 
     //  for horizontal / vertical / diagonal. Diagonal?
Line 32: Line 33:
 
     else
 
     else
 
walllights = scalelight[lightnum];
 
walllights = scalelight[lightnum];
</pre>
+
</syntaxhighlight>
 
The vanilla engine has 16 light levels corresponding to the 256 light values, so increasing or decreasing lightnum as done here corresponds to increasing or decreasing the effective sector light for the wall by 16. A perfectly "horizontal" wall is brightened, while a perfectly "vertical" one is darkened; every other wall uses the light level of the front sector.
 
The vanilla engine has 16 light levels corresponding to the 256 light values, so increasing or decreasing lightnum as done here corresponds to increasing or decreasing the effective sector light for the wall by 16. A perfectly "horizontal" wall is brightened, while a perfectly "vertical" one is darkened; every other wall uses the light level of the front sector.
  

Revision as of 00:51, 26 July 2014

Screenshot from the beginning of E2M2: Containment Area (Doom): the crate maze in this level is a good example of how fake contrast enhances the appearance of the game.
Same scene from E2M2 taken in a hacked engine with fake contrast disabled.

Fake contrast is a feature of the original vanilla Doom engine, which consists in making walls oriented parallel to the East-West axis brighter, while walls parallel to the North-South axis are darker. The aim of fake contrast is to help accentuate the angles in the map's geometry, because with the simple lighting system of the Doom engine (ambient omnidirectional light, no shadows) and the low-resolution paletted textures, the angles could seem flat in rooms.

The system, however, is not perfect. It only works for orthogonal geometry, even though getting free of the orthogonality constraint present in older raycaster engines (such as Wolfenstein 3-D) was one of the main points of the Doom engine. The relatively steep difference detracts from it as well, and has even been perceived as a bug.

Doomsday and ZDoom feature options to completely disable fake contrast or to make it gradually change with wall orientation.

Technical details

In vanilla, it corresponds to a part of the functions R_RenderMaskedSegRange and R_StoreWallRange in r_segs.c, specifically code segments like this: <syntaxhighlight lang="C">

   // Calculate light table.
   // Use different light tables
   //   for horizontal / vertical / diagonal. Diagonal?
   // OPTIMIZE: get rid of LIGHTSEGSHIFT globally
   curline = ds->curline;
   frontsector = curline->frontsector;
   backsector = curline->backsector;
   texnum = texturetranslation[curline->sidedef->midtexture];
   lightnum = (frontsector->lightlevel >> LIGHTSEGSHIFT)+extralight;
   if (curline->v1->y == curline->v2->y)

lightnum--;

   else if (curline->v1->x == curline->v2->x)

lightnum++;

   if (lightnum < 0)		

walllights = scalelight[0];

   else if (lightnum >= LIGHTLEVELS)

walllights = scalelight[LIGHTLEVELS-1];

   else

walllights = scalelight[lightnum]; </syntaxhighlight> The vanilla engine has 16 light levels corresponding to the 256 light values, so increasing or decreasing lightnum as done here corresponds to increasing or decreasing the effective sector light for the wall by 16. A perfectly "horizontal" wall is brightened, while a perfectly "vertical" one is darkened; every other wall uses the light level of the front sector.

Trivia

The idea for fake contrast predates Doom. In Wolfenstein 3D, since the engine does not handle different light levels, the same effect is instead replicated by having each texture in two version: one bright and one dark.

This article incorporates text from the open-content ZDoom documentation project article Fake contrast.