Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sector/level fog implementation #528

Merged
merged 20 commits into from
Aug 21, 2023
Merged
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
11 changes: 9 additions & 2 deletions docs/specifications/UDMF EDGE Extensions.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
===============================================================================
Universal Doom Map Format EDGE extensions DRAFT - 2023.02.27
Universal Doom Map Format EDGE extensions DRAFT - 2023.08.17

Copyright (c) 2023 The EDGE Team.
Permission is granted to copy, distribute and/or modify this document
Expand Down Expand Up @@ -84,7 +84,13 @@ Note: All <bool> fields default to false unless mentioned otherwise.

sector
{
No changes.
fadecolor = <integer>; // Fog color for this sector, in 0xRRGGBB format. Default (no fog) is 0x000000.

fogdensity = <integer>; // Fog density for this sector. EDGE makes an effort to map the GZDoom values recognized
// by map editors (0-510) in the following manner:
// - Values of 0-1 are equivalent to a 20% FOG_DENSITY in SECTORS.DDF
// - The remaining values (2-510) are roughly mapped to the 0-100% FOG_DENSITY scale in SECTORS.DDF;
// for example, a value of 5 would be roughly 1% while 510 would be 100%
}

thing
Expand All @@ -96,6 +102,7 @@ Note: All <bool> fields default to false unless mentioned otherwise.
=======================================
Changelog
=======================================
2023.08.18 - Addition of fadecolor/fogdensity sector fields
2023.02.27 - Initial draft; addition of zfloor/zceiling vertex fields


Expand Down
14 changes: 14 additions & 0 deletions source_files/ddf/level.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ static const commandlist_t level_commands[] =
DF("STATS", wistyle, DDF_LevelGetWistyle),
DF("LEAVING_BACKGROUND", leavingbggraphic, DDF_MainGetLumpName),
DF("ENTERING_BACKGROUND", enteringbggraphic, DDF_MainGetLumpName),
DF("INDOOR_FOG_COLOR", indoor_fog_color, DDF_MainGetRGB),
DF("INDOOR_FOG_DENSITY", indoor_fog_density, DDF_MainGetPercent),
DF("OUTDOOR_FOG_COLOR", outdoor_fog_color, DDF_MainGetRGB),
DF("OUTDOOR_FOG_DENSITY", outdoor_fog_density, DDF_MainGetPercent),

DDF_CMD_END
};
Expand Down Expand Up @@ -450,6 +454,11 @@ void mapdef_c::CopyDetail(mapdef_c &src)
f_end = src.f_end;

forced_skystretch = src.forced_skystretch;

indoor_fog_color = src.indoor_fog_color;
indoor_fog_density = src.indoor_fog_density;
outdoor_fog_color = src.outdoor_fog_color;
outdoor_fog_density = src.outdoor_fog_density;
}

void mapdef_c::Default()
Expand Down Expand Up @@ -484,6 +493,11 @@ void mapdef_c::Default()
f_end.Default();

forced_skystretch = SKS_Unset;

indoor_fog_color = RGB_NO_VALUE;
indoor_fog_density = 0;
outdoor_fog_color = RGB_NO_VALUE;
outdoor_fog_density = 0;
}


Expand Down
5 changes: 5 additions & 0 deletions source_files/ddf/level.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ class mapdef_c
// sky stretch override
skystretch_e forced_skystretch;

rgbcol_t indoor_fog_color;
float indoor_fog_density;
rgbcol_t outdoor_fog_color;
float outdoor_fog_density;

private:
// disable copy construct and assignment operator
explicit mapdef_c(mapdef_c &rhs) { (void) rhs; }
Expand Down
3 changes: 3 additions & 0 deletions source_files/ddf/line.h
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,9 @@ class sectortype_c
float floor_bob;
float ceiling_bob;

rgbcol_t fog_color;
float fog_density;

private:
// disable copy construct and assignment operator
explicit sectortype_c(sectortype_c &rhs) { (void) rhs; }
Expand Down
9 changes: 9 additions & 0 deletions source_files/ddf/sector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ static const commandlist_t sect_commands[] =
DF("FLOOR_BOB", floor_bob, DDF_MainGetFloat),
DF("CEILING_BOB", ceiling_bob, DDF_MainGetFloat),

DF("FOG_COLOR", fog_color, DDF_MainGetRGB),
DF("FOG_DENSITY", fog_density, DDF_MainGetPercent),

DDF_CMD_END
};

Expand Down Expand Up @@ -516,6 +519,9 @@ void sectortype_c::CopyDetail(sectortype_c &src)

