if (!r_coronas.integer)
return;
R_Mesh_Matrix(&r_identitymatrix);
- viewdist = DotProduct(r_origin, vpn);
+ viewdist = DotProduct(r_vieworigin, r_viewforward);
for (i = 0;i < r_numdlights;i++)
{
rd = r_dlight + i;
- dist = (DotProduct(rd->origin, vpn) - viewdist);
- if (dist >= 24.0f && CL_TraceLine(rd->origin, r_origin, NULL, NULL, 0, true, NULL) == 1)
+ dist = (DotProduct(rd->origin, r_viewforward) - viewdist);
+ if (dist >= 24.0f && CL_TraceLine(rd->origin, r_vieworigin, NULL, NULL, true, NULL, SUPERCONTENTS_SOLID) == 1)
{
cscale = (1.0f / 131072.0f);
scale = rd->cullradius * 0.25f;
cscale *= 4.0f;
scale *= 2.0f;
}
- R_DrawSprite(GL_ONE, GL_ONE, lightcorona, true, rd->origin, vright, vup, scale, -scale, -scale, scale, rd->light[0] * cscale, rd->light[1] * cscale, rd->light[2] * cscale, 1);
+ R_DrawSprite(GL_ONE, GL_ONE, lightcorona, true, rd->origin, r_viewright, r_viewup, scale, -scale, -scale, scale, rd->light[0] * cscale, rd->light[1] * cscale, rd->light[2] * cscale, 1);
}
}
}
{
surf->dlightbits[0] = surf->dlightbits[1] = surf->dlightbits[2] = surf->dlightbits[3] = surf->dlightbits[4] = surf->dlightbits[5] = surf->dlightbits[6] = surf->dlightbits[7] = 0;
surf->dlightframe = r_framecount;
- if (r_dlightmap.integer)
- surf->cached_dlight = true;
+ surf->cached_dlight = true;
}
surf->dlightbits[bitindex] |= bit;
}
int i, bit, bitindex;
rdlight_t *rd;
vec3_t lightorigin;
- if (!gl_flashblend.integer && r_dynamic.integer && ent->model)
+ if (!gl_flashblend.integer && r_dynamic.integer && ent->model && ent->model->brushq1.numleafs)
{
for (i = 0, rd = r_dlight;i < r_numdlights;i++, rd++)
{
lightpvsbytes = 0;
if (r_vismarklights.integer && ent->model->brush.FatPVS)
lightpvsbytes = ent->model->brush.FatPVS(ent->model, lightorigin, 0, lightpvs, sizeof(lightpvs));
- R_RecursiveMarkLights(ent, lightorigin, rd, bit, bitindex, ent->model->brushq1.nodes + ent->model->brushq1.hulls[0].firstclipnode, lightpvs, min(lightpvsbytes * 8, ent->model->brushq1.num_leafs - 1));
+ R_RecursiveMarkLights(ent, lightorigin, rd, bit, bitindex, ent->model->brushq1.nodes + ent->model->brushq1.hulls[0].firstclipnode, lightpvs, min(lightpvsbytes * 8, ent->model->brushq1.visleafs));
}
}
}
else
VectorSet(ambientcolor, 1, 1, 1);
- /*
- if (leaf == NULL && cl.worldmodel != NULL)
- leaf = cl.worldmodel->brushq1.PointInLeaf(cl.worldmodel, p);
- if (!leaf || leaf->contents == CONTENTS_SOLID || !cl.worldmodel->brushq1.lightdata)
- {
- VectorSet(ambientcolor, 1, 1, 1);
- return;
- }
- */
-
// FIXME: this .lights related stuff needs to be ported into the Mod_Q1BSP code
if (cl.worldmodel->brushq1.numlights)
{
{
VectorSubtract (p, sl->origin, v);
f = ((1.0f / (DotProduct(v, v) * sl->falloff + sl->distbias)) - sl->subtract);
- if (f > 0 && CL_TraceLine(p, sl->origin, NULL, NULL, 0, false, NULL) == 1)
+ if (f > 0 && CL_TraceLine(p, sl->origin, NULL, NULL, false, NULL, SUPERCONTENTS_SOLID) == 1)
{
f *= d_lightstylevalue[sl->style] * (1.0f / 65536.0f);
VectorMA(ambientcolor, f, sl->light, ambientcolor);
rd = r_dlight + i;
VectorSubtract(p, rd->origin, v);
f = DotProduct(v, v);
- if (f < rd->cullradius2 && CL_TraceLine(p, rd->origin, NULL, NULL, 0, false, NULL) == 1)
+ if (f < rd->cullradius2 && CL_TraceLine(p, rd->origin, NULL, NULL, false, NULL, SUPERCONTENTS_SOLID) == 1)
{
f = (1.0f / (f + LIGHTOFFSET)) - rd->subtract;
VectorMA(ambientcolor, f, rd->light, ambientcolor);
int R_LightModel(float *ambient4f, float *diffusecolor, float *diffusenormal, const entity_render_t *ent, float colorr, float colorg, float colorb, float colora, int worldcoords)
{
int i, j, maxnearlights;
- float v[3], f, mscale, stylescale, intensity, ambientcolor[3];
+ float v[3], f, mscale, stylescale, intensity, ambientcolor[3], tempdiffusenormal[3];
nearlight_t *nl;
mlight_t *sl;
rdlight_t *rd;
else
{
if (cl.worldmodel && cl.worldmodel->brush.LightPoint)
- cl.worldmodel->brush.LightPoint(cl.worldmodel, ent->origin, ambient4f, diffusecolor, diffusenormal);
+ {
+ cl.worldmodel->brush.LightPoint(cl.worldmodel, ent->origin, ambient4f, diffusecolor, tempdiffusenormal);
+ Matrix4x4_Transform3x3(&ent->inversematrix, tempdiffusenormal, diffusenormal);
+ VectorNormalize(diffusenormal);
+ }
else
VectorSet(ambient4f, 1, 1, 1);
}
VectorSubtract (v, rd->origin, v);
if (DotProduct(v, v) < rd->cullradius2)
{
- if (CL_TraceLine(ent->origin, rd->origin, NULL, NULL, 0, false, NULL) != 1)
+ if (CL_TraceLine(ent->origin, rd->origin, NULL, NULL, false, NULL, SUPERCONTENTS_SOLID) != 1)
continue;
VectorSubtract (ent->origin, rd->origin, v);
f = ((1.0f / (DotProduct(v, v) + LIGHTOFFSET)) - rd->subtract);
float color[4], v[3], dot, dist2, f, dnormal[3];
nearlight_t *nl;
usediffuse = DotProduct(diffusecolor, diffusecolor) > 0;
- VectorCopy(diffusenormal, dnormal);
+ // negate the diffuse normal to avoid the need to negate the
+ // dotproduct on each vertex
+ VectorNegate(diffusenormal, dnormal);
if (usediffuse)
VectorNormalize(dnormal);
// directional shading code here
ent->numentlights = 0;
if (cl.worldmodel)
for (i = 0, sl = cl.worldmodel->brushq1.lights;i < cl.worldmodel->brushq1.numlights && ent->numentlights < MAXENTLIGHTS;i++, sl++)
- if (CL_TraceLine(ent->origin, sl->origin, NULL, NULL, 0, false, NULL) == 1)
+ if (CL_TraceLine(ent->origin, sl->origin, NULL, NULL, false, NULL, SUPERCONTENTS_SOLID) == 1)
ent->entlights[ent->numentlights++] = i;
}
ent->entlightsframe = r_framecount;