Move fog calc routines into polymost.c, declare in engine_priv.h.

git-svn-id: https://svn.eduke32.com/eduke32@3303 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2012-12-16 19:18:18 +00:00
parent 5bda3a6ebf
commit 28695e1d97
5 changed files with 106 additions and 97 deletions

View file

@ -120,102 +120,6 @@ extern int32_t drawingskybox;
extern double gyxscale, gxyaspect, ghalfx, grhalfxdown10; 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
#endif #endif

View file

@ -716,6 +716,10 @@ CDECLENDSET 6
ALIGN 16 ALIGN 16
vlineasm1nonpow2: vlineasm1nonpow2:
CDECLBEGINSET 6 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 mov dword [np2_do_palookup+2], ebx
push ebp push ebp
mov ebp, edx ; ebp: vertical place mov ebp, edx ; ebp: vertical place

View file

@ -44,7 +44,7 @@
#include "engine_priv.h" #include "engine_priv.h"
#define CACHEAGETIME 16 #define CACHEAGETIME 16
// #define CLASSIC_NONPOW2_YSIZE_WALLS //#define CLASSIC_NONPOW2_YSIZE_WALLS
#define CLASSIC_NONPOW2_YSIZE_SPRITES #define CLASSIC_NONPOW2_YSIZE_SPRITES
#if !defined DEBUG_MAIN_ARRAYS #if !defined DEBUG_MAIN_ARRAYS

View file

@ -74,7 +74,13 @@ extern int16_t p2[MAXWALLSB];
extern int16_t numscans, numbunches; extern int16_t numscans, numbunches;
#ifdef USE_OPENGL #ifdef USE_OPENGL
// For GL_EXP2 fog:
#define FOGSCALE 0.0000768
extern palette_t palookupfog[MAXPALOOKUPS]; 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 #endif
// int32_t wallmost(int16_t *mostbuf, int32_t w, int32_t sectnum, char dastat); // int32_t wallmost(int16_t *mostbuf, int32_t w, int32_t sectnum, char dastat);

View file

@ -835,6 +835,101 @@ void polymost_glinit()
// Blseek(cachefilehandle, 0, BSEEK_SET); // 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) void invalidatecache(void)
{ {
#ifdef DEBUGGINGAIDS #ifdef DEBUGGINGAIDS