floor_bob = src.floor_bob;
ceiling_bob = src.ceiling_bob;

fog_color = src.fog_color;
fog_density = src.fog_density;
}

//
Expand Down Expand Up @@ -557,6 +563,9 @@ void sectortype_c::Default()

floor_bob = 0.0f;
ceiling_bob = 0.0f;

fog_color = RGB_NO_VALUE;
fog_density = 0;
}


Expand Down
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, NULL, &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
42 changes: 42 additions & 0 deletions source_files/edge/p_setup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,17 @@ static void LoadSectors(int lump)
ss->props.viscosity = VISCOSITY;
ss->props.drag = DRAG;

if (ss->props.special && ss->props.special->fog_color != RGB_NO_VALUE)
{
ss->props.fog_color = ss->props.special->fog_color;
ss->props.fog_density = 0.01f * ss->props.special->fog_density;
}
else
{
ss->props.fog_color = RGB_NO_VALUE;
ss->props.fog_density = 0;
}

ss->p = &ss->props;

ss->sound_player = -1;
Expand Down Expand Up @@ -1451,6 +1462,8 @@ static void LoadUDMFSectors()
{
float cz = 0.0f, fz = 0.0f;
int light = 160, type = 0, tag = 0;
rgbcol_t fog_color = 0;
int fog_density = 0;
char floor_tex[10];
char ceil_tex[10];
strcpy(floor_tex, "-");
Expand Down Expand Up @@ -1495,6 +1508,10 @@ static void LoadUDMFSectors()
type = epi::LEX_Int(value);
else if (key == "id")
tag = epi::LEX_Int(value);
else if (key == "fadecolor")
fog_color = epi::LEX_Int(value);
else if (key == "fogdensity")
fog_density = CLAMP(0, epi::LEX_Int(value), 510);
}
sector_t *ss = sectors + cur_sector;
ss->f_h = fz;
Expand Down Expand Up @@ -1547,6 +1564,31 @@ static void LoadUDMFSectors()
ss->props.viscosity = VISCOSITY;
ss->props.drag = DRAG;

// Allow UDMF sector fog information to override DDFSECT types
if (fog_color != 0) // All black is the established UDMF "no fog" color
{
// Prevent UDMF-specified fog color from having our internal 'no value'...uh...value
if (fog_color == RGB_NO_VALUE)
fog_color ^= RGB_MAKE(1,1,1);
ss->props.fog_color = fog_color;
// Best-effort match for GZDoom's fogdensity values so that UDB, etc
// give predictable results
if (fog_density < 2)
ss->props.fog_density = 0.002f;
else
ss->props.fog_density = 0.005f * ((float)fog_density / 510.0f);
}
else if (ss->props.special && ss->props.special->fog_color != RGB_NO_VALUE)
{
ss->props.fog_color = ss->props.special->fog_color;
ss->props.fog_density = 0.01f * ss->props.special->fog_density;
}
else
{
ss->props.fog_color = RGB_NO_VALUE;
ss->props.fog_density = 0;
}

ss->p = &ss->props;

ss->sound_player = -1;
Expand Down
45 changes: 42 additions & 3 deletions source_files/edge/r_colormap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -660,10 +660,17 @@ class colormap_shader_c : public abstract_shader_c

rgbcol_t whites[32];

rgbcol_t fog_color;
float fog_density;

// for DDFLEVL fog checks
sector_t *sec;

public:
colormap_shader_c(const colourmap_c *CM) : colmap(CM),
light_lev(255), fade_tex(0),
simple_cmap(true), lt_model(LMODEL_Doom)
simple_cmap(true), lt_model(LMODEL_Doom), fog_color(RGB_NO_VALUE), fog_density(0),
sec(nullptr)
{ }

virtual ~colormap_shader_c()
Expand Down Expand Up @@ -736,10 +743,27 @@ class colormap_shader_c : public abstract_shader_c
GLuint tex, float alpha, int *pass_var, int blending,
bool masked, void *data, shader_coord_func_t func)
{
rgbcol_t fc_to_use = fog_color;
float fd_to_use = fog_density;
// check for DDFLEVL fog
if (fc_to_use == RGB_NO_VALUE)
{
if (IS_SKY(sec->ceil))
{
fc_to_use = currmap->outdoor_fog_color;
fd_to_use = 0.01f * currmap->outdoor_fog_density;
}
else
{
fc_to_use = currmap->indoor_fog_color;
fd_to_use = 0.01f * currmap->indoor_fog_density;
}
}

local_gl_vert_t * glvert = RGL_BeginUnit(shape, num_vert,
GL_MODULATE, tex,
(simple_cmap || r_dumbmulti.d) ? GL_MODULATE : GL_DECAL,
fade_tex, *pass_var, blending);
fade_tex, *pass_var, blending, fc_to_use, fd_to_use);

