mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 15:22:04 +00:00
[client] Clean up light loading
By adding Light_AddLight to scene light management
This commit is contained in:
parent
b2928b5ed7
commit
41a12f066b
3 changed files with 28 additions and 32 deletions
|
@ -73,6 +73,7 @@ typedef struct lightingdata_s {
|
||||||
lightingdata_t *Light_CreateLightingData (struct scene_s *scene);
|
lightingdata_t *Light_CreateLightingData (struct scene_s *scene);
|
||||||
void Light_DestroyLightingData (lightingdata_t *ldata);
|
void Light_DestroyLightingData (lightingdata_t *ldata);
|
||||||
void Light_ClearLights (lightingdata_t *ldata);
|
void Light_ClearLights (lightingdata_t *ldata);
|
||||||
|
void Light_AddLight (lightingdata_t *ldata, const light_t *light, int style);
|
||||||
void Light_EnableSun (lightingdata_t *ldata);
|
void Light_EnableSun (lightingdata_t *ldata);
|
||||||
void Light_FindVisibleLights (lightingdata_t *ldata);
|
void Light_FindVisibleLights (lightingdata_t *ldata);
|
||||||
|
|
||||||
|
|
|
@ -124,9 +124,7 @@ parse_sun (lightingdata_t *ldata, plitem_t *entity)
|
||||||
light.direction = light.position;
|
light.direction = light.position;
|
||||||
light.direction[3] = 1;
|
light.direction[3] = 1;
|
||||||
light.attenuation = (vec4f_t) { 0, 0, 1, 0 };
|
light.attenuation = (vec4f_t) { 0, 0, 1, 0 };
|
||||||
DARRAY_APPEND (&ldata->lights, light);
|
Light_AddLight (ldata, &light, 0);
|
||||||
DARRAY_APPEND (&ldata->lightstyles, 0);
|
|
||||||
DARRAY_APPEND (&ldata->lightleafs, -1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static vec4f_t
|
static vec4f_t
|
||||||
|
@ -226,25 +224,6 @@ parse_light (light_t *light, int *style, const plitem_t *entity,
|
||||||
light->attenuation = attenuation;
|
light->attenuation = attenuation;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
locate_lights (model_t *model, lightingdata_t *ldata)
|
|
||||||
{
|
|
||||||
light_t *lights = ldata->lights.a;
|
|
||||||
DARRAY_RESIZE (&ldata->lightleafs, ldata->lights.size);
|
|
||||||
for (size_t i = 0; i < ldata->lights.size; i++) {
|
|
||||||
if (1 || lights[i].position[3]) {
|
|
||||||
mleaf_t *leaf = Mod_PointInLeaf (&lights[i].position[0], model);
|
|
||||||
ldata->lightleafs.a[i] = leaf - model->brush.leafs - 1;
|
|
||||||
} else {
|
|
||||||
if (DotProduct (lights[i].direction, lights[i].direction)) {
|
|
||||||
ldata->lightleafs.a[i] = -1;
|
|
||||||
} else {
|
|
||||||
ldata->lightleafs.a[i] = -2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
CL_LoadLights (plitem_t *entities, scene_t *scene)
|
CL_LoadLights (plitem_t *entities, scene_t *scene)
|
||||||
{
|
{
|
||||||
|
@ -285,8 +264,7 @@ CL_LoadLights (plitem_t *entities, scene_t *scene)
|
||||||
light.color = (vec4f_t) { 1, 1, 1, atof (str) };
|
light.color = (vec4f_t) { 1, 1, 1, atof (str) };
|
||||||
light.attenuation = (vec4f_t) { 0, 0, 1, 0 };
|
light.attenuation = (vec4f_t) { 0, 0, 1, 0 };
|
||||||
light.direction = (vec4f_t) { 0, 0, 0, 1 };
|
light.direction = (vec4f_t) { 0, 0, 0, 1 };
|
||||||
DARRAY_APPEND (&ldata->lights, light);
|
Light_AddLight (ldata, &light, 0);
|
||||||
DARRAY_APPEND (&ldata->lightstyles, 0);
|
|
||||||
}
|
}
|
||||||
} else if (!strncmp (classname, "light", 5)) {
|
} else if (!strncmp (classname, "light", 5)) {
|
||||||
light_t light = {};
|
light_t light = {};
|
||||||
|
@ -295,12 +273,10 @@ CL_LoadLights (plitem_t *entities, scene_t *scene)
|
||||||
parse_light (&light, &style, entity, targets);
|
parse_light (&light, &style, entity, targets);
|
||||||
// some lights have 0 output, so drop them
|
// some lights have 0 output, so drop them
|
||||||
if (light.color[3]) {
|
if (light.color[3]) {
|
||||||
DARRAY_APPEND (&ldata->lights, light);
|
Light_AddLight (ldata, &light, style);
|
||||||
DARRAY_APPEND (&ldata->lightstyles, style);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DARRAY_RESIZE (&ldata->lightvis, ldata->lights.size);
|
|
||||||
// targets does not own the objects, so need to remove them before
|
// targets does not own the objects, so need to remove them before
|
||||||
// freeing targets
|
// freeing targets
|
||||||
for (int i = PL_D_NumKeys (targets); i-- > 0; ) {
|
for (int i = PL_D_NumKeys (targets); i-- > 0; ) {
|
||||||
|
@ -308,11 +284,8 @@ CL_LoadLights (plitem_t *entities, scene_t *scene)
|
||||||
}
|
}
|
||||||
PL_Free (targets);
|
PL_Free (targets);
|
||||||
|
|
||||||
if (ldata->lights.size) {
|
for (size_t i = 0; i < ldata->lights.size; i++) {
|
||||||
locate_lights (model, ldata);
|
dump_light (&ldata->lights.a[i], ldata->lightleafs.a[i]);
|
||||||
for (size_t i = 0; i < ldata->lights.size; i++) {
|
|
||||||
dump_light (&ldata->lights.a[i], ldata->lightleafs.a[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Sys_MaskPrintf (SYS_lighting, "loaded %zd lights\n", ldata->lights.size);
|
Sys_MaskPrintf (SYS_lighting, "loaded %zd lights\n", ldata->lights.size);
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,6 +66,28 @@ Light_ClearLights (lightingdata_t *ldata)
|
||||||
ldata->leaf = 0;
|
ldata->leaf = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Light_AddLight (lightingdata_t *ldata, const light_t *light, int style)
|
||||||
|
{
|
||||||
|
scene_t *scene = ldata->scene;
|
||||||
|
model_t *model = scene->worldmodel;
|
||||||
|
|
||||||
|
DARRAY_APPEND (&ldata->lights, *light);
|
||||||
|
DARRAY_APPEND (&ldata->lightstyles, style);
|
||||||
|
|
||||||
|
int visleaf = -1; // directional light
|
||||||
|
if (light->position[3]) {
|
||||||
|
// positional light
|
||||||
|
mleaf_t *leaf = Mod_PointInLeaf (&light->position[0], model);
|
||||||
|
visleaf = leaf - model->brush.leafs - 1;
|
||||||
|
} else if (!DotProduct (light->direction, light->direction)) {
|
||||||
|
// ambient light
|
||||||
|
visleaf = -2;
|
||||||
|
}
|
||||||
|
DARRAY_APPEND (&ldata->lightleafs, visleaf);
|
||||||
|
DARRAY_APPEND (&ldata->lightvis, 0);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Light_EnableSun (lightingdata_t *ldata)
|
Light_EnableSun (lightingdata_t *ldata)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue