Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/engine/renderer/Material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2036,7 +2036,7 @@ void MaterialSystem::AddAutospriteSurfaces() {
for ( const drawSurf_t &drawSurf : autospriteSurfaces )
{
R_AddDrawSurf( drawSurf.surface, drawSurf.shader,
drawSurf.lightmapNum(), drawSurf.fogNum(), drawSurf.bspSurface );
drawSurf.lightmapNum(), drawSurf.fog, drawSurf.bspSurface );
}
}

Expand Down
10 changes: 0 additions & 10 deletions src/engine/renderer/ShadeCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,6 @@ template<typename Obj> static bool hasExplicitelyDisabledLightMap( Obj* obj )
return GetSurfaceShader( obj )->surfaceFlags & SURF_NOLIGHTMAP;
}

inline size_t GetFogNum( shaderCommands_t* tess )
{
return tess->fogNum;
}

inline size_t GetFogNum( drawSurf_t* drawSurf )
{
return drawSurf->fogNum();
}

inline shaderStage_t* GetSurfaceLastStage( shaderCommands_t* tess )
{
return tess->surfaceLastStage;
Expand Down
2 changes: 1 addition & 1 deletion src/engine/renderer/tr_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5446,7 +5446,7 @@ const RenderCommand *FinalisePortalCommand::ExecuteSelf( ) const
glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP );

Tess_Begin( Tess_StageIteratorColor, shader,
nullptr, false, surface->lightmapNum(), surface->fogNum(), surface->bspSurface );
nullptr, false, surface->lightmapNum(), surface->fog, surface->bspSurface );
rb_surfaceTable[Util::ordinal( *( surface->surface ) )]( surface->surface );
Tess_End();

Expand Down
9 changes: 0 additions & 9 deletions src/engine/renderer/tr_bsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2789,15 +2789,6 @@ static int LeafSurfaceCompare( const void *a, const void *b )
return 1;
}

if ( aa->fogIndex < bb->fogIndex )
{
return -1;
}
else if ( aa->fogIndex > bb->fogIndex )
{
return 1;
}