for (int v_idx=0; v_idx < num_vert; v_idx++)
{
Expand Down Expand Up @@ -904,14 +928,25 @@ class colormap_shader_c : public abstract_shader_c
{
light_lev = _level;
}

void SetFog(rgbcol_t _fog_color, float _fog_density)
{
fog_color = _fog_color;
fog_density = _fog_density;
}

void SetSector(sector_t *_sec)
{
sec = _sec;
}
};


static colormap_shader_c *std_cmap_shader;


abstract_shader_c *R_GetColormapShader(const struct region_properties_s *props,
int light_add)
int light_add, sector_t *sec)
{
if (! std_cmap_shader)
std_cmap_shader = new colormap_shader_c(NULL);
Expand Down Expand Up @@ -950,6 +985,10 @@ abstract_shader_c *R_GetColormapShader(const struct region_properties_s *props,

shader->SetLight(lit_Nom);

shader->SetFog(props->fog_color, props->fog_density);

shader->SetSector(sec);

return shader;
}

Expand Down
2 changes: 1 addition & 1 deletion source_files/edge/r_colormap.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ rgbcol_t V_GetFontColor(const colourmap_c *colmap);
rgbcol_t V_ParseFontColor(const char *name, bool strict = false);

abstract_shader_c *R_GetColormapShader(
const struct region_properties_s *props, int light_add = 0);
const struct region_properties_s *props, int light_add = 0, sector_t *sec = nullptr);

// colour indices from palette
extern int pal_black, pal_white, pal_gray239;
Expand Down
7 changes: 7 additions & 0 deletions source_files/edge/r_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ typedef struct region_properties_s
vec3_t net_push = {0,0,0};

vec3_t old_push = {0,0,0};

// sector fog
rgbcol_t fog_color = RGB_NO_VALUE;
float fog_density = 0;
}
region_properties_t;

Expand Down Expand Up @@ -163,6 +167,9 @@ typedef struct surface_s

// this only used for BOOM deep water (linetype 242)
const colourmap_c *boom_colmap;

// used for fog boundaries if needed
bool fogwall = false;
}
surface_t;

Expand Down
14 changes: 14 additions & 0 deletions source_files/edge/r_image.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1678,6 +1678,20 @@ const image_c *W_ImageForHOMDetect(void)
return dummy_hom[(framecount & 0x10) ? 1 : 0];
}

const image_c *W_ImageForFogWall(rgbcol_t fog_color)
{
std::string fogname = epi::STR_Format("FOGWALL_%d", fog_color);
image_c *fogwall = (image_c *)W_ImageLookup(fogname.c_str(), INS_Graphic, ILF_Null);
if (fogwall)
return fogwall;
imagedef_c *fogdef = new imagedef_c;
fogdef->colour = fog_color;
fogdef->name = fogname;
fogdef->type = IMGDT_Colour;
fogdef->belong = INS_Graphic;
fogwall = AddImageUser(fogdef);
return fogwall;
}

const image_c *W_ImageParseSaveString(char type, const char *name)
{
Expand Down
1 change: 1 addition & 0 deletions source_files/edge/r_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ const image_c *W_ImageLookup(const char *name, image_namespace_e = INS_Graphic,
const image_c *W_ImageForDummySprite(void);
const image_c *W_ImageForDummySkin(void);
const image_c *W_ImageForHOMDetect(void);
const image_c *W_ImageForFogWall(rgbcol_t fog_color);

// savegame code (Only)
const image_c *W_ImageParseSaveString(char type, const char *name);
Expand Down
4 changes: 1 addition & 3 deletions source_files/edge/r_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ DEF_CVAR(r_culling, "0", CVAR_ARCHIVE)
DEF_CVAR_CLAMPED(r_culldist, "3000", CVAR_ARCHIVE, 1000.0f, 16000.0f)
DEF_CVAR(r_cullfog, "0", CVAR_ARCHIVE)

DEF_CVAR(r_fogofwar, "0", CVAR_ARCHIVE)

//
// RGL_SetupMatrices2D
//
Expand Down Expand Up @@ -222,7 +220,7 @@ void RGL_SoftInit(void)
glCullFace(GL_BACK);
glDisable(GL_CULL_FACE);

glHint(GL_FOG_HINT, GL_FASTEST);
glHint(GL_FOG_HINT, GL_NICEST);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
}

Expand Down
Loading