Skip to content

Commit 7c68c06

Browse files
committed
Use new depth-based fog shaders in material system
Use the depth-based fog shaders (currently called "fogGlobal") when the material system is enabled as well. For now they are always run with the 'core' rendering loop. NUKE the fogQuake3 shader and all the code for propagating fog nums with surfaces. Fixes #1798 (marks drawn over fog with material system) by virtue of not drawing fogs with the material system. Also brings improvements described for the core renderer in previous commits: - MSAA works with fog without artifacts - Fog volumes can be open on any side
1 parent be78626 commit 7c68c06

21 files changed

+72
-753
lines changed

src.cmake

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,6 @@ set(GLSL_EMBED_LIST
131131
# Regular shaders
132132
fogGlobal_vp.glsl
133133
fogGlobal_fp.glsl
134-
fogQuake3_vp.glsl
135-
fogQuake3_fp.glsl
136134
generic_vp.glsl
137135
generic_fp.glsl
138136
heatHaze_vp.glsl

src/engine/renderer/GeometryOptimiser.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,6 @@ static int LeafSurfaceCompare( const void* a, const void* b ) {
5454
return 1;
5555
}
5656

57-
if ( aa->fogIndex < bb->fogIndex ) {
58-
return -1;
59-
} else if ( aa->fogIndex > bb->fogIndex ) {
60-
return 1;
61-
}
62-
6357
// sort by leaf
6458
if ( aa->scratch2 < bb->scratch2 ) {
6559
return -1;
@@ -168,7 +162,6 @@ void OptimiseMapGeometryCore( world_t* world, bspSurface_t** rendererSurfaces, i
168162

169163
shader_t* shader1 = surf1->shader;
170164

171-
int fogIndex1 = surf1->fogIndex;
172165
int lightMapNum1 = surf1->lightmapNum;
173166
surf1->viewCount = surf1 - world->surfaces;
174167
surf1->scratch1 = j;
@@ -187,9 +180,8 @@ void OptimiseMapGeometryCore( world_t* world, bspSurface_t** rendererSurfaces, i
187180
}
188181

189182
shader_t* shader2 = surf2->shader;
190-
int fogIndex2 = surf2->fogIndex;
191183
int lightMapNum2 = surf2->lightmapNum;
192-
if ( shader1 != shader2 || fogIndex1 != fogIndex2 || lightMapNum1 != lightMapNum2 ) {
184+
if ( shader1 != shader2 || lightMapNum1 != lightMapNum2 ) {
193185
continue;
194186
}
195187

@@ -315,7 +307,6 @@ void MergeLeafSurfacesCore( world_t* world, bspSurface_t** rendererSurfaces, int
315307
SphereFromBounds( vboSurf->bounds[0], vboSurf->bounds[1], vboSurf->origin, &vboSurf->radius );
316308

317309
mergedSurf->data = ( surfaceType_t* ) vboSurf;
318-
mergedSurf->fogIndex = surf1->fogIndex;
319310
mergedSurf->shader = surf1->shader;
320311
mergedSurf->lightmapNum = surf1->lightmapNum;
321312
mergedSurf->viewCount = -1;
@@ -557,7 +548,6 @@ std::vector<MaterialSurface> OptimiseMapGeometryMaterial( world_t* world, bspSur
557548
srf.skyBrush = surface->skyBrush;
558549

559550
srf.lightMapNum = surface->lightmapNum;
560-
srf.fog = surface->fogIndex;
561551
srf.portalNum = surface->portalNum;
562552

563553
srf.firstIndex = ( ( srfGeneric_t* ) surface->data )->firstIndex;
@@ -568,7 +558,7 @@ std::vector<MaterialSurface> OptimiseMapGeometryMaterial( world_t* world, bspSur
568558
VectorCopy( ( ( srfGeneric_t* ) surface->data )->origin, srf.origin );
569559
srf.radius = ( ( srfGeneric_t* ) surface->data )->radius;
570560

571-
materialSystem.GenerateMaterial( &srf, world->globalFog );
561+
materialSystem.GenerateMaterial( &srf );
572562

573563
static const float MAX_NORMAL_SURFACE_DISTANCE = 65536.0f * sqrtf( 2.0f );
574564
if ( VectorLength( ( ( srfGeneric_t* ) surface->data )->bounds[0] ) > MAX_NORMAL_SURFACE_DISTANCE

src/engine/renderer/Material.cpp

Lines changed: 5 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -334,14 +334,6 @@ void UpdateSurfaceDataLiquid( uint32_t* materials, shaderStage_t* pStage, bool,
334334
gl_liquidShaderMaterial->WriteUniformsToBuffer( materials, GLShader::MATERIAL );
335335
}
336336

337-
void UpdateSurfaceDataFog( uint32_t* materials, shaderStage_t* pStage, bool, bool, bool ) {
338-
// shader_t* shader = pStage->shader;
339-
340-
materials += pStage->bufferOffset;
341-
342-
gl_fogQuake3ShaderMaterial->WriteUniformsToBuffer( materials, GLShader::MATERIAL );
343-
}
344-
345337
/*
346338
* Buffer layout:
347339
* // Static surfaces data:
@@ -746,10 +738,10 @@ class ListMaterialsCmd : public Cmd::StaticCmd {
746738
shaderSortName.at( materialPack.fromSort ), shaderSortName.at( materialPack.toSort ) );
747739
for ( const Material& material : materialPack.materials ) {
748740
Print( "id: %u, sync: %5s, stateBits: %10x, GLShader: %s, GLProgramID: %u,"
749-
" deform: %i, fog: %i, drawCmdCount: %u",
741+
" deform: %i, drawCmdCount: %u",
750742
material.id, material.useSync, material.stateBits,
751743
material.shader->_name, material.program,
752-
material.deformIndex, material.fog, material.drawCommandCount );
744+
material.deformIndex, material.drawCommandCount );
753745
}
754746
}
755747
}
@@ -762,7 +754,6 @@ static std::string GetStageInfo( const shaderStage_t* pStage, const uint32_t dyn
762754
{ BindShaderGeneric3D, "genericMaterial " },
763755
{ BindShaderLightMapping, "lightMappingMaterial" },
764756
{ BindShaderHeatHaze, "heatHazeMaterial " },
765-
{ BindShaderFog, "fogQuake3Material " },
766757
{ BindShaderLiquid, "liquidMaterial " },
767758
{ BindShaderScreen, "screenMaterial " },
768759
{ BindShaderSkybox, "skyboxMaterial " },
@@ -1090,43 +1081,6 @@ void BindShaderLiquid( Material* material ) {
10901081
gl_liquidShaderMaterial->SetUniform_PortalMapBindless( GL_BindToTMU( 1, tr.portalRenderImage ) );
10911082
}
10921083

1093-
void BindShaderFog( Material* material ) {
1094-
// Bind shader program.
1095-
gl_fogQuake3ShaderMaterial->SetDeform( material->deformIndex );
1096-
gl_fogQuake3ShaderMaterial->BindProgram();
1097-
1098-
// Set shader uniforms.
1099-
const fog_t* fog = tr.world->fogs + material->fog;
1100-
1101-
// rotate the gradient vector for this orientation
1102-
float eyeT;
1103-
vec4_t fogDepthVector;
1104-
if ( fog->hasSurface ) {
1105-
VectorCopy( fog->surface, fogDepthVector );
1106-
fogDepthVector[ 3 ] = -fog->surface[ 3 ];
1107-
eyeT = DotProduct( backEnd.viewParms.orientation.origin, fogDepthVector ) + fogDepthVector[ 3 ];
1108-
} else {
1109-
Vector4Set( fogDepthVector, 0, 0, 0, 1 );
1110-
eyeT = 1; // non-surface fog always has eye inside
1111-
}
1112-
1113-
// Note: things that seemingly should be per-shader or per-surface can be set as global uniforms
1114-
// since fognum is grouped with the GL state stuff, segregating each fognum in a separate draw call.
1115-
1116-
gl_fogQuake3ShaderMaterial->SetUniform_ViewOrigin( backEnd.viewParms.orientation.origin );
1117-
gl_fogQuake3ShaderMaterial->SetUniform_FogGradient(
1118-
1.0f / fog->shader->fogParms.depthForOpaque, fog->shader->fogParms.falloffExp );
1119-
gl_fogQuake3ShaderMaterial->SetUniform_FogDepthVector( fogDepthVector );
1120-
gl_fogQuake3ShaderMaterial->SetUniform_FogEyeT( eyeT );
1121-
1122-
gl_fogQuake3ShaderMaterial->SetUniform_ColorGlobal_Uint( fog->shader->fogParms.color );
1123-
1124-
gl_fogQuake3ShaderMaterial->SetUniform_ModelMatrix( backEnd.orientation.transformMatrix );
1125-
gl_fogQuake3ShaderMaterial->SetUniform_ModelViewProjectionMatrix( glState.modelViewProjectionMatrix[glState.stackIndex] );
1126-
1127-
gl_fogQuake3ShaderMaterial->SetUniform_Time( backEnd.refdef.floatTime - backEnd.currentEntity->e.shaderTime );
1128-
}
1129-
11301084
void ProcessMaterialNONE( Material*, shaderStage_t*, MaterialSurface* ) {
11311085
ASSERT_UNREACHABLE();
11321086
}
@@ -1264,15 +1218,6 @@ void ProcessMaterialLiquid( Material* material, shaderStage_t* pStage, MaterialS
12641218
material->program = gl_liquidShaderMaterial->GetProgram( materialSystem.buildOneShader );
12651219
}
12661220

1267-
void ProcessMaterialFog( Material* material, shaderStage_t* pStage, MaterialSurface* surface ) {
1268-
material->shader = gl_fogQuake3ShaderMaterial;
1269-
material->fog = surface->fog;
1270-
1271-
gl_fogQuake3ShaderMaterial->SetDeform( pStage->deformIndex );
1272-
1273-
material->program = gl_fogQuake3ShaderMaterial->GetProgram( materialSystem.buildOneShader );
1274-
}
1275-
12761221
void MaterialSystem::AddStage( MaterialSurface* surface, shaderStage_t* pStage, uint32_t stage,
12771222
const bool mayUseVertexOverbright, const bool vertexLit, const bool fullbright ) {
12781223
const int variant = ( mayUseVertexOverbright ? ShaderStageVariant::VERTEX_OVERBRIGHT : 0 )
@@ -1496,7 +1441,7 @@ void MaterialSystem::ProcessStage( MaterialSurface* surface, shaderStage_t* pSta
14961441
/* This will only generate a material itself
14971442
A material represents a distinct global OpenGL state (e. g. blend function, depth test, depth write etc.)
14981443
Materials can have a dependency on other materials to make sure that consecutive stages are rendered in the proper order */
1499-
void MaterialSystem::GenerateMaterial( MaterialSurface* surface, int globalFog ) {
1444+
void MaterialSystem::GenerateMaterial( MaterialSurface* surface ) {
15001445
uint32_t stage = 0;
15011446
uint32_t previousMaterialID = 0;
15021447

@@ -1516,13 +1461,6 @@ void MaterialSystem::GenerateMaterial( MaterialSurface* surface, int globalFog )
15161461

15171462
surface->stages++;
15181463
}
1519-
1520-
if ( !surface->shader->noFog && surface->fog >= 1 && surface->fog != globalFog ) {
1521-
uint32_t unused;
1522-
ProcessStage( surface, surface->shader->fogShader->stages, surface->shader->fogShader, packIDs, stage, unused, true );
1523-
1524-
surface->stages++;
1525-
}
15261464
}
15271465

15281466
void MaterialSystem::SetWorldBounds( vec3_t bounds[2] ) {
@@ -1918,7 +1856,6 @@ bool MaterialSystem::AddPortalSurface( uint32_t viewID, PortalSurface* portalSur
19181856
{
19191857
drawSurf.bspSurface = portalSurfaces[portalSurface->drawSurfID].bspSurface;
19201858
drawSurf.entity = &tr.worldEntity;
1921-
drawSurf.fog = portalSurfaces[portalSurface->drawSurfID].fog;
19221859
drawSurf.portalNum = portalSurfaces[portalSurface->drawSurfID].portalNum;
19231860
drawSurf.shader = portalSurfaces[portalSurface->drawSurfID].shader;
19241861
drawSurf.surface = portalSurfaces[portalSurface->drawSurfID].surface;
@@ -1994,7 +1931,7 @@ void MaterialSystem::AddAutospriteSurfaces() {
19941931
for ( const bspSurface_t* surface : autospriteSurfaces )
19951932
{
19961933
R_AddDrawSurf( surface->data, surface->shader,
1997-
surface->lightmapNum, surface->fogIndex, true );
1934+
surface->lightmapNum, true );
19981935
}
19991936
}
20001937

@@ -2046,7 +1983,7 @@ void MaterialSystem::RenderMaterials( const shaderSort_t fromSort, const shaderS
20461983
}
20471984

20481985
tr.drawingSky = true;
2049-
Tess_Begin( Tess_StageIteratorSky, skyShader, false, -1, 0, false );
1986+
Tess_Begin( Tess_StageIteratorSky, skyShader, false, -1, false );
20501987
Tess_End();
20511988
}
20521989
}
@@ -2096,12 +2033,6 @@ void MaterialSystem::RenderMaterial( Material& material, const uint32_t viewID )
20962033
stateBits &= ~( GLS_SRCBLEND_BITS | GLS_DSTBLEND_BITS );
20972034
}
20982035

2099-
if( material.shaderBinder == BindShaderFog ) {
2100-
if ( r_noFog->integer || ( backEnd.refdef.rdflags & RDF_NOWORLDMODEL ) ) {
2101-
return;
2102-
}
2103-
}
2104-
21052036
backEnd.currentEntity = &tr.worldEntity;
21062037

21072038
GL_State( stateBits );

src/engine/renderer/Material.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ struct MaterialSurface {
8585
bool skyBrush;
8686

8787
int16_t lightMapNum;
88-
int fog;
8988
int portalNum = -1;
9089

9190
GLuint firstIndex;
@@ -148,15 +147,13 @@ struct Material {
148147

149148
bool usePolygonOffset = false;
150149

151-
int fog = 0;
152-
153150
uint32_t drawCommandCount = 0;
154151
bool texturesResident = false;
155152
std::vector<Texture*> textures;
156153

157154
bool operator==( const Material& other ) {
158155
return program == other.program && stateBits == other.stateBits
159-
&& fog == other.fog && cullType == other.cullType && usePolygonOffset == other.usePolygonOffset;
156+
&& cullType == other.cullType && usePolygonOffset == other.usePolygonOffset;
160157
}
161158

162159
void AddTexture( Texture* texture ) {
@@ -381,7 +378,7 @@ class MaterialSystem {
381378
const bool mayUseVertexOverbright, const bool vertexLit, const bool fullbright );
382379
void ProcessStage( MaterialSurface* surface, shaderStage_t* pStage, shader_t* shader, uint32_t* packIDs, uint32_t& stage,
383380
uint32_t& previousMaterialID, bool skipStageSync = false );
384-
void GenerateMaterial( MaterialSurface* surface, int globalFog );
381+
void GenerateMaterial( MaterialSurface* surface );
385382
void GenerateWorldMaterialsBuffer();
386383
void GenerateWorldCommandBuffer( std::vector<MaterialSurface>& surfaces );
387384
void GeneratePortalBoundingSpheres();
@@ -462,7 +459,6 @@ void UpdateSurfaceDataSkybox( uint32_t* materials, shaderStage_t* pStage, bool,
462459
void UpdateSurfaceDataScreen( uint32_t* materials, shaderStage_t* pStage, bool, bool, bool );
463460
void UpdateSurfaceDataHeatHaze( uint32_t* materials, shaderStage_t* pStage, bool, bool, bool );
464461
void UpdateSurfaceDataLiquid( uint32_t* materials, shaderStage_t* pStage, bool, bool, bool );
465-
void UpdateSurfaceDataFog( uint32_t* materials, shaderStage_t* pStage, bool, bool, bool );
466462

467463
void BindShaderNONE( Material* );
468464
void BindShaderNOP( Material* );
@@ -473,7 +469,6 @@ void BindShaderSkybox( Material* material );
473469
void BindShaderScreen( Material* material );
474470
void BindShaderHeatHaze( Material* material );
475471
void BindShaderLiquid( Material* material );
476-
void BindShaderFog( Material* material );
477472

478473
void ProcessMaterialNONE( Material*, shaderStage_t*, MaterialSurface* );
479474
void ProcessMaterialNOP( Material*, shaderStage_t*, MaterialSurface* );
@@ -484,6 +479,5 @@ void ProcessMaterialSkybox( Material* material, shaderStage_t* pStage, MaterialS
484479
void ProcessMaterialScreen( Material* material, shaderStage_t* pStage, MaterialSurface* /* surface */ );
485480
void ProcessMaterialHeatHaze( Material* material, shaderStage_t* pStage, MaterialSurface* surface );
486481
void ProcessMaterialLiquid( Material* material, shaderStage_t* pStage, MaterialSurface* /* surface */ );
487-
void ProcessMaterialFog( Material* material, shaderStage_t* pStage, MaterialSurface* surface );
488482

489483
#endif // MATERIAL_H

src/engine/renderer/gl_shader.cpp

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ GLShader_generic *gl_genericShader = nullptr;
6868
GLShader_genericMaterial *gl_genericShaderMaterial = nullptr;
6969
GLShader_lightMapping *gl_lightMappingShader = nullptr;
7070
GLShader_lightMappingMaterial *gl_lightMappingShaderMaterial = nullptr;
71-
GLShader_fogQuake3 *gl_fogQuake3Shader = nullptr;
72-
GLShader_fogQuake3Material *gl_fogQuake3ShaderMaterial = nullptr;
7371
GLShader_heatHaze *gl_heatHazeShader = nullptr;
7472
GLShader_heatHazeMaterial *gl_heatHazeShaderMaterial = nullptr;
7573
GLShader_liquid *gl_liquidShader = nullptr;
@@ -2690,38 +2688,6 @@ GLShader_skyboxMaterial::GLShader_skyboxMaterial() :
26902688
u_ModelViewProjectionMatrix( this )
26912689
{}
26922690

2693-
GLShader_fogQuake3::GLShader_fogQuake3() :
2694-
GLShader( "fogQuake3", ATTR_POSITION | ATTR_QTANGENT,
2695-
false, "fogQuake3", "fogQuake3" ),
2696-
u_ModelMatrix( this ),
2697-
u_ModelViewProjectionMatrix( this ),
2698-
u_ColorGlobal_Float( this ),
2699-
u_ColorGlobal_Uint( this ),
2700-
u_Bones( this ),
2701-
u_VertexInterpolation( this ),
2702-
u_ViewOrigin( this ),
2703-
u_FogGradient( this ),
2704-
u_FogDepthVector( this ),
2705-
u_FogEyeT( this ),
2706-
GLDeformStage( this ),
2707-
GLCompileMacro_USE_VERTEX_SKINNING( this ),
2708-
GLCompileMacro_USE_VERTEX_ANIMATION( this )
2709-
{
2710-
}
2711-
2712-
GLShader_fogQuake3Material::GLShader_fogQuake3Material() :
2713-
GLShader( "fogQuake3Material", ATTR_POSITION | ATTR_QTANGENT,
2714-
true, "fogQuake3", "fogQuake3" ),
2715-
u_ModelMatrix( this ),
2716-
u_ModelViewProjectionMatrix( this ),
2717-
u_ColorGlobal_Uint( this ),
2718-
u_ViewOrigin( this ),
2719-
u_FogGradient( this ),
2720-
u_FogDepthVector( this ),
2721-
u_FogEyeT( this ),
2722-
GLDeformStage( this ) {
2723-
}
2724-
27252691
// TODO: rename
27262692
GLShader_fogGlobal::GLShader_fogGlobal() :
27272693
GLShader( "fogGlobal", ATTR_POSITION | ATTR_FOG_SURFACE,

0 commit comments

Comments
 (0)