mirror of
https://github.com/ZDoom/Raze.git
synced 2024-11-16 01:11:44 +00:00
Detail map material bit.
git-svn-id: https://svn.eduke32.com/eduke32@1168 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
f0c5278293
commit
b50b229c1d
4 changed files with 147 additions and 40 deletions
|
@ -43,6 +43,15 @@ extern int pr_gpusmoothing;
|
||||||
extern int glerror;
|
extern int glerror;
|
||||||
|
|
||||||
// MATERIAL
|
// MATERIAL
|
||||||
|
typedef enum {
|
||||||
|
PR_BIT_ANIM_INTERPOLATION,
|
||||||
|
PR_BIT_DIFFUSE_MAP,
|
||||||
|
PR_BIT_DIFFUSE_DETAIL_MAP,
|
||||||
|
PR_BIT_DIFFUSE_MODULATION,
|
||||||
|
PR_BIT_DEFAULT, // must be just before last
|
||||||
|
PR_BIT_COUNT // must be last
|
||||||
|
} prbittype;
|
||||||
|
|
||||||
typedef struct s_prmaterial {
|
typedef struct s_prmaterial {
|
||||||
// PR_BIT_ANIM_INTERPOLATION
|
// PR_BIT_ANIM_INTERPOLATION
|
||||||
GLfloat frameprogress;
|
GLfloat frameprogress;
|
||||||
|
@ -50,11 +59,37 @@ typedef struct s_prmaterial {
|
||||||
GLsizei nextframedatastride;
|
GLsizei nextframedatastride;
|
||||||
// PR_BIT_DIFFUSE_MAP
|
// PR_BIT_DIFFUSE_MAP
|
||||||
GLuint diffusemap;
|
GLuint diffusemap;
|
||||||
GLfloat diffusescalex, diffusescaley;
|
GLfloat diffusescale[2];
|
||||||
|
// PR_BIT_DIFFUSE_DETAIL_MAP
|
||||||
|
GLuint detailmap;
|
||||||
|
GLfloat detailscale[2];
|
||||||
// PR_BIT_DIFFUSE_MODULATION
|
// PR_BIT_DIFFUSE_MODULATION
|
||||||
GLfloat diffusemodulation[4];
|
GLfloat diffusemodulation[4];
|
||||||
} _prmaterial;
|
} _prmaterial;
|
||||||
|
|
||||||
|
typedef struct s_prrograminfo {
|
||||||
|
GLhandleARB handle;
|
||||||
|
// PR_BIT_ANIM_INTERPOLATION
|
||||||
|
GLint attrib_nextFrameData;
|
||||||
|
GLint uniform_frameProgress;
|
||||||
|
// PR_BIT_DIFFUSE_MAP
|
||||||
|
GLint uniform_diffuseMap;
|
||||||
|
GLint uniform_diffuseScale;
|
||||||
|
// PR_BIT_DIFFUSE_DETAIL_MAP
|
||||||
|
GLint uniform_detailMap;
|
||||||
|
GLint uniform_detailScale;
|
||||||
|
} _prprograminfo;
|
||||||
|
|
||||||
|
#define PR_INFO_LOG_BUFFER_SIZE 512
|
||||||
|
|
||||||
|
typedef struct s_prprogrambit {
|
||||||
|
int bit;
|
||||||
|
char* vert_def;
|
||||||
|
char* vert_prog;
|
||||||
|
char* frag_def;
|
||||||
|
char* frag_prog;
|
||||||
|
} _prprogrambit;
|
||||||
|
|
||||||
// BUILD DATA
|
// BUILD DATA
|
||||||
typedef struct s_prplane {
|
typedef struct s_prplane {
|
||||||
// geometry
|
// geometry
|
||||||
|
@ -135,30 +170,6 @@ typedef struct s_prlight {
|
||||||
} _prlight;
|
} _prlight;
|
||||||
|
|
||||||
// PROGRAMS
|
// PROGRAMS
|
||||||
#define PR_INFO_LOG_BUFFER_SIZE 512
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
PR_BIT_ANIM_INTERPOLATION,
|
|
||||||
PR_BIT_DIFFUSE_MAP,
|
|
||||||
PR_BIT_DIFFUSE_MODULATION,
|
|
||||||
PR_BIT_DEFAULT, // must be just before last
|
|
||||||
PR_BIT_COUNT // must be last
|
|
||||||
} prbittype;
|
|
||||||
|
|
||||||
typedef struct s_prprogrambit {
|
|
||||||
int bit;
|
|
||||||
char* vert_def;
|
|
||||||
char* vert_prog;
|
|
||||||
char* frag_def;
|
|
||||||
char* frag_prog;
|
|
||||||
} _prprogrambit;
|
|
||||||
|
|
||||||
typedef struct s_prrograminfo {
|
|
||||||
GLhandleARB handle;
|
|
||||||
// PR_BIT_ANIM_INTERPOLATION
|
|
||||||
GLint attrib_nextFrameData;
|
|
||||||
GLint uniform_frameProgress;
|
|
||||||
} _prprograminfo;
|
|
||||||
|
|
||||||
// CONTROL
|
// CONTROL
|
||||||
extern int updatesectors;
|
extern int updatesectors;
|
||||||
|
|
|
@ -34,6 +34,7 @@ typedef struct pthtyp_t
|
||||||
char *palmap;int size;
|
char *palmap;int size;
|
||||||
} pthtyp;
|
} pthtyp;
|
||||||
|
|
||||||
|
hicreplctyp * hicfindsubst(int picnum, int palnum, int skybox);
|
||||||
pthtyp * gltexcache (int dapicnum, int dapalnum, int dameth);
|
pthtyp * gltexcache (int dapicnum, int dapalnum, int dameth);
|
||||||
|
|
||||||
extern palette_t hictinting[MAXPALOOKUPS];
|
extern palette_t hictinting[MAXPALOOKUPS];
|
||||||
|
|
|
@ -28,7 +28,7 @@ static char hicfirstinit = 0;
|
||||||
//
|
//
|
||||||
// find the index into hicreplc[] which contains the replacement tile particulars
|
// find the index into hicreplc[] which contains the replacement tile particulars
|
||||||
//
|
//
|
||||||
static hicreplctyp * hicfindsubst(int picnum, int palnum, int skybox)
|
hicreplctyp * hicfindsubst(int picnum, int palnum, int skybox)
|
||||||
{
|
{
|
||||||
hicreplctyp *hr;
|
hicreplctyp *hr;
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ int pr_verbosity = 1; // 0: silent, 1: errors and one-times, 2
|
||||||
int pr_wireframe = 0;
|
int pr_wireframe = 0;
|
||||||
int pr_vbos = 2;
|
int pr_vbos = 2;
|
||||||
int pr_mirrordepth = 1;
|
int pr_mirrordepth = 1;
|
||||||
int pr_gpusmoothing = 0;
|
int pr_gpusmoothing = 1;
|
||||||
|
|
||||||
int glerror;
|
int glerror;
|
||||||
|
|
||||||
|
@ -147,9 +147,10 @@ _prprogrambit prprogrambits[PR_BIT_COUNT] = {
|
||||||
{
|
{
|
||||||
1 << PR_BIT_DIFFUSE_MAP,
|
1 << PR_BIT_DIFFUSE_MAP,
|
||||||
// vert_def
|
// vert_def
|
||||||
"",
|
"uniform vec2 diffuseScale;\n"
|
||||||
|
"\n",
|
||||||
// vert_prog
|
// vert_prog
|
||||||
"gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;\n"
|
"gl_TexCoord[0] = vec4(diffuseScale, 1.0, 1.0) * gl_MultiTexCoord0;\n"
|
||||||
"\n",
|
"\n",
|
||||||
// frag_def
|
// frag_def
|
||||||
"uniform sampler2D diffuseMap;\n"
|
"uniform sampler2D diffuseMap;\n"
|
||||||
|
@ -158,6 +159,22 @@ _prprogrambit prprogrambits[PR_BIT_COUNT] = {
|
||||||
" result *= texture2D(diffuseMap, gl_TexCoord[0].st);\n"
|
" result *= texture2D(diffuseMap, gl_TexCoord[0].st);\n"
|
||||||
"\n",
|
"\n",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
1 << PR_BIT_DIFFUSE_DETAIL_MAP,
|
||||||
|
// vert_def
|
||||||
|
"uniform vec2 detailScale;\n"
|
||||||
|
"\n",
|
||||||
|
// vert_prog
|
||||||
|
"gl_TexCoord[1] = vec4(detailScale, 1.0, 1.0) * gl_MultiTexCoord0;\n"
|
||||||
|
"\n",
|
||||||
|
// frag_def
|
||||||
|
"uniform sampler2D detailMap;\n"
|
||||||
|
"\n",
|
||||||
|
// frag_prog
|
||||||
|
" result *= texture2D(detailMap, gl_TexCoord[1].st);\n"
|
||||||
|
" result.rgb *= 2.0;\n"
|
||||||
|
"\n",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
1 << PR_BIT_DIFFUSE_MODULATION,
|
1 << PR_BIT_DIFFUSE_MODULATION,
|
||||||
// vert_def
|
// vert_def
|
||||||
|
@ -610,10 +627,10 @@ void polymer_drawsprite(int snum)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((tspr->cstat & 4) || (((tspr->cstat>>4) & 3) == 2))
|
if ((tspr->cstat & 4) || (((tspr->cstat>>4) & 3) == 2))
|
||||||
spriteplane.material.diffusescalex = -spriteplane.material.diffusescalex;
|
spriteplane.material.diffusescale[0] = -spriteplane.material.diffusescale[0];
|
||||||
|
|
||||||
if (tspr->cstat & 8)
|
if (tspr->cstat & 8)
|
||||||
spriteplane.material.diffusescaley = -spriteplane.material.diffusescaley;
|
spriteplane.material.diffusescale[1] = -spriteplane.material.diffusescale[1];
|
||||||
|
|
||||||
if ((tspr->cstat & 64) && (((tspr->cstat>>4) & 3) == 1))
|
if ((tspr->cstat & 64) && (((tspr->cstat>>4) & 3) == 1))
|
||||||
bglEnable(GL_CULL_FACE);
|
bglEnable(GL_CULL_FACE);
|
||||||
|
@ -2221,18 +2238,22 @@ static void polymer_drawskybox(short tilenum)
|
||||||
static void polymer_drawmdsprite(spritetype *tspr)
|
static void polymer_drawmdsprite(spritetype *tspr)
|
||||||
{
|
{
|
||||||
md3model* m;
|
md3model* m;
|
||||||
|
mdskinmap_t* sk;
|
||||||
|
md3xyzn_t *v0, *v1;
|
||||||
|
md3surf_t *s;
|
||||||
|
char lpal;
|
||||||
float spos[3];
|
float spos[3];
|
||||||
float ang;
|
float ang;
|
||||||
float scale;
|
float scale;
|
||||||
int surfi;
|
int surfi;
|
||||||
GLfloat* color;
|
GLfloat* color;
|
||||||
md3xyzn_t *v0, *v1;
|
|
||||||
md3surf_t *s;
|
|
||||||
int materialbits;
|
int materialbits;
|
||||||
|
|
||||||
m = (md3model*)models[tile2model[Ptile2tile(tspr->picnum,sprite[tspr->owner].pal)].modelid];
|
m = (md3model*)models[tile2model[Ptile2tile(tspr->picnum,sprite[tspr->owner].pal)].modelid];
|
||||||
updateanimation((md2model *)m,tspr);
|
updateanimation((md2model *)m,tspr);
|
||||||
|
|
||||||
|
lpal = (tspr->owner >= MAXSPRITES) ? tspr->pal : sprite[tspr->owner].pal;
|
||||||
|
|
||||||
if ((pr_vbos > 1) && (m->indices == NULL))
|
if ((pr_vbos > 1) && (m->indices == NULL))
|
||||||
polymer_loadmodelvbos(m);
|
polymer_loadmodelvbos(m);
|
||||||
|
|
||||||
|
@ -2322,6 +2343,15 @@ static void polymer_drawmdsprite(spritetype *tspr)
|
||||||
if (!mdspritematerial.diffusemap)
|
if (!mdspritematerial.diffusemap)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
mdspritematerial.detailmap =
|
||||||
|
mdloadskin((md2model *)m,tile2model[Ptile2tile(tspr->picnum,lpal)].skinnum,DETAILPAL,surfi);
|
||||||
|
|
||||||
|
for (sk = m->skinmap; sk; sk = sk->next)
|
||||||
|
if ((int)sk->palette == DETAILPAL &&
|
||||||
|
sk->skinnum == tile2model[Ptile2tile(tspr->picnum,lpal)].skinnum &&
|
||||||
|
sk->surfnum == surfi)
|
||||||
|
mdspritematerial.detailscale[0] = mdspritematerial.detailscale[1] = sk->param;
|
||||||
|
|
||||||
if (pr_vbos > 1)
|
if (pr_vbos > 1)
|
||||||
{
|
{
|
||||||
bglBindBufferARB(GL_ARRAY_BUFFER_ARB, m->texcoords[surfi]);
|
bglBindBufferARB(GL_ARRAY_BUFFER_ARB, m->texcoords[surfi]);
|
||||||
|
@ -2416,7 +2446,10 @@ static void polymer_getscratchmaterial(_prmaterial* material)
|
||||||
material->nextframedatastride = 0;
|
material->nextframedatastride = 0;
|
||||||
// PR_BIT_DIFFUSE_MAP
|
// PR_BIT_DIFFUSE_MAP
|
||||||
material->diffusemap = 0;
|
material->diffusemap = 0;
|
||||||
material->diffusescalex = material->diffusescaley = 1.0f;
|
material->diffusescale[0] = material->diffusescale[1] = 1.0f;
|
||||||
|
// PR_BIT_DIFFUSE_DETAIL_MAP
|
||||||
|
material->detailmap = 0;
|
||||||
|
material->detailscale[0] = material->detailscale[1] = 1.0f;
|
||||||
// PR_BIT_DIFFUSE_MODULATION
|
// PR_BIT_DIFFUSE_MODULATION
|
||||||
material->diffusemodulation[0] =
|
material->diffusemodulation[0] =
|
||||||
material->diffusemodulation[1] =
|
material->diffusemodulation[1] =
|
||||||
|
@ -2427,12 +2460,15 @@ static void polymer_getscratchmaterial(_prmaterial* material)
|
||||||
static void polymer_getbuildmaterial(_prmaterial* material, short tilenum, char pal, signed char shade)
|
static void polymer_getbuildmaterial(_prmaterial* material, short tilenum, char pal, signed char shade)
|
||||||
{
|
{
|
||||||
pthtyp* pth;
|
pthtyp* pth;
|
||||||
|
pthtyp* detailpth;
|
||||||
|
|
||||||
polymer_getscratchmaterial(material);
|
polymer_getscratchmaterial(material);
|
||||||
|
|
||||||
|
// PR_BIT_DIFFUSE_MAP
|
||||||
if (!waloff[tilenum])
|
if (!waloff[tilenum])
|
||||||
loadtile(tilenum);
|
loadtile(tilenum);
|
||||||
|
|
||||||
|
pth = NULL;
|
||||||
pth = gltexcache(tilenum, pal, 0);
|
pth = gltexcache(tilenum, pal, 0);
|
||||||
|
|
||||||
if (pth)
|
if (pth)
|
||||||
|
@ -2440,10 +2476,33 @@ static void polymer_getbuildmaterial(_prmaterial* material, short tilenu
|
||||||
|
|
||||||
if (pth->hicr)
|
if (pth->hicr)
|
||||||
{
|
{
|
||||||
material->diffusescalex = pth->hicr->xscale;
|
material->diffusescale[0] = pth->hicr->xscale;
|
||||||
material->diffusescaley = pth->hicr->yscale;
|
material->diffusescale[1] = pth->hicr->yscale;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PR_BIT_DIFFUSE_DETAIL_MAP
|
||||||
|
if (r_detailmapping && hicfindsubst(tilenum, DETAILPAL, 0))
|
||||||
|
{
|
||||||
|
detailpth = NULL;
|
||||||
|
detailpth = gltexcache(tilenum, DETAILPAL, 0);
|
||||||
|
|
||||||
|
if (detailpth && (detailpth->hicr->palnum == DETAILPAL))
|
||||||
|
{
|
||||||
|
material->detailmap = detailpth->glpic;
|
||||||
|
|
||||||
|
material->detailscale[0] = detailpth->hicr->xscale;
|
||||||
|
material->detailscale[1] = detailpth->hicr->yscale;
|
||||||
|
|
||||||
|
// scale by the diffuse map scale if there's one defined
|
||||||
|
if (pth->hicr)
|
||||||
|
{
|
||||||
|
material->detailscale[0] *= material->diffusescale[0];
|
||||||
|
material->detailscale[1] *= material->diffusescale[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// PR_BIT_DIFFUSE_MODULATION
|
||||||
material->diffusemodulation[0] =
|
material->diffusemodulation[0] =
|
||||||
material->diffusemodulation[1] =
|
material->diffusemodulation[1] =
|
||||||
material->diffusemodulation[2] =
|
material->diffusemodulation[2] =
|
||||||
|
@ -2460,6 +2519,7 @@ static void polymer_getbuildmaterial(_prmaterial* material, short tilenu
|
||||||
static int polymer_bindmaterial(_prmaterial material)
|
static int polymer_bindmaterial(_prmaterial material)
|
||||||
{
|
{
|
||||||
int programbits;
|
int programbits;
|
||||||
|
int texunit;
|
||||||
|
|
||||||
programbits = prprogrambits[PR_BIT_DEFAULT].bit;
|
programbits = prprogrambits[PR_BIT_DEFAULT].bit;
|
||||||
|
|
||||||
|
@ -2473,6 +2533,10 @@ static int polymer_bindmaterial(_prmaterial material)
|
||||||
if (material.diffusemap)
|
if (material.diffusemap)
|
||||||
programbits |= prprogrambits[PR_BIT_DIFFUSE_MAP].bit;
|
programbits |= prprogrambits[PR_BIT_DIFFUSE_MAP].bit;
|
||||||
|
|
||||||
|
// PR_BIT_DIFFUSE_DETAIL_MAP
|
||||||
|
if (material.detailmap)
|
||||||
|
programbits |= prprogrambits[PR_BIT_DIFFUSE_DETAIL_MAP].bit;
|
||||||
|
|
||||||
// PR_BIT_DIFFUSE_MODULATION
|
// PR_BIT_DIFFUSE_MODULATION
|
||||||
if ((material.diffusemodulation[0] != 1.0f) || (material.diffusemodulation[1] != 1.0f) ||
|
if ((material.diffusemodulation[0] != 1.0f) || (material.diffusemodulation[1] != 1.0f) ||
|
||||||
(material.diffusemodulation[2] != 1.0f) || (material.diffusemodulation[3] != 1.0f))
|
(material.diffusemodulation[2] != 1.0f) || (material.diffusemodulation[3] != 1.0f))
|
||||||
|
@ -2486,6 +2550,8 @@ static int polymer_bindmaterial(_prmaterial material)
|
||||||
|
|
||||||
// --------- bit setup
|
// --------- bit setup
|
||||||
|
|
||||||
|
texunit = 0;
|
||||||
|
|
||||||
// PR_BIT_ANIM_INTERPOLATION
|
// PR_BIT_ANIM_INTERPOLATION
|
||||||
if (programbits & prprogrambits[PR_BIT_ANIM_INTERPOLATION].bit)
|
if (programbits & prprogrambits[PR_BIT_ANIM_INTERPOLATION].bit)
|
||||||
{
|
{
|
||||||
|
@ -2501,12 +2567,25 @@ static int polymer_bindmaterial(_prmaterial material)
|
||||||
// PR_BIT_DIFFUSE_MAP
|
// PR_BIT_DIFFUSE_MAP
|
||||||
if (programbits & prprogrambits[PR_BIT_DIFFUSE_MAP].bit)
|
if (programbits & prprogrambits[PR_BIT_DIFFUSE_MAP].bit)
|
||||||
{
|
{
|
||||||
|
bglActiveTextureARB(texunit + GL_TEXTURE0_ARB);
|
||||||
bglBindTexture(GL_TEXTURE_2D, material.diffusemap);
|
bglBindTexture(GL_TEXTURE_2D, material.diffusemap);
|
||||||
|
|
||||||
bglMatrixMode(GL_TEXTURE);
|
bglUniform1iARB(prprograms[programbits].uniform_diffuseMap, texunit);
|
||||||
bglLoadIdentity();
|
bglUniform2fvARB(prprograms[programbits].uniform_diffuseScale, 1, material.diffusescale);
|
||||||
bglScalef(material.diffusescalex, material.diffusescaley, 1.0f);
|
|
||||||
bglMatrixMode(GL_MODELVIEW);
|
texunit++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// PR_BIT_DIFFUSE_DETAIL_MAP
|
||||||
|
if (programbits & prprogrambits[PR_BIT_DIFFUSE_DETAIL_MAP].bit)
|
||||||
|
{
|
||||||
|
bglActiveTextureARB(texunit + GL_TEXTURE0_ARB);
|
||||||
|
bglBindTexture(GL_TEXTURE_2D, material.detailmap);
|
||||||
|
|
||||||
|
bglUniform1iARB(prprograms[programbits].uniform_detailMap, texunit);
|
||||||
|
bglUniform2fvARB(prprograms[programbits].uniform_detailScale, 1, material.detailscale);
|
||||||
|
|
||||||
|
texunit++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// PR_BIT_DIFFUSE_MODULATION
|
// PR_BIT_DIFFUSE_MODULATION
|
||||||
|
@ -2518,6 +2597,8 @@ static int polymer_bindmaterial(_prmaterial material)
|
||||||
material.diffusemodulation[3]);
|
material.diffusemodulation[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bglActiveTextureARB(GL_TEXTURE0_ARB);
|
||||||
|
|
||||||
return (programbits);
|
return (programbits);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2607,6 +2688,20 @@ static void polymer_compileprogram(int programbits)
|
||||||
prprograms[programbits].attrib_nextFrameData = bglGetAttribLocationARB(program, "nextFrameData");
|
prprograms[programbits].attrib_nextFrameData = bglGetAttribLocationARB(program, "nextFrameData");
|
||||||
prprograms[programbits].uniform_frameProgress = bglGetUniformLocationARB(program, "frameProgress");
|
prprograms[programbits].uniform_frameProgress = bglGetUniformLocationARB(program, "frameProgress");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PR_BIT_DIFFUSE_MAP
|
||||||
|
if (programbits & prprogrambits[PR_BIT_DIFFUSE_MAP].bit)
|
||||||
|
{
|
||||||
|
prprograms[programbits].uniform_diffuseMap = bglGetUniformLocationARB(program, "diffuseMap");
|
||||||
|
prprograms[programbits].uniform_diffuseScale = bglGetUniformLocationARB(program, "diffuseScale");
|
||||||
|
}
|
||||||
|
|
||||||
|
// PR_BIT_DIFFUSE_DETAIL_MAP
|
||||||
|
if (programbits & prprogrambits[PR_BIT_DIFFUSE_DETAIL_MAP].bit)
|
||||||
|
{
|
||||||
|
prprograms[programbits].uniform_detailMap = bglGetUniformLocationARB(program, "detailMap");
|
||||||
|
prprograms[programbits].uniform_detailScale = bglGetUniformLocationARB(program, "detailScale");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue