diff --git a/polymer/eduke32/build/include/polymer.h b/polymer/eduke32/build/include/polymer.h index 08e6e71a9..be7fc1901 100644 --- a/polymer/eduke32/build/include/polymer.h +++ b/polymer/eduke32/build/include/polymer.h @@ -61,6 +61,7 @@ typedef enum { PR_BIT_SPECULAR_MAP, PR_BIT_SPECULAR_MATERIAL, PR_BIT_MIRROR_MAP, + PR_BIT_FOG, PR_BIT_GLOW_MAP, PR_BIT_SHADOW_MAP, PR_BIT_SPOT_LIGHT, diff --git a/polymer/eduke32/build/include/polymost.h b/polymer/eduke32/build/include/polymost.h index 19c301d08..f982ec496 100644 --- a/polymer/eduke32/build/include/polymost.h +++ b/polymer/eduke32/build/include/polymost.h @@ -7,6 +7,8 @@ #define CULL_DELAY 2 #define MAXCULLCHECKS 1024 +#define FOGSCALE 0.0000640 + extern int32_t lastcullcheck; extern char cullmodel[MAXSPRITES]; extern int32_t cullcheckcnt; @@ -20,7 +22,7 @@ extern float gtang; extern float glox1, gloy1; extern double gxyaspect, grhalfxdown10x; extern double gcosang, gsinang, gcosang2, gsinang2; -extern double gchang, gshang, gctang, gstang; +extern double gchang, gshang, gctang, gstang, gvisibility; struct glfiltermodes { char *name; @@ -119,6 +121,10 @@ extern float shadescale; extern int32_t globalnoeffect; extern int32_t drawingskybox; +extern float fogresult, fogcol[4], fogtable[4*MAXPALOOKUPS]; + +void fogcalc(const int32_t shade, const int32_t vis, const int32_t pal); + #endif #endif diff --git a/polymer/eduke32/build/src/polymer.c b/polymer/eduke32/build/src/polymer.c index 938048e0a..e457c82d5 100644 --- a/polymer/eduke32/build/src/polymer.c +++ b/polymer/eduke32/build/src/polymer.c @@ -3,6 +3,7 @@ #define POLYMER_C #include "polymer.h" +#include "engine_priv.h" // CVARS int32_t pr_maxlightpasses = 5; @@ -333,6 +334,24 @@ _prprogrambit prprogrambits[PR_BIT_COUNT] = { " result = vec4((result.rgb * (1.0 - specTexel.a)) + (mirrorTexel.rgb * specTexel.rgb * specTexel.a), result.a);\n" "\n", }, + { + 1 << PR_BIT_FOG, + // vert_def + "", + // vert_prog + "", + // frag_def + "", + // frag_prog + " float fragDepth;\n" + " float fogFactor;\n" + "\n" + " fragDepth = gl_FragCoord.z / gl_FragCoord.w / 35;\n" + " fragDepth *= fragDepth;\n" + " fogFactor = exp2(-gl_Fog.density * gl_Fog.density * fragDepth * 1.442695);\n" + " result.rgb = mix(gl_Fog.color.rgb, result.rgb, fogFactor);\n" + "\n", + }, { 1 << PR_BIT_GLOW_MAP, // vert_def @@ -572,8 +591,6 @@ int32_t polymer_init(void) void polymer_glinit(void) { - float a; - bglClearColor(0.0f, 0.0f, 0.0f, 1.0f); bglClearStencil(0); bglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); @@ -610,15 +627,6 @@ void polymer_glinit(void) bglDisable(GL_FOG); - bglFogi(GL_FOG_MODE, GL_EXP2); - //glFogfv(GL_FOG_COLOR, fogColor); - bglEnable(GL_FOG); - - a = (1 - ((float)(visibility) / 512.0f)) / 10.0f; - bglFogf(GL_FOG_DENSITY, 0.1f - a); - bglFogf(GL_FOG_START, 0.0f); - bglFogf(GL_FOG_END, 1000000.0f); - bglEnable(GL_CULL_FACE); bglCullFace(GL_BACK); } @@ -657,6 +665,9 @@ void polymer_drawrooms(int32_t daposx, int32_t daposy, int32_t da if (pr_verbosity >= 3) OSD_Printf("PR : Drawing rooms...\n"); + // fogcalc needs this + gvisibility = ((float)globalvisibility)*FOGSCALE; + ang = (float)(daang) / (2048.0f / 360.0f); horizang = (float)(-getangle(128, dahoriz-100)) / (2048.0f / 360.0f); tiltang = (gtang * 90.0f); @@ -806,12 +817,20 @@ void polymer_rotatesprite(int32_t sx, int32_t sy, int32_t z, int1 void polymer_drawmaskwall(int32_t damaskwallcnt) { + sectortype *sec; + walltype *wal; _prwall *w; if (pr_verbosity >= 3) OSD_Printf("PR : Masked wall %i...\n", damaskwallcnt); + sec = §or[sectorofwall(maskwall[damaskwallcnt])]; + wal = &wall[maskwall[damaskwallcnt]]; w = prwalls[maskwall[damaskwallcnt]]; + fogcalc(wal->shade,sec->visibility,sec->floorpal); + bglFogf(GL_FOG_DENSITY,fogresult); + bglFogfv(GL_FOG_COLOR,fogcol); + bglEnable(GL_CULL_FACE); polymer_drawplane(&w->mask); @@ -831,6 +850,10 @@ void polymer_drawsprite(int32_t snum) tspr = tspriteptr[snum]; + fogcalc(tspr->shade,sector[tspr->sectnum].visibility,sector[tspr->sectnum].floorpal); + bglFogf(GL_FOG_DENSITY,fogresult); + bglFogfv(GL_FOG_COLOR,fogcol); + if (usemodels && tile2model[Ptile2tile(tspr->picnum,tspr->pal)].modelid >= 0 && tile2model[Ptile2tile(tspr->picnum,tspr->pal)].framenum >= 0) { polymer_drawmdsprite(tspr); @@ -1897,8 +1920,17 @@ static void polymer_drawsector(int16_t sectnum) sec = §or[sectnum]; s = prsectors[sectnum]; + fogcalc(sec->floorshade,sec->visibility,sec->floorpal); + bglFogf(GL_FOG_DENSITY,fogresult); + bglFogfv(GL_FOG_COLOR,fogcol); + if (!(sec->floorstat & 1)) polymer_drawplane(&s->floor); + + fogcalc(sec->ceilingshade,sec->visibility,sec->ceilingpal); + bglFogf(GL_FOG_DENSITY,fogresult); + bglFogfv(GL_FOG_COLOR,fogcol); + if (!(sec->ceilingstat & 1)) polymer_drawplane(&s->ceil); @@ -2364,12 +2396,20 @@ static void polymer_updatewall(int16_t wallnum) static void polymer_drawwall(int16_t sectnum, int16_t wallnum) { + sectortype *sec; + walltype *wal; _prwall *w; if (pr_verbosity >= 3) OSD_Printf("PR : Drawing wall %i...\n", wallnum); + sec = §or[sectnum]; + wal = &wall[wallnum]; w = prwalls[wallnum]; + fogcalc(wal->shade,sec->visibility,sec->floorpal); + bglFogf(GL_FOG_DENSITY,fogresult); + bglFogfv(GL_FOG_COLOR,fogcol); + if ((w->underover & 1) && !(w->underover & 4)) { polymer_drawplane(&w->wall); @@ -3282,6 +3322,9 @@ static int32_t polymer_bindmaterial(_prmaterial material, char* lights, int if (!curlight && material.mirrormap) programbits |= prprogrambits[PR_BIT_MIRROR_MAP].bit; + // PR_BIT_FOG + programbits |= prprogrambits[PR_BIT_FOG].bit; + // PR_BIT_GLOW_MAP if (!curlight && material.glowmap) programbits |= prprogrambits[PR_BIT_GLOW_MAP].bit; diff --git a/polymer/eduke32/build/src/polymost.c b/polymer/eduke32/build/src/polymost.c index 13d32f1f9..82545b861 100644 --- a/polymer/eduke32/build/src/polymost.c +++ b/polymer/eduke32/build/src/polymost.c @@ -99,7 +99,6 @@ static double dxb1[MAXWALLSB], dxb2[MAXWALLSB]; #define USEZBUFFER 1 //1:use zbuffer (slow, nice sprite rendering), 0:no zbuffer (fast, bad sprite rendering) #define LINTERPSIZ 4 //log2 of interpolation size. 4:pretty fast&acceptable quality, 0:best quality/slow! #define DEPTHDEBUG 0 //1:render distance instead of texture, for debugging only!, 0:default -#define FOGSCALE 0.0000640 float shadescale = 1.050; @@ -196,9 +195,9 @@ int32_t r_fullbrights = 1; // is medium quality a good default? int32_t r_downsize = 1; -static float fogresult, fogcol[4], fogtable[4*MAXPALOOKUPS]; +float fogresult, fogcol[4], fogtable[4*MAXPALOOKUPS]; -static inline void fogcalc(const int32_t shade, const int32_t vis, const int32_t pal) +void fogcalc(const int32_t shade, const int32_t vis, const int32_t pal) { float f;