Skip to content

Commit 8104069

Browse files
committed
Switch lightFactor to use u_ColorModulateColorGen
`tr.mapLightFactor` is already in `u_ColorModulateColorGen` anyway, so there's no need for the extra uniform.
1 parent 1d56e7d commit 8104069

File tree

8 files changed

+22
-41
lines changed

8 files changed

+22
-41
lines changed

src/engine/renderer/Material.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,12 +285,8 @@ void UpdateSurfaceDataLightMapping( uint32_t* materials, Material& material, dra
285285
bool enableGridLighting = ( lightMode == lightMode_t::GRID );
286286
bool enableGridDeluxeMapping = ( deluxeMode == deluxeMode_t::GRID );
287287

288-
// u_LightFactor
289-
gl_lightMappingShaderMaterial->SetUniform_LightFactor(
290-
lightMode == lightMode_t::FULLBRIGHT ? 1.0f : tr.mapLightFactor );
291-
292288
// u_ColorModulate
293-
gl_lightMappingShaderMaterial->SetUniform_ColorModulateColorGen( rgbGen, alphaGen );
289+
gl_lightMappingShaderMaterial->SetUniform_ColorModulateColorGen( rgbGen, alphaGen, false, lightMode != lightMode_t::FULLBRIGHT );
294290

295291
// u_Color
296292
gl_lightMappingShaderMaterial->SetUniform_Color( tess.svars.color );

src/engine/renderer/gl_shader.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2267,7 +2267,6 @@ GLShader_lightMapping::GLShader_lightMapping( GLShaderManager *manager ) :
22672267
u_ViewOrigin( this ),
22682268
u_ModelMatrix( this ),
22692269
u_ModelViewProjectionMatrix( this ),
2270-
u_LightFactor( this ),
22712270
u_Bones( this ),
22722271
u_VertexInterpolation( this ),
22732272
u_ReliefDepthScale( this ),
@@ -2336,7 +2335,6 @@ GLShader_lightMappingMaterial::GLShader_lightMappingMaterial( GLShaderManager* m
23362335
u_ViewOrigin( this ),
23372336
u_ModelMatrix( this ),
23382337
u_ModelViewProjectionMatrix( this ),
2339-
u_LightFactor( this ),
23402338
u_ReliefDepthScale( this ),
23412339
u_ReliefOffsetBias( this ),
23422340
u_NormalScale( this ),

src/engine/renderer/gl_shader.h

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2136,21 +2136,6 @@ class GLCompileMacro_USE_PHYSICAL_MAPPING :
21362136
}
21372137
};
21382138

2139-
class u_LightFactor :
2140-
GLUniform1f
2141-
{
2142-
public:
2143-
u_LightFactor( GLShader *shader ) :
2144-
GLUniform1f( shader, "u_LightFactor" )
2145-
{
2146-
}
2147-
2148-
void SetUniform_LightFactor( const float lightFactor )
2149-
{
2150-
this->SetValue( lightFactor );
2151-
}
2152-
};
2153-
21542139
class u_ColorMap :
21552140
GLUniformSampler2D {
21562141
public:
@@ -3621,7 +3606,7 @@ class u_ColorModulateColorGen :
36213606
}
36223607

36233608
void SetUniform_ColorModulateColorGen( colorGen_t colorGen, alphaGen_t alphaGen, bool vertexOverbright = false,
3624-
const bool styleLightMap = false ) {
3609+
const bool useMapLightFactor = false ) {
36253610
uint32_t colorModulate = 0;
36263611
bool needAttrib = false;
36273612

@@ -3654,7 +3639,7 @@ class u_ColorModulateColorGen :
36543639
break;
36553640
}
36563641

