Skip to content

Commit 8212089

Browse files
committed
Update overbright-related comments
1 parent f49cbfe commit 8212089

File tree

4 files changed

+49
-47
lines changed

4 files changed

+49
-47
lines changed

src/engine/renderer/Material.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,14 @@ static void ComputeDynamics( shaderStage_t* pStage ) {
5959
// TODO: Move color and texMatrices stuff to a compute shader
6060
pStage->colorDynamic = false;
6161
switch ( pStage->rgbGen ) {
62+
case colorGen_t::CGEN_IDENTITY_LIGHTING:
6263
case colorGen_t::CGEN_IDENTITY:
6364
case colorGen_t::CGEN_ONE_MINUS_VERTEX:
64-
default:
65-
case colorGen_t::CGEN_IDENTITY_LIGHTING:
66-
/* Historically CGEN_IDENTITY_LIGHTING was done this way:
67-
68-
tess.svars.color = Color::White * tr.identityLight;
69-
70-
But tr.identityLight is always 1.0f in Dæmon engine
71-
as the as the overbright bit implementation is fully
72-
software. */
7365
case colorGen_t::CGEN_VERTEX:
7466
case colorGen_t::CGEN_CONST:
67+
default:
68+
break;
69+
7570
case colorGen_t::CGEN_ENTITY:
7671
case colorGen_t::CGEN_ONE_MINUS_ENTITY:
7772
{

src/engine/renderer/tr_image.cpp

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3054,17 +3054,11 @@ void R_InitImages()
30543054
tr.lightmaps.reserve( 128 );
30553055
tr.deluxemaps.reserve( 128 );
30563056

3057-
//TODO rewrite WoT with new info :)
3058-
/* These are the values expected by the rest of the renderer
3059-
(esp. tr_bsp), used for "gamma correction of the map".
3060-
Both were set to 0 if we had neither COMPAT_ET nor COMPAT_Q3,
3061-
it may be interesting to remember.
3062-
3063-
Quake 3 and Tremulous values:
3064-
3065-
tr.overbrightBits = 0; // Software implementation.
3066-
tr.mapOverBrightBits = 2; // Quake 3 default.
3067-
tr.identityLight = 1.0f / ( 1 << tr.overbrightBits );
3057+
/*
3058+
**** Map overbright bits ****
3059+
Lightmaps and vertex light colors are notionally scaled up by a factor of
3060+
pow(2, tr.mapOverBrightBits). This is a good idea because we would like a bright light
3061+
to make a texture brighter than its original diffuse image.
30683062
30693063
Games like Quake 3 and Tremulous require tr.mapOverBrightBits
30703064
to be set to 2. Because this engine is primarily maintained for
@@ -3090,29 +3084,41 @@ void R_InitImages()
30903084
require to set a different default than what Unvanquished
30913085
requires.
30923086
3093-
Using a non-zero value for tr.mapOverBrightBits turns light
3094-
non-linear and makes deluxe mapping buggy though.
3095-
3096-
Mappers may port and fix maps by multiplying the lights by 2.5
3097-
and set the mapOverBrightBits key to 0 in map entities lump.
3098-
3099-
It will be possible to assume tr.mapOverBrightBits is 0 when
3100-
loading maps compiled with sRGB lightmaps as there is no
3101-
legacy map using sRGB lightmap yet, and then we will be
3102-
able to avoid the need to explicitly set mapOverBrightBits
3103-
to 0 in map entities. It will be required to assume that
3104-
tr.mapOverBrightBits is 0 when loading maps compiled with
3105-
sRGB lightmaps because otherwise the color shift computation
3106-
will break the light computation, not only the deluxe one.
3107-
3108-
In legacy engines, tr.overbrightBits was non-zero when
3109-
hardware overbright bits were enabled, zero when disabled.
3110-
This engine do not implement hardware overbright bit, so
3111-
this is always zero, and we can remove it and simplify all
3112-
the computations making use of it.
3113-
3114-
Because tr.overbrightBits is always 0, tr.identityLight is
3115-
always 1.0f. We can entirely remove it. */
3087+
**** r_overbrightBits ****
3088+
Although lightmaps are scaled up by pow(2, tr.overbrightBits), the actual ceiling for lightmap
3089+
values is pow(2, tr.overbrightBits). tr.overbrightBits may
3090+
be less than tr.mapOverbrightBits. This is a STUPID configuration because then you are
3091+
just throwing away 1 or bits of precision from the lightmap. But it was used for many games.
3092+
3093+
The excess (tr.mapOverbrightBits - tr.overbrightBits) bits of scaling are done to the lightmap
3094+
before uploading it. If some component exceeds 1, the color is proportionally downscaled until
3095+
the max component is 1.
3096+
3097+
Quake 3 and vanilla Tremulous used these default cvar values:
3098+
r_overbrightBits - 1
3099+
r_mapOverBrightBits - 2
3100+
3101+
So the same as Daemon. But if the game was not running in fullscreen mode or the system was
3102+
not detected as supporting hardware gamma control, tr.overbrightBit would be set to 0.
3103+
Tremfusion shipped with r_overbrightBits 0 and r_ignorehwgamma 1, either of which forces
3104+
tr.overbrightBits to 0, making it the same as the vanilla client's windowed mode.
3105+
3106+
**** How Quake 3 originally implemented overbright ****
3107+
When hardware overbright was on (tr.overbrightBits = 1), the color buffer notionally ranged
3108+
from 0 to 2, rather than 0 to 1. So a buffer with 8-bit colors only had 7 bits of
3109+
output precision (all values 128+ produced the same output), but the extra bit was useful
3110+
for intermediate values during blending. The rescaling was effected by using the hardware
3111+
gamma ramp, which affected the whole monitor (or whole system).
3112+
Shaders for materials that were not illuminated by any precomputed lighting could use
3113+
CGEN_IDENTITY_LIGHTING to multiply by tr.identityLight, which would cancel out the
3114+
rescaling so that the material looked the same regardless of tr.overbrightBits.
3115+
3116+
In Daemon tr.identityLight is usually 1, so any distincion between
3117+
CGEN_IDENTITY/CGEN_IDENTITY_LIGHTING is ignored. But if you set the cvar r_overbrightQ3,
3118+
which emulates Quake 3's technique of brightening the whole color buffer, it will be used.
3119+
3120+
For even more information, see https://github.com/DaemonEngine/Daemon/issues/1542.
3121+
*/
31163122

31173123
// TODO is there any reason to set these before a map is loaded?
31183124
tr.mapOverBrightBits = r_overbrightDefaultExponent.Get();

src/engine/renderer/tr_init.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
9393
cvar_t *r_precomputedLighting;
9494
Cvar::Cvar<int> r_overbrightDefaultExponent("r_overbrightDefaultExponent", "default map light color shift (multiply by 2^x)", Cvar::NONE, 2);
9595
Cvar::Range<Cvar::Cvar<int>> r_overbrightBits("r_overbrightBits", "clamp lightmap colors to 2^x", Cvar::NONE, 1, 0, 3);
96+
97+
// also set r_highPrecisionRendering 0 for an even more authentic q3 experience
9698
Cvar::Cvar<bool> r_overbrightQ3("r_overbrightQ3", "brighten entire color buffer like Quake 3 (incompatible with newer assets)", Cvar::NONE, false);
99+
97100
Cvar::Cvar<bool> r_overbrightIgnoreMapSettings("r_overbrightIgnoreMapSettings", "force usage of r_overbrightDefaultClamp / r_overbrightDefaultExponent, ignoring worldspawn", Cvar::NONE, false);
98101
Cvar::Range<Cvar::Cvar<int>> r_lightMode("r_lightMode", "lighting mode: 0: fullbright (cheat), 1: vertex light, 2: grid light (cheat), 3: light map", Cvar::NONE, Util::ordinal(lightMode_t::MAP), Util::ordinal(lightMode_t::FULLBRIGHT), Util::ordinal(lightMode_t::MAP));
99102
Cvar::Cvar<bool> r_colorGrading( "r_colorGrading", "Use color grading", Cvar::NONE, true );

src/engine/renderer/tr_shade.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -848,12 +848,10 @@ void Render_generic3D( shaderStage_t *pStage )
848848
colorGen_t rgbGen = SetRgbGen( pStage );
849849
alphaGen_t alphaGen = SetAlphaGen( pStage );
850850

851-
// Here, it's safe to multiply the overbright factor for vertex lighting into the color gen`
852-
// since the `generic` fragment shader only takes a single input color. `lightMapping` on the
853-
// hand needs to know the real diffuse color, hence the separate u_LightFactor.
854851
bool mayUseVertexOverbright = pStage->type == stageType_t::ST_COLORMAP && tess.bspSurface;
855852
const bool styleLightMap = pStage->type == stageType_t::ST_STYLELIGHTMAP || pStage->type == stageType_t::ST_STYLECOLORMAP;
856-
gl_genericShader->SetUniform_ColorModulateColorGen( rgbGen, alphaGen, mayUseVertexOverbright, styleLightMap );
853+
gl_genericShader->SetUniform_ColorModulateColorGen(
854+
rgbGen, alphaGen, mayUseVertexOverbright, /*useMapLightFactor=*/ styleLightMap);
857855

858856
// u_Color
859857
gl_genericShader->SetUniform_Color( tess.svars.color );

0 commit comments

Comments
 (0)