Skip to content

Commit 80ccdaf

Browse files
committed
client: render: enabled updating fog parameters at every render pass, not only at frame start
1 parent 4d2423b commit 80ccdaf

File tree

4 files changed

+54
-42
lines changed

4 files changed

+54
-42
lines changed

client/render/gl_backend.cpp

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ GNU General Public License for more details.
3737
#include "screenfade.h"
3838
#include "shake.h"
3939

40-
#define SKY_FOG_DENSITY_FACTOR 0.00005f // experimentally determined value (chislo s potolka)
41-
#define WATER_FOG_DENSITY_FACTOR 0.000025f
42-
4340
/*
4441
==============
4542
R_Speeds_Printf
@@ -375,42 +372,7 @@ bool GL_BackendStartFrame( ref_viewpass_t *rvp, RefParams params )
375372
else tr.waterentity = NULL;
376373

377374
R_GrassSetupFrame();
378-
379-
// check for fog
380-
if( tr.waterentity )
381-
{
382-
entity_state_t *state = &tr.waterentity->curstate;
383-
384-
if( state->rendercolor.r || state->rendercolor.g || state->rendercolor.b )
385-
{
386-
// enable global exponential color fog
387-
tr.fogColor[0] = (state->rendercolor.r) / 255.0f;
388-
tr.fogColor[1] = (state->rendercolor.g) / 255.0f;
389-
tr.fogColor[2] = (state->rendercolor.b) / 255.0f;
390-
tr.fogDensity = state->renderamt * WATER_FOG_DENSITY_FACTOR;
391-
tr.fogEnabled = true;
392-
}
393-
}
394-
else if( tr.movevars->fog_settings != 0 )
395-
{
396-
// enable global exponential color fog
397-
// apply gamma-correction because user sets color in sRGB space
398-
tr.fogColor[0] = pow((tr.movevars->fog_settings & 0xFF000000 >> 24) / 255.0f, 1.f / 2.2f);
399-
tr.fogColor[1] = pow((tr.movevars->fog_settings & 0xFF0000 >> 16) / 255.0f, 1.f / 2.2f);
400-
tr.fogColor[2] = pow((tr.movevars->fog_settings & 0xFF00 >> 8) / 255.0f, 1.f / 2.2f);
401-
402-
const float skyScaleMultiplier = FBitSet(RI->params, RP_SKYPORTALVIEW) ? tr.sky_camera->curstate.scale : 1.0f;
403-
tr.fogDensity = (tr.movevars->fog_settings & 0xFF) * SKY_FOG_DENSITY_FACTOR * skyScaleMultiplier;
404-
tr.fogEnabled = true;
405-
}
406-
else
407-
{
408-
tr.fogColor[0] = 0.0f;
409-
tr.fogColor[1] = 0.0f;
410-
tr.fogColor[2] = 0.0f;
411-
tr.fogDensity = 0.0f;
412-
tr.fogEnabled = false;
413-
}
375+
// R_UpdateFogParameters();
414376

415377
// apply the underwater warp
416378
if( tr.waterlevel >= 3 )

client/render/gl_local.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,7 @@ terrain_t *R_FindTerrain( const char *texname );
880880
void R_InitShadowTextures( void );
881881
void R_FreeLandscapes( void );
882882
byte R_LightToTexGamma( byte input );
883+
void R_UpdateFogParameters();
883884

884885
//
885886
// gl_rsurf.cpp

client/render/gl_rmain.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,7 @@ void R_RenderScene( const ref_viewpass_t *rvp, RefParams params )
957957
R_SetupGLstate();
958958
R_Clear(~0, tr.ignore_2d_skybox);
959959

960+
R_UpdateFogParameters();
960961
R_DrawSkyBox();
961962
R_RenderSolidBrushList();
962963
R_RenderSolidStudioList();

client/render/gl_rmisc.cpp

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ GNU General Public License for more details.
2929
#include "gl_unit_cube.h"
3030
#include "r_weather.h"
3131

32-
#define DEFAULT_SMOOTHNESS 0.0f
33-
#define FILTER_SIZE 2
32+
#define DEFAULT_SMOOTHNESS 0.0f
33+
#define FILTER_SIZE 2
34+
#define SKY_FOG_DENSITY_FACTOR 0.00005f // experimentally determined value (chislo s potolka)
35+
#define WATER_FOG_DENSITY_FACTOR 0.000025f
3436

3537
// defined in cdll_int.cpp
3638
extern void CL_NewMap();
@@ -967,4 +969,50 @@ void GL_MapChanged( void )
967969
g_StudioRenderer.VidInit();
968970

969971
GL_InitModelLightCache();
970-
}
972+
}
973+
974+
void R_UpdateFogParameters()
975+
{
976+
cl_entity_t *waterEntity = nullptr;
977+
if (tr.waterlevel >= 3)
978+
{
979+
// FIXME: how to allow fog on a world water?
980+
int waterent = WATER_ENTITY(RI->view.origin);
981+
if (waterent > 0 && waterent < tr.viewparams.max_entities)
982+
waterEntity = GET_ENTITY(waterent);
983+
}
984+
985+
if (waterEntity)
986+
{
987+
const entity_state_t *state = &waterEntity->curstate;
988+
if( state->rendercolor.r || state->rendercolor.g || state->rendercolor.b )
989+
{
990+
// enable global exponential color fog
991+
tr.fogColor[0] = state->rendercolor.r / 255.0f;
992+
tr.fogColor[1] = state->rendercolor.g / 255.0f;
993+
tr.fogColor[2] = state->rendercolor.b / 255.0f;
994+
tr.fogDensity = state->renderamt * WATER_FOG_DENSITY_FACTOR;
995+
tr.fogEnabled = true;
996+
}
997+
}
998+
else if (tr.movevars->fog_settings != 0)
999+
{
1000+
// enable global exponential color fog
1001+
// apply gamma-correction because user sets color in sRGB space
1002+
tr.fogColor[0] = pow((tr.movevars->fog_settings & 0xFF000000 >> 24) / 255.0f, 1.f / 2.2f);
1003+
tr.fogColor[1] = pow((tr.movevars->fog_settings & 0xFF0000 >> 16) / 255.0f, 1.f / 2.2f);
1004+
tr.fogColor[2] = pow((tr.movevars->fog_settings & 0xFF00 >> 8) / 255.0f, 1.f / 2.2f);
1005+
1006+
const float skyScaleMultiplier = FBitSet(RI->params, RP_SKYPORTALVIEW) ? tr.sky_camera->curstate.scale : 1.0f;
1007+
tr.fogDensity = (tr.movevars->fog_settings & 0xFF) * SKY_FOG_DENSITY_FACTOR * skyScaleMultiplier;
1008+
tr.fogEnabled = true;
1009+
}
1010+
else
1011+
{
1012+
tr.fogColor[0] = 0.0f;
1013+
tr.fogColor[1] = 0.0f;
1014+
tr.fogColor[2] = 0.0f;
1015+
tr.fogDensity = 0.0f;
1016+
tr.fogEnabled = false;
1017+
}
1018+
}

0 commit comments

Comments
 (0)