@@ -299,7 +299,7 @@ static void GLSL_InitGPUShadersOrError()
299299 }
300300
301301 // Fog GLSL is always loaded and built because disabling fog is cheat.
302- gl_shaderManager.LoadShader ( gl_fogGlobalShader );
302+ gl_shaderManager.LoadShader ( gl_fogShader );
303303
304304 if ( r_heatHaze->integer )
305305 {
@@ -478,7 +478,7 @@ void GLSL_ShutdownGPUShaders()
478478 gl_reflectionShaderMaterial = nullptr ;
479479 gl_skyboxShader = nullptr ;
480480 gl_skyboxShaderMaterial = nullptr ;
481- gl_fogGlobalShader = nullptr ;
481+ gl_fogShader = nullptr ;
482482 gl_heatHazeShader = nullptr ;
483483 gl_heatHazeShaderMaterial = nullptr ;
484484 gl_screenShader = nullptr ;
@@ -1580,6 +1580,69 @@ void Render_liquid( shaderStage_t *pStage )
15801580 GL_CheckErrors ();
15811581}
15821582
1583+ void Render_fog ( shaderStage_t *stage )
1584+ {
1585+ if ( backEnd.refdef .rdflags & RDF_NOWORLDMODEL )
1586+ {
1587+ return ;
1588+ }
1589+
1590+ if ( r_noFog->integer )
1591+ {
1592+ return ;
1593+ }
1594+
1595+ GLIMP_LOGCOMMENT ( " --- Render_fog ---" );
1596+
1597+ RB_PrepareForSamplingDepthMap ();
1598+
1599+ GL_Cull ( stage->shader ->cullType );
1600+
1601+ gl_fogShader->SetOutsideFog ( stage->type == stageType_t::ST_FOGMAP_OUTER );
1602+
1603+ gl_fogShader->BindProgram ();
1604+
1605+ GL_State ( stage->stateBits );
1606+
1607+ gl_fogShader->SetUniform_FogGradient (
1608+ 1 .0f / stage->shader ->fogParms .depthForOpaque , stage->shader ->fogParms .falloffExp );
1609+ gl_fogShader->SetUniform_ViewOrigin ( backEnd.viewParms .orientation .origin );
1610+ SetUniform_Color ( gl_fogShader, stage->shader ->fogParms .color );
1611+
1612+ switch ( stage->type )
1613+ {
1614+ case stageType_t::ST_FOGMAP_INNER:
1615+ {
1616+ // It's important to avoid far plane clipping
1617+ matrix_t projection, mvp;
1618+ MatrixPerspectiveProjectionFovXYInfiniteRH ( projection, tr.refdef .fov_x , tr.refdef .fov_y , 1 .0f );
1619+ MatrixMultiply ( projection, glState.modelViewMatrix [ glState.stackIndex ], mvp );
1620+ gl_fogShader->SetUniform_ModelViewProjectionMatrix ( mvp );
1621+ break ;
1622+ }
1623+ case stageType_t::ST_FOGMAP_OUTER:
1624+ {
1625+ gl_fogShader->SetUniform_ModelViewProjectionMatrix ( glState.modelViewProjectionMatrix [ glState.stackIndex ] );
1626+ break ;
1627+ }
1628+ default :
1629+ ASSERT_UNREACHABLE ();
1630+ }
1631+
1632+ gl_fogShader->SetUniform_UnprojectMatrix ( backEnd.viewParms .unprojectionMatrix );
1633+
1634+ // bind u_DepthMap
1635+ gl_fogShader->SetUniform_DepthMapBindless (
1636+ GL_BindToTMU ( 1 , tr.depthSamplerImage )
1637+ );
1638+
1639+ gl_fogShader->SetRequiredVertexPointers ();
1640+
1641+ Tess_DrawElements ();
1642+
1643+ GL_CheckErrors ();
1644+ }
1645+
15831646/*
15841647===============
15851648Tess_ComputeColor
0 commit comments