// sort by leaf
if ( aa->interactionBits < bb->interactionBits )
{
Expand Down
27 changes: 8 additions & 19 deletions src/engine/renderer/tr_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -1602,38 +1602,32 @@ enum class ssaoMode {
// 1. shaderNum
// 2. lightmapNum
// 3. entityNum
// 4. fogNum
// 5. index
// 4. index

static const uint64_t SORT_INDEX_BITS = 16;
static const uint64_t SORT_FOGNUM_BITS = 13;
static const uint64_t SORT_ENTITYNUM_BITS = 10;
static const uint64_t SORT_INDEX_BITS = 20;
static const uint64_t SORT_ENTITYNUM_BITS = 13;
static const uint64_t SORT_LIGHTMAP_BITS = 9;
static const uint64_t SORT_SHADER_BITS = 16;
static const uint64_t SORT_UNUSED_BITS = 6;

static_assert( SORT_SHADER_BITS +
SORT_LIGHTMAP_BITS +
SORT_ENTITYNUM_BITS +
SORT_FOGNUM_BITS +
SORT_INDEX_BITS == 64, "invalid number of drawSurface sort bits" );
SORT_INDEX_BITS +
SORT_UNUSED_BITS == 64, "invalid number of drawSurface sort bits" );

static const uint64_t SORT_FOGNUM_SHIFT = SORT_INDEX_BITS;
static const uint64_t SORT_ENTITYNUM_SHIFT = SORT_FOGNUM_BITS + SORT_FOGNUM_SHIFT;
static const uint64_t SORT_ENTITYNUM_SHIFT = SORT_INDEX_BITS;
static const uint64_t SORT_LIGHTMAP_SHIFT = SORT_ENTITYNUM_BITS + SORT_ENTITYNUM_SHIFT;
static const uint64_t SORT_SHADER_SHIFT = SORT_LIGHTMAP_BITS + SORT_LIGHTMAP_SHIFT;

#define MASKBITS( b ) ( 1 << (b) ) - 1
static const uint32_t SORT_INDEX_MASK = MASKBITS( SORT_INDEX_BITS );
static const uint32_t SORT_FOGNUM_MASK = MASKBITS( SORT_FOGNUM_BITS );
static const uint32_t SORT_ENTITYNUM_MASK = MASKBITS( SORT_ENTITYNUM_BITS );
static const uint32_t SORT_LIGHTMAP_MASK = MASKBITS( SORT_LIGHTMAP_BITS );
static const uint32_t SORT_SHADER_MASK = MASKBITS( SORT_SHADER_BITS );

static_assert( SORT_INDEX_MASK >= MAX_DRAWSURFS - 1, "not enough index bits" );

// need space for 0 fog (no fog), in addition to MAX_MAP_FOGS
static_assert( SORT_FOGNUM_MASK >= MAX_MAP_FOGS, "not enough fognum bits" );

// need space for tr.worldEntity, in addition to MAX_REF_ENTITIES
static_assert( SORT_ENTITYNUM_MASK >= MAX_REF_ENTITIES, "not enough entity bits" );

Expand All @@ -1652,7 +1646,6 @@ enum class ssaoMode {
int fog;
int portalNum = -1;


uint32_t materialPackIDs[MAX_SHADER_STAGES];
uint32_t materialIDs[MAX_SHADER_STAGES];

Expand All @@ -1671,21 +1664,17 @@ enum class ssaoMode {
inline int entityNum() const {
return int( ( sort >> SORT_ENTITYNUM_SHIFT ) & SORT_ENTITYNUM_MASK ) - 1;
}
inline int fogNum() const {
return int( ( sort >> SORT_FOGNUM_SHIFT ) & SORT_FOGNUM_MASK );
}
inline int lightmapNum() const {
return int( ( sort >> SORT_LIGHTMAP_SHIFT ) & SORT_LIGHTMAP_MASK ) - 1;
}
inline int shaderNum() const {
return int( sort >> SORT_SHADER_SHIFT );
}

inline void setSort( int shaderNum, int lightmapNum, int entityNum, int fogNum, int index ) {
inline void setSort( int shaderNum, int lightmapNum, int entityNum, int index ) {
entityNum = entityNum + 1; //world entity is -1
lightmapNum = lightmapNum + 1; //no lightmap is -1
sort = uint64_t( index & SORT_INDEX_MASK ) |
( uint64_t( fogNum & SORT_FOGNUM_MASK ) << SORT_FOGNUM_SHIFT ) |
( uint64_t( entityNum & SORT_ENTITYNUM_MASK ) << SORT_ENTITYNUM_SHIFT ) |
( uint64_t( lightmapNum & SORT_LIGHTMAP_MASK ) << SORT_LIGHTMAP_SHIFT ) |
( uint64_t( shaderNum & SORT_SHADER_MASK ) << SORT_SHADER_SHIFT );
Expand Down
6 changes: 4 additions & 2 deletions src/engine/renderer/tr_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1863,7 +1863,9 @@ int R_AddDrawSurf( surfaceType_t *surface, shader_t *shader, int lightmapNum, in
drawSurf->surface = surface;
drawSurf->shader = shader;
drawSurf->bspSurface = bspSurface;
drawSurf->fog = fogNum;
/* Allow the renderer backend to merge main surfaces that have fog, ignoring the fogNum,
as it only matters for the emitted fog surfaces */
drawSurf->fog = ( shader == tr.fogEqualShader || shader == tr.fogLEShader ) ? fogNum : 0;
drawSurf->portalNum = portalNum;

int entityNum;
Expand All @@ -1882,7 +1884,7 @@ int R_AddDrawSurf( surfaceType_t *surface, shader_t *shader, int lightmapNum, in
index = MAX_DRAWSURFS - index; // reverse the sorting (front:back -> back:front)
}

drawSurf->setSort( shader->sortedIndex, lightmapNum, entityNum, fogNum, index );
drawSurf->setSort( shader->sortedIndex, lightmapNum, entityNum, index );

tr.refdef.numDrawSurfs++;

Expand Down