Skip to content
Draft
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
3 changes: 2 additions & 1 deletion src.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ set(GLSL_EMBED_LIST
blur_fp.glsl
cameraEffects_fp.glsl
contrast_fp.glsl
fogGlobal_fp.glsl
fxaa_fp.glsl
fxaa3_11_fp.glsl
motionblur_fp.glsl
Expand All @@ -130,6 +129,8 @@ set(GLSL_EMBED_LIST
vertexSkinning_vp.glsl

# Regular shaders
fogGlobal_vp.glsl
fogGlobal_fp.glsl
fogQuake3_vp.glsl
fogQuake3_fp.glsl
generic_vp.glsl
Expand Down
1 change: 0 additions & 1 deletion src/engine/renderer/GeometryOptimiser.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ void MarkShaderBuildScreen( const shaderStage_t* pStage );
void MarkShaderBuildPortal( const shaderStage_t* pStage );
void MarkShaderBuildHeatHaze( const shaderStage_t* pStage );
void MarkShaderBuildLiquid( const shaderStage_t* pStage );
void MarkShaderBuildFog( const shaderStage_t* pStage );

void MarkShaderBuildIQM( const IQModel_t* model );
void MarkShaderBuildMDV( const mdvModel_t* model );
Expand Down
6 changes: 3 additions & 3 deletions src/engine/renderer/Material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1114,11 +1114,11 @@ void BindShaderFog( Material* material ) {
// since fognum is grouped with the GL state stuff, segregating each fognum in a separate draw call.

gl_fogQuake3ShaderMaterial->SetUniform_ViewOrigin( backEnd.viewParms.orientation.origin );
gl_fogQuake3ShaderMaterial->SetUniform_FogDensity( fog->tcScale );
gl_fogQuake3ShaderMaterial->SetUniform_FogDensity( 1.0f / fog->shader->fogParms.depthForOpaque );
gl_fogQuake3ShaderMaterial->SetUniform_FogDepthVector( fogDepthVector );
gl_fogQuake3ShaderMaterial->SetUniform_FogEyeT( eyeT );

gl_fogQuake3ShaderMaterial->SetUniform_ColorGlobal_Uint( fog->color );
gl_fogQuake3ShaderMaterial->SetUniform_ColorGlobal_Uint( fog->shader->fogParms.color );

gl_fogQuake3ShaderMaterial->SetUniform_ModelMatrix( backEnd.orientation.transformMatrix );
gl_fogQuake3ShaderMaterial->SetUniform_ModelViewProjectionMatrix( glState.modelViewProjectionMatrix[glState.stackIndex] );
Expand Down Expand Up @@ -2096,7 +2096,7 @@ void MaterialSystem::RenderMaterial( Material& material, const uint32_t viewID )
}

if( material.shaderBinder == BindShaderFog ) {
if ( r_noFog->integer || !r_wolfFog->integer || ( backEnd.refdef.rdflags & RDF_NOWORLDMODEL ) ) {
if ( r_noFog->integer || ( backEnd.refdef.rdflags & RDF_NOWORLDMODEL ) ) {
return;
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/engine/renderer/gl_shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2719,10 +2719,12 @@ GLShader_fogQuake3Material::GLShader_fogQuake3Material() :
GLDeformStage( this ) {
}

// TODO: rename
GLShader_fogGlobal::GLShader_fogGlobal() :
GLShader( "fogGlobal", ATTR_POSITION,
false, "screenSpace", "fogGlobal" ),
false, "fogGlobal", "fogGlobal" ),
u_DepthMap( this ),
u_ModelViewProjectionMatrix( this ),
u_UnprojectMatrix( this ),
u_Color_Float( this ),
u_Color_Uint( this ),
Expand Down
1 change: 1 addition & 0 deletions src/engine/renderer/gl_shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -3194,6 +3194,7 @@ class GLShader_fogQuake3Material :
class GLShader_fogGlobal :
public GLShader,
public u_DepthMap,
public u_ModelViewProjectionMatrix,
public u_UnprojectMatrix,
public u_Color_Float,
public u_Color_Uint,
Expand Down
7 changes: 6 additions & 1 deletion src/engine/renderer/glsl_source/fogGlobal_fp.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

#define DEPTHMAP_GLSL

IN(smooth) vec3 var_Position;

uniform sampler2D u_DepthMap;

uniform colorPack u_Color;
Expand All @@ -37,6 +39,7 @@ uniform mat4 u_UnprojectMatrix;

DECLARE_OUTPUT(vec4)

// This shader can be used to draw a fog volume the viewer is inside of.
void main()
{
#insert material_fp
Expand All @@ -50,7 +53,9 @@ void main()
P.xyz /= P.w;

// calculate the length in fog (t is always 1 if eye is in fog)
float s = distance(u_ViewOrigin, P.xyz) * u_FogDensity;
float depthDist = distance(u_ViewOrigin, P.xyz);
float fogBoundaryDist = distance(u_ViewOrigin, var_Position);
float s = min(depthDist, fogBoundaryDist) * u_FogDensity;

vec4 color = vec4(1, 1, 1, GetFogAlpha(s, 1.0));

Expand Down
46 changes: 46 additions & 0 deletions src/engine/renderer/glsl_source/fogGlobal_vp.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
===========================================================================

Daemon BSD Source Code
Copyright (c) 2026 Daemon Developers
All rights reserved.

This file is part of the Daemon BSD Source Code (Daemon Source Code).

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Daemon developers nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

===========================================================================
*/

uniform mat4 u_ModelViewProjectionMatrix;

IN vec3 attr_Position;

OUT(smooth) vec3 var_Position;

void main()
{
vec4 position = vec4(attr_Position, 1.0);
gl_Position = u_ModelViewProjectionMatrix * position;
var_Position = attr_Position;
}
39 changes: 14 additions & 25 deletions src/engine/renderer/tr_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1423,54 +1423,46 @@ void RB_RenderPostDepthLightTile()
GL_CheckErrors();
}

void RB_RenderGlobalFog()
// TODO: move with other Render_ functions
void Render_fogGlobal( shaderStage_t *stage )
{
if ( backEnd.refdef.rdflags & RDF_NOWORLDMODEL )
{
return;
}

if ( r_noFog->integer )
{
return;
}

if ( !tr.world || tr.world->globalFog < 0 )
{
return;
}

GLIMP_LOGCOMMENT( "--- RB_RenderGlobalFog ---" );

RB_PrepareForSamplingDepthMap();

GL_Cull( cullType_t::CT_TWO_SIDED );
GL_Cull( cullType_t::CT_FRONT_SIDED );

gl_fogGlobalShader->BindProgram();

// go back to the world modelview matrix
backEnd.orientation = backEnd.viewParms.world;

{
fog_t* fog = &tr.world->fogs[ tr.world->globalFog ];

GLIMP_LOGCOMMENT( "--- RB_RenderGlobalFog( fogNum = %i ) ---", tr.world->globalFog );

GL_State( GLS_DEPTHTEST_DISABLE | GLS_SRCBLEND_SRC_ALPHA | GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA );

gl_fogGlobalShader->SetUniform_FogDensity( fog->tcScale );
gl_fogGlobalShader->SetUniform_FogDensity( 1.0f / stage->shader->fogParms.depthForOpaque );
gl_fogGlobalShader->SetUniform_ViewOrigin( backEnd.viewParms.orientation.origin );
SetUniform_Color( gl_fogGlobalShader, fog->color );
SetUniform_Color( gl_fogGlobalShader, stage->shader->fogParms.color );
}

// It's important to avoid far plane clipping
matrix_t projection, mvp;
MatrixPerspectiveProjectionFovXYInfiniteRH( projection, tr.refdef.fov_x, tr.refdef.fov_y, 1.0f );
MatrixMultiply( projection, glState.modelViewMatrix[ glState.stackIndex ], mvp );

gl_fogGlobalShader->SetUniform_ModelViewProjectionMatrix( mvp );
gl_fogGlobalShader->SetUniform_UnprojectMatrix( backEnd.viewParms.unprojectionMatrix );

// bind u_DepthMap
gl_fogGlobalShader->SetUniform_DepthMapBindless(
GL_BindToTMU( 1, tr.depthSamplerImage )
);

Tess_InstantScreenSpaceQuad();
gl_fogGlobalShader->SetRequiredVertexPointers();

Tess_DrawElements();

GL_CheckErrors();
}
Expand Down Expand Up @@ -2801,9 +2793,6 @@ static void RB_RenderView( bool depthPass )

RB_RenderSSAO();

// render global fog post process effect
RB_RenderGlobalFog();

TransitionMainToMSAA( GL_COLOR_BUFFER_BIT );

// draw everything that is translucent
Expand Down
53 changes: 35 additions & 18 deletions src/engine/renderer/tr_bsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3217,8 +3217,6 @@ static void R_LoadFogs( lump_t *l, lump_t *brushesLump, lump_t *sidesLump )
int count, brushesCount, sidesCount;
int sideNum;
int planeNum;
shader_t *shader;
float d;
int firstSide = 0;

Log::Debug("...loading fogs" );
Expand Down Expand Up @@ -3264,6 +3262,9 @@ static void R_LoadFogs( lump_t *l, lump_t *brushesLump, lump_t *sidesLump )

sidesCount = sidesLump->filelen / sizeof( *sides );

std::vector<std::array<float, 3>> fogVerts(8 * count);
std::vector<glIndex_t> fogIndexes(6 * 6 * count);

for ( i = 0; i < count; i++, fogs++ )
{
out->originalBrushNumber = LittleLong( fogs->brushNum );
Expand Down Expand Up @@ -3316,26 +3317,28 @@ static void R_LoadFogs( lump_t *l, lump_t *brushesLump, lump_t *sidesLump )
out->bounds[ 1 ][ 2 ] = s_worldData.planes[ planeNum ].dist;
}

// get information from the shader for fog parameters
// it says RSF_3D but if there is no shader text found it should probably just error instead
// of trying to create an implicit shader from an image...
shader = R_FindShader( fogs->shader, RSF_3D );

out->fogParms = shader->fogParms;

out->color = Color::Adapt( shader->fogParms.color );

if ( tr.worldLinearizeTexture )
// add faces of fog brush for drawing fog from inside
for ( int p = 0; p < 8; p++ )
{
out->color = out->color.ConvertFromSRGB();
fogVerts[ i * 8 + p ][ 0 ] = out->bounds[ p & 1 ][ 0 ];
fogVerts[ i * 8 + p ][ 1 ] = out->bounds[ ( p >> 1 ) & 1 ][ 1 ];
fogVerts[ i * 8 + p ][ 2 ] = out->bounds[ p >> 2 ][ 2 ];
}
constexpr int box[ 36 ] = { 2, 3, 0, 0, 3, 1, 0, 1, 4, 4, 1, 5, 2, 0, 6, 6, 0, 4,
1, 3, 5, 5, 3, 7, 3, 2, 7, 7, 2, 6, 7, 6, 5, 5, 6, 4 };
for ( int p = 0; p < 36; p++ )
{
fogIndexes[ 36 * i + p ] = 8 * i + box[ p ];
}

out->color *= tr.identityLight;

out->color.SetAlpha( 1 );
// add draw surf for fog brush faces
out->surf.firstIndex = 36 * i;
out->surf.numTriangles = 12;
out->surf.surfaceType = surfaceType_t::SF_TRIANGLES;

d = shader->fogParms.depthForOpaque < 1 ? 1 : shader->fogParms.depthForOpaque;
out->tcScale = 1.0f / d;
// it says RSF_3D but if there is no shader text found it should probably just error instead
// of trying to create an implicit shader from an image...
out->shader = R_FindShader( fogs->shader, RSF_3D );

// ydnar: global fog sets clearcolor/zfar
if ( out->originalBrushNumber == -1 )
Expand All @@ -3362,6 +3365,20 @@ static void R_LoadFogs( lump_t *l, lump_t *brushesLump, lump_t *sidesLump )
out++;
}

vertexAttributeSpec_t attributes[] {
{ ATTR_INDEX_POSITION, GL_FLOAT, GL_FLOAT, &fogVerts[ 0 ], 3, sizeof( fogVerts[ 0 ] ), 0 },
};
VBO_t *fogVBO = R_CreateStaticVBO(
"fogs VBO", std::begin( attributes ), std::end( attributes ), fogVerts.size() );
IBO_t *fogIBO = R_CreateStaticIBO( "fogs IBO", &fogIndexes[ 0 ], fogIndexes.size() );
SetupVAOBuffers( fogVBO, fogIBO, ATTR_POSITION, &fogVBO->VAO );

for ( int j = 1; j < s_worldData.numFogs; j++ )
{
s_worldData.fogs[ j ].surf.vbo = fogVBO;
s_worldData.fogs[ j ].surf.ibo = fogIBO;
}

Log::Debug("%i fog volumes loaded", s_worldData.numFogs );
}

Expand Down
4 changes: 2 additions & 2 deletions src/engine/renderer/tr_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ Cvar::Cvar<int> r_rendererAPI( "r_rendererAPI", "Renderer API: 0: OpenGL, 1: Vul

cvar_t *r_showImages;

cvar_t *r_wolfFog;
cvar_t *r_noFog;

Cvar::Range<Cvar::Cvar<float>> r_forceAmbient( "r_forceAmbient", "Minimal light amount in lightGrid; -1 to use map value",
Expand Down Expand Up @@ -1157,7 +1156,6 @@ ScreenshotCmd screenshotPNGRegistration("screenshotPNG", ssFormat_t::SSF_PNG, "p
r_heatHaze = Cvar_Get( "r_heatHaze", "1", CVAR_LATCH | CVAR_ARCHIVE );
r_noMarksOnTrisurfs = Cvar_Get( "r_noMarksOnTrisurfs", "1", CVAR_CHEAT );

r_wolfFog = Cvar_Get( "r_wolfFog", "1", CVAR_CHEAT );
r_noFog = Cvar_Get( "r_noFog", "0", CVAR_CHEAT );

Cvar::Latch( r_forceAmbient );
Expand Down Expand Up @@ -1543,6 +1541,8 @@ ScreenshotCmd screenshotPNGRegistration("screenshotPNG", ssFormat_t::SSF_PNG, "p
gl_fogQuake3Shader->SetDeform( 0 );
gl_fogQuake3Shader->MarkProgramForBuilding();
}

gl_fogGlobalShader->MarkProgramForBuilding();
}

for ( int i = 0; i < tr.numModels; i++ ) {
Expand Down
Loading
Loading