Allocates and sets a lightmap based on the surface elements given
| 1307 | |
| 1308 | // Allocates and sets a lightmap based on the surface elements given |
| 1309 | void AssignRoomSurfaceToLightmap(int roomnum, int facenum, rad_surface *sp) { |
| 1310 | face *fp = &Rooms[roomnum].faces[facenum]; |
| 1311 | room *rp = &Rooms[roomnum]; |
| 1312 | |
| 1313 | int i, t, lmi_handle; |
| 1314 | int xres, yres; |
| 1315 | int lw, lh; |
| 1316 | int x1 = sp->x1; |
| 1317 | int y1 = sp->y1; |
| 1318 | int use_lightmap = 1; |
| 1319 | |
| 1320 | xres = sp->xresolution; |
| 1321 | yres = sp->yresolution; |
| 1322 | |
| 1323 | ASSERT(fp->lmi_handle != BAD_LMI_INDEX); |
| 1324 | lmi_handle = fp->lmi_handle; |
| 1325 | |
| 1326 | lw = lmi_w(lmi_handle); |
| 1327 | lh = lmi_h(lmi_handle); |
| 1328 | |
| 1329 | ASSERT((xres + x1) <= lw); |
| 1330 | ASSERT((yres + y1) <= lh); |
| 1331 | |
| 1332 | ASSERT(lw >= 2); |
| 1333 | ASSERT(lh >= 2); |
| 1334 | |
| 1335 | uint16_t *dest_data = lm_data(LightmapInfo[lmi_handle].lm_handle); |
| 1336 | |
| 1337 | // Set face pointer |
| 1338 | if (GameTextures[fp->tmap].flags & TF_ALPHA) |
| 1339 | use_lightmap = 0; |
| 1340 | if (GameTextures[fp->tmap].flags & (TF_FORCE_LIGHTMAP | TF_SATURATE_LIGHTMAP)) |
| 1341 | use_lightmap = 1; |
| 1342 | |
| 1343 | if (use_lightmap) |
| 1344 | fp->flags |= FF_LIGHTMAP; |
| 1345 | |
| 1346 | for (i = 0; i < yres; i++) { |
| 1347 | for (t = 0; t < xres; t++) { |
| 1348 | if (!(sp->elements[i * xres + t].flags & EF_IGNORE)) { |
| 1349 | ddgr_color color = GR_16_TO_COLOR(dest_data[(i + y1) * lw + (t + x1)]); |
| 1350 | int red = GR_COLOR_RED(color); |
| 1351 | int green = GR_COLOR_GREEN(color); |
| 1352 | int blue = GR_COLOR_BLUE(color); |
| 1353 | |
| 1354 | float fr, fg, fb; |
| 1355 | |
| 1356 | if (!(dest_data[(i + y1) * lw + (t + x1)] & OPAQUE_FLAG)) { |
| 1357 | red = green = blue = 0; |
| 1358 | } |
| 1359 | |
| 1360 | fr = std::min(1.0f, sp->elements[i * xres + t].exitance.r + Ambient_red + Room_ambience_r[roomnum]); |
| 1361 | fg = std::min(1.0f, sp->elements[i * xres + t].exitance.g + Ambient_green + Room_ambience_g[roomnum]); |
| 1362 | fb = std::min(1.0f, sp->elements[i * xres + t].exitance.b + Ambient_blue + Room_ambience_b[roomnum]); |
| 1363 | |
| 1364 | fr = (fr * 255) + .5; |
| 1365 | fg = (fg * 255) + .5; |
| 1366 | fb = (fb * 255) + .5; |
no test coverage detected