2003-10-01 21:01:41 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 2001-2002 Charles Hollemeersch
|
|
|
|
Copyright (C) 2003 Jarno Paananen
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
PENTA: the whole file is freakin penta...
|
|
|
|
|
|
|
|
Generic bumpmapping with some Geforce optimizations
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "quakedef.h"
|
|
|
|
|
2003-11-02 19:51:39 +00:00
|
|
|
static cvar_t sh_fakespecular = {"sh_fakespecular","1", true};
|
2003-10-01 21:01:41 +00:00
|
|
|
|
|
|
|
//#define GENDEBUG
|
|
|
|
|
|
|
|
#if defined(GENDEBUG) && defined(_WIN32)
|
|
|
|
static void generic_checkerror()
|
|
|
|
{
|
|
|
|
GLuint error = glGetError();
|
|
|
|
if ( error != GL_NO_ERROR )
|
|
|
|
{
|
|
|
|
_asm { int 3 };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
|
|
|
|
#define generic_checkerror() do { } while(0)
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2003-11-02 19:51:39 +00:00
|
|
|
/************************
|
|
|
|
|
|
|
|
Generic "fragment programs"
|
|
|
|
|
|
|
|
************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
Light attenuation shader
|
|
|
|
*/
|
2004-03-24 00:20:38 +00:00
|
|
|
void GL_EnableGenericAttShader(void)
|
|
|
|
{
|
|
|
|
GL_Bind(glow_texture_object);
|
|
|
|
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
|
|
|
GL_EnableMultitexture();
|
|
|
|
GL_Bind(glow_texture_object);
|
|
|
|
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
2003-11-02 19:51:39 +00:00
|
|
|
}
|
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
void GL_DisableGenericAttShader(void)
|
|
|
|
{
|
|
|
|
GL_DisableMultitexture();
|
2003-11-02 19:51:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Color map modulation shader
|
|
|
|
primary color = light color
|
|
|
|
tu0 = light filter cube map
|
|
|
|
tu1 = material color map
|
|
|
|
*/
|
2004-03-24 00:20:38 +00:00
|
|
|
void GL_EnableGenericColorShader (qboolean specular)
|
|
|
|
{
|
|
|
|
GL_SelectTexture(GL_TEXTURE0_ARB);
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
glEnable(GL_TEXTURE_CUBE_MAP_ARB);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
GL_SelectTexture(GL_TEXTURE0_ARB);
|
|
|
|
glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, currentshadowlight->filtercube);
|
|
|
|
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
|
2003-11-02 19:51:39 +00:00
|
|
|
glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);
|
|
|
|
glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE);
|
|
|
|
glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
|
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
if (!specular)
|
|
|
|
{
|
|
|
|
GL_EnableMultitexture();
|
|
|
|
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
|
|
|
|
glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);
|
|
|
|
glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE);
|
|
|
|
glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GL_EnableMultitexture();
|
|
|
|
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
|
|
|
|
glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);
|
|
|
|
glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE);
|
|
|
|
glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_ALPHA);
|
|
|
|
glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
|
|
|
|
}
|
2003-11-02 19:51:39 +00:00
|
|
|
|
|
|
|
}
|
2003-10-01 21:01:41 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
void GL_DisableGenericColorShader (qboolean specular)
|
|
|
|
{
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
if (!specular)
|
|
|
|
{
|
|
|
|
GL_DisableMultitexture();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
|
|
|
|
GL_DisableMultitexture();
|
|
|
|
}
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
glDisable(GL_TEXTURE_CUBE_MAP_ARB);
|
2003-11-02 19:51:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Diffuse dot product shader
|
|
|
|
|
|
|
|
texture coords for unit 0: Tangent space light vector
|
|
|
|
texture coords for unit 1: Normal map texture coords
|
|
|
|
*/
|
2004-03-24 00:20:38 +00:00
|
|
|
void GL_EnableGenericDiffuseShader(void)
|
|
|
|
{
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
GL_SelectTexture(GL_TEXTURE0_ARB);
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
glEnable(GL_TEXTURE_CUBE_MAP_ARB);
|
|
|
|
glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, normcube_texture_object);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
|
2003-11-02 19:51:39 +00:00
|
|
|
glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
|
|
|
|
glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE);
|
|
|
|
glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE);
|
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
GL_EnableMultitexture();
|
|
|
|
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
|
2003-11-02 19:51:39 +00:00
|
|
|
glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);
|
|
|
|
glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE);
|
|
|
|
glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_DOT3_RGBA_ARB);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
void GL_DisableGenericDiffuseShader (void)
|
|
|
|
{
|
|
|
|
GL_DisableMultitexture();
|
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
glDisable(GL_TEXTURE_CUBE_MAP_ARB);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
|
|
|
}
|
2003-10-01 21:01:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
/************************
|
|
|
|
|
2003-11-02 19:51:39 +00:00
|
|
|
Generic triangle list routines
|
|
|
|
|
2003-10-01 21:01:41 +00:00
|
|
|
*************************/
|
|
|
|
|
|
|
|
void FormatError(); // In gl_bumpgf.c
|
|
|
|
|
2003-11-02 19:51:39 +00:00
|
|
|
/*
|
2003-10-01 21:01:41 +00:00
|
|
|
void Generic_drawTriangleListBump (const vertexdef_t *verts, int *indecies,
|
2003-11-02 19:51:39 +00:00
|
|
|
int numIndecies, shader_t *shader,
|
|
|
|
const transform_t *tr, const lightobject_t *lo)
|
2003-10-01 21:01:41 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
glEnableClientState(GL_VERTEX_ARRAY);
|
2004-03-24 00:20:38 +00:00
|
|
|
GL_VertexPointer(3, GL_FLOAT, verts->vertexstride, verts->vertices);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2003-10-01 21:01:41 +00:00
|
|
|
GL_AddColor();
|
|
|
|
glColor3fv(¤tshadowlight->color[0]);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2003-10-01 21:01:41 +00:00
|
|
|
Generic_EnableBumpShader(tr,currentshadowlight->origin,true, shader);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2003-10-01 21:01:41 +00:00
|
|
|
//bind the correct textures
|
|
|
|
GL_SelectTexture(GL_TEXTURE0_ARB);
|
|
|
|
qglClientActiveTextureARB(GL_TEXTURE0_ARB);
|
|
|
|
if (shader->numbumpstages > 0)
|
2004-03-24 00:20:38 +00:00
|
|
|
GL_BindAdvanced(shader->bumpstages[0].texture[0]);
|
2003-10-01 21:01:41 +00:00
|
|
|
if (!verts->texcoords)
|
2004-03-24 00:20:38 +00:00
|
|
|
FormatError();
|
2003-10-01 21:01:41 +00:00
|
|
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
2004-03-24 00:20:38 +00:00
|
|
|
GL_TexCoordPointer(2, GL_FLOAT, verts->texcoordstride, verts->texcoords);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2003-10-01 21:01:41 +00:00
|
|
|
GL_SelectTexture(GL_TEXTURE1_ARB);
|
|
|
|
qglClientActiveTextureARB(GL_TEXTURE1_ARB);
|
|
|
|
if (shader->numcolorstages > 0)
|
2004-03-24 00:20:38 +00:00
|
|
|
GL_BindAdvanced(shader->colorstages[0].texture[0]);
|
2003-10-01 21:01:41 +00:00
|
|
|
if (!verts->tangents)
|
2004-03-24 00:20:38 +00:00
|
|
|
FormatError();
|
2003-10-01 21:01:41 +00:00
|
|
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
2004-03-24 00:20:38 +00:00
|
|
|
GL_TexCoordPointer(3, GL_FLOAT, verts->tangentstride, verts->tangents);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2003-10-01 21:01:41 +00:00
|
|
|
if (!verts->binormals)
|
2004-03-24 00:20:38 +00:00
|
|
|
FormatError();
|
2003-10-01 21:01:41 +00:00
|
|
|
GL_SelectTexture(GL_TEXTURE2_ARB);
|
|
|
|
qglClientActiveTextureARB(GL_TEXTURE2_ARB);
|
|
|
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
2004-03-24 00:20:38 +00:00
|
|
|
GL_TexCoordPointer(3, GL_FLOAT, verts->binormalstride, verts->binormals);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2003-10-01 21:01:41 +00:00
|
|
|
if (!verts->normals)
|
2004-03-24 00:20:38 +00:00
|
|
|
FormatError();
|
2003-10-01 21:01:41 +00:00
|
|
|
GL_SelectTexture(GL_TEXTURE3_ARB);
|
|
|
|
qglClientActiveTextureARB(GL_TEXTURE3_ARB);
|
|
|
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
2004-03-24 00:20:38 +00:00
|
|
|
GL_TexCoordPointer(3, GL_FLOAT, verts->normalstride, verts->normals);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2003-10-01 21:01:41 +00:00
|
|
|
glDrawElements(GL_TRIANGLES, numIndecies, GL_UNSIGNED_INT, indecies);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2003-10-01 21:01:41 +00:00
|
|
|
qglClientActiveTextureARB(GL_TEXTURE3_ARB);
|
|
|
|
glDisableClientState(GL_VERTEX_ARRAY);
|
|
|
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2003-10-01 21:01:41 +00:00
|
|
|
qglClientActiveTextureARB(GL_TEXTURE2_ARB);
|
|
|
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2003-10-01 21:01:41 +00:00
|
|
|
qglClientActiveTextureARB(GL_TEXTURE1_ARB);
|
|
|
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2003-10-01 21:01:41 +00:00
|
|
|
qglClientActiveTextureARB(GL_TEXTURE0_ARB);
|
|
|
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
|
|
Generic_DisableBumpShader(shader);
|
|
|
|
}
|
2003-11-02 19:51:39 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
static const lightobject_t *currentLo;
|
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
void VertWV(float *pos, float *tex, float *lm, float *tg, float *bn, float*nr)
|
|
|
|
{
|
|
|
|
glTexCoord3fv(pos);
|
|
|
|
qglMultiTexCoord2fvARB(GL_TEXTURE1_ARB, tex);
|
|
|
|
glVertex3fv(pos);
|
2003-11-02 19:51:39 +00:00
|
|
|
}
|
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
void VertTex(float *pos, float *tex, float *lm, float *tg, float *bn, float*nr)
|
|
|
|
{
|
|
|
|
glTexCoord2fv(tex);
|
|
|
|
glVertex3fv(pos);
|
2003-11-02 19:51:39 +00:00
|
|
|
}
|
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
void VertFakeSpecular(float *pos, float *tex, float *lm, float *tg, float *bn, float*nr)
|
|
|
|
{
|
|
|
|
glNormal3fv(nr);
|
|
|
|
glTexCoord3fv(pos);
|
|
|
|
qglMultiTexCoord2fvARB(GL_TEXTURE1_ARB, tex);
|
|
|
|
glVertex3fv(pos);
|
2003-11-02 19:51:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
void VertAtt(float *pos, float *tex, float *lm, float *tg, float *bn, float*nr)
|
|
|
|
{
|
|
|
|
vec3_t nearToVert;
|
|
|
|
float tu, tv, tw;
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
VectorSubtract (pos, currentLo->objectorigin, nearToVert);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
tu = (nearToVert[0]/currentshadowlight->radiusv[0])*0.5+0.5;
|
|
|
|
tv = (nearToVert[1]/currentshadowlight->radiusv[1])*0.5+0.5;
|
|
|
|
tw = (nearToVert[2]/currentshadowlight->radiusv[2])*0.5+0.5;
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
glTexCoord2f(tu, tv);
|
|
|
|
qglMultiTexCoord2fARB(GL_TEXTURE1_ARB, tw, 0.5);
|
|
|
|
glVertex3fv(pos);
|
2003-11-02 19:51:39 +00:00
|
|
|
}
|
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
void VertDiffuse(float *pos, float *tex, float *lm, float *tg, float *bn, float*nr)
|
|
|
|
{
|
|
|
|
vec3_t lightDir, tsLightDir;
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
VectorSubtract(currentLo->objectorigin, pos, lightDir);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
tsLightDir[0] = DotProduct(lightDir,tg);
|
|
|
|
tsLightDir[1] = -DotProduct(lightDir,bn);
|
|
|
|
tsLightDir[2] = DotProduct(lightDir,nr);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
qglMultiTexCoord3fvARB(GL_TEXTURE0_ARB, &tsLightDir[0]);
|
|
|
|
qglMultiTexCoord2fvARB(GL_TEXTURE1_ARB, tex);
|
|
|
|
glVertex3fv(pos);
|
2003-11-02 19:51:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Generic_DrawTriWithFunc(const vertexdef_t *verts, int *indecies,
|
2004-03-24 00:20:38 +00:00
|
|
|
int numIndecies,
|
|
|
|
void (*VertFunc) (float *, float *, float *,
|
|
|
|
float *, float *, float*))
|
2003-11-02 19:51:39 +00:00
|
|
|
{
|
2004-03-24 00:20:38 +00:00
|
|
|
int i;
|
|
|
|
vertexdef_t v = *verts;
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
if (!v.vertexstride) v.vertexstride = 12;
|
|
|
|
if (!v.texcoordstride) v.texcoordstride = 8;
|
|
|
|
if (!v.lightmapstride) v.lightmapstride = 8;
|
|
|
|
if (!v.tangentstride) v.lightmapstride = 12;
|
|
|
|
if (!v.binormalstride) v.binormalstride = 12;
|
|
|
|
if (!v.normalstride) v.normalstride = 12;
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
glBegin(GL_TRIANGLES);
|
|
|
|
for (i=0; i<numIndecies; i++)
|
|
|
|
{
|
|
|
|
int ind = indecies[i];
|
|
|
|
|
|
|
|
VertFunc( (float *)((byte *)v.vertices + ind*v.vertexstride),
|
|
|
|
(float *)((byte *)v.texcoords + ind*v.texcoordstride),
|
|
|
|
(float *)((byte *)v.lightmapcoords + ind*v.lightmapstride),
|
|
|
|
(float *)((byte *)v.tangents + ind*v.tangentstride),
|
|
|
|
(float *)((byte *)v.binormals + ind*v.binormalstride),
|
|
|
|
(float *)((byte *)v.normals + ind*v.normalstride)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
glEnd();
|
2003-11-02 19:51:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Generic_drawTriangleListBump (const vertexdef_t *verts, int *indecies,
|
2004-03-24 00:20:38 +00:00
|
|
|
int numIndecies, shader_t *shader,
|
|
|
|
const transform_t *tr, const lightobject_t *lo)
|
2003-11-02 19:51:39 +00:00
|
|
|
{
|
|
|
|
glDepthMask (0);
|
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
currentLo = lo;
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
//attenuate with projected 2D attenuation map
|
2003-11-02 19:51:39 +00:00
|
|
|
GL_DrawAlpha();
|
|
|
|
GL_EnableGenericAttShader();
|
2004-03-24 00:20:38 +00:00
|
|
|
Generic_DrawTriWithFunc(verts, indecies, numIndecies, VertAtt);
|
2003-11-02 19:51:39 +00:00
|
|
|
GL_DisableGenericAttShader();
|
|
|
|
|
|
|
|
// modulate diffuse bump (n dot l) to alpha
|
|
|
|
GL_ModulateAlphaDrawAlpha();
|
|
|
|
GL_EnableGenericDiffuseShader();
|
2004-03-24 00:20:38 +00:00
|
|
|
if (shader->numbumpstages > 0) {
|
|
|
|
GL_BindAdvanced(shader->bumpstages[0].texture[0]);
|
|
|
|
}
|
|
|
|
Generic_DrawTriWithFunc(verts, indecies, numIndecies, VertDiffuse);
|
2003-11-02 19:51:39 +00:00
|
|
|
GL_DisableGenericDiffuseShader ();
|
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
//Do fake specular
|
|
|
|
if (sh_fakespecular.value)
|
|
|
|
{
|
|
|
|
float black[4] = {0.0, 0.0, 0.0, 1.0};
|
|
|
|
float white[4] = {1.0, 1.0, 1.0, 1.0};
|
|
|
|
float pos[4];
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
GL_ModulateAlphaDrawColor();
|
|
|
|
glColorMask(true, true, true, false);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
glEnable(GL_LIGHTING);
|
|
|
|
glEnable(GL_LIGHT0);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
VectorCopy(lo->objectorigin, pos);
|
|
|
|
pos[3] = 1.0;
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
glLightfv(GL_LIGHT0, GL_POSITION, pos);
|
|
|
|
glLightfv(GL_LIGHT0, GL_DIFFUSE, black);
|
|
|
|
glLightfv(GL_LIGHT0, GL_AMBIENT, black);
|
|
|
|
glLightfv(GL_LIGHT0, GL_SPECULAR, ¤tshadowlight->color[0]);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, white);
|
|
|
|
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 16);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
glEnable(GL_COLOR_MATERIAL);
|
|
|
|
glColor4fv(white);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
GL_EnableGenericColorShader (true);
|
|
|
|
if (shader->numbumpstages > 0)
|
|
|
|
{
|
|
|
|
GL_BindAdvanced(shader->bumpstages[0].texture[0]);
|
2003-11-02 19:51:39 +00:00
|
|
|
}
|
2004-03-24 00:20:38 +00:00
|
|
|
Generic_DrawTriWithFunc(verts, indecies, numIndecies, VertFakeSpecular);
|
|
|
|
GL_DisableGenericColorShader (true);
|
|
|
|
|
|
|
|
glDisable(GL_LIGHTING);
|
|
|
|
}
|
2003-11-02 19:51:39 +00:00
|
|
|
|
|
|
|
// Then modulate Color map and light filter with alpha and add to color
|
2004-03-24 00:20:38 +00:00
|
|
|
GL_ModulateAlphaDrawColor();
|
2003-11-02 19:51:39 +00:00
|
|
|
glColor3fv(¤tshadowlight->color[0]);
|
|
|
|
if ( currentshadowlight->filtercube )
|
|
|
|
{
|
2004-03-24 00:20:38 +00:00
|
|
|
glMatrixMode(GL_TEXTURE);
|
|
|
|
glPushMatrix();
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
GL_SetupCubeMapMatrix(tr);
|
|
|
|
GL_EnableGenericColorShader (false);
|
|
|
|
if (shader->numcolorstages > 0) {
|
|
|
|
GL_BindAdvanced(shader->colorstages[0].texture[0]);
|
|
|
|
}
|
|
|
|
Generic_DrawTriWithFunc(verts, indecies, numIndecies, VertWV);
|
|
|
|
GL_DisableGenericColorShader (false);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
glPopMatrix();
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
2003-11-02 19:51:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-03-24 00:20:38 +00:00
|
|
|
// Just alpha * light color
|
|
|
|
GL_DisableMultitexture();
|
|
|
|
if (shader->numcolorstages > 0)
|
|
|
|
{
|
|
|
|
GL_BindAdvanced(shader->colorstages[0].texture[0]);
|
|
|
|
}
|
|
|
|
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
|
|
|
Generic_DrawTriWithFunc(verts, indecies, numIndecies, VertTex);
|
2003-11-02 19:51:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GL_DrawColor();
|
|
|
|
glColor3f (1,1,1);
|
|
|
|
glDisable (GL_BLEND);
|
|
|
|
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
glDepthMask (1);
|
|
|
|
}
|
2003-10-01 21:01:41 +00:00
|
|
|
|
|
|
|
void Generic_drawTriangleListBase (vertexdef_t *verts, int *indecies,
|
2004-03-24 00:20:38 +00:00
|
|
|
int numIndecies, shader_t *shader,
|
|
|
|
int lightmapIndex)
|
2003-10-01 21:01:41 +00:00
|
|
|
{
|
|
|
|
int i;
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
GL_VertexPointer(3, GL_FLOAT, verts->vertexstride, verts->vertices);
|
2003-10-01 21:01:41 +00:00
|
|
|
glEnableClientState(GL_VERTEX_ARRAY);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2003-10-01 21:01:41 +00:00
|
|
|
GL_SelectTexture(GL_TEXTURE0_ARB);
|
|
|
|
qglClientActiveTextureARB(GL_TEXTURE0_ARB);
|
2004-03-24 00:20:38 +00:00
|
|
|
GL_TexCoordPointer(2, GL_FLOAT, verts->texcoordstride, verts->texcoords);
|
2003-10-01 21:01:41 +00:00
|
|
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2003-10-01 21:01:41 +00:00
|
|
|
if (!shader->cull)
|
|
|
|
{
|
2004-03-24 00:20:38 +00:00
|
|
|
glDisable(GL_CULL_FACE);
|
2003-10-01 21:01:41 +00:00
|
|
|
}
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2003-10-01 21:01:41 +00:00
|
|
|
for ( i = 0; i < shader->numstages; i++)
|
|
|
|
{
|
2004-03-24 00:20:38 +00:00
|
|
|
Generic_SetupSimpleStage(&shader->stages[i]);
|
|
|
|
glDrawElements(GL_TRIANGLES,numIndecies,GL_UNSIGNED_INT,indecies);
|
|
|
|
glPopMatrix();
|
2003-10-01 21:01:41 +00:00
|
|
|
}
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2003-10-01 21:01:41 +00:00
|
|
|
if (verts->lightmapcoords && (lightmapIndex >= 0) && (shader->flags & SURF_PPLIGHT))
|
|
|
|
{
|
2004-03-24 00:20:38 +00:00
|
|
|
if (shader->numstages && shader->numcolorstages)
|
|
|
|
{
|
|
|
|
if (shader->colorstages[0].src_blend >= 0)
|
|
|
|
{
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(shader->colorstages[0].src_blend, shader->colorstages[0].dst_blend);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_ONE, GL_ONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
}
|
2003-10-01 21:01:41 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
if (shader->numcolorstages)
|
|
|
|
{
|
|
|
|
if (shader->colorstages[0].numtextures)
|
|
|
|
GL_BindAdvanced(shader->colorstages[0].texture[0]);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
if (shader->colorstages[0].alphatresh > 0)
|
|
|
|
{
|
|
|
|
glEnable(GL_ALPHA_TEST);
|
|
|
|
glAlphaFunc(GL_GEQUAL, shader->colorstages[0].alphatresh);
|
|
|
|
}
|
|
|
|
}
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
GL_SelectTexture(GL_TEXTURE0_ARB);
|
|
|
|
qglClientActiveTextureARB(GL_TEXTURE0_ARB);
|
|
|
|
GL_TexCoordPointer(2, GL_FLOAT, verts->texcoordstride, verts->texcoords);
|
|
|
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
|
|
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
GL_SelectTexture(GL_TEXTURE1_ARB);
|
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
GL_Bind(lightmap_textures+lightmapIndex);
|
|
|
|
qglClientActiveTextureARB(GL_TEXTURE1_ARB);
|
|
|
|
GL_TexCoordPointer(2, GL_FLOAT, verts->lightmapstride, verts->lightmapcoords);
|
|
|
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
glDrawElements(GL_TRIANGLES,numIndecies,GL_UNSIGNED_INT,indecies);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
GL_SelectTexture(GL_TEXTURE0_ARB);
|
2003-10-01 21:01:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-03-24 00:20:38 +00:00
|
|
|
if (verts->colors && (shader->flags & SURF_PPLIGHT))
|
|
|
|
{
|
|
|
|
GL_ColorPointer(3, GL_UNSIGNED_BYTE, verts->colorstride, verts->colors);
|
|
|
|
glEnableClientState(GL_COLOR_ARRAY);
|
|
|
|
glShadeModel(GL_SMOOTH);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
if (shader->numstages && shader->numcolorstages)
|
|
|
|
{
|
|
|
|
if (shader->colorstages[0].src_blend >= 0)
|
|
|
|
{
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(shader->colorstages[0].src_blend, shader->colorstages[0].dst_blend);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_ONE, GL_ONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
}
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
if (shader->numcolorstages)
|
|
|
|
{
|
|
|
|
if (shader->colorstages[0].numtextures)
|
|
|
|
GL_BindAdvanced(shader->colorstages[0].texture[0]);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
if (shader->colorstages[0].alphatresh > 0)
|
|
|
|
{
|
|
|
|
glEnable(GL_ALPHA_TEST);
|
|
|
|
glAlphaFunc(GL_GEQUAL, shader->colorstages[0].alphatresh);
|
|
|
|
}
|
|
|
|
}
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
glDrawElements(GL_TRIANGLES,numIndecies,GL_UNSIGNED_INT,indecies);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
glDisableClientState(GL_COLOR_ARRAY);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (shader->flags & SURF_PPLIGHT)
|
|
|
|
{
|
|
|
|
glColor3f(0,0,0);
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
glDrawElements(GL_TRIANGLES,numIndecies,GL_UNSIGNED_INT,indecies);
|
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
}
|
|
|
|
}
|
2003-10-01 21:01:41 +00:00
|
|
|
}
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2003-10-01 21:01:41 +00:00
|
|
|
if (!shader->cull)
|
|
|
|
{
|
2004-03-24 00:20:38 +00:00
|
|
|
glEnable(GL_CULL_FACE);
|
|
|
|
//Con_Printf("Cullstuff %s\n",shader->name);
|
2003-10-01 21:01:41 +00:00
|
|
|
}
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2003-10-01 21:01:41 +00:00
|
|
|
qglClientActiveTextureARB(GL_TEXTURE0_ARB);
|
|
|
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
|
|
glDisableClientState(GL_VERTEX_ARRAY);
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
glDisable(GL_ALPHA_TEST);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*************************
|
|
|
|
|
|
|
|
Generic world surfaces routines
|
|
|
|
|
|
|
|
**************************/
|
|
|
|
|
|
|
|
void Generic_sendSurfacesBase(msurface_t **surfs, int numSurfaces,
|
|
|
|
qboolean bindLightmap)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
glpoly_t *p;
|
|
|
|
msurface_t *surf;
|
|
|
|
float *v;
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2003-10-01 21:01:41 +00:00
|
|
|
for ( i = 0; i < numSurfaces; i++)
|
2004-03-24 00:20:38 +00:00
|
|
|
{
|
|
|
|
surf = surfs[i];
|
|
|
|
if (surf->visframe != r_framecount)
|
|
|
|
continue;
|
|
|
|
p = surf->polys;
|
|
|
|
if (bindLightmap)
|
2003-10-01 21:01:41 +00:00
|
|
|
{
|
2004-03-24 00:20:38 +00:00
|
|
|
if (surf->lightmaptexturenum < 0)
|
|
|
|
continue;
|
|
|
|
GL_Bind(lightmap_textures+surf->lightmaptexturenum);
|
|
|
|
}
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
glBegin(GL_TRIANGLES);
|
|
|
|
for (j=0; j<surf->polys->numindecies; j++) {
|
|
|
|
v = (float *)(&cl.worldmodel->userVerts[surf->polys->indecies[j]]);
|
|
|
|
qglMultiTexCoord2fvARB(GL_TEXTURE0_ARB, &v[3]);
|
|
|
|
qglMultiTexCoord3fvARB(GL_TEXTURE1_ARB, &v[5]);
|
|
|
|
glVertex3fv(&v[0]);
|
|
|
|
}
|
|
|
|
glEnd();
|
2003-10-01 21:01:41 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Generic_drawSurfaceListBase (vertexdef_t* verts, msurface_t** surfs,
|
2004-03-24 00:20:38 +00:00
|
|
|
int numSurfaces, shader_t* shader)
|
2003-10-01 21:01:41 +00:00
|
|
|
{
|
|
|
|
int i;
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2003-10-01 21:01:41 +00:00
|
|
|
GL_SelectTexture(GL_TEXTURE0_ARB);
|
|
|
|
glColor3ub(255,255,255);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2003-10-01 21:01:41 +00:00
|
|
|
if (!shader->cull)
|
|
|
|
{
|
2004-03-24 00:20:38 +00:00
|
|
|
glDisable(GL_CULL_FACE);
|
|
|
|
//Con_Printf("Cullstuff %s\n",shader->name);
|
2003-10-01 21:01:41 +00:00
|
|
|
}
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2003-10-01 21:01:41 +00:00
|
|
|
for (i = 0; i < shader->numstages; i++)
|
|
|
|
{
|
2004-03-24 00:20:38 +00:00
|
|
|
Generic_SetupSimpleStage(&shader->stages[i]);
|
|
|
|
Generic_sendSurfacesBase(surfs, numSurfaces, false);
|
|
|
|
glPopMatrix();
|
2003-10-01 21:01:41 +00:00
|
|
|
}
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2003-10-01 21:01:41 +00:00
|
|
|
if (verts->lightmapcoords && (shader->flags & SURF_PPLIGHT))
|
|
|
|
{
|
2004-03-24 00:20:38 +00:00
|
|
|
GL_SelectTexture(GL_TEXTURE1_ARB);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
// Regular lightmapping
|
|
|
|
if (shader->numstages && shader->numcolorstages)
|
|
|
|
{
|
|
|
|
if (shader->colorstages[0].src_blend >= 0)
|
|
|
|
{
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(shader->colorstages[0].src_blend,
|
|
|
|
shader->colorstages[0].dst_blend);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_ONE, GL_ONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
}
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
GL_SelectTexture(GL_TEXTURE0_ARB);
|
|
|
|
if (shader->numcolorstages)
|
|
|
|
{
|
|
|
|
if (shader->colorstages[0].numtextures)
|
|
|
|
GL_BindAdvanced(shader->colorstages[0].texture[0]);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
if (shader->colorstages[0].alphatresh > 0)
|
|
|
|
{
|
|
|
|
glEnable(GL_ALPHA_TEST);
|
|
|
|
glAlphaFunc(GL_GEQUAL, shader->colorstages[0].alphatresh);
|
|
|
|
}
|
|
|
|
}
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
|
|
|
GL_EnableMultitexture();
|
|
|
|
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
|
|
|
glColor3f(sh_lightmapbright.value, sh_lightmapbright.value,
|
|
|
|
sh_lightmapbright.value);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
Generic_sendSurfacesBase(surfs, numSurfaces, true);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
GL_DisableMultitexture();
|
|
|
|
GL_SelectTexture(GL_TEXTURE0_ARB);
|
2003-10-01 21:01:41 +00:00
|
|
|
}
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2003-10-01 21:01:41 +00:00
|
|
|
if (!shader->cull)
|
|
|
|
{
|
2004-03-24 00:20:38 +00:00
|
|
|
glEnable(GL_CULL_FACE);
|
2003-10-01 21:01:41 +00:00
|
|
|
}
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2003-10-01 21:01:41 +00:00
|
|
|
glDisable(GL_ALPHA_TEST);
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Generic_sendSurfacesDiffuse(msurface_t **surfs, int numSurfaces)
|
|
|
|
{
|
|
|
|
int i,j;
|
|
|
|
glpoly_t *p;
|
|
|
|
msurface_t *surf;
|
|
|
|
shader_t *shader, *lastshader;
|
|
|
|
float *v;
|
|
|
|
qboolean cull;
|
|
|
|
vec3_t lightDir;
|
|
|
|
float tsLightDir[3];
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2003-10-01 21:01:41 +00:00
|
|
|
cull = true;
|
|
|
|
lastshader = NULL;
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2003-10-01 21:01:41 +00:00
|
|
|
for (i=0; i<numSurfaces; i++)
|
|
|
|
{
|
2004-03-24 00:20:38 +00:00
|
|
|
surf = surfs[i];
|
2003-10-01 21:01:41 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
if (surf->visframe != r_framecount)
|
|
|
|
continue;
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
if (!(surf->flags & SURF_PPLIGHT))
|
|
|
|
continue;
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
shader = surf->shader->shader;
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
if (shader->numbumpstages > 0)
|
|
|
|
GL_BindAdvanced(shader->bumpstages[0].texture[0]);
|
|
|
|
else
|
|
|
|
continue;
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
p = surf->polys;
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
//less state changes
|
|
|
|
if (lastshader != shader)
|
|
|
|
{
|
|
|
|
if (!shader->cull)
|
|
|
|
{
|
|
|
|
glDisable(GL_CULL_FACE);
|
|
|
|
cull = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!cull)
|
|
|
|
glEnable(GL_CULL_FACE);
|
|
|
|
cull = true;
|
|
|
|
}
|
|
|
|
lastshader = shader;
|
|
|
|
}
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
glBegin(GL_TRIANGLES);
|
|
|
|
for (j=0; j<surf->polys->numindecies; j++) {
|
|
|
|
v = (float *)(&cl.worldmodel->userVerts[surf->polys->indecies[j]]);
|
|
|
|
|
|
|
|
VectorSubtract(currentshadowlight->origin, (&v[0]), lightDir);
|
|
|
|
if (surf->flags & SURF_PLANEBACK) {
|
|
|
|
tsLightDir[2] = -DotProduct(lightDir,surf->plane->normal);
|
|
|
|
} else {
|
|
|
|
tsLightDir[2] = DotProduct(lightDir,surf->plane->normal);
|
|
|
|
}
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
tsLightDir[1] = -DotProduct(lightDir,surf->binormal);
|
|
|
|
tsLightDir[0] = DotProduct(lightDir,surf->tangent);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
qglMultiTexCoord3fvARB(GL_TEXTURE0_ARB, &tsLightDir[0]);
|
|
|
|
qglMultiTexCoord2fvARB(GL_TEXTURE1_ARB, &v[3]);
|
|
|
|
glVertex3fv(&v[0]);
|
|
|
|
}
|
|
|
|
glEnd();
|
2003-10-01 21:01:41 +00:00
|
|
|
}
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2003-10-01 21:01:41 +00:00
|
|
|
if (!cull)
|
2004-03-24 00:20:38 +00:00
|
|
|
glEnable(GL_CULL_FACE);
|
2003-10-01 21:01:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Generic_sendSurfacesATT(msurface_t **surfs, int numSurfaces)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
glpoly_t *p;
|
|
|
|
msurface_t *surf;
|
|
|
|
shader_t *shader, *lastshader;
|
|
|
|
qboolean cull;
|
2003-11-02 19:51:39 +00:00
|
|
|
float tu, tv, tw;
|
|
|
|
vec3_t nearToVert;
|
2003-10-01 21:01:41 +00:00
|
|
|
float *v;
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2003-10-01 21:01:41 +00:00
|
|
|
cull = true;
|
|
|
|
lastshader = NULL;
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2003-10-01 21:01:41 +00:00
|
|
|
for ( i = 0; i < numSurfaces; i++)
|
|
|
|
{
|
2004-03-24 00:20:38 +00:00
|
|
|
surf = surfs[i];
|
|
|
|
if (surf->visframe != r_framecount)
|
|
|
|
continue;
|
|
|
|
if (!(surf->flags & SURF_PPLIGHT))
|
|
|
|
continue;
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
shader = surf->shader->shader;
|
|
|
|
if (shader->numbumpstages == 0)
|
|
|
|
continue;
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
p = surf->polys;
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
if (lastshader != shader)
|
|
|
|
{
|
|
|
|
if (!shader->cull)
|
|
|
|
{
|
|
|
|
glDisable(GL_CULL_FACE);
|
|
|
|
cull = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!cull)
|
|
|
|
glEnable(GL_CULL_FACE);
|
|
|
|
cull = true;
|
|
|
|
}
|
|
|
|
lastshader = shader;
|
|
|
|
}
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
glColor4f(1, 1, 1, 1);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
glBegin(GL_TRIANGLES);
|
|
|
|
for (j=0; j<surf->polys->numindecies; j++)
|
|
|
|
{
|
|
|
|
v = (float *)(&cl.worldmodel->userVerts[surf->polys->indecies[j]]);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
VectorSubtract (v, currentshadowlight->origin, nearToVert);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
tu = (nearToVert[0]/currentshadowlight->radiusv[0])*0.5+0.5;
|
|
|
|
tv = (nearToVert[1]/currentshadowlight->radiusv[1])*0.5+0.5;
|
|
|
|
tw = (nearToVert[2]/currentshadowlight->radiusv[2])*0.5+0.5;
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
glTexCoord2f(tu, tv);
|
|
|
|
qglMultiTexCoord2fARB(GL_TEXTURE1_ARB, tw, 0.5);
|
|
|
|
glVertex3fv(&v[0]);
|
|
|
|
}
|
|
|
|
glEnd();
|
2003-10-01 21:01:41 +00:00
|
|
|
}
|
|
|
|
if (!cull)
|
2004-03-24 00:20:38 +00:00
|
|
|
glEnable(GL_CULL_FACE);
|
2003-10-01 21:01:41 +00:00
|
|
|
}
|
|
|
|
|
2003-11-02 19:51:39 +00:00
|
|
|
void Generic_sendSurfacesWV(msurface_t **surfs, int numSurfaces, qboolean specular)
|
2003-10-01 21:01:41 +00:00
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
glpoly_t *p;
|
|
|
|
msurface_t *surf;
|
|
|
|
shader_t *shader, *lastshader;
|
|
|
|
qboolean cull;
|
|
|
|
float *v;
|
|
|
|
cull = true;
|
|
|
|
lastshader = NULL;
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2003-10-01 21:01:41 +00:00
|
|
|
for ( i = 0; i < numSurfaces; i++)
|
|
|
|
{
|
2004-03-24 00:20:38 +00:00
|
|
|
surf = surfs[i];
|
|
|
|
if (surf->visframe != r_framecount)
|
|
|
|
continue;
|
|
|
|
if (!(surf->flags & SURF_PPLIGHT))
|
|
|
|
continue;
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
shader = surf->shader->shader;
|
|
|
|
if (shader->numbumpstages == 0)
|
|
|
|
continue;
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
p = surf->polys;
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
if (lastshader != shader)
|
|
|
|
{
|
|
|
|
if (!shader->cull)
|
|
|
|
{
|
|
|
|
glDisable(GL_CULL_FACE);
|
|
|
|
cull = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!cull)
|
|
|
|
glEnable(GL_CULL_FACE);
|
|
|
|
cull = true;
|
|
|
|
}
|
|
|
|
lastshader = shader;
|
|
|
|
GL_SelectTexture(GL_TEXTURE1_ARB);
|
|
|
|
if (!specular)
|
|
|
|
{
|
|
|
|
if (shader->numcolorstages > 0)
|
|
|
|
GL_BindAdvanced(shader->colorstages[0].texture[0]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (shader->numbumpstages > 0)
|
|
|
|
GL_BindAdvanced(shader->bumpstages[0].texture[0]);
|
|
|
|
}
|
|
|
|
}
|
2003-10-01 21:01:41 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
glNormal3fv(surf->plane->normal);
|
2003-10-01 21:01:41 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
glBegin(GL_TRIANGLES);
|
|
|
|
for (j=0; j<surf->polys->numindecies; j++)
|
|
|
|
{
|
|
|
|
v = (float *)(&cl.worldmodel->userVerts[surf->polys->indecies[j]]);
|
|
|
|
glTexCoord3fv(&v[0]);
|
|
|
|
qglMultiTexCoord2fARB(GL_TEXTURE1_ARB, v[3], v[4]);
|
|
|
|
glVertex3fv(&v[0]);
|
|
|
|
}
|
|
|
|
glEnd();
|
2003-10-01 21:01:41 +00:00
|
|
|
}
|
|
|
|
if (!cull)
|
2004-03-24 00:20:38 +00:00
|
|
|
glEnable(GL_CULL_FACE);
|
2003-10-01 21:01:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Generic_sendSurfacesTex(msurface_t **surfs, int numSurfaces)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
glpoly_t *p;
|
|
|
|
msurface_t *surf;
|
|
|
|
shader_t *shader, *lastshader;
|
|
|
|
qboolean cull;
|
|
|
|
float *v;
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2003-10-01 21:01:41 +00:00
|
|
|
cull = true;
|
|
|
|
lastshader = NULL;
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2003-10-01 21:01:41 +00:00
|
|
|
for ( i = 0; i < numSurfaces; i++)
|
|
|
|
{
|
2004-03-24 00:20:38 +00:00
|
|
|
surf = surfs[i];
|
|
|
|
if (surf->visframe != r_framecount)
|
|
|
|
continue;
|
|
|
|
if (!(surf->flags & SURF_PPLIGHT))
|
|
|
|
continue;
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
shader = surf->shader->shader;
|
|
|
|
if (shader->numbumpstages == 0)
|
|
|
|
continue;
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
p = surf->polys;
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
if (lastshader != shader)
|
|
|
|
{
|
|
|
|
if (!shader->cull)
|
|
|
|
{
|
|
|
|
glDisable(GL_CULL_FACE);
|
|
|
|
cull = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!cull)
|
|
|
|
glEnable(GL_CULL_FACE);
|
|
|
|
cull = true;
|
|
|
|
}
|
|
|
|
lastshader = shader;
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
GL_SelectTexture(GL_TEXTURE0_ARB);
|
|
|
|
if (shader->numcolorstages > 0)
|
|
|
|
GL_BindAdvanced(shader->colorstages[0].texture[0]);
|
|
|
|
}
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
/*
|
|
|
|
glBegin(GL_TRIANGLE_FAN);
|
|
|
|
v = (float *)(&globalVertexTable[surf->polys->firstvertex]);
|
|
|
|
for (j = 0; j < p->numverts; j++, v+= VERTEXSIZE)
|
|
|
|
{
|
|
|
|
glTexCoord2fv(&v[3]);
|
|
|
|
glVertex3fv(&v[0]);
|
|
|
|
}
|
|
|
|
glEnd();
|
|
|
|
*/
|
|
|
|
|
|
|
|
glBegin(GL_TRIANGLES);
|
|
|
|
for (j=0; j<surf->polys->numindecies; j++)
|
|
|
|
{
|
|
|
|
v = (float *)(&cl.worldmodel->userVerts[surf->polys->indecies[j]]);
|
|
|
|
glTexCoord2fv(&v[3]);
|
|
|
|
glVertex3fv(&v[0]);
|
|
|
|
}
|
|
|
|
glEnd();
|
2003-10-01 21:01:41 +00:00
|
|
|
}
|
|
|
|
if (!cull)
|
2004-03-24 00:20:38 +00:00
|
|
|
glEnable(GL_CULL_FACE);
|
2003-10-01 21:01:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Generic_drawSurfaceListBump (vertexdef_t *verts, msurface_t **surfs,
|
2004-03-24 00:20:38 +00:00
|
|
|
int numSurfaces,const transform_t *tr,
|
|
|
|
const lightobject_t *lo)
|
2003-10-01 21:01:41 +00:00
|
|
|
{
|
|
|
|
glDepthMask (0);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
//attenuate with projected 2D attenuation map
|
2003-10-01 21:01:41 +00:00
|
|
|
GL_DrawAlpha();
|
2003-11-02 19:51:39 +00:00
|
|
|
GL_EnableGenericAttShader();
|
|
|
|
Generic_sendSurfacesATT(surfs, numSurfaces);
|
|
|
|
GL_DisableGenericAttShader();
|
2003-10-01 21:01:41 +00:00
|
|
|
|
2003-11-02 19:51:39 +00:00
|
|
|
// modulate diffuse bump (n dot l) to alpha
|
2003-10-01 21:01:41 +00:00
|
|
|
GL_ModulateAlphaDrawAlpha();
|
2003-11-02 19:51:39 +00:00
|
|
|
GL_EnableGenericDiffuseShader();
|
|
|
|
Generic_sendSurfacesDiffuse(surfs, numSurfaces);
|
|
|
|
GL_DisableGenericDiffuseShader ();
|
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
//Do fake specular
|
|
|
|
if (sh_fakespecular.value)
|
|
|
|
{
|
|
|
|
//This is so fake...
|
|
|
|
//-it gets attenuated with the diffuse dot product and the light attenuation
|
|
|
|
//-The specular gets caclulated per vertex
|
|
|
|
//-But it remotely looks like specular at the cost of one extra pass
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
float black[4] = {0.0, 0.0, 0.0, 1.0};
|
|
|
|
float white[4] = {1.0, 1.0, 1.0, 1.0};
|
|
|
|
float pos[4];
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
GL_ModulateAlphaDrawColor();
|
|
|
|
glColorMask(true, true, true, false);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
glEnable(GL_LIGHTING);
|
|
|
|
glEnable(GL_LIGHT0);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
VectorCopy(lo->objectorigin, pos);
|
|
|
|
pos[3] = 1.0;
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
glLightfv(GL_LIGHT0, GL_POSITION, pos);
|
|
|
|
glLightfv(GL_LIGHT0, GL_DIFFUSE, black);
|
|
|
|
glLightfv(GL_LIGHT0, GL_AMBIENT, black);
|
|
|
|
glLightfv(GL_LIGHT0, GL_SPECULAR, ¤tshadowlight->color[0]);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, white);
|
|
|
|
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 16);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
glEnable(GL_COLOR_MATERIAL);
|
|
|
|
glColor4fv(white);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
GL_EnableGenericColorShader (true);
|
|
|
|
Generic_sendSurfacesWV(surfs, numSurfaces, true);
|
|
|
|
GL_DisableGenericColorShader (true);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
glDisable(GL_LIGHTING);
|
|
|
|
}
|
2003-10-01 21:01:41 +00:00
|
|
|
|
|
|
|
// Then modulate Color map and light filter with alpha and add to color
|
2004-03-24 00:20:38 +00:00
|
|
|
GL_ModulateAlphaDrawColor();
|
2003-10-01 21:01:41 +00:00
|
|
|
glColor3fv(¤tshadowlight->baseColor[0]);
|
|
|
|
if ( currentshadowlight->filtercube )
|
|
|
|
{
|
2004-03-24 00:20:38 +00:00
|
|
|
glMatrixMode(GL_TEXTURE);
|
|
|
|
glPushMatrix();
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
GL_SetupCubeMapMatrix(tr);
|
|
|
|
GL_EnableGenericColorShader (false);
|
|
|
|
Generic_sendSurfacesWV(surfs, numSurfaces, false);
|
|
|
|
GL_DisableGenericColorShader (false);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
glPopMatrix();
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
2003-10-01 21:01:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-03-24 00:20:38 +00:00
|
|
|
// Just alpha * light color
|
2003-11-02 19:51:39 +00:00
|
|
|
GL_SelectTexture(GL_TEXTURE1_ARB);
|
|
|
|
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
|
|
|
|
GL_SelectTexture(GL_TEXTURE0_ARB);
|
|
|
|
|
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
|
2003-11-02 19:51:39 +00:00
|
|
|
|
|
|
|
glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);
|
|
|
|
|
|
|
|
glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE);
|
|
|
|
|
|
|
|
glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
|
|
|
|
|
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
//glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
|
|
|
Generic_sendSurfacesTex(surfs, numSurfaces);
|
2003-10-01 21:01:41 +00:00
|
|
|
}
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2003-10-01 21:01:41 +00:00
|
|
|
GL_DrawColor();
|
|
|
|
glColor3f (1,1,1);
|
|
|
|
glDisable (GL_BLEND);
|
|
|
|
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
glDepthMask (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Generic_freeDriver(void)
|
|
|
|
{
|
|
|
|
//nothing here...
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void BUMP_InitGeneric(void)
|
|
|
|
{
|
|
|
|
if ( gl_cardtype != GENERIC && gl_cardtype != GEFORCE )
|
2004-03-24 00:20:38 +00:00
|
|
|
return;
|
2003-11-02 19:51:39 +00:00
|
|
|
|
2004-03-24 00:20:38 +00:00
|
|
|
Cvar_RegisterVariable(&sh_fakespecular);
|
2003-10-01 21:01:41 +00:00
|
|
|
//bind the correct stuff to the bump mapping driver
|
|
|
|
gl_bumpdriver.drawSurfaceListBase = Generic_drawSurfaceListBase;
|
|
|
|
gl_bumpdriver.drawSurfaceListBump = Generic_drawSurfaceListBump;
|
|
|
|
gl_bumpdriver.drawTriangleListBase = Generic_drawTriangleListBase;
|
|
|
|
gl_bumpdriver.drawTriangleListBump = Generic_drawTriangleListBump;
|
|
|
|
gl_bumpdriver.freeDriver = Generic_freeDriver;
|
|
|
|
}
|