@@ -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 ;
@@ -1590,6 +1590,69 @@ void Render_liquid( shaderStage_t *pStage )
15901590 GL_CheckErrors ();
15911591}
15921592
1593+ void Render_fog ( shaderStage_t *stage )
1594+ {
1595+ if ( backEnd.refdef .rdflags & RDF_NOWORLDMODEL )
1596+ {
1597+ return ;
1598+ }
1599+
1600+ if ( r_noFog->integer )
1601+ {
1602+ return ;
1603+ }
1604+
1605+ GLIMP_LOGCOMMENT ( " --- Render_fog ---" );
1606+
1607+ RB_PrepareForSamplingDepthMap ();
1608+
1609+ GL_Cull ( stage->shader ->cullType );
1610+
1611+ gl_fogShader->SetOutsideFog ( stage->type == stageType_t::ST_FOGMAP_OUTER );
1612+
1613+ gl_fogShader->BindProgram ();
1614+
1615+ GL_State ( stage->stateBits );
1616+
1617+ gl_fogShader->SetUniform_FogGradient (
1618+ 1 .0f / stage->shader ->fogParms .depthForOpaque , stage->shader ->fogParms .falloffExp );
1619+ gl_fogShader->SetUniform_ViewOrigin ( backEnd.viewParms .orientation .origin );
1620+ SetUniform_Color ( gl_fogShader, stage->shader ->fogParms .color );
1621+
1622+ switch ( stage->type )
1623+ {
1624+ case stageType_t::ST_FOGMAP_INNER:
1625+ {
1626+ // It's important to avoid far plane clipping
1627+ matrix_t projection, mvp;
1628+ MatrixPerspectiveProjectionFovXYInfiniteRH ( projection, tr.refdef .fov_x , tr.refdef .fov_y , 1 .0f );
1629+ MatrixMultiply ( projection, glState.modelViewMatrix [ glState.stackIndex ], mvp );
1630+ gl_fogShader->SetUniform_ModelViewProjectionMatrix ( mvp );
1631+ break ;
1632+ }
1633+ case stageType_t::ST_FOGMAP_OUTER:
1634+ {
1635+ gl_fogShader->SetUniform_ModelViewProjectionMatrix ( glState.modelViewProjectionMatrix [ glState.stackIndex ] );
1636+ break ;
1637+ }
1638+ default :
1639+ ASSERT_UNREACHABLE ();
1640+ }
1641+
1642+ gl_fogShader->SetUniform_UnprojectMatrix ( backEnd.viewParms .unprojectionMatrix );
1643+
1644+ // bind u_DepthMap
1645+ gl_fogShader->SetUniform_DepthMapBindless (
1646+ GL_BindToTMU ( 1 , tr.depthSamplerImage )
1647+ );
1648+
1649+ gl_fogShader->SetRequiredVertexPointers ();
1650+
1651+ Tess_DrawElements ();
1652+
1653+ GL_CheckErrors ();
1654+ }
1655+
15931656/*
15941657===============
15951658Tess_ComputeColor
0 commit comments