- // now switch to 2D drawing mode by calling a 2D drawing function
- // then polygon drawing will draw as 2D stuff, and NOT get queued until the
- // next R_RenderScene call
- drawstring('0 0 0', "", '1 1 0', '1 1 1', 0, 0);
-
- if(autocvar_r_fakelight >= 2 || autocvar_r_fullbright)
- if (!(serverflags & SERVERFLAG_ALLOW_FULLBRIGHT))
- {
- // apply night vision effect
- vector tc_00, tc_01, tc_10, tc_11;
- vector rgb = '0 0 0';
-
- if(!nightvision_noise)
- {
- nightvision_noise = new(nightvision_noise);
- }
- if(!nightvision_noise2)
- {
- nightvision_noise2 = new(nightvision_noise2);
- }
-
- // color tint in yellow
- drawfill('0 0 0', autocvar_vid_conwidth * '1 0 0' + autocvar_vid_conheight * '0 1 0', '0.5 1 0.3', 1, DRAWFLAG_MODULATE);
-
- // draw BG
- a = Noise_Pink(nightvision_noise, frametime * 1.5) * 0.05 + 0.15;
- rgb = '1 1 1';
- tc_00 = '0 0 0' + '0.2 0 0' * sin(time * 0.3) + '0 0.3 0' * cos(time * 0.7);
- tc_01 = '0 2.25 0' + '0.6 0 0' * cos(time * 1.2) - '0 0.3 0' * sin(time * 2.2);
- tc_10 = '1.5 0 0' - '0.2 0 0' * sin(time * 0.5) + '0 0.5 0' * cos(time * 1.7);
- //tc_11 = '1 1 0' + '0.6 0 0' * sin(time * 0.6) + '0 0.3 0' * cos(time * 0.1);
- tc_11 = tc_01 + tc_10 - tc_00;
- R_BeginPolygon("gfx/nightvision-bg.tga", DRAWFLAG_ADDITIVE);
- R_PolygonVertex('0 0 0', tc_00, rgb, a);
- R_PolygonVertex(autocvar_vid_conwidth * '1 0 0', tc_10, rgb, a);
- R_PolygonVertex(autocvar_vid_conwidth * '1 0 0' + autocvar_vid_conheight * '0 1 0', tc_11, rgb, a);
- R_PolygonVertex(autocvar_vid_conheight * '0 1 0', tc_01, rgb, a);
- R_EndPolygon();
-
- // draw FG
- a = Noise_Pink(nightvision_noise2, frametime * 0.1) * 0.05 + 0.12;
- rgb = '0.3 0.6 0.4' + '0.1 0.4 0.2' * Noise_White(nightvision_noise2, frametime);
- tc_00 = '0 0 0' + '1 0 0' * Noise_White(nightvision_noise2, frametime) + '0 1 0' * Noise_White(nightvision_noise2, frametime);
- tc_01 = tc_00 + '0 3 0' * (1 + Noise_White(nightvision_noise2, frametime) * 0.2);
- tc_10 = tc_00 + '2 0 0' * (1 + Noise_White(nightvision_noise2, frametime) * 0.3);
- tc_11 = tc_01 + tc_10 - tc_00;
- R_BeginPolygon("gfx/nightvision-fg.tga", DRAWFLAG_ADDITIVE);
- R_PolygonVertex('0 0 0', tc_00, rgb, a);
- R_PolygonVertex(autocvar_vid_conwidth * '1 0 0', tc_10, rgb, a);
- R_PolygonVertex(autocvar_vid_conwidth * '1 0 0' + autocvar_vid_conheight * '0 1 0', tc_11, rgb, a);
- R_PolygonVertex(autocvar_vid_conheight * '0 1 0', tc_01, rgb, a);
- R_EndPolygon();
- }
-
- if(autocvar_cl_reticle && !MUTATOR_CALLHOOK(DrawReticle))
- {
- string reticle_image = string_null;
- bool wep_zoomed = false;
- for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
- {
- entity wepe = viewmodels[slot];
- Weapon wep = wepe.activeweapon;
- if(wep != WEP_Null && wep.wr_zoom)
- {
- bool do_zoom = wep.wr_zoom(wep, NULL);
- if(!reticle_image && wep.w_reticle && wep.w_reticle != "")
- reticle_image = wep.w_reticle;
- wep_zoomed += do_zoom;
- }
- }
- // Draw the aiming reticle for weapons that use it
- // reticle_type is changed to the item we are zooming / aiming with, to decide which reticle to use
- // It must be a persisted float for fading out to work properly (you let go of the zoom button for
- // the view to go back to normal, so reticle_type would become 0 as we fade out)
- if(spectatee_status || is_dead || hud != HUD_NORMAL || local_player.viewloc)
- {
- // no zoom reticle while dead
- reticle_type = 0;
- }
- else if(wep_zoomed && autocvar_cl_reticle_weapon)
- {
- if(reticle_image) { reticle_type = 2; }
- else { reticle_type = 0; }
- }
- else if(button_zoom || zoomscript_caught)
- {
- // normal zoom
- reticle_type = 1;
- }
-
- if(reticle_type)
- {
- if(autocvar_cl_reticle_stretch)
- {
- reticle_size.x = vid_conwidth;
- reticle_size.y = vid_conheight;
- reticle_pos.x = 0;
- reticle_pos.y = 0;
- }
- else
- {
- reticle_size.x = max(vid_conwidth, vid_conheight);
- reticle_size.y = max(vid_conwidth, vid_conheight);
- reticle_pos.x = (vid_conwidth - reticle_size.x) / 2;
- reticle_pos.y = (vid_conheight - reticle_size.y) / 2;
- }
-
- if(zoomscript_caught)
- f = 1;
- else
- f = current_zoomfraction;
-
- if(f)
- {
- switch(reticle_type)
- {
- case 1: drawpic(reticle_pos, "gfx/reticle_normal", reticle_size, '1 1 1', f * autocvar_cl_reticle_normal_alpha, DRAWFLAG_NORMAL); break;
- case 2: if(reticle_image) drawpic(reticle_pos, reticle_image, reticle_size, '1 1 1', f * autocvar_cl_reticle_weapon_alpha, DRAWFLAG_NORMAL); break;
- }
- }
- }
- }
- else
- {
- if(reticle_type != 0) { reticle_type = 0; }
- }
-
-
- // improved polyblend
- if(autocvar_hud_contents && !MUTATOR_CALLHOOK(HUD_Contents))
- {
- float contentalpha_temp, incontent, liquidalpha, contentfadetime;
- vector liquidcolor;
-
- switch(pointcontents(view_origin))
- {
- case CONTENT_WATER:
- liquidalpha = autocvar_hud_contents_water_alpha;
- liquidcolor = stov(autocvar_hud_contents_water_color);
- incontent = 1;
- break;
-
- case CONTENT_LAVA:
- liquidalpha = autocvar_hud_contents_lava_alpha;
- liquidcolor = stov(autocvar_hud_contents_lava_color);
- incontent = 1;
- break;
-
- case CONTENT_SLIME:
- liquidalpha = autocvar_hud_contents_slime_alpha;
- liquidcolor = stov(autocvar_hud_contents_slime_color);
- incontent = 1;
- break;
-
- default:
- liquidalpha = 0;
- liquidcolor = '0 0 0';
- incontent = 0;
- break;
- }
-
- if(incontent) // fade in/out at different speeds so you can do e.g. instant fade when entering water and slow when leaving it.
- { // also lets delcare previous values for blending properties, this way it isn't reset until after you have entered a different content
- contentfadetime = autocvar_hud_contents_fadeintime;
- liquidalpha_prev = liquidalpha;
- liquidcolor_prev = liquidcolor;
- }
- else
- contentfadetime = autocvar_hud_contents_fadeouttime;
-
- contentalpha_temp = bound(0, drawframetime / max(0.0001, contentfadetime), 1);
- contentavgalpha = contentavgalpha * (1 - contentalpha_temp) + incontent * contentalpha_temp;
-
- if(contentavgalpha)
- drawfill('0 0 0', vec2(vid_conwidth, vid_conheight), liquidcolor_prev, contentavgalpha * liquidalpha_prev, DRAWFLAG_NORMAL);
-
- if(autocvar_hud_postprocessing)
- {
- if(autocvar_hud_contents_blur && contentavgalpha)
- {
- content_blurpostprocess.x = 1;
- content_blurpostprocess.y = contentavgalpha * autocvar_hud_contents_blur;
- content_blurpostprocess.z = contentavgalpha * autocvar_hud_contents_blur_alpha;
- }
- else
- {
- content_blurpostprocess.x = 0;
- content_blurpostprocess.y = 0;
- content_blurpostprocess.z = 0;
- }
- }
- }
-
- if(autocvar_hud_damage && !STAT(FROZEN))
- {
- splash_size.x = max(vid_conwidth, vid_conheight);
- splash_size.y = max(vid_conwidth, vid_conheight);
- splash_pos.x = (vid_conwidth - splash_size.x) / 2;
- splash_pos.y = (vid_conheight - splash_size.y) / 2;
-
- float myhealth_flash_temp;
- myhealth = STAT(HEALTH);
-
- // fade out
- myhealth_flash = max(0, myhealth_flash - autocvar_hud_damage_fade_rate * frametime);
- // add new damage
- myhealth_flash = bound(0, myhealth_flash + dmg_take * autocvar_hud_damage_factor, autocvar_hud_damage_maxalpha);
-
- float pain_threshold, pain_threshold_lower, pain_threshold_lower_health;
- pain_threshold = autocvar_hud_damage_pain_threshold;
- pain_threshold_lower = autocvar_hud_damage_pain_threshold_lower;
- pain_threshold_lower_health = autocvar_hud_damage_pain_threshold_lower_health;
-
- if(pain_threshold_lower && myhealth < pain_threshold_lower_health)
- {
- pain_threshold = pain_threshold - max(autocvar_hud_damage_pain_threshold_pulsating_min, fabs(sin(M_PI * time / autocvar_hud_damage_pain_threshold_pulsating_period))) * pain_threshold_lower * (1 - max(0, myhealth)/pain_threshold_lower_health);
- }
-
- myhealth_flash_temp = bound(0, myhealth_flash - pain_threshold, 1);
-
- if(myhealth_prev < 1)
- {
- if(myhealth >= 1)
- {
- myhealth_flash = 0; // just spawned, clear the flash immediately
- myhealth_flash_temp = 0;
- }
- else
- {
- myhealth_flash += autocvar_hud_damage_fade_rate * frametime; // dead
- }
- }
-
- if(spectatee_status == -1 || intermission)
- {
- myhealth_flash = 0; // observing, or match ended
- myhealth_flash_temp = 0;
- }
-
- myhealth_prev = myhealth;
-
- // IDEA: change damage color/picture based on player model for robot/alien species?
- // pro: matches model better
- // contra: it's not red because blood is red, but because red is an alarming color, so red should stay
- // maybe different reddish pics?
- if(autocvar_cl_gentle_damage || autocvar_cl_gentle)
- {
- if(autocvar_cl_gentle_damage == 2)
- {
- if(myhealth_flash < pain_threshold) // only randomize when the flash is gone
- myhealth_gentlergb = randomvec();
- }
- else
- myhealth_gentlergb = stov(autocvar_hud_damage_gentle_color);
-
- if(myhealth_flash_temp > 0)
- drawfill('0 0 0', vec2(vid_conwidth, vid_conheight), myhealth_gentlergb, autocvar_hud_damage_gentle_alpha_multiplier * bound(0, myhealth_flash_temp, 1) * autocvar_hud_damage, DRAWFLAG_NORMAL);
- }
- else if(myhealth_flash_temp > 0)
- drawpic(splash_pos, "gfx/blood", splash_size, stov(autocvar_hud_damage_color), bound(0, myhealth_flash_temp, 1) * autocvar_hud_damage, DRAWFLAG_NORMAL);
-
- if(autocvar_hud_postprocessing) // we still need to set this anyway even when chase_active is set, this way it doesn't get stuck on.
- {
- if(autocvar_hud_damage_blur && myhealth_flash_temp)
- {
- damage_blurpostprocess.x = 1;
- damage_blurpostprocess.y = bound(0, myhealth_flash_temp, 1) * autocvar_hud_damage_blur;
- damage_blurpostprocess.z = bound(0, myhealth_flash_temp, 1) * autocvar_hud_damage_blur_alpha;
- }
- else
- {
- damage_blurpostprocess.x = 0;
- damage_blurpostprocess.y = 0;
- damage_blurpostprocess.z = 0;
- }
- }
- }
-
- float e1 = (autocvar_hud_postprocessing_maxbluralpha != 0);
- float e2 = (autocvar_hud_powerup != 0);
- if(autocvar_hud_postprocessing && (e1 || e2)) // TODO: Remove this code and re-do the postprocess handling in the engine, where it properly belongs.
- {
- // enable or disable rendering types if they are used or not
- if(cvar("r_glsl_postprocess_uservec1_enable") != e1) { cvar_set("r_glsl_postprocess_uservec1_enable", ftos(e1)); }
- if(cvar("r_glsl_postprocess_uservec2_enable") != e2) { cvar_set("r_glsl_postprocess_uservec2_enable", ftos(e2)); }
-
- // blur postprocess handling done first (used by hud_damage and hud_contents)
- if((damage_blurpostprocess.x || content_blurpostprocess.x))
- {
- float blurradius = bound(0, damage_blurpostprocess.y + content_blurpostprocess.y, autocvar_hud_postprocessing_maxblurradius);
- float bluralpha = bound(0, damage_blurpostprocess.z + content_blurpostprocess.z, autocvar_hud_postprocessing_maxbluralpha);
- if(blurradius != old_blurradius || bluralpha != old_bluralpha) // reduce cvar_set spam as much as possible
- {
- cvar_set("r_glsl_postprocess_uservec1", strcat(ftos(blurradius), " ", ftos(bluralpha), " 0 0"));
- old_blurradius = blurradius;
- old_bluralpha = bluralpha;
- }
- }
- else if(cvar_string("r_glsl_postprocess_uservec1") != "0 0 0 0") // reduce cvar_set spam as much as possible
- {
- cvar_set("r_glsl_postprocess_uservec1", "0 0 0 0");
- old_blurradius = 0;
- old_bluralpha = 0;
- }
-
- // edge detection postprocess handling done second (used by hud_powerup)
- float sharpen_intensity = 0, strength_finished = STAT(STRENGTH_FINISHED), invincible_finished = STAT(INVINCIBLE_FINISHED);
- if (strength_finished - time > 0) { sharpen_intensity += (strength_finished - time); }
- if (invincible_finished - time > 0) { sharpen_intensity += (invincible_finished - time); }
-
- sharpen_intensity = bound(0, ((STAT(HEALTH) > 0) ? sharpen_intensity : 0), 5); // Check to see if player is alive (if not, set 0) - also bound to fade out starting at 5 seconds.
-
- if(autocvar_hud_powerup && sharpen_intensity > 0)
- {
- if(sharpen_intensity != old_sharpen_intensity) // reduce cvar_set spam as much as possible
- {
- cvar_set("r_glsl_postprocess_uservec2", strcat(ftos((sharpen_intensity / 5) * autocvar_hud_powerup), " ", ftos(-sharpen_intensity * autocvar_hud_powerup), " 0 0"));
- old_sharpen_intensity = sharpen_intensity;
- }
- }
- else if(cvar_string("r_glsl_postprocess_uservec2") != "0 0 0 0") // reduce cvar_set spam as much as possible
- {
- cvar_set("r_glsl_postprocess_uservec2", "0 0 0 0");
- old_sharpen_intensity = 0;
- }
-
- if(cvar("r_glsl_postprocess") == 0)
- cvar_set("r_glsl_postprocess", "2");
- }
- else if(cvar("r_glsl_postprocess") == 2)
- cvar_set("r_glsl_postprocess", "0");