entity_render_t *ent;
model_t *model;
vec3_t org;
- if (cl.worldmodel == NULL || !cl.worldmodel->brushq1.nodes)
+ if (r_refdef.worldmodel == NULL || !r_refdef.worldmodel->brushq1.nodes)
return;
fcolor[0] = cr1;
fcolor[1] = cg1;
fcolor[6] = cb2 - cb1;
fcolor[7] = (ca2 - ca1) * (1.0f / 64.0f);
- R_StainNode(cl.worldmodel->brushq1.nodes + cl.worldmodel->brushq1.hulls[0].firstclipnode, cl.worldmodel, origin, radius, fcolor);
+ R_StainNode(r_refdef.worldmodel->brushq1.nodes + r_refdef.worldmodel->brushq1.hulls[0].firstclipnode, r_refdef.worldmodel, origin, radius, fcolor);
// look for embedded bmodels
for (n = 0;n < cl_num_brushmodel_entities;n++)
texture = surf->texinfo->texture;
if (texture->animated)
- texture = texture->anim_frames[ent->frame != 0][(texture->anim_total[ent->frame != 0] >= 2) ? ((int) (cl.time * 5.0f) % texture->anim_total[ent->frame != 0]) : 0];
+ texture = texture->anim_frames[ent->frame != 0][(texture->anim_total[ent->frame != 0] >= 2) ? ((int) (r_refdef.time * 5.0f) % texture->anim_total[ent->frame != 0]) : 0];
currentalpha = ent->alpha;
if (surf->flags & SURF_WATERALPHA)
currentalpha *= r_wateralpha.value;
base = fullbright ? 2.0f : r_ambient.value * (1.0f / 64.0f);
if (surf->flags & SURF_DRAWTURB)
base *= 0.5f;
- if ((surf->flags & SURF_DRAWTURB) && gl_textureshader && r_watershader.value && !fogenabled)
+ if ((surf->flags & SURF_DRAWTURB) && gl_textureshader && r_watershader.value && !fogenabled && fullbright && ent->colormod[0] == 1 && ent->colormod[1] == 1 && ent->colormod[2] == 1)
{
// NVIDIA Geforce3 distortion texture shader on water
GL_Color(1, 1, 1, currentalpha);
memset(&m, 0, sizeof(m));
m.pointer_vertex = surf->mesh.data_vertex3f;
- m.tex[0] = R_GetTexture(mod_shared_distorttexture[(int)(cl.time * 16)&63]);
+ m.tex[0] = R_GetTexture(mod_shared_distorttexture[(int)(r_refdef.time * 16)&63]);
m.tex[1] = R_GetTexture(texture->skin.base);
m.texcombinergb[0] = GL_REPLACE;
m.texcombinergb[1] = GL_REPLACE;
m.pointer_texcoord[0] = surf->mesh.data_texcoordtexture2f;
m.pointer_texcoord[1] = surf->mesh.data_texcoordtexture2f;
Matrix4x4_CreateFromQuakeEntity(&m.texmatrix[0], 0, 0, 0, 0, 0, 0, r_watershader.value);
- Matrix4x4_CreateTranslate(&m.texmatrix[1], sin(cl.time) * 0.025 * r_waterscroll.value, sin(cl.time * 0.8f) * 0.025 * r_waterscroll.value, 0);
+ Matrix4x4_CreateTranslate(&m.texmatrix[1], sin(r_refdef.time) * 0.025 * r_waterscroll.value, sin(r_refdef.time * 0.8f) * 0.025 * r_waterscroll.value, 0);
R_Mesh_State(&m);
GL_ActiveTexture(0);
if (turb)
{
// scrolling in texture matrix
- Matrix4x4_CreateTranslate(&m.texmatrix[0], sin(cl.time) * 0.025 * r_waterscroll.value, sin(cl.time * 0.8f) * 0.025 * r_waterscroll.value, 0);
+ Matrix4x4_CreateTranslate(&m.texmatrix[0], sin(r_refdef.time) * 0.025 * r_waterscroll.value, sin(r_refdef.time * 0.8f) * 0.025 * r_waterscroll.value, 0);
}
colorscale = 1;
if (gl_combine.integer)
m.texrgbscale[0] = 4;
colorscale *= 0.25f;
}
- R_FillColors(varray_color4f, surf->mesh.num_vertices, base, base, base, currentalpha);
+ R_FillColors(varray_color4f, surf->mesh.num_vertices, base * ent->colormod[0], base * ent->colormod[1], base * ent->colormod[2], currentalpha);
if (!fullbright)
{
if (surf->dlightframe == r_framecount)
if (turb)
{
// scrolling in texture matrix
- Matrix4x4_CreateTranslate(&m.texmatrix[0], sin(cl.time) * 0.025 * r_waterscroll.value, sin(cl.time * 0.8f) * 0.025 * r_waterscroll.value, 0);
+ Matrix4x4_CreateTranslate(&m.texmatrix[0], sin(r_refdef.time) * 0.025 * r_waterscroll.value, sin(r_refdef.time * 0.8f) * 0.025 * r_waterscroll.value, 0);
}
}
R_Mesh_State(&m);
if (turb)
{
// scrolling in texture matrix
- Matrix4x4_CreateTranslate(&m.texmatrix[0], sin(cl.time) * 0.025 * r_waterscroll.value, sin(cl.time * 0.8f) * 0.025 * r_waterscroll.value, 0);
+ Matrix4x4_CreateTranslate(&m.texmatrix[0], sin(r_refdef.time) * 0.025 * r_waterscroll.value, sin(r_refdef.time * 0.8f) * 0.025 * r_waterscroll.value, 0);
}
}
R_Mesh_State(&m);
m.tex[3] = R_GetTexture(texture->skin.glow);
m.texcombinergb[3] = GL_ADD;
}
- GL_Color(r_lightmapintensity, r_lightmapintensity, r_lightmapintensity, 1);
+ GL_Color(r_lightmapintensity * ent->colormod[0], r_lightmapintensity * ent->colormod[1], r_lightmapintensity * ent->colormod[2], 1);
while((surf = *surfchain++) != NULL)
{
m.texrgbscale[1] = 2;
m.tex[2] = R_GetTexture(texture->skin.detail);
m.texrgbscale[2] = 2;
- GL_Color(r_lightmapintensity, r_lightmapintensity, r_lightmapintensity, 1);
+ GL_Color(r_lightmapintensity * ent->colormod[0], r_lightmapintensity * ent->colormod[1], r_lightmapintensity * ent->colormod[2], 1);
while((surf = *surfchain++) != NULL)
{
m.tex[0] = R_GetTexture(texture->skin.base);
m.tex[1] = R_GetTexture((**surfchain).lightmaptexture);
m.texrgbscale[1] = 2;
- GL_Color(r_lightmapintensity, r_lightmapintensity, r_lightmapintensity, 1);
+ GL_Color(r_lightmapintensity * ent->colormod[0], r_lightmapintensity * ent->colormod[1], r_lightmapintensity * ent->colormod[2], 1);
while((surf = *surfchain++) != NULL)
{
if (surf->visframe == r_framecount)
GL_BlendFunc(GL_ONE, GL_ZERO);
m.tex[0] = R_GetTexture(texture->skin.base);
if (ent->flags & RENDER_LIGHT)
- GL_Color(r_lightmapintensity, r_lightmapintensity, r_lightmapintensity, 1);
+ GL_Color(r_lightmapintensity * ent->colormod[0], r_lightmapintensity * ent->colormod[1], r_lightmapintensity * ent->colormod[2], 1);
else
- GL_Color(1, 1, 1, 1);
+ GL_Color(ent->colormod[0], ent->colormod[1], ent->colormod[2], 1);
while((surf = *surfchain++) != NULL)
{
if (surf->visframe == r_framecount)
GL_DepthMask(false);
GL_DepthTest(true);
m.tex[0] = R_GetTexture(texture->skin.base);
- GL_Color(r_ambient.value * (1.0f / 128.0f), r_ambient.value * (1.0f / 128.0f), r_ambient.value * (1.0f / 128.0f), 1);
+ GL_Color(r_ambient.value * (1.0f / 128.0f) * ent->colormod[0], r_ambient.value * (1.0f / 128.0f) * ent->colormod[1], r_ambient.value * (1.0f / 128.0f) * ent->colormod[2], 1);
while((surf = *surfchain++) != NULL)
{
if (surf->visframe == r_framecount)
return;
alttextures = ent->frame != 0;
- texframe = (int)(cl.time * 5.0f);
+ texframe = (int)(r_refdef.time * 5.0f);
for (i = 0;i < ent->model->brushq1.numtextures;i++)
{
t = ent->model->brushq1.textures + i;
if (model->brushq1.light_stylevalue[i] != d_lightstylevalue[model->brushq1.light_style[i]])
{
model->brushq1.light_stylevalue[i] = d_lightstylevalue[model->brushq1.light_style[i]];
- for (surfacechain = model->brushq1.light_styleupdatechains[i];(surface = *surfacechain);surfacechain++)
- surface->cached_dlight = true;
+ if ((surfacechain = model->brushq1.light_styleupdatechains[i]))
+ for (;(surface = *surfacechain);surfacechain++)
+ surface->cached_dlight = true;
}
}
}
int i;
float *v;
rmeshstate_t m;
- const entity_render_t *ent = calldata1;
- const mportal_t *portal = ent->model->brushq1.portals + calldata2;
+ const mportal_t *portal = calldata1;
GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
GL_DepthMask(false);
GL_DepthTest(true);
- R_Mesh_Matrix(&ent->matrix);
+ R_Mesh_Matrix(&r_identitymatrix);
memset(&m, 0, sizeof(m));
m.pointer_vertex = varray_vertex3f;
R_Mesh_State(&m);
- i = portal - ent->model->brushq1.portals;
+ i = calldata2;
GL_Color(((i & 0x0007) >> 0) * (1.0f / 7.0f),
((i & 0x0038) >> 3) * (1.0f / 7.0f),
((i & 0x01C0) >> 6) * (1.0f / 7.0f),
}
// LordHavoc: this is just a nice debugging tool, very slow
-static void R_DrawPortals(entity_render_t *ent)
+static void R_DrawPortals(void)
{
- int i;
- mportal_t *portal, *endportal;
- float temp[3], center[3], f;
- if (ent->model == NULL)
+ int i, portalnum;
+ mportal_t *portal;
+ float center[3], f;
+ model_t *model = r_refdef.worldmodel;
+ if (model == NULL)
return;
- for (portal = ent->model->brushq1.portals, endportal = portal + ent->model->brushq1.numportals;portal < endportal;portal++)
+ for (portalnum = 0, portal = model->brushq1.portals;portalnum < model->brushq1.numportals;portalnum++, portal++)
{
if (portal->numpoints <= POLYGONELEMENTS_MAXPOINTS)
{
- VectorClear(temp);
+ VectorClear(center);
for (i = 0;i < portal->numpoints;i++)
- VectorAdd(temp, portal->points[i].position, temp);
+ VectorAdd(center, portal->points[i].position, center);
f = ixtable[portal->numpoints];
- VectorScale(temp, f, temp);
- Matrix4x4_Transform(&ent->matrix, temp, center);
- R_MeshQueue_AddTransparent(center, R_DrawPortal_Callback, ent, portal - ent->model->brushq1.portals);
+ VectorScale(center, f, center);
+ R_MeshQueue_AddTransparent(center, R_DrawPortal_Callback, portal, portalnum);
}
}
}
R_UpdateLightmapInfo(ent);
}
-void R_SurfaceWorldNode (entity_render_t *ent)
+void R_SurfaceWorldNode (void)
{
int i, *surfacevisframes, *surfacepvsframes, surfnum;
msurface_t *surf;
mleaf_t *leaf;
model_t *model;
- vec3_t modelorg;
// equivilant to quake's RecursiveWorldNode but faster and more effective
- model = ent->model;
+ model = r_refdef.worldmodel;
if (model == NULL)
return;
surfacevisframes = model->brushq1.surfacevisframes + model->firstmodelsurface;
surfacepvsframes = model->brushq1.surfacepvsframes + model->firstmodelsurface;
- Matrix4x4_Transform(&ent->inversematrix, r_vieworigin, modelorg);
for (leaf = model->brushq1.pvsleafchain;leaf;leaf = leaf->pvschain)
{
surfnum = model->brushq1.pvssurflist[i];
surf = model->brushq1.surfaces + surfnum;
#if WORLDNODECULLBACKFACES
- if (PlaneDist(modelorg, surf->plane) < surf->plane->dist)
+ if (PlaneDist(r_vieworigin, surf->plane) < surf->plane->dist)
{
if ((surf->flags & SURF_PLANEBACK) && !R_CullBox (surf->poly_mins, surf->poly_maxs))
surfacevisframes[surfnum] = r_framecount;
}
}
-static void R_PortalWorldNode(entity_render_t *ent, mleaf_t *viewleaf)
+static void R_PortalWorldNode(mleaf_t *viewleaf)
{
int c, leafstackpos, *mark, *surfacevisframes;
#if WORLDNODECULLBACKFACES
#endif
mleaf_t *leaf, *leafstack[8192];
mportal_t *p;
- vec3_t modelorg;
msurface_t *surfaces;
- if (ent->model == NULL)
+ model_t *model = r_refdef.worldmodel;
+ if (model == NULL)
return;
// LordHavoc: portal-passage worldnode with PVS;
// follows portals leading outward from viewleaf, does not venture
// offscreen or into leafs that are not visible, faster than Quake's
// RecursiveWorldNode
- surfaces = ent->model->brushq1.surfaces;
- surfacevisframes = ent->model->brushq1.surfacevisframes;
- Matrix4x4_Transform(&ent->inversematrix, r_vieworigin, modelorg);
+ surfaces = model->brushq1.surfaces;
+ surfacevisframes = model->brushq1.surfacevisframes;
viewleaf->worldnodeframe = r_framecount;
leafstack[0] = viewleaf;
leafstackpos = 1;
if (surfacevisframes[n] != r_framecount)
{
surf = surfaces + n;
- if (PlaneDist(modelorg, surf->plane) < surf->plane->dist)
+ if (PlaneDist(r_vieworigin, surf->plane) < surf->plane->dist)
{
if ((surf->flags & SURF_PLANEBACK))
surfacevisframes[n] = r_framecount;
{
// LordHavoc: this DotProduct hurts less than a cache miss
// (which is more likely to happen if backflowing through leafs)
- if (DotProduct(modelorg, p->plane.normal) < (p->plane.dist + 1))
+ if (DotProduct(r_vieworigin, p->plane.normal) < (p->plane.dist + 1))
{
leaf = p->past;
if (leaf->worldnodeframe != r_framecount)
}
}
-void R_PVSUpdate (entity_render_t *ent, mleaf_t *viewleaf)
+void R_PVSUpdate (mleaf_t *viewleaf)
{
int j, c, *surfacepvsframes, *mark;
mleaf_t *leaf;
model_t *model;
- model = ent->model;
+ model = r_refdef.worldmodel;
if (model && (model->brushq1.pvsviewleaf != viewleaf || model->brushq1.pvsviewleafnovis != r_novis.integer))
{
model->brushq1.pvsframecount++;
}
}
-void R_WorldVisibility(entity_render_t *ent)
+void R_WorldVisibility(void)
{
- vec3_t modelorg;
mleaf_t *viewleaf;
- Matrix4x4_Transform(&ent->inversematrix, r_vieworigin, modelorg);
- viewleaf = (ent->model && ent->model->brushq1.PointInLeaf) ? ent->model->brushq1.PointInLeaf(ent->model, modelorg) : NULL;
- R_PVSUpdate(ent, viewleaf);
+ viewleaf = (r_refdef.worldmodel && r_refdef.worldmodel->brushq1.PointInLeaf) ? r_refdef.worldmodel->brushq1.PointInLeaf(r_refdef.worldmodel, r_vieworigin) : NULL;
+ R_PVSUpdate(viewleaf);
if (!viewleaf)
return;
if (r_surfaceworldnode.integer || viewleaf->contents == CONTENTS_SOLID)
- R_SurfaceWorldNode (ent);
+ R_SurfaceWorldNode();
else
- R_PortalWorldNode (ent, viewleaf);
+ R_PortalWorldNode(viewleaf);
if (r_drawportals.integer)
- R_DrawPortals(ent);
+ R_DrawPortals();
}
void R_Q1BSP_DrawSky(entity_render_t *ent)
{
if (ent->model == NULL)
return;
- if (ent != &cl_entities[0].render)
+ if (ent != r_refdef.worldentity)
R_PrepareBrushModel(ent);
R_PrepareSurfaces(ent);
R_DrawSurfaces(ent, SURF_DRAWSKY);
if (ent->model == NULL)
return;
c_bmodels++;
- if (ent != &cl_entities[0].render)
+ if (ent != r_refdef.worldentity)
R_PrepareBrushModel(ent);
R_PrepareSurfaces(ent);
R_UpdateTextureInfo(ent);
}
}
-void R_Q1BSP_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, vec3_t relativeeyeorigin, float lightradius, float *lightcolor, const matrix4x4_t *matrix_modeltolight, const matrix4x4_t *matrix_modeltoattenuationxyz, const matrix4x4_t *matrix_modeltoattenuationz, rtexture_t *lightcubemap, int numsurfaces, const int *surfacelist)
+void R_Q1BSP_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, vec3_t relativeeyeorigin, float lightradius, float *lightcolor, const matrix4x4_t *matrix_modeltolight, const matrix4x4_t *matrix_modeltoattenuationxyz, const matrix4x4_t *matrix_modeltoattenuationz, rtexture_t *lightcubemap, vec_t ambientscale, vec_t diffusescale, vec_t specularscale, int numsurfaces, const int *surfacelist)
{
model_t *model = ent->model;
vec3_t lightmins, lightmaxs, modelorg;
if (t->flags & SURF_LIGHTMAP && t->skin.fog == NULL)
Mod_ShadowMesh_AddMesh(r_shadow_mempool, r_shadow_compilingrtlight->static_meshchain_light, surface->texinfo->texture->skin.base, surface->texinfo->texture->skin.gloss, surface->texinfo->texture->skin.nmap, surface->mesh.data_vertex3f, surface->mesh.data_svector3f, surface->mesh.data_tvector3f, surface->mesh.data_normal3f, surface->mesh.data_texcoordtexture2f, surface->mesh.num_triangles, surface->mesh.data_element3i);
}
- else if (ent != &cl_entities[0].render || surface->visframe == r_framecount)
+ else if (ent != r_refdef.worldentity || surface->visframe == r_framecount)
{
t = surface->texinfo->texture->currentframe;
// FIXME: transparent surfaces need to be lit later
if (t->flags & SURF_LIGHTMAP && t->rendertype == SURFRENDER_OPAQUE)
- R_Shadow_RenderLighting(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i, surface->mesh.data_vertex3f, surface->mesh.data_svector3f, surface->mesh.data_tvector3f, surface->mesh.data_normal3f, surface->mesh.data_texcoordtexture2f, relativelightorigin, relativeeyeorigin, lightcolor, matrix_modeltolight, matrix_modeltoattenuationxyz, matrix_modeltoattenuationz, t->skin.base, t->skin.nmap, t->skin.gloss, lightcubemap, LIGHTING_DIFFUSE | LIGHTING_SPECULAR);
+ R_Shadow_RenderLighting(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i, surface->mesh.data_vertex3f, surface->mesh.data_svector3f, surface->mesh.data_tvector3f, surface->mesh.data_normal3f, surface->mesh.data_texcoordtexture2f, relativelightorigin, relativeeyeorigin, lightcolor, matrix_modeltolight, matrix_modeltoattenuationxyz, matrix_modeltoattenuationz, t->skin.base, t->skin.nmap, t->skin.gloss, lightcubemap, ambientscale, diffusescale, specularscale);
}
}
}
memset(&m, 0, sizeof(m));
m.pointer_vertex = brush->points->v;
R_Mesh_State(&m);
- i = ((int)brush) / sizeof(colbrushf_t);
+ i = (int)(((size_t)brush) / sizeof(colbrushf_t));
GL_Color((i & 31) * (1.0f / 32.0f), ((i >> 5) & 31) * (1.0f / 32.0f), ((i >> 10) & 31) * (1.0f / 32.0f), 0.2f);
GL_LockArrays(0, brush->numpoints);
R_Mesh_Draw(brush->numpoints, brush->numtriangles, brush->elements);
memset(&m, 0, sizeof(m));
m.pointer_vertex = face->data_collisionvertex3f;
R_Mesh_State(&m);
- i = ((int)face) / sizeof(q3msurface_t);
+ i = (int)(((size_t)face) / sizeof(q3msurface_t));
GL_Color((i & 31) * (1.0f / 32.0f), ((i >> 5) & 31) * (1.0f / 32.0f), ((i >> 10) & 31) * (1.0f / 32.0f), 0.2f);
GL_LockArrays(0, face->num_collisionvertices);
R_Mesh_Draw(face->num_collisionvertices, face->num_collisiontriangles, face->data_collisionelement3i);
rmeshstate_t m;
R_Mesh_Matrix(&ent->matrix);
memset(&m, 0, sizeof(m));
- if (ent->effects & EF_ADDITIVE)
+ if ((ent->effects & EF_ADDITIVE) || (face->texture->textureflags & Q3TEXTUREFLAG_ADDITIVE))
GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
else
GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
{
m.tex[1] = R_GetTexture(face->lightmaptexture);
m.pointer_texcoord[1] = face->data_texcoordlightmap2f;
- GL_Color(1, 1, 1, ent->alpha);
+ GL_Color(ent->colormod[0], ent->colormod[1], ent->colormod[2], ent->alpha);
}
else
{
- if (ent->alpha == 1)
+ if (ent->colormod[0] == 1 && ent->colormod[1] == 1 && ent->colormod[2] == 1 && ent->alpha == 1)
m.pointer_color = face->data_color4f;
else
{
int i;
for (i = 0;i < face->num_vertices;i++)
{
- varray_color4f[i*4+0] = face->data_color4f[i*4+0];
- varray_color4f[i*4+1] = face->data_color4f[i*4+1];
- varray_color4f[i*4+2] = face->data_color4f[i*4+2];
+ varray_color4f[i*4+0] = face->data_color4f[i*4+0] * ent->colormod[0];
+ varray_color4f[i*4+1] = face->data_color4f[i*4+1] * ent->colormod[1];
+ varray_color4f[i*4+2] = face->data_color4f[i*4+2] * ent->colormod[2];
varray_color4f[i*4+3] = face->data_color4f[i*4+3] * ent->alpha;
}
m.pointer_color = varray_color4f;
int i;
for (i = 0;i < face->num_vertices;i++)
{
- varray_color4f[i*4+0] = face->data_color4f[i*4+0] * 2.0f;
- varray_color4f[i*4+1] = face->data_color4f[i*4+1] * 2.0f;
- varray_color4f[i*4+2] = face->data_color4f[i*4+2] * 2.0f;
+ varray_color4f[i*4+0] = face->data_color4f[i*4+0] * ent->colormod[0] * 2.0f;
+ varray_color4f[i*4+1] = face->data_color4f[i*4+1] * ent->colormod[1] * 2.0f;
+ varray_color4f[i*4+2] = face->data_color4f[i*4+2] * ent->colormod[2] * 2.0f;
varray_color4f[i*4+3] = face->data_color4f[i*4+3] * ent->alpha;
}
m.pointer_color = varray_color4f;
}
- m.pointer_vertex = face->data_vertex3f;
+ if (face->texture->textureflags & (Q3TEXTUREFLAG_AUTOSPRITE | Q3TEXTUREFLAG_AUTOSPRITE2))
+ {
+ int i, j;
+ float center[3], center2[3], forward[3], right[3], up[3], v[4][3];
+ matrix4x4_t matrix1, imatrix1;
+ R_Mesh_Matrix(&r_identitymatrix);
+ // a single autosprite surface can contain multiple sprites...
+ for (j = 0;j < face->num_vertices - 3;j += 4)
+ {
+ VectorClear(center);
+ for (i = 0;i < 4;i++)
+ VectorAdd(center, face->data_vertex3f + (j+i) * 3, center);
+ VectorScale(center, 0.25f, center);
+ Matrix4x4_Transform(&ent->matrix, center, center2);
+ // FIXME: calculate vectors from triangle edges instead of using texture vectors as an easy way out?
+ Matrix4x4_FromVectors(&matrix1, face->data_normal3f + j*3, face->data_svector3f + j*3, face->data_tvector3f + j*3, center);
+ Matrix4x4_Invert_Simple(&imatrix1, &matrix1);
+ for (i = 0;i < 4;i++)
+ Matrix4x4_Transform(&imatrix1, face->data_vertex3f + (j+i)*3, v[i]);
+ if (face->texture->textureflags & Q3TEXTUREFLAG_AUTOSPRITE2)
+ {
+ forward[0] = r_vieworigin[0] - center2[0];
+ forward[1] = r_vieworigin[1] - center2[1];
+ forward[2] = 0;
+ VectorNormalize(forward);
+ right[0] = forward[1];
+ right[1] = -forward[0];
+ right[2] = 0;
+ up[0] = 0;
+ up[1] = 0;
+ up[2] = 1;
+ }
+ else
+ {
+ VectorCopy(r_viewforward, forward);
+ VectorCopy(r_viewright, right);
+ VectorCopy(r_viewup, up);
+ }
+ for (i = 0;i < 4;i++)
+ VectorMAMAMAM(1, center2, v[i][0], forward, v[i][1], right, v[i][2], up, varray_vertex3f + (i+j) * 3);
+ }
+ m.pointer_vertex = varray_vertex3f;
+ }
+ else
+ m.pointer_vertex = face->data_vertex3f;
R_Mesh_State(&m);
- qglDisable(GL_CULL_FACE);
+ if (face->texture->textureflags & Q3TEXTUREFLAG_TWOSIDED)
+ qglDisable(GL_CULL_FACE);
GL_LockArrays(0, face->num_vertices);
R_Mesh_Draw(face->num_vertices, face->num_triangles, face->data_element3i);
GL_LockArrays(0, 0);
- qglEnable(GL_CULL_FACE);
+ if (face->texture->textureflags & Q3TEXTUREFLAG_TWOSIDED)
+ qglEnable(GL_CULL_FACE);
}
void R_Q3BSP_DrawFaceList(entity_render_t *ent, q3mtexture_t *t, int texturenumfaces, q3msurface_t **texturefacelist)
GL_DepthMask(true);
GL_DepthTest(true);
GL_BlendFunc(GL_ONE, GL_ZERO);
+ qglDisable(GL_CULL_FACE);
memset(&m, 0, sizeof(m));
for (texturefaceindex = 0;texturefaceindex < texturenumfaces;texturefaceindex++)
{
R_Mesh_Draw(face->num_vertices, face->num_triangles, face->data_element3i);
GL_LockArrays(0, 0);
}
+ qglEnable(GL_CULL_FACE);
return;
}
// anything else is a typical wall, lightmap * texture + glow
GL_DepthMask(true);
GL_DepthTest(true);
GL_BlendFunc(GL_ONE, GL_ZERO);
- GL_Color(1, 1, 1, 1);
+ GL_Color(ent->colormod[0], ent->colormod[1], ent->colormod[2], 1);
+ if (t->textureflags & Q3TEXTUREFLAG_TWOSIDED)
+ qglDisable(GL_CULL_FACE);
memset(&m, 0, sizeof(m));
m.tex[0] = R_GetTexture(t->skin.base);
for (texturefaceindex = 0;texturefaceindex < texturenumfaces;texturefaceindex++)
}
if (t->skin.glow)
{
+ GL_Color(1, 1, 1, 1);
GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
GL_DepthMask(false);
m.tex[0] = R_GetTexture(t->skin.glow);
GL_LockArrays(0, 0);
}
}
+ if (t->textureflags & Q3TEXTUREFLAG_TWOSIDED)
+ qglEnable(GL_CULL_FACE);
return;
}
+ if (t->textureflags & Q3TEXTUREFLAG_TWOSIDED)
+ qglDisable(GL_CULL_FACE);
if (r_lightmapintensity <= 0)
{
GL_DepthMask(true);
m.texrgbscale[1] = 2;
if (face->lightmaptexture)
{
- GL_Color(r_lightmapintensity, r_lightmapintensity, r_lightmapintensity, 1);
+ GL_Color(r_lightmapintensity * ent->colormod[0], r_lightmapintensity * ent->colormod[1], r_lightmapintensity * ent->colormod[2], 1);
m.pointer_color = NULL;
}
- else if (r_lightmapintensity == 1)
+ else if (r_lightmapintensity == 1 && ent->colormod[0] == 1 && ent->colormod[1] == 1 && ent->colormod[2] == 1)
m.pointer_color = face->data_color4f;
else
{
m.pointer_color = varray_color4f;
for (i = 0;i < face->num_vertices;i++)
{
- varray_color4f[i*4+0] = face->data_color4f[i*4+0] * r_lightmapintensity;
- varray_color4f[i*4+1] = face->data_color4f[i*4+1] * r_lightmapintensity;
- varray_color4f[i*4+2] = face->data_color4f[i*4+2] * r_lightmapintensity;
+ varray_color4f[i*4+0] = face->data_color4f[i*4+0] * ent->colormod[0] * r_lightmapintensity;
+ varray_color4f[i*4+1] = face->data_color4f[i*4+1] * ent->colormod[1] * r_lightmapintensity;
+ varray_color4f[i*4+2] = face->data_color4f[i*4+2] * ent->colormod[2] * r_lightmapintensity;
varray_color4f[i*4+3] = face->data_color4f[i*4+3];
}
}
}
GL_BlendFunc(GL_DST_COLOR, GL_SRC_COLOR);
GL_DepthMask(false);
- GL_Color(r_lightmapintensity, r_lightmapintensity, r_lightmapintensity, 1);
+ GL_Color(r_lightmapintensity * ent->colormod[0], r_lightmapintensity * ent->colormod[1], r_lightmapintensity * ent->colormod[2], 1);
memset(&m, 0, sizeof(m));
m.tex[0] = R_GetTexture(t->skin.base);
for (texturefaceindex = 0;texturefaceindex < texturenumfaces;texturefaceindex++)
{
GL_BlendFunc(GL_ONE, GL_ONE);
GL_DepthMask(false);
- GL_Color(r_ambient.value * (1.0f / 128.0f), r_ambient.value * (1.0f / 128.0f), r_ambient.value * (1.0f / 128.0f), 1);
+ GL_Color(r_ambient.value * (1.0f / 128.0f) * ent->colormod[0], r_ambient.value * (1.0f / 128.0f) * ent->colormod[1], r_ambient.value * (1.0f / 128.0f) * ent->colormod[2], 1);
memset(&m, 0, sizeof(m));
m.tex[0] = R_GetTexture(t->skin.base);
for (texturefaceindex = 0;texturefaceindex < texturenumfaces;texturefaceindex++)
GL_LockArrays(0, 0);
}
}
+ if (t->textureflags & Q3TEXTUREFLAG_TWOSIDED)
+ qglEnable(GL_CULL_FACE);
}
void R_Q3BSP_DrawFaces(entity_render_t *ent, int skyfaces)
flags = Q3SURFACEFLAG_SKY;
else
flags = 0;
- if (ent == &cl_entities[0].render)
+ if (ent == r_refdef.worldentity)
{
int j;
q3mleaf_t *leaf;
- R_Surf_ClearSurfaceVisible(cl.worldmodel->brushq3.num_faces);
- for (j = 0, leaf = cl.worldmodel->brushq3.data_leafs;j < cl.worldmodel->brushq3.num_leafs;j++, leaf++)
+ R_Surf_ClearSurfaceVisible(r_refdef.worldmodel->brushq3.num_faces);
+ for (j = 0, leaf = r_refdef.worldmodel->brushq3.data_leafs;j < r_refdef.worldmodel->brushq3.num_leafs;j++, leaf++)
{
if (CHECKPVSBIT(r_pvsbits, leaf->clusterindex) && !R_CullBox(leaf->mins, leaf->maxs))
{
if (r_surf_surfacevisible[t->facenumlist[i]])
{
face = t->facelist[i];
- if (!R_CullBox(face->mins, face->maxs))
+ if (!R_CullBox(face->mins, face->maxs) && face->num_triangles)
{
if (numfaces >= maxfaces)
{
numfaces = 0;
for (i = 0, face = model->brushq3.data_thismodel->firstface;i < model->brushq3.data_thismodel->numfaces;i++, face++)
{
- if ((face->texture->surfaceflags & flagsmask) == flags)
- {
+ if ((face->texture->surfaceflags & flagsmask) == flags && face->num_triangles)
+ {
if (t != face->texture || numfaces >= maxfaces)
{
if (numfaces)
surfaceindex = surface - model->brushq3.data_faces;
if (!CHECKPVSBIT(outsurfacepvs, surfaceindex))
{
- if (BoxesOverlap(lightmins, lightmaxs, surface->mins, surface->maxs) && !(surface->texture->surfaceparms & Q3SURFACEPARM_TRANS) && !(surface->texture->surfaceflags & (Q3SURFACEFLAG_SKY | Q3SURFACEFLAG_NODRAW)))
+ if (BoxesOverlap(lightmins, lightmaxs, surface->mins, surface->maxs) && !(surface->texture->surfaceparms & Q3SURFACEPARM_TRANS) && !(surface->texture->surfaceflags & (Q3SURFACEFLAG_SKY | Q3SURFACEFLAG_NODRAW)) && surface->num_triangles)
{
- for (triangleindex = 0, t = surface->num_firstshadowmeshtriangle, e = model->brush.shadowmesh->element3i + t * 3;triangleindex < surface->num_triangles;triangleindex++, t++, e += 3)
+ if (surface->texture->textureflags & Q3TEXTUREFLAG_TWOSIDED)
{
- v[0] = model->brush.shadowmesh->vertex3f + e[0] * 3;
- v[1] = model->brush.shadowmesh->vertex3f + e[1] * 3;
- v[2] = model->brush.shadowmesh->vertex3f + e[2] * 3;
- if (PointInfrontOfTriangle(relativelightorigin, v[0], v[1], v[2]) && lightmaxs[0] > min(v[0][0], min(v[1][0], v[2][0])) && lightmins[0] < max(v[0][0], max(v[1][0], v[2][0])) && lightmaxs[1] > min(v[0][1], min(v[1][1], v[2][1])) && lightmins[1] < max(v[0][1], max(v[1][1], v[2][1])) && lightmaxs[2] > min(v[0][2], min(v[1][2], v[2][2])) && lightmins[2] < max(v[0][2], max(v[1][2], v[2][2])))
+ for (triangleindex = 0, t = surface->num_firstshadowmeshtriangle, e = model->brush.shadowmesh->element3i + t * 3;triangleindex < surface->num_triangles;triangleindex++, t++, e += 3)
{
- SETPVSBIT(outsurfacepvs, surfaceindex);
- outsurfacelist[outnumsurfaces++] = surfaceindex;
- break;
+ v[0] = model->brush.shadowmesh->vertex3f + e[0] * 3;
+ v[1] = model->brush.shadowmesh->vertex3f + e[1] * 3;
+ v[2] = model->brush.shadowmesh->vertex3f + e[2] * 3;
+ if (lightmaxs[0] > min(v[0][0], min(v[1][0], v[2][0])) && lightmins[0] < max(v[0][0], max(v[1][0], v[2][0])) && lightmaxs[1] > min(v[0][1], min(v[1][1], v[2][1])) && lightmins[1] < max(v[0][1], max(v[1][1], v[2][1])) && lightmaxs[2] > min(v[0][2], min(v[1][2], v[2][2])) && lightmins[2] < max(v[0][2], max(v[1][2], v[2][2])))
+ {
+ SETPVSBIT(outsurfacepvs, surfaceindex);
+ outsurfacelist[outnumsurfaces++] = surfaceindex;
+ break;
+ }
+ }
+ }
+ else
+ {
+ for (triangleindex = 0, t = surface->num_firstshadowmeshtriangle, e = model->brush.shadowmesh->element3i + t * 3;triangleindex < surface->num_triangles;triangleindex++, t++, e += 3)
+ {
+ v[0] = model->brush.shadowmesh->vertex3f + e[0] * 3;
+ v[1] = model->brush.shadowmesh->vertex3f + e[1] * 3;
+ v[2] = model->brush.shadowmesh->vertex3f + e[2] * 3;
+ if (PointInfrontOfTriangle(relativelightorigin, v[0], v[1], v[2]) && lightmaxs[0] > min(v[0][0], min(v[1][0], v[2][0])) && lightmins[0] < max(v[0][0], max(v[1][0], v[2][0])) && lightmaxs[1] > min(v[0][1], min(v[1][1], v[2][1])) && lightmins[1] < max(v[0][1], max(v[1][1], v[2][1])) && lightmaxs[2] > min(v[0][2], min(v[1][2], v[2][2])) && lightmins[2] < max(v[0][2], max(v[1][2], v[2][2])))
+ {
+ SETPVSBIT(outsurfacepvs, surfaceindex);
+ outsurfacelist[outnumsurfaces++] = surfaceindex;
+ break;
+ }
}
}
}
{
surface = model->brushq3.data_faces + surfacelist[surfacelistindex];
// FIXME: check some manner of face->rendermode here?
- if (!(surface->texture->surfaceflags & Q3SURFACEFLAG_NODRAW) && surface->num_triangles && !(surface->texture->surfaceparms & Q3SURFACEPARM_TRANS))
+ if (!(surface->texture->surfaceflags & Q3SURFACEFLAG_NODRAW) && !(surface->texture->surfaceparms & (Q3SURFACEPARM_SKY | Q3SURFACEPARM_TRANS)) && !(surface->texture->textureflags & Q3TEXTUREFLAG_TWOSIDED))
R_Shadow_MarkVolumeFromBox(surface->num_firstshadowmeshtriangle, surface->num_triangles, model->brush.shadowmesh->vertex3f, model->brush.shadowmesh->element3i, relativelightorigin, lightmins, lightmaxs, surface->mins, surface->maxs);
}
R_Shadow_VolumeFromList(model->brush.shadowmesh->numverts, model->brush.shadowmesh->numtriangles, model->brush.shadowmesh->vertex3f, model->brush.shadowmesh->element3i, model->brush.shadowmesh->neighbor3i, relativelightorigin, lightradius + model->radius + r_shadow_projectdistance.value, numshadowmark, shadowmarklist);
}
}
-void R_Q3BSP_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, vec3_t relativeeyeorigin, float lightradius, float *lightcolor, const matrix4x4_t *matrix_modeltolight, const matrix4x4_t *matrix_modeltoattenuationxyz, const matrix4x4_t *matrix_modeltoattenuationz, rtexture_t *lightcubemap, int numsurfaces, const int *surfacelist)
+void R_Q3BSP_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, vec3_t relativeeyeorigin, float lightradius, float *lightcolor, const matrix4x4_t *matrix_modeltolight, const matrix4x4_t *matrix_modeltoattenuationxyz, const matrix4x4_t *matrix_modeltoattenuationz, rtexture_t *lightcubemap, vec_t ambientscale, vec_t diffusescale, vec_t specularscale, int numsurfaces, const int *surfacelist)
{
model_t *model = ent->model;
vec3_t lightmins, lightmaxs, modelorg;
// if compiling an rtlight, capture the mesh
Mod_ShadowMesh_AddMesh(r_shadow_mempool, r_shadow_compilingrtlight->static_meshchain_light, surface->texture->skin.base, surface->texture->skin.gloss, surface->texture->skin.nmap, surface->data_vertex3f, surface->data_svector3f, surface->data_tvector3f, surface->data_normal3f, surface->data_texcoordtexture2f, surface->num_triangles, surface->data_element3i);
}
- else if ((ent != &cl_entities[0].render || surface->visframe == r_framecount) && !(surface->texture->surfaceflags & Q3SURFACEFLAG_NODRAW) && surface->num_triangles)
- R_Shadow_RenderLighting(surface->num_vertices, surface->num_triangles, surface->data_element3i, surface->data_vertex3f, surface->data_svector3f, surface->data_tvector3f, surface->data_normal3f, surface->data_texcoordtexture2f, relativelightorigin, relativeeyeorigin, lightcolor, matrix_modeltolight, matrix_modeltoattenuationxyz, matrix_modeltoattenuationz, surface->texture->skin.base, surface->texture->skin.nmap, surface->texture->skin.gloss, lightcubemap, LIGHTING_DIFFUSE | LIGHTING_SPECULAR);
+ else if (!(surface->texture->surfaceflags & Q3SURFACEFLAG_NODRAW) && surface->num_triangles)
+ {
+ if (surface->texture->textureflags & Q3TEXTUREFLAG_TWOSIDED)
+ qglDisable(GL_CULL_FACE);
+ R_Shadow_RenderLighting(surface->num_vertices, surface->num_triangles, surface->data_element3i, surface->data_vertex3f, surface->data_svector3f, surface->data_tvector3f, surface->data_normal3f, surface->data_texcoordtexture2f, relativelightorigin, relativeeyeorigin, lightcolor, matrix_modeltolight, matrix_modeltoattenuationxyz, matrix_modeltoattenuationz, surface->texture->skin.base, surface->texture->skin.nmap, surface->texture->skin.gloss, lightcubemap, ambientscale, diffusescale, specularscale);
+ if (surface->texture->textureflags & Q3TEXTUREFLAG_TWOSIDED)
+ qglEnable(GL_CULL_FACE);
+ }
}
}
}