示例#1
0
/**
 * @brief Manages state for stages supporting static, dynamic, and per-pixel lighting.
 */
static void R_StageLighting (const mBspSurface_t *surf, const materialStage_t *stage)
{
	/* if the surface has a lightmap, and the stage specifies lighting.. */
	if ((surf->flags & MSURF_LIGHTMAP) &&
			(stage->flags & (STAGE_LIGHTMAP | STAGE_LIGHTING))) {
		R_EnableTexture(&texunit_lightmap, true);
		R_BindLightmapTexture(surf->lightmap_texnum);

		/* hardware lighting */
		/** @todo fix it and enable it back for r_materials 1 */
		if (r_materials->integer > 1) {
			if ((stage->flags & STAGE_LIGHTING)) {
				R_EnableLighting(r_state.world_program, true);
				R_SetSurfaceBumpMappingParameters(surf, stage->image->normalmap, stage->image->specularmap);
			} else {
				R_SetSurfaceBumpMappingParameters(surf, nullptr, nullptr);
				R_EnableLighting(nullptr, false);
			}
		}
	} else {
		if (!r_state.lighting_enabled)
			return;
		R_EnableLighting(nullptr, false);

		R_EnableTexture(&texunit_lightmap, false);
	}
}
示例#2
0
/**
 * @brief Set the surface state according to surface flags and bind the texture
 * @sa R_DrawSurfaces
 */
static void R_SetSurfaceState (const mBspSurface_t *surf)
{
	image_t *image;

	if (r_state.blend_enabled) {  /* alpha blend */
		vec4_t color = {1.0, 1.0, 1.0, 1.0};
		switch (surf->texinfo->flags & (SURF_BLEND33 | SURF_BLEND66)) {
		case SURF_BLEND33:
			color[3] = 0.33;
			break;
		case SURF_BLEND66:
			color[3] = 0.66;
			break;
		}

		R_Color(color);
	}

	image = surf->texinfo->image;
	R_BindTexture(image->texnum);  /* texture */

	if (texunit_lightmap.enabled) {  /* lightmap */
		if (surf->flags & MSURF_LIGHTMAP)
			R_BindLightmapTexture(surf->lightmap_texnum);
	}

	R_SetSurfaceBumpMappingParameters(surf, image->normalmap, image->specularmap);

	R_EnableGlowMap(image->glowmap);

	R_CheckError();
}