{
int i, numsurfaces, *surfacevisframes;
model_t *model;
- msurface_t *surf, *surfaces;
+ msurface_t *surf, *surfaces, **surfchain;
vec3_t modelorg;
if (!ent->model)
if (r_dynamic.integer && r_shadow_lightingmode < 1)
R_MarkLights(ent);
+ if (model->light_ambient != r_ambient.value || model->light_scalebit != r_lightmapscalebit)
+ {
+ model->light_ambient = r_ambient.value;
+ model->light_scalebit = r_lightmapscalebit;
+ for (i = 0;i < model->nummodelsurfaces;i++)
+ model->surfaces[i + model->firstmodelsurface].cached_dlight = true;
+ }
+ else
+ {
+ for (i = 0;i < model->light_styles;i++)
+ {
+ if (model->light_stylevalue[i] != d_lightstylevalue[model->light_style[i]])
+ {
+ model->light_stylevalue[i] = d_lightstylevalue[model->light_style[i]];
+ for (surfchain = model->light_styleupdatechains[i];*surfchain;surfchain++)
+ (**surfchain).cached_dlight = true;
+ }
+ }
+ }
+
for (i = 0, surf = surfaces;i < numsurfaces;i++, surf++)
{
if (surfacevisframes[i] == r_framecount)
{
c_faces++;
surf->visframe = r_framecount;
+#if 1
+ if (surf->cached_dlight && surf->lightmaptexture != NULL && !r_vertexsurfaces.integer)
+ R_BuildLightMap(ent, surf, false); // base lighting changed
+#else
if (!r_vertexsurfaces.integer && surf->lightmaptexture != NULL)
{
if (surf->cached_dlight
R_BuildLightMap(ent, surf, true); // only dlights
}
}
+#endif
}
}
}
#endif
}
+void Mod_BuildLightmapUpdateChains(mempool_t *mempool, model_t *model)
+{
+ int i, j, stylecounts[256], totalcount, remapstyles[256];
+ msurface_t *surf;
+ memset(stylecounts, 0, sizeof(stylecounts));
+ for (i = 0;i < model->nummodelsurfaces;i++)
+ {
+ surf = model->surfaces + model->firstmodelsurface + i;
+ for (j = 0;j < MAXLIGHTMAPS;j++)
+ stylecounts[surf->styles[j]]++;
+ }
+ totalcount = 0;
+ model->light_styles = 0;
+ for (i = 0;i < 255;i++)
+ {
+ if (stylecounts[i])
+ {
+ remapstyles[i] = model->light_styles++;
+ totalcount += stylecounts[i] + 1;
+ }
+ }
+ if (!totalcount)
+ return;
+ model->light_style = Mem_Alloc(mempool, model->light_styles * sizeof(qbyte));
+ model->light_stylevalue = Mem_Alloc(mempool, model->light_styles * sizeof(int));
+ model->light_styleupdatechains = Mem_Alloc(mempool, model->light_styles * sizeof(msurface_t **));
+ model->light_styleupdatechainsbuffer = Mem_Alloc(mempool, totalcount * sizeof(msurface_t *));
+ model->light_styles = 0;
+ for (i = 0;i < 255;i++)
+ if (stylecounts[i])
+ model->light_style[model->light_styles++] = i;
+ j = 0;
+ for (i = 0;i < model->light_styles;i++)
+ {
+ model->light_styleupdatechains[i] = model->light_styleupdatechainsbuffer + j;
+ j += stylecounts[model->light_style[i]] + 1;
+ }
+ for (i = 0;i < model->nummodelsurfaces;i++)
+ {
+ surf = model->surfaces + model->firstmodelsurface + i;
+ for (j = 0;j < MAXLIGHTMAPS;j++)
+ if (surf->styles[j] != 255)
+ *model->light_styleupdatechains[remapstyles[surf->styles[j]]]++ = surf;
+ }
+ j = 0;
+ for (i = 0;i < model->light_styles;i++)
+ {
+ *model->light_styleupdatechains[i] = NULL;
+ model->light_styleupdatechains[i] = model->light_styleupdatechainsbuffer + j;
+ j += stylecounts[model->light_style[i]] + 1;
+ }
+}
+
void Mod_BuildPVSTextureChains(model_t *model)
{
int i, j;
mod->pvstexturechainsbuffer = Mem_Alloc(originalloadmodel->mempool, (mod->nummodelsurfaces + mod->numtextures) * sizeof(msurface_t *));
mod->pvstexturechainslength = Mem_Alloc(originalloadmodel->mempool, mod->numtextures * sizeof(int));
Mod_BuildPVSTextureChains(mod);
+ Mod_BuildLightmapUpdateChains(originalloadmodel->mempool, mod);
if (mod->nummodelsurfaces)
{
// LordHavoc: calculate bmodel bounding box rather than trusting what it says
mplane_t *plane;
// SURF_ flags
int flags;
- // rendering chain
- struct msurface_s *texturechain;
// look up in model->surfedges[], negative numbers are backwards edges
int firstedge;
vec3_t poly_mins, poly_maxs, poly_center;
// neighboring surfaces (one per poly_numverts)
- struct msurface_s **neighborsurfaces;
+ //struct msurface_s **neighborsurfaces;
// currently used only for generating static shadow volumes
int castshadow;
// these are regenerated every frame
// lighting info
+ // if this == r_framecount there are dynamic lights on the surface
int dlightframe;
+ // which dynamic lights are touching this surface
+ // (only access this if dlightframe is current)
int dlightbits[8];
// avoid redundent addition of dlights
int lightframe;
msurface_t **pvstexturechainsbuffer;
int *pvstexturechainslength;
+ // lightmap update chains for light styles
+ int light_styles;
+ qbyte *light_style;
+ int *light_stylevalue;
+ msurface_t ***light_styleupdatechains;
+ msurface_t **light_styleupdatechainsbuffer;
+ int light_scalebit;
+ float light_ambient;
// skin animation info
animscene_t *skinscenes; // [numskins]
{
surf->dlightbits[0] = surf->dlightbits[1] = surf->dlightbits[2] = surf->dlightbits[3] = surf->dlightbits[4] = surf->dlightbits[5] = surf->dlightbits[6] = surf->dlightbits[7] = 0;
surf->dlightframe = r_framecount;
+ if (r_dlightmap.integer)
+ surf->cached_dlight = true;
}
surf->dlightbits[bitindex] |= bit;
}
{
surf->dlightbits[0] = surf->dlightbits[1] = surf->dlightbits[2] = surf->dlightbits[3] = surf->dlightbits[4] = surf->dlightbits[5] = surf->dlightbits[6] = surf->dlightbits[7] = 0;
surf->dlightframe = r_framecount;
+ if (r_dlightmap.integer)
+ surf->cached_dlight = true;
}
surf->dlightbits[bitindex] |= bit;
}
extern cvar_t r_fullbright;
extern cvar_t r_wateralpha;
extern cvar_t r_dynamic;
+extern cvar_t r_dlightmap;
void R_Init (void);
void R_RenderView (void); // must set r_refdef first