From: lordhavoc Date: Wed, 15 May 2002 04:00:37 +0000 (+0000) Subject: directional static lighting support (but not fast yet), for maps compiled with (as... X-Git-Tag: RELEASE_0_2_0_RC1~513 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=3dc29de768c9d71f4073d44dc5e1a82ca7e8e280;p=xonotic%2Fdarkplaces.git directional static lighting support (but not fast yet), for maps compiled with (as yet unreleased) new version of hlight git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@1839 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/model_brush.c b/model_brush.c index 3301a7b4..0c87d8b8 100644 --- a/model_brush.c +++ b/model_brush.c @@ -546,6 +546,66 @@ static void Mod_LoadLighting (lump_t *l) } } +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); + } +} + /* ================= @@ -2453,6 +2513,8 @@ void Mod_LoadBrushModel (model_t *mod, void *buffer) mainmempool = mod->mempool; loadname = mod->name; + Mod_LoadLightList (); + // // set up the submodels (FIXME: this is confusing) // diff --git a/model_brush.h b/model_brush.h index 04bae33c..1ab081b0 100644 --- a/model_brush.h +++ b/model_brush.h @@ -277,6 +277,19 @@ typedef struct mportal_s } mportal_t; +typedef struct mlight_s +{ + vec3_t origin; + float falloff; + vec3_t light; + float subtract; + vec3_t spotdir; + float spotcone; // cosine of spotlight cone angle (or 0 if not a spotlight) + int style; + int numleafs; // used only for loading calculations, number of leafs this shines on +} +mlight_t; + extern rtexture_t *r_notexture; extern texture_t r_notexture_mip; diff --git a/model_shared.h b/model_shared.h index 2e70d783..d55844e3 100644 --- a/model_shared.h +++ b/model_shared.h @@ -173,6 +173,9 @@ typedef struct model_s int numportalpoints; mvertex_t *portalpoints; + int numlights; + mlight_t *lights; + // skin animation info animscene_t *skinscenes; // [numskins] // skin frame info diff --git a/r_light.c b/r_light.c index a7e392c7..2e99dfff 100644 --- a/r_light.c +++ b/r_light.c @@ -730,6 +730,7 @@ void R_CompleteLightPoint (vec3_t color, vec3_t p, int dynamic, mleaf_t *leaf) vec3_t dist; float f; rdlight_t *rd; + mlight_t *sl; if (leaf == NULL) leaf = Mod_PointInLeaf(p, cl.worldmodel); @@ -746,7 +747,30 @@ void R_CompleteLightPoint (vec3_t color, vec3_t p, int dynamic, mleaf_t *leaf) } 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) { @@ -787,7 +811,8 @@ void R_ModelLightPoint (vec3_t color, vec3_t p, int *dlightbits) } 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) { @@ -814,10 +839,13 @@ void R_LightModel(int numverts, float colorr, float colorg, float colorb, int wo 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) { @@ -854,6 +882,26 @@ void R_LightModel(int numverts, float colorr, float colorg, float colorb, int wo } } */ + // 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)))) @@ -879,6 +927,7 @@ void R_LightModel(int numverts, float colorr, float colorg, float colorb, int wo 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++; } @@ -908,7 +957,7 @@ void R_LightModel(int numverts, float colorr, float colorg, float colorb, int wo 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