#include "cl_collision.h"
#include "r_shadow.h"
-cvar_t r_quickmodels = {0, "r_quickmodels", "1"};
-
typedef struct
{
float m[3][4];
void GL_Models_Init(void)
{
- Cvar_RegisterVariable(&r_quickmodels);
-
R_RegisterModule("GL_Models", gl_models_start, gl_models_shutdown, gl_models_newmap);
}
-/*
-void R_AliasTransformVerts(int vertcount)
-{
- vec3_t point;
- float *av;
- av = aliasvert;
- while (vertcount >= 4)
- {
- VectorCopy(av, point);softwaretransform(point, av);av += 4;
- VectorCopy(av, point);softwaretransform(point, av);av += 4;
- VectorCopy(av, point);softwaretransform(point, av);av += 4;
- VectorCopy(av, point);softwaretransform(point, av);av += 4;
- vertcount -= 4;
- }
- while(vertcount > 0)
- {
- VectorCopy(av, point);softwaretransform(point, av);av += 4;
- vertcount--;
- }
-}
-*/
-
void R_AliasLerpVerts(int vertcount, float *vertices, float *normals,
float lerp1, const trivertx_t *verts1, const vec3_t fscale1, const vec3_t translate1,
float lerp2, const trivertx_t *verts2, const vec3_t fscale2, const vec3_t translate2,
void R_DrawQ1Q2AliasModelCallback (const void *calldata1, int calldata2)
{
- int i, c, pantsfullbright, shirtfullbright, colormapped, tex;
+ int i, c, fullbright, pantsfullbright, shirtfullbright, colormapped, tex;
float pantscolor[3], shirtcolor[3];
- float fog, colorscale;
+ float fog, ifog, colorscale;
vec3_t diff;
qbyte *bcolor;
rmeshstate_t m;
const entity_render_t *ent = calldata1;
int blendfunc1, blendfunc2;
-// softwaretransformforentity(ent);
R_Mesh_Matrix(&ent->matrix);
+ model = ent->model;
+ R_Mesh_ResizeCheck(model->numverts);
+
+ skinframe = R_FetchSkinFrame(ent);
+
+ fullbright = (ent->effects & EF_FULLBRIGHT) != 0;
+
fog = 0;
if (fogenabled)
{
// 1. render model as normal, scaled by inverse of fog alpha (darkens it)
// 2. render fog as additive
}
-
- model = ent->model;
- R_Mesh_ResizeCheck(model->numverts);
-
- skinframe = R_FetchSkinFrame(ent);
+ ifog = 1 - fog;
if (ent->effects & EF_ADDITIVE)
{
blendfunc2 = GL_ZERO;
}
- colorscale = r_colorscale;
- if (gl_combine.integer)
- colorscale *= 0.25f;
-
if (!skinframe->base && !skinframe->pants && !skinframe->shirt && !skinframe->glow)
{
// untextured
memset(&m, 0, sizeof(m));
m.blendfunc1 = blendfunc1;
m.blendfunc2 = blendfunc2;
+ colorscale = r_colorscale;
if (gl_combine.integer)
+ {
+ colorscale *= 0.25f;
m.texrgbscale[0] = 4;
+ }
m.tex[0] = R_GetTexture(r_notexture);
R_Mesh_State(&m);
-
c_alias_polys += model->numtris;
for (i = 0;i < model->numverts * 2;i++)
varray_texcoord[0][i] = model->mdlmd2data_texcoords[i] * 8.0f;
- aliasvert = varray_vertex;
- aliasvertcolor = varray_color;
- R_LerpMDLMD2Vertices(ent, aliasvert, aliasvertnorm);
- R_LightModel(ent, model->numverts, colorscale, colorscale, colorscale, false);
- aliasvert = aliasvertbuf;
- aliasvertcolor = aliasvertcolorbuf;
+ R_LerpMDLMD2Vertices(ent, varray_vertex, aliasvertnorm);
+ R_LightModel(ent, model->numverts, varray_vertex, aliasvertnorm, varray_color, colorscale, colorscale, colorscale, false);
GL_UseColorArray();
R_Mesh_Draw(model->numverts, model->numtris, model->mdlmd2data_indices);
return;
}
-
colormapped = !skinframe->merged || (ent->colormap >= 0 && skinframe->base && (skinframe->pants || skinframe->shirt));
- if (r_quickmodels.integer && !colormapped && !fog && !skinframe->glow && !skinframe->fog)
- {
- // fastpath for the normal situation (one texture)
- memset(&m, 0, sizeof(m));
- m.blendfunc1 = blendfunc1;
- m.blendfunc2 = blendfunc2;
- if (gl_combine.integer)
- m.texrgbscale[0] = 4;
- m.tex[0] = R_GetTexture(skinframe->merged);
- R_Mesh_State(&m);
-
- c_alias_polys += model->numtris;
- memcpy(varray_texcoord[0], model->mdlmd2data_texcoords, model->numverts * sizeof(float[2]));
- aliasvert = varray_vertex;
- aliasvertcolor = varray_color;
- R_LerpMDLMD2Vertices(ent, aliasvert, aliasvertnorm);
- R_LightModel(ent, model->numverts, colorscale, colorscale, colorscale, false);
- aliasvert = aliasvertbuf;
- aliasvertcolor = aliasvertcolorbuf;
- GL_UseColorArray();
- R_Mesh_Draw(model->numverts, model->numtris, model->mdlmd2data_indices);
- return;
- }
-
- R_LerpMDLMD2Vertices(ent, aliasvert, aliasvertnorm);
- R_LightModel(ent, model->numverts, colorscale * (1 - fog), colorscale * (1 - fog), colorscale * (1 - fog), false);
-
if (colormapped)
{
// 128-224 are backwards ranges
memset(&m, 0, sizeof(m));
m.blendfunc1 = blendfunc1;
m.blendfunc2 = blendfunc2;
+ colorscale = r_colorscale;
if (gl_combine.integer)
+ {
+ colorscale *= 0.25f;
m.texrgbscale[0] = 4;
+ }
m.tex[0] = tex;
R_Mesh_State(&m);
-
- blendfunc1 = GL_SRC_ALPHA;
- blendfunc2 = GL_ONE;
- c_alias_polys += model->numtris;
- R_ModulateColors(aliasvertcolor, varray_color, model->numverts, colorscale, colorscale, colorscale);
- memcpy(varray_vertex, aliasvert, model->numverts * sizeof(float[4]));
+ R_LerpMDLMD2Vertices(ent, varray_vertex, aliasvertnorm);
memcpy(varray_texcoord[0], model->mdlmd2data_texcoords, model->numverts * sizeof(float[2]));
- GL_UseColorArray();
+ if (fullbright)
+ GL_Color(colorscale * ifog, colorscale * ifog, colorscale * ifog, ent->alpha);
+ else
+ {
+ GL_UseColorArray();
+ R_LightModel(ent, model->numverts, varray_vertex, aliasvertnorm, varray_color, colorscale * ifog, colorscale * ifog, colorscale * ifog, false);
+ }
R_Mesh_Draw(model->numverts, model->numtris, model->mdlmd2data_indices);
+ c_alias_polys += model->numtris;
+ blendfunc1 = GL_SRC_ALPHA;
+ blendfunc2 = GL_ONE;
}
if (colormapped)
memset(&m, 0, sizeof(m));
m.blendfunc1 = blendfunc1;
m.blendfunc2 = blendfunc2;
+ colorscale = r_colorscale;
if (gl_combine.integer)
+ {
+ colorscale *= 0.25f;
m.texrgbscale[0] = 4;
+ }
m.tex[0] = tex;
R_Mesh_State(&m);
-
- blendfunc1 = GL_SRC_ALPHA;
- blendfunc2 = GL_ONE;
- c_alias_polys += model->numtris;
+ R_LerpMDLMD2Vertices(ent, varray_vertex, aliasvertnorm);
+ memcpy(varray_texcoord[0], model->mdlmd2data_texcoords, model->numverts * sizeof(float[2]));
if (pantsfullbright)
- GL_Color(pantscolor[0] * colorscale, pantscolor[1] * colorscale, pantscolor[2] * colorscale, ent->alpha);
+ GL_Color(pantscolor[0] * colorscale * ifog, pantscolor[1] * colorscale * ifog, pantscolor[2] * colorscale * ifog, ent->alpha);
else
{
GL_UseColorArray();
- R_ModulateColors(aliasvertcolor, varray_color, model->numverts, pantscolor[0] * colorscale, pantscolor[1] * colorscale, pantscolor[2] * colorscale);
+ R_LightModel(ent, model->numverts, varray_vertex, aliasvertnorm, varray_color, pantscolor[0] * colorscale * ifog, pantscolor[1] * colorscale * ifog, pantscolor[2] * colorscale * ifog, false);
}
- memcpy(varray_vertex, aliasvert, model->numverts * sizeof(float[4]));
- memcpy(varray_texcoord[0], model->mdlmd2data_texcoords, model->numverts * sizeof(float[2]));
R_Mesh_Draw(model->numverts, model->numtris, model->mdlmd2data_indices);
+ c_alias_polys += model->numtris;
+ blendfunc1 = GL_SRC_ALPHA;
+ blendfunc2 = GL_ONE;
}
}
if (skinframe->shirt)
memset(&m, 0, sizeof(m));
m.blendfunc1 = blendfunc1;
m.blendfunc2 = blendfunc2;
+ colorscale = r_colorscale;
if (gl_combine.integer)
+ {
+ colorscale *= 0.25f;
m.texrgbscale[0] = 4;
+ }
m.tex[0] = tex;
R_Mesh_State(&m);
-
- blendfunc1 = GL_SRC_ALPHA;
- blendfunc2 = GL_ONE;
- c_alias_polys += model->numtris;
+ R_LerpMDLMD2Vertices(ent, varray_vertex, aliasvertnorm);
+ memcpy(varray_texcoord[0], model->mdlmd2data_texcoords, model->numverts * sizeof(float[2]));
if (shirtfullbright)
- GL_Color(shirtcolor[0] * colorscale, shirtcolor[1] * colorscale, shirtcolor[2] * colorscale, ent->alpha);
+ GL_Color(shirtcolor[0] * colorscale * ifog, shirtcolor[1] * colorscale * ifog, shirtcolor[2] * colorscale * ifog, ent->alpha);
else
{
GL_UseColorArray();
- R_ModulateColors(aliasvertcolor, varray_color, model->numverts, shirtcolor[0] * colorscale, shirtcolor[1] * colorscale, shirtcolor[2] * colorscale);
+ R_LightModel(ent, model->numverts, varray_vertex, aliasvertnorm, varray_color, shirtcolor[0] * colorscale * ifog, shirtcolor[1] * colorscale * ifog, shirtcolor[2] * colorscale * ifog, false);
}
- memcpy(varray_vertex, aliasvert, model->numverts * sizeof(float[4]));
- memcpy(varray_texcoord[0], model->mdlmd2data_texcoords, model->numverts * sizeof(float[2]));
R_Mesh_Draw(model->numverts, model->numtris, model->mdlmd2data_indices);
+ c_alias_polys += model->numtris;
+ blendfunc1 = GL_SRC_ALPHA;
+ blendfunc2 = GL_ONE;
}
}
}
blendfunc1 = GL_SRC_ALPHA;
blendfunc2 = GL_ONE;
c_alias_polys += model->numtris;
- memcpy(varray_vertex, aliasvert, model->numverts * sizeof(float[4]));
+ R_LerpMDLMD2Vertices(ent, varray_vertex, aliasvertnorm);
memcpy(varray_texcoord[0], model->mdlmd2data_texcoords, model->numverts * sizeof(float[2]));
- GL_Color((1 - fog) * r_colorscale, (1 - fog) * r_colorscale, (1 - fog) * r_colorscale, ent->alpha);
+ GL_Color(ifog * r_colorscale, ifog * r_colorscale, ifog * r_colorscale, ent->alpha);
R_Mesh_Draw(model->numverts, model->numtris, model->mdlmd2data_indices);
}
}
R_Mesh_State(&m);
c_alias_polys += model->numtris;
- memcpy(varray_vertex, aliasvert, model->numverts * sizeof(float[4]));
+ R_LerpMDLMD2Vertices(ent, varray_vertex, aliasvertnorm);
memcpy(varray_texcoord[0], model->mdlmd2data_texcoords, model->numverts * sizeof(float[2]));
GL_Color(fogcolor[0] * fog * r_colorscale, fogcolor[1] * fog * r_colorscale, fogcolor[2] * fog * r_colorscale, ent->alpha);
R_Mesh_Draw(model->numverts, model->numtris, model->mdlmd2data_indices);
}
}
+void R_DrawQ1Q2AliasModelShadowVolume(entity_render_t *ent, vec3_t relativelightorigin, float lightradius, int visiblevolume)
+{
+ float projectdistance;
+ projectdistance = lightradius + ent->model->radius - sqrt(DotProduct(relativelightorigin, relativelightorigin));
+ if (projectdistance > 0.1)
+ {
+ R_Mesh_ResizeCheck(ent->model->numverts * 2);
+ R_LerpMDLMD2Vertices(ent, varray_vertex, aliasvertnorm);
+ R_Shadow_Volume(ent->model->numverts, ent->model->numtris, varray_vertex, ent->model->mdlmd2data_indices, ent->model->mdlmd2data_triangleneighbors, relativelightorigin, lightradius, projectdistance, visiblevolume);
+ }
+}
+
extern cvar_t r_shadows;
void R_DrawQ1Q2AliasModelFakeShadow (entity_render_t *ent)
{
rmeshstate_t m;
model_t *model;
float *v, planenormal[3], planedist, dist, projection[3], floororigin[3], surfnormal[3], lightdirection[3], v2[3];
- mlight_t *sl;
- rdlight_t *rd;
+ /*
if (r_shadows.integer > 1)
{
float f, lightscale, lightcolor[3];
vec3_t temp;
+ mlight_t *sl;
+ rdlight_t *rd;
memset(&m, 0, sizeof(m));
m.blendfunc1 = GL_ONE;
m.blendfunc2 = GL_ONE;
}
return;
}
+ */
lightdirection[0] = 0.5;
lightdirection[1] = 0.2;
zymbonematrix *out, rootmatrix, m;
const zymbonematrix *bone1, *bone2, *bone3, *bone4;
- /*
- // LordHavoc: combine transform from zym coordinate space to quake coordinate space with model to world transform matrix
- rootmatrix.m[0][0] = softwaretransform_matrix[0][1];
- rootmatrix.m[0][1] = -softwaretransform_matrix[0][0];
- rootmatrix.m[0][2] = softwaretransform_matrix[0][2];
- rootmatrix.m[0][3] = softwaretransform_matrix[0][3];
- rootmatrix.m[1][0] = softwaretransform_matrix[1][1];
- rootmatrix.m[1][1] = -softwaretransform_matrix[1][0];
- rootmatrix.m[1][2] = softwaretransform_matrix[1][2];
- rootmatrix.m[1][3] = softwaretransform_matrix[1][3];
- rootmatrix.m[2][0] = softwaretransform_matrix[2][1];
- rootmatrix.m[2][1] = -softwaretransform_matrix[2][0];
- rootmatrix.m[2][2] = softwaretransform_matrix[2][2];
- rootmatrix.m[2][3] = softwaretransform_matrix[2][3];
- */
rootmatrix.m[0][0] = 1;
rootmatrix.m[0][1] = 0;
rootmatrix.m[0][2] = 0;
return true;
}
-void ZymoticTransformVerts(int vertcount, int *bonecounts, zymvertex_t *vert)
+void ZymoticTransformVerts(int vertcount, float *vertex, int *bonecounts, zymvertex_t *vert)
{
int c;
- float *out = aliasvert;
+ float *out = vertex;
zymbonematrix *matrix;
while(vertcount--)
{
}
}
-void ZymoticCalcNormals(int vertcount, int shadercount, int *renderlist)
+void ZymoticCalcNormals(int vertcount, float *vertex, float *normals, int shadercount, int *renderlist)
{
int a, b, c, d;
float *out, v1[3], v2[3], normal[3], s;
int *u;
// clear normals
- memset(aliasvertnorm, 0, sizeof(float) * vertcount * 3);
+ memset(normals, 0, sizeof(float) * vertcount * 3);
memset(aliasvertusage, 0, sizeof(int) * vertcount);
// parse render list and accumulate surface normals
while(shadercount--)
a = renderlist[0]*4;
b = renderlist[1]*4;
c = renderlist[2]*4;
- v1[0] = aliasvert[a+0] - aliasvert[b+0];
- v1[1] = aliasvert[a+1] - aliasvert[b+1];
- v1[2] = aliasvert[a+2] - aliasvert[b+2];
- v2[0] = aliasvert[c+0] - aliasvert[b+0];
- v2[1] = aliasvert[c+1] - aliasvert[b+1];
- v2[2] = aliasvert[c+2] - aliasvert[b+2];
+ v1[0] = vertex[a+0] - vertex[b+0];
+ v1[1] = vertex[a+1] - vertex[b+1];
+ v1[2] = vertex[a+2] - vertex[b+2];
+ v2[0] = vertex[c+0] - vertex[b+0];
+ v2[1] = vertex[c+1] - vertex[b+1];
+ v2[2] = vertex[c+2] - vertex[b+2];
CrossProduct(v1, v2, normal);
VectorNormalizeFast(normal);
// add surface normal to vertices
a = renderlist[0] * 3;
- aliasvertnorm[a+0] += normal[0];
- aliasvertnorm[a+1] += normal[1];
- aliasvertnorm[a+2] += normal[2];
+ normals[a+0] += normal[0];
+ normals[a+1] += normal[1];
+ normals[a+2] += normal[2];
aliasvertusage[renderlist[0]]++;
a = renderlist[1] * 3;
- aliasvertnorm[a+0] += normal[0];
- aliasvertnorm[a+1] += normal[1];
- aliasvertnorm[a+2] += normal[2];
+ normals[a+0] += normal[0];
+ normals[a+1] += normal[1];
+ normals[a+2] += normal[2];
aliasvertusage[renderlist[1]]++;
a = renderlist[2] * 3;
- aliasvertnorm[a+0] += normal[0];
- aliasvertnorm[a+1] += normal[1];
- aliasvertnorm[a+2] += normal[2];
+ normals[a+0] += normal[0];
+ normals[a+1] += normal[1];
+ normals[a+2] += normal[2];
aliasvertusage[renderlist[2]]++;
renderlist += 3;
}
}
// FIXME: precalc this
// average surface normals
- out = aliasvertnorm;
+ out = normals;
u = aliasvertusage;
while(vertcount--)
{
void R_DrawZymoticModelMeshCallback (const void *calldata1, int calldata2)
{
- float fog, colorscale;
+ float fog, ifog, colorscale;
vec3_t diff;
int i, *renderlist, *elements;
zymtype1header_t *m;
// 1. render model as normal, scaled by inverse of fog alpha (darkens it)
// 2. render fog as additive
}
-
- ZymoticLerpBones(m->numbones, (zymbonematrix *)(m->lump_poses.start + (int) m), ent->frameblend, (zymbone_t *)(m->lump_bones.start + (int) m));
- ZymoticTransformVerts(numverts, (int *)(m->lump_vertbonecounts.start + (int) m), (zymvertex_t *)(m->lump_verts.start + (int) m));
- ZymoticCalcNormals(numverts, m->numshaders, (int *)(m->lump_render.start + (int) m));
-
- R_LightModel(ent, numverts, 1 - fog, 1 - fog, 1 - fog, false);
+ ifog = 1 - fog;
memset(&mstate, 0, sizeof(mstate));
if (ent->effects & EF_ADDITIVE)
}
mstate.tex[0] = R_GetTexture(texture);
R_Mesh_State(&mstate);
-
- c_alias_polys += numtriangles;
- memcpy(varray_vertex, aliasvert, numverts * sizeof(float[4]));
- R_ModulateColors(aliasvertcolor, varray_color, numverts, colorscale, colorscale, colorscale);
+ ZymoticLerpBones(m->numbones, (zymbonematrix *)(m->lump_poses.start + (int) m), ent->frameblend, (zymbone_t *)(m->lump_bones.start + (int) m));
+ ZymoticTransformVerts(numverts, varray_vertex, (int *)(m->lump_vertbonecounts.start + (int) m), (zymvertex_t *)(m->lump_verts.start + (int) m));
+ ZymoticCalcNormals(numverts, varray_vertex, aliasvertnorm, m->numshaders, (int *)(m->lump_render.start + (int) m));
memcpy(varray_texcoord[0], (float *)(m->lump_texcoords.start + (int) m), numverts * sizeof(float[2]));
GL_UseColorArray();
+ R_LightModel(ent, numverts, varray_vertex, aliasvertnorm, varray_color, ifog * colorscale, ifog * colorscale, ifog * colorscale, false);
R_Mesh_Draw(numverts, numtriangles, elements);
+ c_alias_polys += numtriangles;
if (fog)
{
// FIXME: need alpha mask for fogging...
//mstate.tex[0] = R_GetTexture(texture);
R_Mesh_State(&mstate);
-
- c_alias_polys += numtriangles;
- memcpy(varray_vertex, aliasvert, numverts * sizeof(float[4]));
- //memcpy(mesh_texcoord[0], (float *)(m->lump_texcoords.start + (int) m), numverts * sizeof(float[2]));
GL_Color(fogcolor[0] * r_colorscale, fogcolor[1] * r_colorscale, fogcolor[2] * r_colorscale, ent->alpha * fog);
R_Mesh_Draw(numverts, numtriangles, elements);
+ c_alias_polys += numtriangles;
}
}