+ // muzzleflash fades over time, and is offset a bit
+ if (e->persistent.muzzleflash > 0 && r_refdef.numlights < MAX_DLIGHTS)
+ {
+ vec3_t v2;
+ vec3_t color;
+ trace_t trace;
+ matrix4x4_t tempmatrix;
+ Matrix4x4_Transform(&e->render.matrix, muzzleflashorigin, v2);
+ trace = CL_Move(origin, vec3_origin, vec3_origin, v2, MOVE_NOMONSTERS, NULL, SUPERCONTENTS_SOLID | SUPERCONTENTS_SKY, true, false, NULL, false);
+ Matrix4x4_Normalize(&tempmatrix, &e->render.matrix);
+ Matrix4x4_SetOrigin(&tempmatrix, trace.endpos[0], trace.endpos[1], trace.endpos[2]);
+ Matrix4x4_Scale(&tempmatrix, 150, 1);
+ VectorSet(color, e->persistent.muzzleflash * 4.0f, e->persistent.muzzleflash * 4.0f, e->persistent.muzzleflash * 4.0f);
+ R_RTLight_Update(&r_refdef.lights[r_refdef.numlights++], false, &tempmatrix, color, -1, NULL, true, 0, 0.25, 0, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
+ }
+ // LordHavoc: if the model has no flags, don't check each
+ if (e->render.model && e->render.model->flags && (!e->state_current.tagentity && !(e->render.flags & RENDER_VIEWMODEL)))
+ {
+ if (e->render.model->flags & EF_GIB)
+ trailtype = EFFECT_TR_BLOOD;
+ else if (e->render.model->flags & EF_ZOMGIB)
+ trailtype = EFFECT_TR_SLIGHTBLOOD;
+ else if (e->render.model->flags & EF_TRACER)
+ trailtype = EFFECT_TR_WIZSPIKE;
+ else if (e->render.model->flags & EF_TRACER2)
+ trailtype = EFFECT_TR_KNIGHTSPIKE;
+ else if (e->render.model->flags & EF_ROCKET)
+ trailtype = EFFECT_TR_ROCKET;
+ else if (e->render.model->flags & EF_GRENADE)
+ {
+ // LordHavoc: e->render.alpha == -1 is for Nehahra dem compatibility (cigar smoke)
+ trailtype = e->render.alpha == -1 ? EFFECT_TR_NEHAHRASMOKE : EFFECT_TR_GRENADE;
+ }
+ else if (e->render.model->flags & EF_TRACER3)
+ trailtype = EFFECT_TR_VORESPIKE;
+ }
+ // LordHavoc: customizable glow
+ if (e->state_current.glowsize)
+ {
+ // * 4 for the expansion from 0-255 to 0-1023 range,
+ // / 255 to scale down byte colors
+ dlightradius = max(dlightradius, e->state_current.glowsize * 4);
+ VectorMA(dlightcolor, (1.0f / 255.0f), (unsigned char *)&palette_complete[e->state_current.glowcolor], dlightcolor);
+ }
+ // make the glow dlight
+ if (dlightradius > 0 && (dlightcolor[0] || dlightcolor[1] || dlightcolor[2]) && !(e->render.flags & RENDER_VIEWMODEL) && r_refdef.numlights < MAX_DLIGHTS)
+ {
+ matrix4x4_t dlightmatrix;
+ Matrix4x4_Normalize(&dlightmatrix, &e->render.matrix);
+ // hack to make glowing player light shine on their gun
+ //if (e->state_current.number == cl.viewentity/* && !chase_active.integer*/)
+ // Matrix4x4_AdjustOrigin(&dlightmatrix, 0, 0, 30);
+ Matrix4x4_Scale(&dlightmatrix, dlightradius, 1);
+ R_RTLight_Update(&r_refdef.lights[r_refdef.numlights++], false, &dlightmatrix, dlightcolor, -1, NULL, true, 1, 0.25, 0, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
+ }
+ // custom rtlight
+ if ((e->state_current.lightpflags & PFLAGS_FULLDYNAMIC) && r_refdef.numlights < MAX_DLIGHTS)
+ {
+ matrix4x4_t dlightmatrix;
+ float light[4];
+ VectorScale(e->state_current.light, (1.0f / 256.0f), light);
+ light[3] = e->state_current.light[3];
+ if (light[0] == 0 && light[1] == 0 && light[2] == 0)
+ VectorSet(light, 1, 1, 1);
+ if (light[3] == 0)
+ light[3] = 350;
+ // FIXME: add ambient/diffuse/specular scales as an extension ontop of TENEBRAE_GFX_DLIGHTS?
+ Matrix4x4_Normalize(&dlightmatrix, &e->render.matrix);
+ Matrix4x4_Scale(&dlightmatrix, light[3], 1);
+ R_RTLight_Update(&r_refdef.lights[r_refdef.numlights++], false, &dlightmatrix, light, e->state_current.lightstyle, e->state_current.skin > 0 ? va("cubemaps/%i", e->state_current.skin) : NULL, !(e->state_current.lightpflags & PFLAGS_NOSHADOW), (e->state_current.lightpflags & PFLAGS_CORONA) != 0, 0.25, 0, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
+ }
+ // do trail light
+ if (e->render.flags & RENDER_GLOWTRAIL)
+ trailtype = EFFECT_TR_GLOWTRAIL;
+ if (trailtype)
+ CL_ParticleTrail(trailtype, 0, origin, origin, vec3_origin, vec3_origin, NULL, e->state_current.glowcolor, true, false);
+
+ // don't show entities with no modelindex (note: this still shows
+ // entities which have a modelindex that resolved to a NULL model)
+ if (e->render.model && !(e->render.effects & EF_NODRAW) && r_refdef.numentities < r_refdef.maxentities)
+ r_refdef.entities[r_refdef.numentities++] = &e->render;
+ //if (cl.viewentity && e->state_current.number == cl.viewentity)
+ // Matrix4x4_Print(&e->render.matrix);