diff --git a/polymer/eduke32/build/include/polymost.h b/polymer/eduke32/build/include/polymost.h index 23b76961c..08eea69ab 100644 --- a/polymer/eduke32/build/include/polymost.h +++ b/polymer/eduke32/build/include/polymost.h @@ -120,102 +120,6 @@ extern int32_t drawingskybox; extern double gyxscale, gxyaspect, ghalfx, grhalfxdown10; -// For GL_EXP2 fog: -#define FOGSCALE 0.0000768 -// For GL_LINEAR fog: -#define FOGDISTCONST 150 -#define FULLVIS_BEGIN 2.9e38 -#define FULLVIS_END 3.0e38 - -extern char nofog; // in windows/SDL layers -extern float fogresult, fogresult2, fogcol[4], fogtable[4*MAXPALOOKUPS]; -extern int32_t g_visibility; - -static inline void fogcalc(int32_t shade, int32_t vis, int32_t pal) -{ - Bmemcpy(fogcol, &fogtable[pal<<2], sizeof(fogcol)); - - if (r_usenewshading==2) - { - float combvis = (float)(g_visibility * (uint8_t)(vis+16)); - - bglFogi(GL_FOG_MODE, GL_LINEAR); - - if (combvis == 0) - { - fogresult = FULLVIS_BEGIN; - fogresult2 = FULLVIS_END; - return; - } - - fogresult = -(FOGDISTCONST * shade)/combvis; - fogresult2 = (FOGDISTCONST * (numshades-1-shade))/combvis; - } - else - { - float f; - - bglFogi(GL_FOG_MODE, GL_EXP2); - - if (r_usenewshading==1) - { - f = 0.9f * shade; - f = (vis > 239) ? (float)(gvisibility*((vis-240+f))) : - (float)(gvisibility*(vis+16+f)); - } - else - { - f = (shade < 0) ? shade * 3.5f : shade * .66f; - f = (vis > 239) ? (float)(gvisibility*((vis-240+f)/(klabs(vis-256)))) : - (float)(gvisibility*(vis+16+f)); - } - - if (f < 0.001f) - f = 0.001f; - else if (f > 100.0f) - f = 100.0f; - - fogresult = f; - } -} - -static inline void calc_and_apply_fog(int32_t shade, int32_t vis, int32_t pal) -{ - if (!nofog) - { - fogcalc(shade, vis, pal); - bglFogfv(GL_FOG_COLOR, fogcol); - - if (r_usenewshading==2) - { - bglFogf(GL_FOG_START, fogresult); - bglFogf(GL_FOG_END, fogresult2); - } - else - { - bglFogf(GL_FOG_DENSITY, fogresult); - } - } -} - -static inline void calc_and_apply_fog_factor(int32_t shade, int32_t vis, int32_t pal, float factor) -{ - if (!nofog) - { - fogcalc(shade, vis, pal); - bglFogfv(GL_FOG_COLOR, fogcol); - - if (r_usenewshading==2) - { - bglFogf(GL_FOG_START, FULLVIS_BEGIN); - bglFogf(GL_FOG_END, FULLVIS_END); - } - else - { - bglFogf(GL_FOG_DENSITY, fogresult*factor); - } - } -} #endif #endif diff --git a/polymer/eduke32/build/src/a.nasm b/polymer/eduke32/build/src/a.nasm index 051bc2a24..3f5d50e20 100644 --- a/polymer/eduke32/build/src/a.nasm +++ b/polymer/eduke32/build/src/a.nasm @@ -716,6 +716,10 @@ CDECLENDSET 6 ALIGN 16 vlineasm1nonpow2: CDECLBEGINSET 6 + ; NOTE: this seems to be not debuggable with valgrind --smc-check=all, + ; a crash reading the dummy address 0xbeeff0XX appears, as if only the + ; low byte has been written into. + ; (Valgrind bug?) mov dword [np2_do_palookup+2], ebx push ebp mov ebp, edx ; ebp: vertical place diff --git a/polymer/eduke32/build/src/engine.c b/polymer/eduke32/build/src/engine.c index d7fbc6b03..445cd6746 100644 --- a/polymer/eduke32/build/src/engine.c +++ b/polymer/eduke32/build/src/engine.c @@ -44,7 +44,7 @@ #include "engine_priv.h" #define CACHEAGETIME 16 -// #define CLASSIC_NONPOW2_YSIZE_WALLS +//#define CLASSIC_NONPOW2_YSIZE_WALLS #define CLASSIC_NONPOW2_YSIZE_SPRITES #if !defined DEBUG_MAIN_ARRAYS diff --git a/polymer/eduke32/build/src/engine_priv.h b/polymer/eduke32/build/src/engine_priv.h index 6226be985..2aaf6d699 100644 --- a/polymer/eduke32/build/src/engine_priv.h +++ b/polymer/eduke32/build/src/engine_priv.h @@ -74,7 +74,13 @@ extern int16_t p2[MAXWALLSB]; extern int16_t numscans, numbunches; #ifdef USE_OPENGL + +// For GL_EXP2 fog: +#define FOGSCALE 0.0000768 + extern palette_t palookupfog[MAXPALOOKUPS]; +void calc_and_apply_fog(int32_t shade, int32_t vis, int32_t pal); +void calc_and_apply_fog_factor(int32_t shade, int32_t vis, int32_t pal, float factor); #endif // int32_t wallmost(int16_t *mostbuf, int32_t w, int32_t sectnum, char dastat); diff --git a/polymer/eduke32/build/src/polymost.c b/polymer/eduke32/build/src/polymost.c index 766651abd..473ba2837 100644 --- a/polymer/eduke32/build/src/polymost.c +++ b/polymer/eduke32/build/src/polymost.c @@ -835,6 +835,101 @@ void polymost_glinit() // Blseek(cachefilehandle, 0, BSEEK_SET); } +////////// VISIBILITY FOG ROUTINES ////////// +extern char nofog; // in windows/SDL layers + +// For GL_LINEAR fog: +#define FOGDISTCONST 150 +#define FULLVIS_BEGIN 2.9e38 +#define FULLVIS_END 3.0e38 + +static inline void fogcalc(int32_t shade, int32_t vis, int32_t pal) +{ + Bmemcpy(fogcol, &fogtable[pal<<2], sizeof(fogcol)); + + if (r_usenewshading==2) + { + float combvis = (float)(g_visibility * (uint8_t)(vis+16)); + + bglFogi(GL_FOG_MODE, GL_LINEAR); + + if (combvis == 0) + { + fogresult = FULLVIS_BEGIN; + fogresult2 = FULLVIS_END; + return; + } + + fogresult = -(FOGDISTCONST * shade)/combvis; + fogresult2 = (FOGDISTCONST * (numshades-1-shade))/combvis; + } + else + { + float f; + + bglFogi(GL_FOG_MODE, GL_EXP2); + + if (r_usenewshading==1) + { + f = 0.9f * shade; + f = (vis > 239) ? (float)(gvisibility*((vis-240+f))) : + (float)(gvisibility*(vis+16+f)); + } + else + { + f = (shade < 0) ? shade * 3.5f : shade * .66f; + f = (vis > 239) ? (float)(gvisibility*((vis-240+f)/(klabs(vis-256)))) : + (float)(gvisibility*(vis+16+f)); + } + + if (f < 0.001f) + f = 0.001f; + else if (f > 100.0f) + f = 100.0f; + + fogresult = f; + } +} + +void calc_and_apply_fog(int32_t shade, int32_t vis, int32_t pal) +{ + if (!nofog) + { + fogcalc(shade, vis, pal); + bglFogfv(GL_FOG_COLOR, fogcol); + + if (r_usenewshading==2) + { + bglFogf(GL_FOG_START, fogresult); + bglFogf(GL_FOG_END, fogresult2); + } + else + { + bglFogf(GL_FOG_DENSITY, fogresult); + } + } +} + +void calc_and_apply_fog_factor(int32_t shade, int32_t vis, int32_t pal, float factor) +{ + if (!nofog) + { + fogcalc(shade, vis, pal); + bglFogfv(GL_FOG_COLOR, fogcol); + + if (r_usenewshading==2) + { + bglFogf(GL_FOG_START, FULLVIS_BEGIN); + bglFogf(GL_FOG_END, FULLVIS_END); + } + else + { + bglFogf(GL_FOG_DENSITY, fogresult*factor); + } + } +} +//////////////////// + void invalidatecache(void) { #ifdef DEBUGGINGAIDS