-void R_LightModel(int numverts)
-{
- int i, j, nearlights = 0;
- float color[3], basecolor[3], v[3], t, *av, *avn, *avc, a, number, f, hardness, hardnessoffset, dist2;
- struct
- {
- vec3_t origin;
- vec_t cullradius2;
- vec3_t light;
- vec_t lightsubtract;
- }
- nearlight[MAX_DLIGHTS], *nl;
- int modeldlightbits[8];
- //staticlight_t *sl;
- a = currentrenderentity->alpha;
- if (currentrenderentity->effects & EF_FULLBRIGHT)
- basecolor[0] = basecolor[1] = basecolor[2] = 1;
- else
- {
- if (r_lightmodels.integer)
- {
- R_ModelLightPoint(basecolor, currentrenderentity->origin, modeldlightbits);
-
- nl = &nearlight[0];
- /*
- // this code is unused for now
- for (i = 0, sl = staticlight;i < staticlights && nearlights < MAX_DLIGHTS;i++, sl++)
- {
- if (TraceLine(currentrenderentity->origin, sl->origin, NULL, NULL, 0) == 1)
- {
- nl->fadetype = sl->fadetype;
- nl->distancescale = sl->distancescale;
- nl->radius = sl->radius;
- VectorCopy(sl->origin, nl->origin);
- VectorCopy(sl->color, nl->light);
- nl->cullradius2 = 99999999;
- nl->lightsubtract = 0;
- nl++;
- nearlights++;
- }
- }
- */
- for (i = 0;i < r_numdlights && nearlights < MAX_DLIGHTS;i++)
- {
- if (!(modeldlightbits[i >> 5] & (1 << (i & 31))))
- continue;
- if (currentrenderentity == r_dlight[i].ent)
- {
- f = (1.0f / LIGHTOFFSET) - nl->lightsubtract;
- if (f > 0)
- VectorMA(basecolor, f, r_dlight[i].light, basecolor);
- }
- else
- {
- // convert 0-255 radius coloring to 0-1, while also amplifying the brightness by 16
- //if (TraceLine(currentrenderentity->origin, r_dlight[i].origin, NULL, NULL, 0) == 1)
- {
- // transform the light into the model's coordinate system
- //if (gl_transform.integer)
- // softwareuntransform(r_dlight[i].origin, nl->origin);
- //else
- VectorCopy(r_dlight[i].origin, nl->origin);
- nl->cullradius2 = r_dlight[i].cullradius2;
- VectorCopy(r_dlight[i].light, nl->light);
- nl->lightsubtract = r_dlight[i].lightsubtract;
- nl++;
- nearlights++;
- }
- }
- }
- }
- else
- R_CompleteLightPoint (basecolor, currentrenderentity->origin, true, NULL);
- }
- avc = aliasvertcolor;
- if (nearlights)
- {
- av = aliasvert;
- avn = aliasvertnorm;
- hardness = r_lightmodelhardness.value;
- hardnessoffset = (1.0f - hardness);
- for (i = 0;i < numverts;i++)
- {
- VectorCopy(basecolor, color);
- for (j = 0, nl = &nearlight[0];j < nearlights;j++, nl++)
- {
- // distance attenuation
- VectorSubtract(nl->origin, av, v);
- dist2 = DotProduct(v,v);
- if (dist2 < nl->cullradius2)
- {
- f = (1.0f / (dist2 + LIGHTOFFSET)) - nl->lightsubtract;
- if (f > 0)
- {
- // directional shading
- #if SLOWMATH
- t = 1.0f / sqrt(dist2);
- #else
- number = DotProduct(v, v);
- *((long *)&t) = 0x5f3759df - ((* (long *) &number) >> 1);
- t = t * (1.5f - (number * 0.5f * t * t));
- #endif
- // DotProduct(avn,v) * t is dotproduct with a normalized v,
- // the hardness variables are for backlighting/shinyness
- f *= DotProduct(avn,v) * t * hardness + hardnessoffset;
- if (f > 0)
- VectorMA(color, f, nl->light, color);
- }
- }
- }
-
- VectorCopy(color, avc);
- avc[3] = a;
- avc += 4;
- av += 4;
- avn += 3;
- }
- }
- else
- {
- for (i = 0;i < numverts;i++)
- {
- VectorCopy(basecolor, avc);
- avc[3] = a;
- avc += 4;
- }
- }
-}