Skip to content

Commit e268533

Browse files
committed
fixup: glsl 120 int is 16-bit
1 parent fd1f225 commit e268533

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
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 ) << 26;
3610+
lightFactor = uint32_t( tr.mapLightFactor ) << 12;
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 ) << 26;
3627+
lightFactor = uint32_t( tr.mapLightFactor ) << 12;
36283628
}
36293629

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

36323632
switch ( alphaGen ) {
36333633
case alphaGen_t::AGEN_VERTEX:

src/engine/renderer/glsl_source/common.glsl

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,11 @@ Bit 2: color += lightFactor
7777
Bit 3: alpha * 1
7878
Bit 4: alpha * ( -1 )
7979
Bit 5: alpha = 1
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. */
80+
Bits 6-11: available for future usage
81+
Bits 12-15: lightFactor:
82+
Bit 16: intentionally left blank, some rewrite is required (see below)
83+
if that bit has to be used once all the other bits are exhausted.
84+
Bits 17-32: unusable as GLSL 1.20 int is 16-bit. */
8485

8586
float colorModArray[3] = float[3] ( 0.0f, 1.0f, -1.0f );
8687

@@ -124,16 +125,16 @@ vec4 ColorModulateToColor( const in int colorMod, const in float lightFactor ) {
124125

125126
float ColorModulateToLightFactor( const in int colorMod ) {
126127
#if defined(HAVE_EXT_gpu_shader4)
127-
/* The day the 31st bit is used, this should be done instead:
128-
return float( ( colorMod >> 26 ) & 0xF ); */
129-
return float( colorMod >> 26 );
128+
/* The day the 16th bit is used, this should be done instead:
129+
return float( ( colorMod >> 12 ) & 0xF ); */
130+
return float( colorMod >> 12 );
130131
#else
131-
/* The day the 31st bit used, this should be rewritten to
132+
/* The day the 16th bit used, this should be rewritten to
132133
extract the value without the sign, like that:
133134
int v = colorMod;
134-
if ( v < 0 ) v = 2147483647 - abs( v ) + 1;
135-
return float( v / 67108864 ); */
136-
return float( colorMod / 67108864 );
135+
if ( v < 0 ) v = 32767 - abs( v ) + 1;
136+
return float( v / 4096 ); */
137+
return float( colorMod / 4096 );
137138
#endif
138139
}
139140

0 commit comments

Comments
 (0)