Skip to content

Commit b2977e7

Browse files
committed
renderer: move lightFactor to the end of u_ColorModulateColorGen
Move lightFactor to the end of u_ColorModulateColorGen. It makes it more future proof by allowing future patches using new bits to be kept small and not have to care about it.
1 parent f7960ad commit b2977e7

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/engine/renderer/gl_shader.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3590,7 +3590,7 @@ class u_ColorModulateColorGen :
35903590
// vertexOverbright is only needed for non-lightmapped cases. When there is a
35913591
// lightmap, this is done by multiplying with the overbright-scaled white image
35923592
colorModulate |= Util::ordinal( ColorModulate::COLOR_LIGHTFACTOR );
3593-
lightFactor = uint32_t( tr.mapLightFactor ) << 6;
3593+
lightFactor = uint32_t( tr.mapLightFactor ) << 26;
35943594
} else {
35953595
colorModulate |= Util::ordinal( ColorModulate::COLOR_ONE );
35963596
}
@@ -3607,10 +3607,10 @@ class u_ColorModulateColorGen :
36073607

36083608
if ( useMapLightFactor ) {
36093609
ASSERT_EQ( vertexOverbright, false );
3610-
lightFactor = uint32_t( tr.mapLightFactor ) << 6;
3610+
lightFactor = uint32_t( tr.mapLightFactor ) << 26;
36113611
}
36123612

3613-
colorModulate |= lightFactor ? lightFactor : 1 << 6;
3613+
colorModulate |= lightFactor ? lightFactor : 1 << 26;
36143614

36153615
switch ( alphaGen ) {
36163616
case alphaGen_t::AGEN_VERTEX:

src/engine/renderer/glsl_source/common.glsl

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,10 @@ Bit 2: color += lightFactor
7777
Bit 3: alpha * 1
7878
Bit 4: alpha * ( -1 )
7979
Bit 5: alpha = 1
80-
Bit 6-9: lightFactor
81-
All bits after lightFactor should be left zeroed. */
80+
Bits 6-25: available for future usage
81+
Bits 26-30: lightFactor:
82+
Bit 31: intentionally left blank, some rewrite is required (see below)
83+
if that bit has to be used once all the other bits are exhausted. */
8284

8385
float colorModArray[3] = float[3] ( 0.0f, 1.0f, -1.0f );
8486

@@ -122,9 +124,16 @@ vec4 ColorModulateToColor( const in int colorMod, const in float lightFactor ) {
122124

123125
float ColorModulateToLightFactor( const in int colorMod ) {
124126
#if __VERSION__ > 120
125-
return ( colorMod >> 6 ) & 0xF;
127+
/* The day the 31st bit is used, this should be done instead:
128+
return ( colorMod >> 26 ) & 0xF; */
129+
return colorMod >> 26;
126130
#else
127-
return float( colorMod / 64 );
131+
/* The day the 31st bit used, this should be rewritten to
132+
extract the value without the sign, like that:
133+
int v = colorMod;
134+
if ( v < 0 ) v = 2147483647 - abs( v ) + 1;
135+
return float( v / 67108864 ); */
136+
return float( colorMod / 67108864 );
128137
#endif
129138
}
130139

0 commit comments

Comments
 (0)