Skip to content

Commit

Permalink
Tint psprites with fog color; other fog-related tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
dashodanger committed Aug 21, 2023
1 parent 04df80e commit e455259
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 20 deletions.
2 changes: 1 addition & 1 deletion source_files/edge/m_option.cc
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ static menuinfo_t gameplay_optmenu =
static optmenuitem_t perfoptions[] =
{
{OPT_Boolean, "Draw Distance Culling", YesNo, 2,
&r_culling.d, M_UpdateCVARFromInt, "Sector Fog will be disabled when this is On", &r_culling},
&r_culling.d, M_UpdateCVARFromInt, "Sector/Level Fog will be disabled when this is On", &r_culling},
{OPT_FracSlider, "Maximum Draw Distance", NULL, 0,
&r_culldist.f, M_UpdateCVARFromFloat, "Only effective when Draw Distance Culling is On", &r_culldist, 200.0f, 1000.0f, 8000.0f, "%g Units"},
{OPT_Switch, "Outdoor Culling Fog Color", "Match Sky/White/Grey/Black", 4,
Expand Down
5 changes: 4 additions & 1 deletion source_files/edge/r_render.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1535,7 +1535,10 @@ static void ComputeWallTiles(seg_t *seg, drawfloor_t *dfloor, int sidenum, float
}
}

if (!sd->middle.image)
if (sd->middle.fogwall && r_culling.d)
sd->middle.image = nullptr; // Don't delete image in case culling is toggled again

if (!sd->middle.image && !r_culling.d)
{
if (sec_fc == RGB_NO_VALUE && other_fc != RGB_NO_VALUE)
{
Expand Down
38 changes: 30 additions & 8 deletions source_files/edge/r_things.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include "image_data.h"
#include "image_funcs.h"
#include "math_color.h"
#include "str_util.h"

#include "dm_data.h"
Expand Down Expand Up @@ -368,8 +369,7 @@ static void RGL_DrawPSprite(pspdef_t * psp, int which,
local_gl_vert_t * glvert = RGL_BeginUnit(GL_POLYGON, 4,
is_additive ? ENV_SKIP_RGB : GL_MODULATE, tex_id,
is_fuzzy ? GL_MODULATE : ENV_NONE, fuzz_tex,
pass, blending, pass > 0 ? RGB_NO_VALUE: fc_to_use,
fd_to_use);
pass, blending);

for (int v_idx=0; v_idx < 4; v_idx++)
{
Expand All @@ -391,19 +391,41 @@ static void RGL_DrawPSprite(pspdef_t * psp, int which,
}
else if (! is_additive)
{
dest->rgba[0] = data.col[v_idx].mod_R / 255.0;
dest->rgba[1] = data.col[v_idx].mod_G / 255.0;
dest->rgba[2] = data.col[v_idx].mod_B / 255.0;
if (fc_to_use != RGB_NO_VALUE)
{
epi::color_c mixme(data.col[v_idx].mod_R, data.col[v_idx].mod_G, data.col[v_idx].mod_B);
mixme = mixme.Mix(epi::color_c(fc_to_use), I_ROUND(255.0f * (fd_to_use * 100)));
dest->rgba[0] = mixme.r / 255.0;
dest->rgba[1] = mixme.g / 255.0;
dest->rgba[2] = mixme.b / 255.0;
}
else
{
dest->rgba[0] = data.col[v_idx].mod_R / 255.0;
dest->rgba[1] = data.col[v_idx].mod_G / 255.0;
dest->rgba[2] = data.col[v_idx].mod_B / 255.0;
}

data.col[v_idx].mod_R -= 256;
data.col[v_idx].mod_G -= 256;
data.col[v_idx].mod_B -= 256;
}
else
{
dest->rgba[0] = data.col[v_idx].add_R / 255.0;
dest->rgba[1] = data.col[v_idx].add_G / 255.0;
dest->rgba[2] = data.col[v_idx].add_B / 255.0;
if (fc_to_use != RGB_NO_VALUE)
{
epi::color_c mixme(data.col[v_idx].add_R, data.col[v_idx].add_G, data.col[v_idx].add_B);
mixme = mixme.Mix(epi::color_c(fc_to_use), I_ROUND(255.0f * (fd_to_use * 100)));
dest->rgba[0] = mixme.r / 255.0;
dest->rgba[1] = mixme.g / 255.0;
dest->rgba[2] = mixme.b / 255.0;
}
else
{
dest->rgba[0] = data.col[v_idx].add_R / 255.0;
dest->rgba[1] = data.col[v_idx].add_G / 255.0;
dest->rgba[2] = data.col[v_idx].add_B / 255.0;
}
}

dest->rgba[3] = trans;
Expand Down
31 changes: 21 additions & 10 deletions source_files/edge/r_units.cc
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,9 @@ void RGL_DrawUnits(void)
int active_pass = 0;
int active_blending = 0;

rgbcol_t active_fog_rgb = RGB_NO_VALUE;
float active_fog_density = 0;

for (int i=0; i < cur_unit; i++)
local_unit_map[i] = & local_units[i];

Expand Down Expand Up @@ -400,6 +403,8 @@ void RGL_DrawUnits(void)
glFogf(GL_FOG_END, r_farclip.f - 250.0f);
glEnable(GL_FOG);
}
else
glFogi(GL_FOG_MODE, GL_EXP); // if needed

for (int j=0; j < cur_unit; j++)
{
Expand All @@ -411,16 +416,22 @@ void RGL_DrawUnits(void)

if (!r_culling.d && unit->fog_color != RGB_NO_VALUE)
{
rgbcol_t frgb = unit->fog_color;
GLfloat fc[4];
fc[0] = (float)RGB_RED(frgb)/255.0f;
fc[1] = (float)RGB_GRN(frgb)/255.0f;
fc[2] = (float)RGB_BLU(frgb)/255.0f;
fc[3] = 1.0f;
glClearColor(fc[0], fc[1], fc[2], 1.0f);
glFogi(GL_FOG_MODE, GL_EXP);
glFogfv(GL_FOG_COLOR, fc);
glFogf(GL_FOG_DENSITY, std::log1p(unit->fog_density));
if (unit->fog_color != active_fog_rgb)
{
active_fog_rgb = unit->fog_color;
GLfloat fc[4];
fc[0] = (float)RGB_RED(active_fog_rgb)/255.0f;
fc[1] = (float)RGB_GRN(active_fog_rgb)/255.0f;
fc[2] = (float)RGB_BLU(active_fog_rgb)/255.0f;
fc[3] = 1.0f;
glClearColor(fc[0], fc[1], fc[2], 1.0f);
glFogfv(GL_FOG_COLOR, fc);
}
if (unit->fog_density != active_fog_density)
{
active_fog_density = unit->fog_density;
glFogf(GL_FOG_DENSITY, std::log1p(active_fog_density));
}
glEnable(GL_FOG);
}
else if (!r_culling.d)
Expand Down

0 comments on commit e455259

Please sign in to comment.