3657-
if ( styleLightMap ) {
3642+
if ( useMapLightFactor ) {
36583643
ASSERT_EQ( vertexOverbright, false );
36593644
colorModulate |= uint32_t( tr.mapLightFactor ) << 5;
36603645
} else {
@@ -4013,7 +3998,6 @@ class GLShader_lightMapping :
40133998
public u_ViewOrigin,
40143999
public u_ModelMatrix,
40154000
public u_ModelViewProjectionMatrix,
4016-
public u_LightFactor,
40174001
public u_Bones,
40184002
public u_VertexInterpolation,
40194003
public u_ReliefDepthScale,
@@ -4065,7 +4049,6 @@ class GLShader_lightMappingMaterial :
40654049
public u_ViewOrigin,
40664050
public u_ModelMatrix,
40674051
public u_ModelViewProjectionMatrix,
4068-
public u_LightFactor,
40694052
public u_ReliefDepthScale,
40704053
public u_ReliefOffsetBias,
40714054
public u_NormalScale,

src/engine/renderer/glsl_source/common.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
===========================================================================
33
44
Daemon BSD Source Code
5-
Copyright (c) 2024 Daemon Developers
5+
Copyright (c) 2024-2025 Daemon Developers
66
All rights reserved.
77
88
This file is part of the Daemon BSD Source Code (Daemon Source Code).

src/engine/renderer/glsl_source/computeLight_fp.glsl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2323

2424
#define COMPUTELIGHT_GLSL
2525

26-
uniform float u_LightFactor;
27-
2826
#if !defined(USE_BSP_SURFACE)
2927
#define USE_MODEL_SURFACE
3028
#endif
@@ -52,13 +50,13 @@ vec4 EnvironmentalSpecularFactor( vec3 viewDir, vec3 normal )
5250
// lighting helper functions
5351

5452
#if defined(USE_GRID_LIGHTING) || defined(USE_GRID_DELUXE_MAPPING)
55-
void ReadLightGrid( in vec4 texel, out vec3 ambientColor, out vec3 lightColor ) {
53+
void ReadLightGrid( in vec4 texel, in float lightFactor, out vec3 ambientColor, out vec3 lightColor ) {
5654
float ambientScale = 2.0 * texel.a;
5755
float directedScale = 2.0 - ambientScale;
5856
ambientColor = ambientScale * texel.rgb;
5957
lightColor = directedScale * texel.rgb;
60-
ambientColor *= u_LightFactor;
61-
lightColor *= u_LightFactor;
58+
ambientColor *= lightFactor;
59+
lightColor *= lightFactor;
6260
}
6361
#endif
6462

src/engine/renderer/glsl_source/lightMapping_fp.glsl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2222

2323
/* lightMapping_fp.glsl */
2424

25+
#insert common
2526
#insert computeLight_fp
2627
#insert reliefMapping_fp
2728

@@ -34,6 +35,8 @@ uniform sampler2D u_GlowMap;
3435
uniform float u_AlphaThreshold;
3536
uniform vec3 u_ViewOrigin;
3637

38+
uniform uint u_ColorModulateColorGen;
39+
3740
IN(smooth) vec3 var_Position;
3841
IN(smooth) vec2 var_TexCoords;
3942
IN(smooth) vec4 var_Color;
@@ -140,19 +143,20 @@ void main()
140143
vec4 texel = texture3D(u_LightGrid2, lightGridPos);
141144
vec3 lightDir = normalize(texel.xyz - (128.0 / 255.0));
142145
#endif
143-
146+
147+
float lightFactor = ColorModulateToLightFactor( u_ColorModulateColorGen );
144148
#if defined(USE_LIGHT_MAPPING)
145149
// Compute light color from world space lightmap.
146150
// When doing vertex lighting with full-range overbright, this reads out
147151
// 1<<overbrightBits and serves for the overbright shift for vertex colors.
148152
vec3 lightColor = texture2D(u_LightMap, var_TexLight).rgb;
149-
lightColor *= u_LightFactor;
153+
lightColor *= lightFactor;
150154

151155
color.rgb = vec3(0.0);
152156
#else
153157
// Compute light color from lightgrid.
154158
vec3 ambientColor, lightColor;
155-
ReadLightGrid(texture3D(u_LightGrid1, lightGridPos), ambientColor, lightColor);
159+
ReadLightGrid(texture3D(u_LightGrid1, lightGridPos), lightFactor, ambientColor, lightColor);
156160

157161
color.rgb = ambientColor * r_AmbientScale * diffuse.rgb;
158162
#endif

src/engine/renderer/glsl_source/liquid_fp.glsl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2222

2323
/* liquid_fp.glsl */
2424

25+
#insert common
2526
#insert computeLight_fp
2627
#insert reliefMapping_fp
2728

@@ -30,7 +31,11 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
3031
uniform sampler2D u_CurrentMap;
3132
uniform sampler2D u_PortalMap;
3233
uniform sampler2D u_DepthMap;
34+
3335
uniform vec3 u_ViewOrigin;
36+
37+
uniform uint u_ColorModulateColorGen;
38+
3439
uniform float u_FogDensity;
3540
uniform vec3 u_FogColor;
3641
uniform float u_RefractionIndex;
@@ -131,7 +136,8 @@ void main()
131136
// compute light color from light grid
132137
vec3 ambientColor, lightColor;
133138
#if defined(USE_GRID_LIGHTING) || defined(USE_GRID_DELUXE_MAPPING)
134-
ReadLightGrid(texture3D(u_LightGrid1, lightGridPos), ambientColor, lightColor);
139+
float lightFactor = ColorModulateToLightFactor( u_ColorModulateColorGen );
140+
ReadLightGrid(texture3D(u_LightGrid1, lightGridPos), lightFactor, ambientColor, lightColor);
135141
#else // !( defined(USE_GRID_LIGHTING) && defined(USE_GRID_DELUXE_MAPPING) )
136142
ambientColor = vec3( 0.0, 0.0, 0.0 );
137143
lightColor = vec3( 0.0, 0.0, 0.0 );

src/engine/renderer/tr_shade.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,12 +1059,8 @@ void Render_lightMapping( shaderStage_t *pStage )
10591059
// u_DeformGen
10601060
gl_lightMappingShader->SetUniform_Time( backEnd.refdef.floatTime - backEnd.currentEntity->e.shaderTime );
10611061

1062-
// u_LightFactor
1063-
gl_lightMappingShader->SetUniform_LightFactor(
1064-
lightMode == lightMode_t::FULLBRIGHT ? 1.0f : tr.mapLightFactor );
1065-
10661062
// u_ColorModulate
1067-
gl_lightMappingShader->SetUniform_ColorModulateColorGen( rgbGen, alphaGen );
1063+
gl_lightMappingShader->SetUniform_ColorModulateColorGen( rgbGen, alphaGen, false, lightMode != lightMode_t::FULLBRIGHT );
10681064

10691065
// u_Color
10701066
gl_lightMappingShader->SetUniform_Color( tess.svars.color );

0 commit comments

Comments
 (0)