Skip to content

Commit 38455c5

Browse files
committed
Enable realtime lights for vertex-lit surfaces
Use the lightMapping GLSL shader instead of `generic` to render BSP surfaces that are vertex-lit due to an explicit `rgbGen vertex`. This makes them use the same code path as BSP surfaces where vertex lighting is automatically selected due to the absence of a lightmap. So now it is possible to render realtime lights on explicitly vertex-lit surfaces, though they are still not as bright as they should be due to #1415. In the following commit, this will let us remove some ugly code used for applying the overbright factor to the `generic` shader.
1 parent b929882 commit 38455c5

File tree

5 files changed

+22
-3
lines changed

5 files changed

+22
-3
lines changed

src/engine/renderer/Material.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,8 @@ void MaterialSystem::GenerateWorldCommandBuffer( std::vector<MaterialSurface>& s
680680
surfaceCommand.drawCommand.baseInstance |= surface.texDataDynamic[stage]
681681
? ( surface.texDataIDs[stage] + texData.size() ) << TEX_BUNDLE_BITS
682682
: surface.texDataIDs[stage] << TEX_BUNDLE_BITS;
683-
surfaceCommand.drawCommand.baseInstance |= ( HasLightMap( &surface ) ? GetLightMapNum( &surface ) : 255 ) << LIGHTMAP_BITS;
683+
surfaceCommand.drawCommand.baseInstance |=
684+
( !pStage->forceVertexLighting && HasLightMap( &surface ) ? GetLightMapNum( &surface ) : 255 ) << LIGHTMAP_BITS;
684685
surfaceCommands[cmdID] = surfaceCommand;
685686

686687
material->drawCommandCount++;

src/engine/renderer/ShadeCommon.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,12 @@ template<typename Obj> void SetLightDeluxeMode(
121121
lightMode = lightMode_t::FULLBRIGHT;
122122
deluxeMode = deluxeMode_t::NONE;
123123

124-
if ( hasExplicitelyDisabledLightMap( stage->shader ) && !isExplicitelyVertexLitSurface( stage->shader ) )
124+
if ( stage->forceVertexLighting )
125+
{
126+
lightMode = lightMode_t::VERTEX;
127+
deluxeMode = deluxeMode_t::NONE;
128+
}
129+
else if ( hasExplicitelyDisabledLightMap( stage->shader ) && !isExplicitelyVertexLitSurface( stage->shader ) )
125130
{
126131
// Use fullbright on “surfaceparm nolightmap” materials.
127132
}

src/engine/renderer/tr_bsp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ static shader_t* ShaderForShaderNum( int shaderNum ) {
871871

872872
dshader_t* dsh = &s_worldData.shaders[shaderNum];
873873

874-
shader_t* shader = R_FindShader( dsh->shader, RSF_3D );
874+
shader_t* shader = R_FindShader( dsh->shader, RSF_3D | RSF_BSP );
875875

876876
// If the shader had errors, just use default shader
877877
if ( shader->defaultShader ) {

src/engine/renderer/tr_local.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,8 @@ enum
964964
// TODO(0.56): move to the public RegisterShaderFlags_t interface
965965
#define RSF_3D ( BIT( 30 ) )
966966

967+
#define RSF_BSP ( BIT ( 29 ) )
968+
967969
using stageRenderer_t = void(*)(shaderStage_t *);
968970
using stageShaderBuildMarker_t = void(*)(const shaderStage_t*);
969971
using surfaceDataUpdater_t = void(*)(uint32_t*, shaderStage_t*, bool, bool, bool);
@@ -1033,6 +1035,8 @@ enum
10331035
bool highQuality;
10341036
bool forceHighQuality;
10351037

1038+
bool forceVertexLighting;
1039+
10361040
bool hasDepthFade; // for soft particles
10371041
float depthFadeValue;
10381042

src/engine/renderer/tr_shader.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5202,6 +5202,14 @@ static void FinishStages()
52025202
lightStageFound = true;
52035203
break;
52045204

5205+
case stageType_t::ST_COLORMAP:
5206+
if ( stage->rgbGen == colorGen_t::CGEN_VERTEX && shader.registerFlags & RSF_BSP )
5207+
{
5208+
// vertex colors used as lighting detected. Enable overbright and realtime lights
5209+
stage->type = stageType_t::ST_DIFFUSEMAP;
5210+
stage->forceVertexLighting = true; // use vertex lighting even if there is a lightmap
5211+
}
5212+
52055213
default:
52065214
break;
52075215
}
@@ -6453,6 +6461,7 @@ class ListShadersCmd : public Cmd::StaticCmd
64536461
shader->registerFlags & RSF_FORCE_LIGHTMAP ? 'L' : '_',
64546462
shader->registerFlags & RSF_SPRITE ? 'S' : '_',
64556463
shader->registerFlags & RSF_3D ? '3' : '_',
6464+
shader->registerFlags & RSF_BSP ? 'B' : '_',
64566465
};
64576466

64586467
if ( !shaderSortName.count( (shaderSort_t) shader->sort ) )

0 commit comments

Comments
 (0)