}
}
+void Mod_LoadLightList(void)
+{
+ int a, n, numlights;
+ char lightsfilename[1024], *s, *t, *lightsstring;
+ mlight_t *e;
+
+ strcpy(lightsfilename, loadmodel->name);
+ COM_StripExtension(lightsfilename, lightsfilename);
+ strcat(lightsfilename, ".lights");
+ s = lightsstring = (char *) COM_LoadFile (lightsfilename, false);
+ if (s)
+ {
+ numlights = 0;
+ while (*s)
+ {
+ while (*s && *s != '\n')
+ s++;
+ if (!*s)
+ {
+ Mem_Free(lightsstring);
+ Host_Error("lights file must end with a newline\n");
+ }
+ s++;
+ numlights++;
+ }
+ loadmodel->lights = Mem_Alloc(loadmodel->mempool, numlights * sizeof(mlight_t));
+ s = lightsstring;
+ n = 0;
+ while (*s && n < numlights)
+ {
+ t = s;
+ while (*s && *s != '\n')
+ s++;
+ if (!*s)
+ {
+ Mem_Free(lightsstring);
+ Host_Error("misparsed lights file!\n");
+ }
+ e = loadmodel->lights + n;
+ *s = 0;
+ a = sscanf(t, "%f %f %f %f %f %f %f %f %f %f %f %f %d", &e->origin[0], &e->origin[1], &e->origin[2], &e->falloff, &e->light[0], &e->light[1], &e->light[2], &e->subtract, &e->spotdir[0], &e->spotdir[1], &e->spotdir[2], &e->spotcone, &e->style);
+ *s = '\n';
+ if (a != 13)
+ {
+ Mem_Free(lightsstring);
+ Host_Error("invalid lights file, found %d parameters on line %i, should be 13 parameters (origin[0] origin[1] origin[2] falloff light[0] light[1] light[2] subtract spotdir[0] spotdir[1] spotdir[2] spotcone style)\n", a, n + 1);
+ }
+ s++;
+ n++;
+ }
+ if (*s)
+ {
+ Mem_Free(lightsstring);
+ Host_Error("misparsed lights file!\n");
+ }
+ loadmodel->numlights = numlights;
+ Mem_Free(lightsstring);
+ }
+}
+
/*
=================
mainmempool = mod->mempool;
loadname = mod->name;
+ Mod_LoadLightList ();
+
//
// set up the submodels (FIXME: this is confusing)
//
vec3_t dist;
float f;
rdlight_t *rd;
+ mlight_t *sl;
if (leaf == NULL)
leaf = Mod_PointInLeaf(p, cl.worldmodel);
}
color[0] = color[1] = color[2] = r_ambient.value * (2.0f / 128.0f);
- RecursiveLightPoint (color, cl.worldmodel->nodes, p[0], p[1], p[2], p[2] - 65536);
+ if (cl.worldmodel->numlights)
+ {
+ for (i = 0;i < cl.worldmodel->numlights;i++)
+ {
+ sl = cl.worldmodel->lights + i;
+ if (d_lightstylevalue[sl->style] > 0)
+ {
+ VectorSubtract (p, sl->origin, dist);
+ f = DotProduct(dist, dist) + 65536.0f;
+ f = (1.0f / f) - sl->subtract;
+ if (f > 0)
+ {
+ if (TraceLine(p, sl->origin, NULL, NULL, 0, false) == 1)
+ {
+ f *= d_lightstylevalue[sl->style] * (1.0f / 32768.0f);
+ VectorMA(color, f, sl->light, color);
+ }
+ }
+ }
+
+ }
+ }
+ else
+ RecursiveLightPoint (color, cl.worldmodel->nodes, p[0], p[1], p[2], p[2] - 65536);
if (dynamic && leaf->dlightframe == r_framecount)
{
}
color[0] = color[1] = color[2] = r_ambient.value * (2.0f / 128.0f);
- RecursiveLightPoint (color, cl.worldmodel->nodes, p[0], p[1], p[2], p[2] - 65536);
+ if (!cl.worldmodel->numlights)
+ RecursiveLightPoint (color, cl.worldmodel->nodes, p[0], p[1], p[2], p[2] - 65536);
if (leaf->dlightframe == r_framecount)
{
vec_t cullradius2;
vec3_t light;
vec_t lightsubtract;
+ vec_t falloff;
+ vec_t offset;
}
nearlight[MAX_DLIGHTS], *nl;
int modeldlightbits[8];
//staticlight_t *sl;
+ mlight_t *sl;
a = currentrenderentity->alpha;
if (currentrenderentity->effects & EF_FULLBRIGHT)
{
}
}
*/
+ // this code is unused for now
+ for (i = 0, sl = cl.worldmodel->lights;i < cl.worldmodel->numlights && nearlights < MAX_DLIGHTS;i++, sl++)
+ {
+ if (TraceLine(currentrenderentity->origin, sl->origin, NULL, NULL, 0, false) == 1)
+ {
+ nl->falloff = sl->falloff;
+ // transform the light into the model's coordinate system
+ if (worldcoords)
+ VectorCopy(sl->origin, nl->origin);
+ else
+ softwareuntransform(sl->origin, nl->origin);
+ f = d_lightstylevalue[sl->style] * (1.0f / 32768.0f);
+ VectorScale(sl->light, f, nl->light);
+ nl->cullradius2 = 99999999;
+ nl->lightsubtract = sl->subtract;
+ nl->offset = 65536.0f;
+ nl++;
+ nearlights++;
+ }
+ }
for (i = 0;i < r_numdlights && nearlights < MAX_DLIGHTS;i++)
{
if (!(modeldlightbits[i >> 5] & (1 << (i & 31))))
nl->light[1] = r_dlight[i].light[1] * colorg;
nl->light[2] = r_dlight[i].light[2] * colorb;
nl->lightsubtract = r_dlight[i].lightsubtract;
+ nl->offset = LIGHTOFFSET;
nl++;
nearlights++;
}
dist2 = DotProduct(v,v);
if (dist2 < nl->cullradius2)
{
- f = (1.0f / (dist2 + LIGHTOFFSET)) - nl->lightsubtract;
+ f = (1.0f / (dist2 + nl->offset)) - nl->lightsubtract;
if (f > 0)
{
// directional shading