@@ -3054,17 +3054,11 @@ void R_InitImages()
3054
3054
tr.lightmaps .reserve ( 128 );
3055
3055
tr.deluxemaps .reserve ( 128 );
3056
3056
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.
3068
3062
3069
3063
Games like Quake 3 and Tremulous require tr.mapOverBrightBits
3070
3064
to be set to 2. Because this engine is primarily maintained for
@@ -3090,29 +3084,41 @@ void R_InitImages()
3090
3084
require to set a different default than what Unvanquished
3091
3085
requires.
3092
3086
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
+ */
3116
3122
3117
3123
// TODO is there any reason to set these before a map is loaded?
3118
3124
tr.mapOverBrightBits = r_overbrightDefaultExponent.Get ();
0 commit comments