MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / RenderSingleLightGlow

Function RenderSingleLightGlow

Descent3/render.cpp:2401–2460  ·  view source on GitHub ↗

Draws a glow around a light

Source from the content-addressed store, hash-verified

2399#define CORONA_DIST_CUTOFF 5.0f
2400// Draws a glow around a light
2401void RenderSingleLightGlow(int index) {
2402 int bm_handle;
2403 room *rp = &Rooms[LightGlows[index].roomnum];
2404 face *fp = &rp->faces[LightGlows[index].facenum];
2405 texture *texp = &GameTextures[fp->tmap];
2406 bm_handle = Fireballs[DEFAULT_CORONA_INDEX + texp->corona_type].bm_handle;
2407
2408 // Get size of light
2409 float size = LightGlows[index].size;
2410 vector center = LightGlows[index].center;
2411
2412 // Get alpha of light
2413 vector tvec = Viewer_eye - rp->verts[fp->face_verts[0]];
2414 vm_NormalizeVectorFast(&tvec);
2415 float facing_scalar = (tvec * fp->normal) * 2;
2416 if (facing_scalar < 0)
2417 return;
2418 tvec = center - Viewer_eye;
2419
2420 float dist = vm_GetMagnitudeFast(&tvec);
2421 if (dist < (size * CORONA_DIST_CUTOFF))
2422 return;
2423 if (dist < (size * (CORONA_DIST_CUTOFF + 15))) {
2424 float dist_scalar = ((dist - (size * CORONA_DIST_CUTOFF)) / (size * 15));
2425 facing_scalar *= dist_scalar;
2426 }
2427
2428 facing_scalar *= LightGlows[index].scalar;
2429 facing_scalar = std::min<float>(facing_scalar, 1.0);
2430 // Take into effect pulsing
2431 ComputeRoomPulseLight(rp);
2432 facing_scalar *= Room_light_val;
2433 rend_SetAlphaValue(facing_scalar * .4 * 255);
2434
2435 float maxc = std::max({texp->r, texp->g, texp->b});
2436 float r, g, b;
2437 if (maxc > 1.0) {
2438 r = texp->r / maxc;
2439 g = texp->g / maxc;
2440 b = texp->b / maxc;
2441 } else {
2442 r = texp->r;
2443 g = texp->g;
2444 b = texp->b;
2445 }
2446 if (LightGlows[index].flags & LGF_FAST) {
2447 rend_SetZBufferWriteMask(0);
2448 rend_SetZBias((-size / 2));
2449 } else {
2450 rend_SetZBufferState(0);
2451 }
2452 ddgr_color color = GR_RGB(r * 255, g * 255, b * 255);
2453 g3_DrawBitmap(&center, size, (size * bm_h(bm_handle, 0)) / bm_w(bm_handle, 0), bm_handle, color);
2454 if (LightGlows[index].flags & LGF_FAST) {
2455 rend_SetZBufferWriteMask(1);
2456 rend_SetZBias(0);
2457 } else {
2458 rend_SetZBufferState(1);

Callers 1

RenderLightGlowsFunction · 0.85

Calls 11

vm_NormalizeVectorFastFunction · 0.85
ComputeRoomPulseLightFunction · 0.85
g3_DrawBitmapFunction · 0.85
bm_hFunction · 0.85
bm_wFunction · 0.85
vm_GetMagnitudeFastFunction · 0.50
rend_SetAlphaValueFunction · 0.50
rend_SetZBufferWriteMaskFunction · 0.50
rend_SetZBiasFunction · 0.50
rend_SetZBufferStateFunction · 0.50
GR_RGBFunction · 0.50

Tested by

no test coverage detected