From: lordhavoc Date: Thu, 17 Jan 2002 01:22:52 +0000 (+0000) Subject: made directional static lighting work, then disabled it because it is not practical... X-Git-Tag: RELEASE_0_2_0_RC1~720 X-Git-Url: https://de.git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=commitdiff_plain;h=83b77bee53d11d3e694f34e242e15cacdce188cd made directional static lighting work, then disabled it because it is not practical without reliable data from the lighting utility git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@1352 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/buildnumber.c b/buildnumber.c index 4124bfc8..b15d6c2a 100644 --- a/buildnumber.c +++ b/buildnumber.c @@ -1,4 +1,4 @@ -#define BUILDNUMBER 619 +#define BUILDNUMBER 656 int buildnumber = BUILDNUMBER; diff --git a/cl_parse.c b/cl_parse.c index 9a06ee43..c2268e5c 100644 --- a/cl_parse.c +++ b/cl_parse.c @@ -239,7 +239,59 @@ void CL_KeepaliveMessage (void) SZ_Clear (&cls.message); } -//FIXME finish this code! +void CL_ParseEntityLump(char *entdata) +{ + char *data; + char key[128], value[4096]; + FOG_clear(); // LordHavoc: no fog until set + R_SetSkyBox(""); // LordHavoc: no environment mapped sky until set + data = entdata; + if (!data) + return; + data = COM_Parse(data); + if (!data) + return; // error + if (com_token[0] != '{') + return; // error + while (1) + { + data = COM_Parse(data); + if (!data) + return; // error + if (com_token[0] == '}') + break; // end of worldspawn + if (com_token[0] == '_') + strcpy(key, com_token + 1); + else + strcpy(key, com_token); + while (key[strlen(key)-1] == ' ') // remove trailing spaces + key[strlen(key)-1] = 0; + data = COM_Parse(data); + if (!data) + return; // error + strcpy(value, com_token); + if (!strcmp("sky", key)) + R_SetSkyBox(value); + else if (!strcmp("skyname", key)) // non-standard, introduced by QuakeForge... sigh. + R_SetSkyBox(value); + else if (!strcmp("qlsky", key)) // non-standard, introduced by QuakeLives (EEK) + R_SetSkyBox(value); + else if (!strcmp("fog", key)) + sscanf(value, "%f %f %f %f", &fog_density, &fog_red, &fog_green, &fog_blue); + else if (!strcmp("fog_density", key)) + fog_density = atof(value); + else if (!strcmp("fog_red", key)) + fog_red = atof(value); + else if (!strcmp("fog_green", key)) + fog_green = atof(value); + else if (!strcmp("fog_blue", key)) + fog_blue = atof(value); + } +} + +/* +//this code is going to be removed + #define MAX_STATICLIGHTS 2048 // tyrlite types #define LIGHTFADE_LMINUSX 0 // light, arghlite, others? @@ -253,15 +305,31 @@ typedef struct int fadetype; // one of the LIGHTFADE_ values int style; vec3_t origin; - vec_t radius; // the point at which lighting stops - vec3_t direction; - vec_t cone; // if non-zero, it is a spot light - vec3_t color; vec_t distancescale; // attenuation - vec_t lightsubtract; // biasing lighting toward black (hlight feature) + + // spotlights + vec3_t direction; // direction + vec_t cone; // cone cosine, any light cosine outside this range is suddenly black + + // LIGHTFADE_LMINUSX + vec_t light; + vec3_t color; + + // LIGHTFADE_LDIVX and LIGHTFADE_LDIVX2 + vec3_t light2; // light * color + vec_t lightsubtract; // hlight feature } staticlight_t; +extern staticlight_t staticlight[MAX_STATICLIGHTS]; +extern int staticlights; + +extern int r_sunlightenabled; +extern vec3_t r_sunlightdirection, r_sunlightcolor; +extern vec3_t r_light_ambientcolor; + + + staticlight_t staticlight[MAX_STATICLIGHTS]; int staticlights; @@ -275,7 +343,7 @@ void CL_ParseEntityLump(char *entdata) char key[128], value[4096]; char targetnamebuffer[65536]; char *targetname[8192], *target[MAX_STATICLIGHTS], light_target[256]; - vec3_t targetnameorigin[8192], targetnametemporigin, v; + vec3_t targetnameorigin[8192], v; int targets, targetnames, targetnamebufferpos, targetnameorigintofillin; int i, j, n; float f1, f2, f3, f4; @@ -306,10 +374,6 @@ void CL_ParseEntityLump(char *entdata) targets = 0; targetnames = 0; targetnamebufferpos = 0; - targetnameorigintofillin = -1; - targetnametemporigin[0] = 0; - targetnametemporigin[1] = 0; - targetnametemporigin[2] = 0; while (1) { data = COM_Parse(data); @@ -334,7 +398,7 @@ void CL_ParseEntityLump(char *entdata) else if (!strcmp("qlsky", key)) // non-standard, introduced by QuakeLives (EEK) R_SetSkyBox(value); else if (!strcmp("fog", key)) - scanf(value, "%f %f %f %f", &fog_density, &fog_red, &fog_green, &fog_blue); + sscanf(value, "%f %f %f %f", &fog_density, &fog_red, &fog_green, &fog_blue); else if (!strcmp("fog_density", key)) fog_density = atof(value); else if (!strcmp("fog_red", key)) @@ -352,37 +416,17 @@ void CL_ParseEntityLump(char *entdata) } else if (!strcmp("sun_color", key)) { - if (scanf(value, "%f %f %f", &v[0], &v[1], &v[2]) == 3) + if (sscanf(value, "%f %f %f", &v[0], &v[1], &v[2]) == 3) VectorCopy(v, sunlightcolor); tyrlite = true; } else if (!strcmp("sun_mangle", key)) { - if (scanf(value, "%f %f %f", &v[0], &v[1], &v[2]) == 3) + if (sscanf(value, "%f %f %f", &v[0], &v[1], &v[2]) == 3) AngleVectors(v, sunlightdirection, NULL, NULL); tyrlite = true; } - else if (!strcmp("origin", key)) - { - if (scanf(value, "%f %f %f", &v[0], &v[1], &v[2]) == 3) - { - VectorCopy(v, targetnametemporigin); - VectorCopy(v, light_origin); - } - } - else if (!strcmp("targetname", key)) - { - if ((targetnames < 8192) && (strlen(value) + 1 + targetnamebufferpos <= 65536)) - { - targetname[targetnames] = targetnamebuffer + targetnamebufferpos; - strcpy(targetnamebuffer + targetnamebufferpos, value); - targetnamebufferpos += strlen(value) + 1; - targetnameorigintofillin = targetnames++; - } - } } - if (targetnameorigintofillin >= 0) - VectorCopy(targetnametemporigin, targetnameorigin[targetnameorigintofillin]); if (sunlight) { @@ -400,6 +444,7 @@ void CL_ParseEntityLump(char *entdata) if (com_token[0] != '{') break; // error light_light = 0; + VectorClear(light_origin); light_lightcolor[0] = light_lightcolor[1] = light_lightcolor[2] = 1.0f; light_color[0] = light_color[1] = light_color[2] = 1.0f; light_direction[0] = light_direction[1] = light_direction[2] = 0.0f; @@ -410,9 +455,6 @@ void CL_ParseEntityLump(char *entdata) light_lightradius = 0; light_enable = false; targetnameorigintofillin = -1; - targetnametemporigin[0] = 0; - targetnametemporigin[1] = 0; - targetnametemporigin[2] = 0; while (1) { data = COM_Parse(data); @@ -432,7 +474,7 @@ void CL_ParseEntityLump(char *entdata) strcpy(value, com_token); if (!strcmp("light", key)) { - n = scanf(value, "%f %f %f %f", &f1, &f2, &f3, &f4); + n = sscanf(value, "%f %f %f %f", &f1, &f2, &f3, &f4); switch(n) { case 1: @@ -463,7 +505,7 @@ void CL_ParseEntityLump(char *entdata) } else if (!strcmp("color", key)) { - n = scanf(value, "%f %f %f", &f1, &f2, &f3); + n = sscanf(value, "%f %f %f", &f1, &f2, &f3); if (n == 3) { light_color[0] = f1; @@ -473,17 +515,21 @@ void CL_ParseEntityLump(char *entdata) // n != 3 is an error } else if (!strcmp("wait", key)) + { light_distancescale = atof(value); + } else if (!strcmp("delay", key)) { light_fadetype = atoi(value); tyrlite = true; } else if (!strcmp("angle", key)) + { light_cone = -cos(atof(value) * M_PI / 360); + } else if (!strcmp("mangle", key)) { - n = scanf(value, "%f %f %f", &v[0], &v[1], &v[2]); + n = sscanf(value, "%f %f %f", &v[0], &v[1], &v[2]); if (n == 3) AngleVectors(v, light_direction, NULL, NULL); // n != 3 is an error @@ -501,12 +547,14 @@ void CL_ParseEntityLump(char *entdata) light_lightradius = atof(value); } else if (!strcmp("classname", key)) + { if (!strncmp(value, "light", 5)) light_enable = true; + } else if (!strcmp("origin", key)) { - if (scanf(value, "%f %f %f", &v[0], &v[1], &v[2]) == 3) - VectorCopy(v, targetnametemporigin); + if (sscanf(value, "%f %f %f", &v[0], &v[1], &v[2]) == 3) + VectorCopy(v, light_origin); } else if (!strcmp("targetname", key)) { @@ -523,19 +571,10 @@ void CL_ParseEntityLump(char *entdata) strcpy(light_target, value); } if (targetnameorigintofillin >= 0) - VectorCopy(targetnametemporigin, targetnameorigin[targetnameorigintofillin]); + VectorCopy(light_origin, targetnameorigin[targetnameorigintofillin]); if (light_enable && staticlights < MAX_STATICLIGHTS && light_light != 0) { - VectorCopy(light_origin, staticlight[staticlights].origin); - staticlight[staticlights].color[0] = light_light * light_lightcolor[0] * light_color[0]; - staticlight[staticlights].color[1] = light_light * light_lightcolor[1] * light_color[1]; - staticlight[staticlights].color[2] = light_light * light_lightcolor[2] * light_color[2]; - VectorCopy(light_direction, staticlight[staticlights].direction); - staticlight[staticlights].cone = light_cone; - staticlight[staticlights].distancescale = light_distancescale; - staticlight[staticlights].fadetype = light_fadetype; - staticlight[staticlights].style = light_style; - if (light_target && (targets < 8192) && (strlen(value) + 1 + targetnamebufferpos <= 65536)) + if (light_target[0] && (targets < 8192) && (strlen(value) + 1 + targetnamebufferpos <= 65536)) { target[staticlights] = targetnamebuffer + targetnamebufferpos; strcpy(targetnamebuffer + targetnamebufferpos, value); @@ -543,6 +582,23 @@ void CL_ParseEntityLump(char *entdata) } else target[staticlights] = NULL; + + staticlight[staticlights].fadetype = light_fadetype; + staticlight[staticlights].style = light_style; + VectorCopy(light_origin, staticlight[staticlights].origin); + staticlight[staticlights].distancescale = light_distancescale; + // these are often altered later by the target name linking + VectorCopy(light_direction, staticlight[staticlights].direction); + staticlight[staticlights].cone = light_cone; + + staticlight[staticlights].light = light_light; + staticlight[staticlights].color[0] = light_lightcolor[0] * light_color[0]; + staticlight[staticlights].color[1] = light_lightcolor[1] * light_color[1]; + staticlight[staticlights].color[2] = light_lightcolor[2] * light_color[2]; + + staticlight[staticlights].light2[0] = light_light * light_lightcolor[0] * light_color[0]; + staticlight[staticlights].light2[1] = light_light * light_lightcolor[1] * light_color[1]; + staticlight[staticlights].light2[2] = light_light * light_lightcolor[2] * light_color[2]; staticlight[staticlights].lightsubtract = 0; if (light_lightradius) { @@ -554,6 +610,8 @@ void CL_ParseEntityLump(char *entdata) } if (cl.worldmodel->ishlbsp) n = LIGHTFADE_LDIVX2; + else if (light_hlight.integer) + n = LIGHTFADE_LDIVX2; else if (tyrlite) n = LIGHTFADE_LMINUSX; else if (hlight) @@ -581,6 +639,7 @@ void CL_ParseEntityLump(char *entdata) staticlight[i].cone = 0; } } +*/ /* ===================== diff --git a/r_light.c b/r_light.c index 340fa75b..395c68c6 100644 --- a/r_light.c +++ b/r_light.c @@ -723,6 +723,7 @@ void R_LightModel(int numverts) } 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; @@ -733,7 +734,25 @@ void R_LightModel(int numverts) R_ModelLightPoint(basecolor, currentrenderentity->origin, modeldlightbits); nl = &nearlight[0]; - for (i = 0;i < r_numdlights;i++) + /* + // 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;