38 float r, g, b, y, max;
41 r = (in[0] +
lm.
add) * modulate;
42 g = (in[1] +
lm.
add) * modulate;
43 b = (in[2] +
lm.
add) * modulate;
71 y = LUMINANCE(r, g, b);
88 out[0] = (byte)tmp[0];
89 out[1] = (byte)tmp[1];
90 out[2] = (byte)tmp[2];
108 #define MAX_SURFACE_EXTENTS 2048
109 #define MAX_LIGHTMAP_EXTENTS ((MAX_SURFACE_EXTENTS >> 4) + 1)
110 #define MAX_BLOCKLIGHTS (MAX_LIGHTMAP_EXTENTS * MAX_LIGHTMAP_EXTENTS)
115 static void add_dynamic_lights(mface_t *surf)
121 vec_t dist, rad, minlight, scale, frac;
123 int i, smax, tmax, s, t, sd, td;
129 for (i = 0; i <
glr.
fd.num_dlights; i++) {
130 if (!(surf->dlightbits & (1 << i)))
133 light = &
glr.
fd.dlights[i];
134 dist = PlaneDiffFast(light->transformed, surf->plane);
135 rad = light->intensity - fabs(dist);
136 if (rad < DLIGHT_CUTOFF)
139 if (gl_dlight_falloff->integer) {
140 minlight = rad - DLIGHT_CUTOFF * 0.8f;
141 scale = rad / minlight;
143 minlight = rad - DLIGHT_CUTOFF;
147 VectorMA(light->transformed, -dist, surf->plane->normal, point);
149 local[0] = DotProduct(point, tex->axis[0]) + tex->offset[0];
150 local[1] = DotProduct(point, tex->axis[1]) + tex->offset[1];
152 local[0] -= surf->texturemins[0];
153 local[1] -= surf->texturemins[1];
156 for (t = 0; t < tmax; t++) {
157 td = abs(local[1] - (t << 4));
158 for (s = 0; s < smax; s++) {
159 sd = abs(local[0] - (s << 4));
161 dist = sd + (td >> 1);
163 dist = td + (sd >> 1);
164 if (dist < minlight) {
165 frac = rad - dist * scale;
166 bl[0] += light->color[0] * frac;
167 bl[1] += light->color[1] * frac;
168 bl[2] += light->color[2] * frac;
184 if (!surf->numstyles) {
193 src = surf->lightmap;
195 if (style->white == 1) {
196 for (j = 0; j < size; j++) {
204 for (j = 0; j < size; j++) {
205 bl[0] = src[0] * style->rgb[0];
206 bl[1] = src[1] * style->rgb[1];
207 bl[2] = src[2] * style->rgb[2];
213 surf->stylecache[0] = style->white;
216 for (i = 1; i < surf->numstyles; i++) {
220 for (j = 0; j < size; j++) {
221 bl[0] += src[0] * style->rgb[0];
222 bl[1] += src[1] * style->rgb[1];
223 bl[2] += src[2] * style->rgb[2];
228 surf->stylecache[i] = style->white;
235 int smax, tmax, size, i;
247 if (surf->dlightframe ==
glr.dlightframe) {
248 add_dynamic_lights(surf);
250 surf->dlightframe = 0;
257 for (i = 0; i < size; i++) {
265 surf->light_s, surf->light_t, smax, tmax,
266 GL_RGBA, GL_UNSIGNED_BYTE, temp);
276 if (!surf->lightmap) {
279 if (surf->drawflags & SURF_NOLM_MASK) {
282 if (!surf->texnum[1]) {
288 if (surf->dlightframe) {
295 for (i = 0; i < surf->numstyles; i++) {
297 if (style->white != surf->stylecache[i]) {
312 #define LM_AllocBlock(w, h, s, t) \
313 GL_AllocBlock(LM_BLOCK_WIDTH, LM_BLOCK_HEIGHT, lm.inuse, w, h, s, t)
334 GL_RGBA, GL_UNSIGNED_BYTE,
lm.
buffer);
341 static lightstyle_t fake;
350 glr.
fd.lightstyles = &fake;
356 for (i = 0; i < MAX_LIGHTSTYLES; i++) {
362 for (i = 1; i < 32; i++) {
393 Com_DPrintf(
"%s: %d lightmaps built\n", __func__,
lm.
nummaps);
399 int smax, tmax, size, i, j;
410 surf->dlightframe = 0;
416 for (i = 0; i < tmax; i++) {
418 for (j = 0; j < smax; j++) {
429 int smax, tmax, s, t;
437 Com_EPrintf(
"%s: LM_MAX_LIGHTMAPS exceeded\n", __func__);
442 Com_EPrintf(
"%s: LM_AllocBlock(%d, %d) failed\n",
443 __func__, smax, tmax);
474 for (i = 0, surf = bsp->faces; i < bsp->numfaces; i++, surf++) {
475 if (!surf->lightmap) {
478 if (surf->drawflags & SURF_NOLM_MASK) {
481 if (!surf->texnum[1]) {
485 if (surf->texnum[1] != texnum) {
489 GL_RGBA, GL_UNSIGNED_BYTE,
lm.
buffer);
491 texnum = surf->texnum[1];
502 GL_RGBA, GL_UNSIGNED_BYTE,
lm.
buffer);
518 if (surf->drawflags & SURF_TRANS33)
521 if (surf->drawflags & SURF_TRANS66)
524 if (surf->drawflags & SURF_WARP)
532 msurfedge_t *src_surfedge;
535 mtexinfo_t *texinfo = surf->texinfo;
536 vec2_t scale, tc, mins, maxs;
537 int i, bmins[2], bmaxs[2];
540 surf->texnum[0] = texinfo->image->texnum;
547 if (!(surf->drawflags & SURF_COLOR_MASK)) {
551 if (surf->drawflags & SURF_WARP) {
555 if (surf->drawflags & SURF_TRANS_MASK) {
557 }
else if (surf->drawflags & SURF_ALPHATEST) {
561 if (surf->drawflags & SURF_FLOWING) {
566 scale[0] = 1.0f / texinfo->image->width;
567 scale[1] = 1.0f / texinfo->image->height;
569 mins[0] = mins[1] = 99999;
570 maxs[0] = maxs[1] = -99999;
572 src_surfedge = surf->firstsurfedge;
573 for (i = 0; i < surf->numsurfedges; i++) {
574 src_edge = src_surfedge->edge;
575 src_vert = src_edge->v[src_surfedge->vert];
579 VectorCopy(src_vert->point, vbo);
585 tc[0] = DotProduct(vbo, texinfo->axis[0]) + texinfo->offset[0];
586 tc[1] = DotProduct(vbo, texinfo->axis[1]) + texinfo->offset[1];
588 if (mins[0] > tc[0]) mins[0] = tc[0];
589 if (maxs[0] < tc[0]) maxs[0] = tc[0];
591 if (mins[1] > tc[1]) mins[1] = tc[1];
592 if (maxs[1] < tc[1]) maxs[1] = tc[1];
594 vbo[4] = tc[0] * scale[0];
595 vbo[5] = tc[1] * scale[1];
605 bmins[0] = floor(mins[0] / 16);
606 bmins[1] = floor(mins[1] / 16);
607 bmaxs[0] = ceil(maxs[0] / 16);
608 bmaxs[1] = ceil(maxs[1] / 16);
610 surf->texturemins[0] = bmins[0] << 4;
611 surf->texturemins[1] = bmins[1] << 4;
613 surf->extents[0] = (bmaxs[0] - bmins[0]) << 4;
614 surf->extents[1] = (bmaxs[1] - bmins[1]) << 4;
625 for (i = 0; i < surf->numsurfedges; i++) {
642 int smax, tmax, size;
652 if (surf->drawflags & SURF_NOLM_MASK)
658 Com_EPrintf(
"%s: bad surface extents\n", __func__);
659 surf->lightmap = NULL;
668 Com_EPrintf(
"%s: MAX_BLOCKLIGHTS exceeded\n", __func__);
669 surf->lightmap = NULL;
675 src = surf->lightmap + surf->numstyles * size * 3;
676 ptr = bsp->lightmap + bsp->numlightmapbytes;
678 Com_EPrintf(
"%s: bad surface lightmap\n", __func__);
679 surf->lightmap = NULL;
695 s = ((surf->light_s << 4) + 8) - surf->texturemins[0];
696 t = ((surf->light_t << 4) + 8) - surf->texturemins[1];
698 for (i = 0; i < surf->numsurfedges; i++) {
714 for (i = 0; i < surf->numsurfedges; i++) {
751 GLintptrARB offset = lastvert *
VERTEX_SIZE *
sizeof(vec_t);
754 Com_DDPrintf(
"%s: %"PRIz
" bytes at %"PRIz
"\n", __func__, size, offset);
765 int i, currvert, lastvert;
776 for (i = 0, surf = bsp->faces; i < bsp->numfaces; i++, surf++) {
777 if (surf->drawflags & SURF_SKY)
793 surf->firstvert = currvert;
802 currvert += surf->numsurfedges;
821 for (i = 0, size = 0; i < 3; i++) {
822 temp = node->maxs[i] - node->mins[i];
829 else if (size > 2048)
878 char buffer[MAX_QPATH];
889 Com_Error(ERR_DROP,
"%s: couldn't load %s: %s",
895 for (i = 0; i < bsp->numtexinfo; i++) {
898 for (i = 0; i < bsp->numnodes; i++) {
899 bsp->nodes[i].visframe = 0;
901 for (i = 0; i < bsp->numleafs; i++) {
902 bsp->leafs[i].visframe = 0;
904 Com_DPrintf(
"%s: reused old world model\n", __func__);
918 for (i = 0, info = bsp->texinfo; i < bsp->numtexinfo; i++, info++) {
919 if (info->c.flags & SURF_WARP)
920 flags = IF_TURBULENT;
924 Q_concat(buffer,
sizeof(buffer),
"textures/", info->name,
".wal", NULL);
926 info->image =
IMG_Find(buffer, IT_WALL, flags);
931 for (i = 0, surf = bsp->faces; i < bsp->numfaces; i++, surf++) {
933 surf->drawflags |= surf->texinfo->c.flags & ~DSURF_PLANEBACK;
936 if (surf->drawflags & SURF_SKY)
939 size += surf->numsurfedges *
VERTEX_SIZE *
sizeof(vec_t);
944 Com_DPrintf(
"%s: %"PRIz
" bytes of vertex data as VBO\n", __func__, size);
950 Com_DPrintf(
"%s: %"PRIz
" bytes of vertex data on hunk\n", __func__, size);