Skip to content

Commit 10060c8

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 a041638 commit 10060c8

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
@@ -3607,7 +3607,7 @@ class u_ColorModulateColorGen :
36073607
// vertexOverbright is only needed for non-lightmapped cases. When there is a
36083608
// lightmap, this is done by multiplying with the overbright-scaled white image
36093609
colorModulate |= Util::ordinal( ColorModulate::COLOR_LIGHTFACTOR );
3610-
lightFactor = uint32_t( tr.mapLightFactor ) << 6;
3610+
lightFactor = uint32_t( tr.mapLightFactor ) << 26;
36113611
} else {
36123612
colorModulate |= Util::ordinal( ColorModulate::COLOR_ONE );
36133613
}
@@ -3624,10 +3624,10 @@ class u_ColorModulateColorGen :
36243624

36253625
if ( useMapLightFactor ) {
36263626
ASSERT_EQ( vertexOverbright, false );
3627-
lightFactor = uint32_t( tr.mapLightFactor ) << 6;
3627+
lightFactor = uint32_t( tr.mapLightFactor ) << 26;
36283628
}
36293629

3630-
colorModulate |= lightFactor ? lightFactor : 1 << 6;
3630+
colorModulate |= lightFactor ? lightFactor : 1 << 26;
36313631

36323632
switch ( alphaGen ) {
36333633
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 defined(HAVE_EXT_gpu_shader4)
125-
return float( ( colorMod >> 6 ) & 0xF );
127+
/* The day the 31st bit is used, this should be done instead:
128+
return float( ( colorMod >> 26 ) & 0xF ); */
129+
return float( 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)