Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/engine/renderer/GeometryOptimiser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -645,12 +645,12 @@ std::vector<MaterialSurface> OptimiseMapGeometryMaterial( world_t* world, bspSur
uint32_t texData = lhs.texDataDynamic[stage]
? ( lhs.texDataIDs[stage] + materialSystem.GetTexDataSize() ) << TEX_BUNDLE_BITS
: lhs.texDataIDs[stage] << TEX_BUNDLE_BITS;
texData |= ( HasLightMap( &lhs ) ? GetLightMapNum( &lhs ) : 255 ) << LIGHTMAP_BITS;
texData |= MaterialSystem::GetLightMapIdx( lhs, tr.worldLight ) << LIGHTMAP_BITS;

uint32_t texData2 = rhs.texDataDynamic[stage]
? ( rhs.texDataIDs[stage] + materialSystem.GetTexDataSize() ) << TEX_BUNDLE_BITS
: rhs.texDataIDs[stage] << TEX_BUNDLE_BITS;
texData2 |= ( HasLightMap( &rhs ) ? GetLightMapNum( &rhs ) : 255 ) << LIGHTMAP_BITS;
texData2 |= MaterialSystem::GetLightMapIdx( rhs, tr.worldLight ) << LIGHTMAP_BITS;

if ( texData < texData2 ) {
return true;
Expand Down
14 changes: 13 additions & 1 deletion src/engine/renderer/Material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,18 @@ void MaterialSystem::GenerateTexturesBuffer( std::vector<TextureData>& textures,
}
}

int MaterialSystem::GetLightMapIdx( const MaterialSurface &surface, lightMode_t mode )
{
if ( mode == lightMode_t::MAP )
{
return GetLightMapNum( &surface ) & 255;
Copy link
Contributor

@VReaperV VReaperV Sep 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not having HasLightMap() can cause a crash on some maps IIRC.

}
else
{
return 255;
}
}

// This generates the buffers with indirect rendering commands etc.
void MaterialSystem::GenerateWorldCommandBuffer( std::vector<MaterialSurface>& surfaces ) {
Log::Debug( "Generating world command buffer" );
Expand Down Expand Up @@ -680,7 +692,7 @@ void MaterialSystem::GenerateWorldCommandBuffer( std::vector<MaterialSurface>& s
surfaceCommand.drawCommand.baseInstance |= surface.texDataDynamic[stage]
? ( surface.texDataIDs[stage] + texData.size() ) << TEX_BUNDLE_BITS
: surface.texDataIDs[stage] << TEX_BUNDLE_BITS;
surfaceCommand.drawCommand.baseInstance |= ( HasLightMap( &surface ) ? GetLightMapNum( &surface ) : 255 ) << LIGHTMAP_BITS;
surfaceCommand.drawCommand.baseInstance |= GetLightMapIdx( surface, tr.worldLight ) << LIGHTMAP_BITS;
surfaceCommands[cmdID] = surfaceCommand;

material->drawCommandCount++;
Expand Down
2 changes: 2 additions & 0 deletions src/engine/renderer/Material.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,8 @@ class MaterialSystem {

bool frameStart = false;

static int GetLightMapIdx( const MaterialSurface &surface, lightMode_t mode );

void AddPortalSurfaces();
void AddAutospriteSurfaces();
void RenderMaterials( const shaderSort_t fromSort, const shaderSort_t toSort, const uint32_t viewID );
Expand Down