overbrights.

git-svn-id: https://svn.code.sf.net/p/fteqw/code/branches/wip@3741 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Spoike 2011-03-02 03:43:38 +00:00
parent 23bc19fc14
commit 79497a07f7
7 changed files with 98 additions and 58 deletions

View file

@ -256,6 +256,15 @@ void Surf_LessenStains(void)
static float time; static float time;
extern cvar_t gl_lightmap_shift;
if (gl_lightmap_shift.modified)
{
gl_lightmap_shift.modified = 0;
for (i=0, surf = cl.worldmodel->surfaces; i<cl.worldmodel->numsurfaces ; i++, surf++)
surf->cached_dlight=-1;//force it
}
if (!r_stains.value) if (!r_stains.value)
return; return;

View file

@ -261,7 +261,7 @@ cvar_t gl_font = SCVARF ("gl_font", "",
cvar_t gl_lateswap = SCVAR ("gl_lateswap", "0"); cvar_t gl_lateswap = SCVAR ("gl_lateswap", "0");
cvar_t gl_lerpimages = SCVAR ("gl_lerpimages", "1"); cvar_t gl_lerpimages = SCVAR ("gl_lerpimages", "1");
cvar_t gl_lightmap_shift = SCVARF ("gl_lightmap_shift", "0", cvar_t gl_lightmap_shift = SCVARF ("gl_lightmap_shift", "0",
CVAR_ARCHIVE | CVAR_LATCH); CVAR_ARCHIVE);
//cvar_t gl_lightmapmode = SCVARF("gl_lightmapmode", "", //cvar_t gl_lightmapmode = SCVARF("gl_lightmapmode", "",
// CVAR_ARCHIVE); // CVAR_ARCHIVE);
cvar_t gl_load24bit = SCVARF ("gl_load24bit", "1", cvar_t gl_load24bit = SCVARF ("gl_load24bit", "1",

View file

@ -1100,6 +1100,7 @@ qboolean CMod_LoadSurfaces (lump_t *l)
#ifndef SERVERONLY #ifndef SERVERONLY
texture_t *Mod_LoadWall(char *name, char *sname) texture_t *Mod_LoadWall(char *name, char *sname)
{ {
q2miptex_t replacementwal;
qbyte *in, *oin; qbyte *in, *oin;
texture_t *tex; texture_t *tex;
q2miptex_t *wal; q2miptex_t *wal;
@ -1113,10 +1114,15 @@ texture_t *Mod_LoadWall(char *name, char *sname)
wal = (void *)FS_LoadMallocFile (name); wal = (void *)FS_LoadMallocFile (name);
if (!wal) if (!wal)
{ {
//they will download eventually... tn.base = R_LoadReplacementTexture(name, loadname, 0);
CL_CheckOrEnqueDownloadFile(name, NULL, 0); wal = &replacementwal;
return NULL; memset(wal, 0, sizeof(*wal));
Q_strncpyz(wal->name, name, sizeof(wal->name));
wal->width = image_width;
wal->height = image_height;
} }
else
tn.base = R_LoadReplacementTexture(wal->name, loadname, IF_NOALPHA);
wal->width = LittleLong(wal->width); wal->width = LittleLong(wal->width);
wal->height = LittleLong(wal->height); wal->height = LittleLong(wal->height);
@ -1137,21 +1143,32 @@ texture_t *Mod_LoadWall(char *name, char *sname)
tex->width = wal->width; tex->width = wal->width;
tex->height = wal->height; tex->height = wal->height;
tn.base = R_LoadReplacementTexture(wal->name, loadname, IF_NOALPHA);
if (!TEXVALID(tn.base)) if (!TEXVALID(tn.base))
{ {
tn.base = R_LoadReplacementTexture(wal->name, "bmodels", IF_NOALPHA); tn.base = R_LoadReplacementTexture(wal->name, "bmodels", IF_NOALPHA);
if (!TEXVALID(tn.base)) if (!TEXVALID(tn.base))
{
if (!wal->offsets[0])
{
//they will download eventually...
CL_CheckOrEnqueDownloadFile(name, NULL, 0);
return NULL;
}
tn.base = R_LoadTexture8Pal24 (wal->name, tex->width, tex->height, (qbyte *)wal+wal->offsets[0], d_q28to24table, IF_NOALPHA|IF_NOGAMMA); tn.base = R_LoadTexture8Pal24 (wal->name, tex->width, tex->height, (qbyte *)wal+wal->offsets[0], d_q28to24table, IF_NOALPHA|IF_NOGAMMA);
}
} }
in = Hunk_TempAllocMore(wal->width*wal->height); if (wal->offsets[0])
oin = (qbyte *)wal+wal->offsets[0]; {
for (j = 0; j < wal->width*wal->height; j++) in = Hunk_TempAllocMore(wal->width*wal->height);
in[j] = (d_q28to24table[oin[j]*3+0] + d_q28to24table[oin[j]*3+1] + d_q28to24table[oin[j]*3+2])/3; oin = (qbyte *)wal+wal->offsets[0];
tn.bump = R_LoadTexture8BumpPal (va("%s_bump", wal->name), tex->width, tex->height, in, true); for (j = 0; j < wal->width*wal->height; j++)
in[j] = (d_q28to24table[oin[j]*3+0] + d_q28to24table[oin[j]*3+1] + d_q28to24table[oin[j]*3+2])/3;
tn.bump = R_LoadTexture8BumpPal (va("%s_bump", wal->name), tex->width, tex->height, in, true);
}
BZ_Free(wal); if (wal != &replacementwal)
BZ_Free(wal);
tex->shader = R_RegisterCustom (sname, Shader_DefaultBSPQ2, NULL); tex->shader = R_RegisterCustom (sname, Shader_DefaultBSPQ2, NULL);
R_BuildDefaultTexnums(&tn, tex->shader); R_BuildDefaultTexnums(&tn, tex->shader);

View file

@ -7,10 +7,6 @@
#endif #endif
#include <d3d9.h> #include <d3d9.h>
/*shaders have a few GL_FOO constants in them. they shouldn't, but they do.*/
#include <GL/gl.h>
#include "glsupp.h"
extern LPDIRECT3DDEVICE9 pD3DDev9; extern LPDIRECT3DDEVICE9 pD3DDev9;
//#define d3dcheck(foo) foo //#define d3dcheck(foo) foo
@ -583,7 +579,7 @@ static void SelectPassTexture(unsigned int tu, shaderpass_t *pass)
switch (pass->blendmode) switch (pass->blendmode)
{ {
case GL_DOT3_RGB_ARB: case PBM_DOTPRODUCT:
IDirect3DDevice9_SetTextureStageState(pD3DDev9, tu, D3DTSS_COLORARG1, D3DTA_TEXTURE); IDirect3DDevice9_SetTextureStageState(pD3DDev9, tu, D3DTSS_COLORARG1, D3DTA_TEXTURE);
IDirect3DDevice9_SetTextureStageState(pD3DDev9, tu, D3DTSS_COLORARG2, D3DTA_CURRENT); IDirect3DDevice9_SetTextureStageState(pD3DDev9, tu, D3DTSS_COLORARG2, D3DTA_CURRENT);
IDirect3DDevice9_SetTextureStageState(pD3DDev9, tu, D3DTSS_COLOROP, D3DTOP_DOTPRODUCT3); IDirect3DDevice9_SetTextureStageState(pD3DDev9, tu, D3DTSS_COLOROP, D3DTOP_DOTPRODUCT3);
@ -592,7 +588,7 @@ static void SelectPassTexture(unsigned int tu, shaderpass_t *pass)
// IDirect3DDevice9_SetTextureStageState(pD3DDev9, tu, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE); // IDirect3DDevice9_SetTextureStageState(pD3DDev9, tu, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
IDirect3DDevice9_SetTextureStageState(pD3DDev9, tu, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); IDirect3DDevice9_SetTextureStageState(pD3DDev9, tu, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
break; break;
case GL_REPLACE: case PBM_REPLACE:
IDirect3DDevice9_SetTextureStageState(pD3DDev9, tu, D3DTSS_COLORARG1, D3DTA_TEXTURE); IDirect3DDevice9_SetTextureStageState(pD3DDev9, tu, D3DTSS_COLORARG1, D3DTA_TEXTURE);
IDirect3DDevice9_SetTextureStageState(pD3DDev9, tu, D3DTSS_COLOROP, D3DTOP_SELECTARG1); IDirect3DDevice9_SetTextureStageState(pD3DDev9, tu, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
@ -609,7 +605,7 @@ static void SelectPassTexture(unsigned int tu, shaderpass_t *pass)
IDirect3DDevice9_SetTextureStageState(pD3DDev9, tu, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); IDirect3DDevice9_SetTextureStageState(pD3DDev9, tu, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
} }
break; break;
case GL_ADD: case PBM_ADD:
IDirect3DDevice9_SetTextureStageState(pD3DDev9, tu, D3DTSS_COLORARG1, D3DTA_TEXTURE); IDirect3DDevice9_SetTextureStageState(pD3DDev9, tu, D3DTSS_COLORARG1, D3DTA_TEXTURE);
IDirect3DDevice9_SetTextureStageState(pD3DDev9, tu, D3DTSS_COLORARG2, D3DTA_CURRENT); IDirect3DDevice9_SetTextureStageState(pD3DDev9, tu, D3DTSS_COLORARG2, D3DTA_CURRENT);
IDirect3DDevice9_SetTextureStageState(pD3DDev9, tu, D3DTSS_COLOROP, D3DTOP_BLENDTEXTUREALPHA); IDirect3DDevice9_SetTextureStageState(pD3DDev9, tu, D3DTSS_COLOROP, D3DTOP_BLENDTEXTUREALPHA);
@ -619,7 +615,7 @@ static void SelectPassTexture(unsigned int tu, shaderpass_t *pass)
IDirect3DDevice9_SetTextureStageState(pD3DDev9, tu, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE); IDirect3DDevice9_SetTextureStageState(pD3DDev9, tu, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
IDirect3DDevice9_SetTextureStageState(pD3DDev9, tu, D3DTSS_ALPHAOP, D3DTOP_MODULATE); IDirect3DDevice9_SetTextureStageState(pD3DDev9, tu, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
break; break;
case GL_DECAL: case PBM_DECAL:
if (!tu) if (!tu)
goto forcemod; goto forcemod;
IDirect3DDevice9_SetTextureStageState(pD3DDev9, tu, D3DTSS_COLORARG1, D3DTA_TEXTURE); IDirect3DDevice9_SetTextureStageState(pD3DDev9, tu, D3DTSS_COLORARG1, D3DTA_TEXTURE);
@ -631,7 +627,7 @@ static void SelectPassTexture(unsigned int tu, shaderpass_t *pass)
IDirect3DDevice9_SetTextureStageState(pD3DDev9, tu, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); IDirect3DDevice9_SetTextureStageState(pD3DDev9, tu, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
break; break;
default: default:
case GL_MODULATE: case PBM_MODULATE:
forcemod: forcemod:
IDirect3DDevice9_SetTextureStageState(pD3DDev9, tu, D3DTSS_COLORARG1, D3DTA_TEXTURE); IDirect3DDevice9_SetTextureStageState(pD3DDev9, tu, D3DTSS_COLORARG1, D3DTA_TEXTURE);
IDirect3DDevice9_SetTextureStageState(pD3DDev9, tu, D3DTSS_COLORARG2, D3DTA_CURRENT); IDirect3DDevice9_SetTextureStageState(pD3DDev9, tu, D3DTSS_COLORARG2, D3DTA_CURRENT);

View file

@ -2187,6 +2187,7 @@ static void DrawPass(const shaderpass_t *pass)
tmu = 0; tmu = 0;
for (; i < lastpass; i++) for (; i < lastpass; i++)
{ {
extern cvar_t gl_overbright;
if (pass[i].texgen == T_GEN_UPPEROVERLAY && !TEXVALID(shaderstate.curtexnums->upperoverlay)) if (pass[i].texgen == T_GEN_UPPEROVERLAY && !TEXVALID(shaderstate.curtexnums->upperoverlay))
continue; continue;
if (pass[i].texgen == T_GEN_LOWEROVERLAY && !TEXVALID(shaderstate.curtexnums->loweroverlay)) if (pass[i].texgen == T_GEN_LOWEROVERLAY && !TEXVALID(shaderstate.curtexnums->loweroverlay))
@ -2199,25 +2200,36 @@ static void DrawPass(const shaderpass_t *pass)
switch (pass[i].blendmode) switch (pass[i].blendmode)
{ {
case GL_DOT3_RGB_ARB: case PBM_DOTPRODUCT:
GL_TexEnv(GL_COMBINE_EXT); GL_TexEnv(GL_COMBINE_ARB);
qglTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE); qglTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
qglTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB); qglTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB);
qglTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, pass[i].blendmode); qglTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_DOT3_RGB_ARB);
qglTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 1);
break; break;
case GL_REPLACE: case PBM_REPLACE:
GL_TexEnv(GL_REPLACE); GL_TexEnv(GL_REPLACE);
break; break;
case GL_DECAL: case PBM_DECAL:
case GL_ADD: if (tmu == 0)
if (tmu != 0) goto forcemod;
{ GL_TexEnv(GL_DECAL);
GL_TexEnv(pass[i].blendmode); break;
break; case PBM_ADD:
} if (tmu == 0)
//fallthrough goto forcemod;
GL_TexEnv(GL_ADD);
break;
case PBM_OVERBRIGHT:
GL_TexEnv(GL_COMBINE_ARB);
qglTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
qglTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB);
qglTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
qglTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, gl_overbright.value+1);
break;
default: default:
case GL_MODULATE: case PBM_MODULATE:
forcemod:
GL_TexEnv(GL_MODULATE); GL_TexEnv(GL_MODULATE);
break; break;
} }

View file

@ -31,13 +31,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <ctype.h> #include <ctype.h>
#ifndef GLQUAKE
/*the shaders have a few GL_FOO constants in them. they shouldn't, but they do.*/
#include <GL/gl.h>
#include "glsupp.h"
#endif
extern texid_t missing_texture; extern texid_t missing_texture;
static qboolean shader_reload_needed; static qboolean shader_reload_needed;
static qboolean shader_rescan_needed; static qboolean shader_rescan_needed;
@ -2558,13 +2551,13 @@ void Shader_SetBlendmode (shaderpass_t *pass)
{ {
if (pass->texgen == T_GEN_DELUXMAP) if (pass->texgen == T_GEN_DELUXMAP)
{ {
pass->blendmode = GL_DOT3_RGB_ARB; pass->blendmode = PBM_DOTPRODUCT;
return; return;
} }
if (pass->texgen < T_GEN_DIFFUSE && !TEXVALID(pass->anim_frames[0]) && !(pass->flags & SHADER_PASS_LIGHTMAP)) if (pass->texgen < T_GEN_DIFFUSE && !TEXVALID(pass->anim_frames[0]) && !(pass->flags & SHADER_PASS_LIGHTMAP))
{ {
pass->blendmode = GL_MODULATE; pass->blendmode = PBM_MODULATE;
return; return;
} }
@ -2572,7 +2565,7 @@ void Shader_SetBlendmode (shaderpass_t *pass)
{ {
if ((pass->rgbgen == RGB_GEN_IDENTITY) && (pass->alphagen == ALPHA_GEN_IDENTITY)) if ((pass->rgbgen == RGB_GEN_IDENTITY) && (pass->alphagen == ALPHA_GEN_IDENTITY))
{ {
pass->blendmode = GL_REPLACE; pass->blendmode = PBM_REPLACE;
} }
else else
{ {
@ -2580,20 +2573,20 @@ void Shader_SetBlendmode (shaderpass_t *pass)
pass->shaderbits &= ~SBITS_BLEND_BITS; pass->shaderbits &= ~SBITS_BLEND_BITS;
pass->shaderbits |= SBITS_SRCBLEND_ONE; pass->shaderbits |= SBITS_SRCBLEND_ONE;
pass->shaderbits |= SBITS_DSTBLEND_ZERO; pass->shaderbits |= SBITS_DSTBLEND_ZERO;
pass->blendmode = GL_MODULATE; pass->blendmode = PBM_MODULATE;
} }
return; return;
} }
if (((pass->shaderbits&SBITS_BLEND_BITS) == (SBITS_SRCBLEND_ZERO|SBITS_DSTBLEND_SRC_COLOR)) || if (((pass->shaderbits&SBITS_BLEND_BITS) == (SBITS_SRCBLEND_ZERO|SBITS_DSTBLEND_SRC_COLOR)) ||
((pass->shaderbits&SBITS_BLEND_BITS) == (SBITS_SRCBLEND_DST_COLOR|SBITS_DSTBLEND_ZERO))) ((pass->shaderbits&SBITS_BLEND_BITS) == (SBITS_SRCBLEND_DST_COLOR|SBITS_DSTBLEND_ZERO)))
pass->blendmode = GL_MODULATE; pass->blendmode = PBM_MODULATE;
else if ((pass->shaderbits&SBITS_BLEND_BITS) == (SBITS_SRCBLEND_ONE|SBITS_DSTBLEND_ONE)) else if ((pass->shaderbits&SBITS_BLEND_BITS) == (SBITS_SRCBLEND_ONE|SBITS_DSTBLEND_ONE))
pass->blendmode = GL_ADD; pass->blendmode = PBM_ADD;
else if ((pass->shaderbits&SBITS_BLEND_BITS) == (SBITS_SRCBLEND_SRC_ALPHA|SBITS_DSTBLEND_ONE_MINUS_SRC_ALPHA)) else if ((pass->shaderbits&SBITS_BLEND_BITS) == (SBITS_SRCBLEND_SRC_ALPHA|SBITS_DSTBLEND_ONE_MINUS_SRC_ALPHA))
pass->blendmode = GL_DECAL; pass->blendmode = PBM_DECAL;
else else
pass->blendmode = GL_MODULATE; pass->blendmode = PBM_MODULATE;
} }
void Shader_Readpass (shader_t *shader, char **ptr) void Shader_Readpass (shader_t *shader, char **ptr)
@ -2765,31 +2758,37 @@ void Shader_SetPassFlush (shaderpass_t *pass, shaderpass_t *pass2)
return; return;
// check if we can use multiple passes // check if we can use multiple passes
if (pass2->blendmode == GL_DOT3_RGB_ARB) if (pass2->blendmode == PBM_DOTPRODUCT)
{ {
pass->numMergedPasses++; pass->numMergedPasses++;
} }
else if (pass->numMergedPasses < be_maxpasses) else if (pass->numMergedPasses < be_maxpasses)
{ {
if ( pass->blendmode == GL_REPLACE ) if ( pass->blendmode == PBM_REPLACE )
{ {
if ((pass2->blendmode == GL_DECAL && config_tex_env_combine) || if ((pass2->blendmode == PBM_DECAL && config_tex_env_combine) ||
(pass2->blendmode == GL_ADD && config_env_add) || (pass2->blendmode == PBM_ADD && config_env_add) ||
(pass2->blendmode && pass2->blendmode != GL_ADD) || config_nv_tex_env_combine4) (pass2->blendmode && pass2->blendmode != PBM_ADD) || config_nv_tex_env_combine4)
{ {
pass->numMergedPasses++; pass->numMergedPasses++;
} }
} }
else if (pass->blendmode == GL_ADD && else if (pass->blendmode == PBM_ADD &&
pass2->blendmode == GL_ADD && config_env_add) pass2->blendmode == PBM_ADD && config_env_add)
{ {
pass->numMergedPasses++; pass->numMergedPasses++;
} }
else if (pass->blendmode == GL_MODULATE && pass2->blendmode == GL_MODULATE) else if (pass->blendmode == PBM_MODULATE && pass2->blendmode == PBM_MODULATE)
{ {
pass->numMergedPasses++; pass->numMergedPasses++;
} }
else
return;
} }
else return;
if (pass2->texgen == T_GEN_LIGHTMAP)
pass2->blendmode = PBM_OVERBRIGHT;
} }
void Shader_SetFeatures ( shader_t *s ) void Shader_SetFeatures ( shader_t *s )
@ -4036,7 +4035,7 @@ void Shader_DoReload(void)
COM_EnumerateFiles("materials/*.mtr", Shader_InitCallback, NULL); COM_EnumerateFiles("materials/*.mtr", Shader_InitCallback, NULL);
COM_EnumerateFiles("shaders/*.shader", Shader_InitCallback, NULL); COM_EnumerateFiles("shaders/*.shader", Shader_InitCallback, NULL);
COM_EnumerateFiles("scripts/*.shader", Shader_InitCallback, NULL); COM_EnumerateFiles("scripts/*.shader", Shader_InitCallback, NULL);
//COM_EnumerateFiles("scripts/*.rscript", Shader_InitCallback, NULL); COM_EnumerateFiles("scripts/*.rscript", Shader_InitCallback, NULL);
shader_reload_needed = true; shader_reload_needed = true;
shader_rescan_needed = false; shader_rescan_needed = false;

View file

@ -143,7 +143,14 @@ typedef struct shaderpass_s {
unsigned int shaderbits; unsigned int shaderbits;
unsigned int blendmode; enum {
PBM_MODULATE,
PBM_OVERBRIGHT,
PBM_DECAL,
PBM_ADD,
PBM_DOTPRODUCT,
PBM_REPLACE
} blendmode;
enum { enum {
RGB_GEN_WAVE, RGB_GEN_WAVE,