Classic-like visibility/fog for OpenGL modes, r_usenewshading 2 (new default).

Implemented using GL_LINEAR fog. The only source of difference (besides the
obvious indexed vs. true color) should now be the distance constant, which
still had to be determined experimentally.  Polymer implements this mode in
its fog fragment program part.

Parallaxed skies are always drawn with full visibility, I'm not sure if there
are any maps that expect otherwise.

Also, accidentally committed: factor out initialization code from
polymost_printext256() into gen_font_glyph_tex(), small game.c changes.

git-svn-id: https://svn.eduke32.com/eduke32@3301 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2012-12-16 19:18:10 +00:00
parent bb46b57d89
commit 922aa3ca8b
5 changed files with 169 additions and 92 deletions

View file

@ -28,6 +28,8 @@
# include "polymost.h" # include "polymost.h"
# include "pragmas.h" # include "pragmas.h"
#define PR_LINEAR_FOG
// CVARS // CVARS
extern int32_t pr_lighting; extern int32_t pr_lighting;
extern int32_t pr_normalmapping; extern int32_t pr_normalmapping;
@ -149,6 +151,10 @@ typedef struct s_prrograminfo {
GLint uniform_specMaterial; GLint uniform_specMaterial;
// PR_BIT_MIRROR_MAP // PR_BIT_MIRROR_MAP
GLint uniform_mirrorMap; GLint uniform_mirrorMap;
#ifdef PR_LINEAR_FOG
// PR_BIT_FOG
GLint uniform_linearFog;
#endif
// PR_BIT_GLOW_MAP // PR_BIT_GLOW_MAP
GLint uniform_glowMap; GLint uniform_glowMap;
// PR_BIT_PROJECTION_MAP // PR_BIT_PROJECTION_MAP

View file

@ -120,16 +120,44 @@ extern int32_t drawingskybox;
extern double gyxscale, gxyaspect, ghalfx, grhalfxdown10; extern double gyxscale, gxyaspect, ghalfx, grhalfxdown10;
// For GL_EXP2 fog:
#define FOGSCALE 0.0000768 #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 char nofog; // in windows/SDL layers
extern float fogresult, fogcol[4], fogtable[4*MAXPALOOKUPS]; 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) 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; float f;
if (r_usenewshading) bglFogi(GL_FOG_MODE, GL_EXP2);
if (r_usenewshading==1)
{ {
f = 0.9f * shade; f = 0.9f * shade;
f = (vis > 239) ? (float)(gvisibility*((vis-240+f))) : f = (vis > 239) ? (float)(gvisibility*((vis-240+f))) :
@ -148,8 +176,7 @@ static inline void fogcalc(int32_t shade, int32_t vis, int32_t pal)
f = 100.0f; f = 100.0f;
fogresult = f; fogresult = f;
}
Bmemcpy(fogcol, &fogtable[pal<<2], sizeof(fogcol));
} }
static inline void calc_and_apply_fog(int32_t shade, int32_t vis, int32_t pal) static inline void calc_and_apply_fog(int32_t shade, int32_t vis, int32_t pal)
@ -157,8 +184,17 @@ static inline void calc_and_apply_fog(int32_t shade, int32_t vis, int32_t pal)
if (!nofog) if (!nofog)
{ {
fogcalc(shade, vis, pal); fogcalc(shade, vis, pal);
bglFogf(GL_FOG_DENSITY, fogresult);
bglFogfv(GL_FOG_COLOR, fogcol); 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);
}
} }
} }
@ -167,8 +203,17 @@ static inline void calc_and_apply_fog_factor(int32_t shade, int32_t vis, int32_t
if (!nofog) if (!nofog)
{ {
fogcalc(shade, vis, pal); fogcalc(shade, vis, pal);
bglFogf(GL_FOG_DENSITY, fogresult*factor);
bglFogfv(GL_FOG_COLOR, fogcol); 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

View file

@ -395,14 +395,28 @@ _prprogrambit prprogrambits[PR_BIT_COUNT] = {
// vert_prog // vert_prog
"", "",
// frag_def // frag_def
#ifdef PR_LINEAR_FOG
"uniform bool linearFog;\n"
#endif
"", "",
// frag_prog // frag_prog
" float fragDepth;\n" " float fragDepth;\n"
" float fogFactor;\n" " float fogFactor;\n"
"\n" "\n"
" fragDepth = gl_FragCoord.z / gl_FragCoord.w / 35.0;\n" " fragDepth = gl_FragCoord.z / gl_FragCoord.w / 35.0;\n"
#ifdef PR_LINEAR_FOG
" if (!linearFog) {\n"
#endif
" fragDepth *= fragDepth;\n" " fragDepth *= fragDepth;\n"
" fogFactor = exp2(-gl_Fog.density * gl_Fog.density * fragDepth * 1.442695);\n" " fogFactor = exp2(-gl_Fog.density * gl_Fog.density * fragDepth * 1.442695);\n"
#ifdef PR_LINEAR_FOG
/* 0.65127==150/230, another constant found out by experiment. :/
* (150 is Polymost's FOGDISTCONST.) */
" } else {\n"
" fogFactor = gl_Fog.scale * (gl_Fog.end - fragDepth*0.65217);\n"
" fogFactor = clamp(fogFactor, 0.0, 1.0);"
" }\n"
#endif
" result.rgb = mix(gl_Fog.color.rgb, result.rgb, fogFactor);\n" " result.rgb = mix(gl_Fog.color.rgb, result.rgb, fogFactor);\n"
"\n", "\n",
}, },
@ -4810,7 +4824,12 @@ static int32_t polymer_bindmaterial(_prmaterial material, int16_t* lights,
texunit++; texunit++;
} }
#ifdef PR_LINEAR_FOG
if (programbits & prprogrambits[PR_BIT_FOG].bit)
{
bglUniform1iARB(prprograms[programbits].uniform_linearFog, r_usenewshading==2);
}
#endif
// PR_BIT_GLOW_MAP // PR_BIT_GLOW_MAP
if (programbits & prprogrambits[PR_BIT_GLOW_MAP].bit) if (programbits & prprogrambits[PR_BIT_GLOW_MAP].bit)
{ {
@ -5103,7 +5122,12 @@ static void polymer_compileprogram(int32_t programbits)
{ {
prprograms[programbits].uniform_mirrorMap = bglGetUniformLocationARB(program, "mirrorMap"); prprograms[programbits].uniform_mirrorMap = bglGetUniformLocationARB(program, "mirrorMap");
} }
#ifdef PR_LINEAR_FOG
if (programbits & prprogrambits[PR_BIT_FOG].bit)
{
prprograms[programbits].uniform_linearFog = bglGetUniformLocationARB(program, "linearFog");
}
#endif
// PR_BIT_GLOW_MAP // PR_BIT_GLOW_MAP
if (programbits & prprogrambits[PR_BIT_GLOW_MAP].bit) if (programbits & prprogrambits[PR_BIT_GLOW_MAP].bit)
{ {

View file

@ -113,7 +113,7 @@ static double dxb1[MAXWALLSB], dxb2[MAXWALLSB];
float shadescale = 1.3f; float shadescale = 1.3f;
int32_t shadescale_unbounded = 0; int32_t shadescale_unbounded = 0;
int32_t r_usenewshading = 1; int32_t r_usenewshading = 2;
static double gviewxrange, ghoriz; static double gviewxrange, ghoriz;
double gyxscale, gxyaspect, ghalfx, grhalfxdown10, grhalfxdown10x; double gyxscale, gxyaspect, ghalfx, grhalfxdown10, grhalfxdown10x;
@ -197,7 +197,7 @@ int32_t r_downsize = 1;
int32_t r_downsizevar = -1; int32_t r_downsizevar = -1;
// used for fogcalc // used for fogcalc
float fogresult, fogcol[4], fogtable[4*MAXPALOOKUPS]; float fogresult, fogresult2, fogcol[4], fogtable[4*MAXPALOOKUPS];
#endif #endif
static char ptempbuf[MAXWALLSB<<1]; static char ptempbuf[MAXWALLSB<<1];
@ -711,26 +711,16 @@ static void clear_cache_internal(void)
// one-time initialization of OpenGL for polymost // one-time initialization of OpenGL for polymost
void polymost_glinit() void polymost_glinit()
{ {
GLfloat col[4];
int32_t i; int32_t i;
if (!Bstrcmp(glinfo.vendor, "NVIDIA Corporation")) if (!Bstrcmp(glinfo.vendor, "NVIDIA Corporation"))
{ bglHint(GL_FOG_HINT, GL_NICEST);
bglHint(GL_FOG_HINT,GL_NICEST);
}
else else
{ bglHint(GL_FOG_HINT, GL_DONT_CARE);
bglHint(GL_FOG_HINT,GL_DONT_CARE);
}
bglFogi(GL_FOG_MODE, GL_EXP2); bglFogi(GL_FOG_MODE, GL_EXP2);
bglFogf(GL_FOG_DENSITY,1.0); //must be > 0, default is 1
/* bglFogf(GL_FOG_START,0.0); //default is 0
bglFogf(GL_FOG_END,1.0); //default is 1 */
col[0] = 0; col[1] = 0; col[2] = 0; col[3] = 0; //range:0 to 1
bglFogfv(GL_FOG_COLOR,col); //default is 0,0,0,0
bglBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); bglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
bglPixelStorei(GL_PACK_ALIGNMENT, 1); bglPixelStorei(GL_PACK_ALIGNMENT, 1);
@ -5996,27 +5986,8 @@ int32_t polymost_drawtilescreen(int32_t tilex, int32_t tiley, int32_t wallnum, i
#endif #endif
} }
int32_t polymost_printext256(int32_t xpos, int32_t ypos, int16_t col, int16_t backcol, const char *name, char fontsize) static int32_t gen_font_glyph_tex(void)
{ {
#ifndef USE_OPENGL
return -1;
#else
GLfloat tx, ty, txc, tyc;
int32_t c;
palette_t p,b;
int32_t arbackcol = (unsigned)backcol < 256 ? backcol : 0;
// FIXME?
if (col < 0)
col = 0;
bricolor(&p, col);
bricolor(&b, arbackcol);
if ((rendmode < 3) || (qsetmode != 200)) return(-1);
if (!polymosttext)
{
// construct a 256x128 8-bit alpha-only texture for the font glyph matrix // construct a 256x128 8-bit alpha-only texture for the font glyph matrix
char *tbuf, *cptr, *tptr; char *tbuf, *cptr, *tptr;
int32_t h,i,j; int32_t h,i,j;
@ -6066,8 +6037,38 @@ int32_t polymost_printext256(int32_t xpos, int32_t ypos, int16_t col, int16_t ba
bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
Bfree(tbuf); Bfree(tbuf);
return 0;
}
int32_t polymost_printext256(int32_t xpos, int32_t ypos, int16_t col, int16_t backcol, const char *name, char fontsize)
{
#ifndef USE_OPENGL
return -1;
#else
GLfloat tx, ty, txc, tyc;
int32_t c;
palette_t p,b;
int32_t arbackcol = (unsigned)backcol < 256 ? backcol : 0;
// FIXME?
if (col < 0)
col = 0;
bricolor(&p, col);
bricolor(&b, arbackcol);
if ((rendmode < 3) || (qsetmode != 200)) return(-1);
if (!polymosttext)
{
if (gen_font_glyph_tex() < 0)
return -1;
}
else
{
bglBindTexture(GL_TEXTURE_2D, polymosttext);
} }
else bglBindTexture(GL_TEXTURE_2D, polymosttext);
setpolymost2dview(); // disables blending, texturing, and depth testing setpolymost2dview(); // disables blending, texturing, and depth testing
bglDisable(GL_ALPHA_TEST); bglDisable(GL_ALPHA_TEST);
@ -6283,7 +6284,7 @@ void polymost_initosdfuncs(void)
{ "r_texturemaxsize","r_texturemaxsize: changes the maximum OpenGL texture size limit",(void *) &gltexmaxsize, CVAR_INT | CVAR_NOSAVE, 0, 4096 }, { "r_texturemaxsize","r_texturemaxsize: changes the maximum OpenGL texture size limit",(void *) &gltexmaxsize, CVAR_INT | CVAR_NOSAVE, 0, 4096 },
{ "r_texturemiplevel","r_texturemiplevel: changes the highest OpenGL mipmap level used",(void *) &gltexmiplevel, CVAR_INT, 0, 6 }, { "r_texturemiplevel","r_texturemiplevel: changes the highest OpenGL mipmap level used",(void *) &gltexmiplevel, CVAR_INT, 0, 6 },
{ "r_texturemode", "r_texturemode: changes the texture filtering settings", (void *) &gltexfiltermode, CVAR_INT|CVAR_FUNCPTR, 0, 5 }, { "r_texturemode", "r_texturemode: changes the texture filtering settings", (void *) &gltexfiltermode, CVAR_INT|CVAR_FUNCPTR, 0, 5 },
{ "r_usenewshading", "r_usenewshading: enable/disable new shading/visibility code", (void *) &r_usenewshading, CVAR_BOOL, 0, 1 }, { "r_usenewshading", "r_usenewshading: visibility code: 0: Polymost, 2: Classic", (void *) &r_usenewshading, CVAR_INT, 0, 2 },
{ "r_vbocount","r_vbocount: sets the number of Vertex Buffer Objects to use when drawing models",(void *) &r_vbocount, CVAR_INT, 1, 256 }, { "r_vbocount","r_vbocount: sets the number of Vertex Buffer Objects to use when drawing models",(void *) &r_vbocount, CVAR_INT, 1, 256 },
{ "r_vbos","r_vbos: enable/disable using Vertex Buffer Objects when drawing models",(void *) &r_vbos, CVAR_BOOL, 0, 1 }, { "r_vbos","r_vbos: enable/disable using Vertex Buffer Objects when drawing models",(void *) &r_vbos, CVAR_BOOL, 0, 1 },
{ "r_vertexarrays","r_vertexarrays: enable/disable using vertex arrays when drawing models",(void *) &r_vertexarrays, CVAR_BOOL, 0, 1 }, { "r_vertexarrays","r_vertexarrays: enable/disable using vertex arrays when drawing models",(void *) &r_vertexarrays, CVAR_BOOL, 0, 1 },

View file

@ -3044,7 +3044,7 @@ void G_DisplayRest(int32_t smoothratio)
} }
} }
static void G_DoThirdPerson(DukePlayer_t *pp, vec3_t *vect,int16_t *vsectnum, int32_t ang, int32_t horiz) static void G_DoThirdPerson(const DukePlayer_t *pp, vec3_t *vect, int16_t *vsectnum, int32_t ang, int32_t horiz)
{ {
spritetype *sp = &sprite[pp->i]; spritetype *sp = &sprite[pp->i];
int32_t i, hx, hy; int32_t i, hx, hy;
@ -7868,10 +7868,11 @@ FAKE_F2:
return; return;
} }
M_ChangeMenu(350); M_ChangeMenu(350);
g_screenCapture = 1; g_screenCapture = 1;
G_DrawRooms(myconnectindex,65536); G_DrawRooms(myconnectindex,65536);
//savetemp("duke3d.tmp",waloff[TILE_SAVESHOT],160*100);
g_screenCapture = 0; g_screenCapture = 0;
FX_StopAllSounds(); FX_StopAllSounds();
S_ClearSoundLocks(); S_ClearSoundLocks();
@ -7938,8 +7939,8 @@ FAKE_F3:
} }
g_screenCapture = 1; g_screenCapture = 1;
G_DrawRooms(myconnectindex,65536); G_DrawRooms(myconnectindex,65536);
//savetemp("duke3d.tmp",waloff[TILE_SAVESHOT],160*100);
g_screenCapture = 0; g_screenCapture = 0;
if (g_lastSaveSlot >= 0) if (g_lastSaveSlot >= 0)
{ {
/* inputloc = Bstrlen(&ud.savegame[g_lastSaveSlot][0]); /* inputloc = Bstrlen(&ud.savegame[g_lastSaveSlot][0]);