Ejemplo n.º 1
0
/**
 * @brief Flares are batched by their texture. Usually, this means one draw operation
 * for all flares in view. Flare visibility is calculated every few millis, and
 * flare alpha is ramped up or down depending on the results of the visibility
 * trace. Flares are also faded according to the angle of their surface to the
 * view origin.
 */
void R_AddFlareBspSurfaces(const r_bsp_surfaces_t *surfs) {
	if (!r_flares->value || r_draw_wireframe->value) {
		return;
	}

	if (!surfs->count) {
		return;
	}

	for (uint32_t i = 0; i < surfs->count; i++) {
		const r_bsp_surface_t *surf = surfs->surfaces[i];

		if (surf->frame != r_locals.frame) {
			continue;
		}

		r_bsp_flare_t *f = surf->flare;

		// periodically test visibility to ramp alpha
		if (r_view.ticks - f->time > 15) {

			if (r_view.ticks - f->time > 500) { // reset old flares
				f->alpha = 0;
			}

			cm_trace_t tr = Cl_Trace(r_view.origin, f->particle.org, NULL, NULL, 0, MASK_CLIP_PROJECTILE);

			f->alpha += (tr.fraction == 1.0) ? 0.03 : -0.15; // ramp
			f->alpha = Clamp(f->alpha, 0.0, 1.0); // clamp

			f->time = r_view.ticks;
		}

		vec3_t view;
		VectorSubtract(f->particle.org, r_view.origin, view);
		const vec_t dist = VectorNormalize(view);

		// fade according to angle
		const vec_t cos = DotProduct(surf->normal, view);
		if (cos > 0.0) {
			continue;
		}

		vec_t alpha = 0.1 + -cos * r_flares->value;

		if (alpha > 1.0) {
			alpha = 1.0;
		}

		alpha = f->alpha * alpha;

		// scale according to distance
		f->particle.scale = f->radius + (f->radius * dist * .0005);
		f->particle.color[3] = alpha;

		R_AddParticle(&f->particle);
	}
}
Ejemplo n.º 2
0
/**
 * @brief Developer tool for viewing static BSP light sources.
 */
void R_DrawBspLights(void) {

	if (!r_draw_bsp_lights->value) {
		return;
	}

	r_bsp_light_t *bl = r_model_state.world->bsp->bsp_lights;
	for (uint16_t i = 0; i < r_model_state.world->bsp->num_bsp_lights; i++, bl++) {

		const r_bsp_leaf_t *l = R_LeafForPoint(bl->light.origin, NULL);
		if (l->vis_frame != r_locals.vis_frame) {
			continue;
		}

		VectorCopy(bl->light.origin, bl->debug.org);
		VectorCopy(bl->light.color, bl->debug.color);
		bl->debug.scale = bl->light.radius * r_draw_bsp_lights->value;

		R_AddParticle(&bl->debug);
	}
}