From: Juhu <5894800-Juhu_@users.noreply.gitlab.com> Date: Sun, 12 Jan 2025 00:44:02 +0000 (+0100) Subject: strafehud: changed terminology surrounding the two gradient rendering methods X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=875f4c5a4e79424bc57f9969f00da7094135b38d;p=xonotic%2Fxonotic-data.pk3dir.git strafehud: changed terminology surrounding the two gradient rendering methods the cvar values are now swapped putting the faster renderer first --- diff --git a/_hud_common.cfg b/_hud_common.cfg index 0ac7c7d0a..385e302b5 100644 --- a/_hud_common.cfg +++ b/_hud_common.cfg @@ -168,7 +168,7 @@ seta _hud_panel_strafehud_demo "0" "strafehud changes angle during configure" seta hud_panel_strafehud_mode "0" "strafehud mode which controls whether the strafehud is centered at 0 = view angle, 1 = velocity angle" seta hud_panel_strafehud_range "90" "the angle range up to 360 degrees displayed on the strafehud, -1 = current fov, 0 = dynamic (chooses the minimum range required to still see the whole area needed for accelerating)" seta hud_panel_strafehud_range_sidestrafe "-2" "the angle range up to 360 degrees displayed on the strafehud when side strafing, 0 = dynamic (chooses the minimum range required to still see the whole area needed for accelerating), -1 = current fov, -2 = same as the normal range" -seta hud_panel_strafehud_style "3" "0 = no styling, 1 = progress bar style for the strafe bar, 2 = gradient for the strafe bar, 3 = fast gradient for the strafe bar (gradient itself will not be projected)" +seta hud_panel_strafehud_style "2" "0 = no styling, 1 = progress bar style for the strafe bar, 2 = accelerated gradient for the strafe bar (no non-linear projection for gradient color/opacity), 3 = software gradient for the strafe bar (slow)" seta hud_panel_strafehud_unit_show "1" "show units" seta hud_panel_strafehud_onground_mode "2" "handling of landing at speeds where friction is higher than optimal acceleration, 0 = fill the whole hud with overturn, 1 = show zones regardless, 2 = show the zones as if airborne (useful for quake2 and quake3 physics)" seta hud_panel_strafehud_onground_friction "1" "set to 1 to account for friction in calculations" diff --git a/qcsrc/client/hud/panel/strafehud.qc b/qcsrc/client/hud/panel/strafehud.qc index bbd2f8167..62b3911dd 100644 --- a/qcsrc/client/hud/panel/strafehud.qc +++ b/qcsrc/client/hud/panel/strafehud.qc @@ -579,7 +579,7 @@ void HUD_StrafeHUD() strafe_ratio = (moveangle - absolute_prebestangle) / (absolute_bestangle - absolute_prebestangle); } - if(autocvar_hud_panel_strafehud_style == STRAFEHUD_STYLE_GRADIENT || autocvar_hud_panel_strafehud_style == STRAFEHUD_STYLE_FAST_GRADIENT) + if(autocvar_hud_panel_strafehud_style == STRAFEHUD_STYLE_GRADIENT || autocvar_hud_panel_strafehud_style == STRAFEHUD_STYLE_SOFT_GRADIENT) currentangle_color = StrafeHUD_MixColors( autocvar_hud_panel_strafehud_angle_neutral_color, currentangle_color, fabs(strafe_ratio)); diff --git a/qcsrc/client/hud/panel/strafehud.qh b/qcsrc/client/hud/panel/strafehud.qh index 8ec7394d4..7497fe275 100644 --- a/qcsrc/client/hud/panel/strafehud.qh +++ b/qcsrc/client/hud/panel/strafehud.qh @@ -11,7 +11,7 @@ bool autocvar_hud_panel_strafehud_dynamichud = true; int autocvar_hud_panel_strafehud_mode = 0; float autocvar_hud_panel_strafehud_range = 90; float autocvar_hud_panel_strafehud_range_sidestrafe = -2; -int autocvar_hud_panel_strafehud_style = 3; +int autocvar_hud_panel_strafehud_style = 2; bool autocvar_hud_panel_strafehud_unit_show = true; int autocvar_hud_panel_strafehud_onground_mode = 2; bool autocvar_hud_panel_strafehud_onground_friction = true; @@ -136,7 +136,7 @@ const int STRAFEHUD_KEYS_BACKWARD = 2; const int STRAFEHUD_STYLE_DRAWFILL = 0; const int STRAFEHUD_STYLE_PROGRESSBAR = 1; const int STRAFEHUD_STYLE_GRADIENT = 2; -const int STRAFEHUD_STYLE_FAST_GRADIENT = 3; +const int STRAFEHUD_STYLE_SOFT_GRADIENT = 3; const int STRAFEHUD_GRADIENT_NONE = 0; const int STRAFEHUD_GRADIENT_LEFT = 1; diff --git a/qcsrc/client/hud/panel/strafehud/draw.qc b/qcsrc/client/hud/panel/strafehud/draw.qc index 96de0b54f..9fec07fb5 100644 --- a/qcsrc/client/hud/panel/strafehud/draw.qc +++ b/qcsrc/client/hud/panel/strafehud/draw.qc @@ -12,14 +12,14 @@ void StrafeHUD_DrawStrafeHUD(float startangle, float offsetangle, vector color, float mirror_offset; float mirror_width; - if(type == STRAFEHUD_STYLE_GRADIENT) + if(type == STRAFEHUD_STYLE_SOFT_GRADIENT) { - project_width = true; // must be fully projected for gradients + project_width = true; // must be fully projected for software gradients if(gradient_type == STRAFEHUD_GRADIENT_NONE) type = STRAFEHUD_STYLE_DRAWFILL; } - if(alpha <= 0 && type != STRAFEHUD_STYLE_GRADIENT && type != STRAFEHUD_STYLE_FAST_GRADIENT || width <= 0) + if(alpha <= 0 && type != STRAFEHUD_STYLE_GRADIENT && type != STRAFEHUD_STYLE_SOFT_GRADIENT || width <= 0) return; // how much is hidden by the current hud angle @@ -53,8 +53,8 @@ void StrafeHUD_DrawStrafeHUD(float startangle, float offsetangle, vector color, float original_offset = offset; - // the fast gradient does the projection later - if(type != STRAFEHUD_STYLE_FAST_GRADIENT) + // the accelerated gradient does the projection later + if(type != STRAFEHUD_STYLE_GRADIENT) { if(project_width && size.x > 0) size.x = StrafeHUD_ProjectWidth(offset, size.x, range); @@ -80,8 +80,8 @@ void StrafeHUD_DrawStrafeHUD(float startangle, float offsetangle, vector color, float original_mirror_offset = mirror_offset; - // the fast gradient does the projection later - if(type != STRAFEHUD_STYLE_FAST_GRADIENT) + // the accelerated gradient does the projection later + if(type != STRAFEHUD_STYLE_GRADIENT) { if(project_width && mirror_size.x > 0) mirror_size.x = StrafeHUD_ProjectWidth(mirror_offset, mirror_size.x, range); @@ -113,7 +113,7 @@ void StrafeHUD_DrawStrafeHUD(float startangle, float offsetangle, vector color, break; case STRAFEHUD_STYLE_GRADIENT: // gradient style (types: 1 = left, 2 = right, 3 = both) - case STRAFEHUD_STYLE_FAST_GRADIENT: + case STRAFEHUD_STYLE_SOFT_GRADIENT: // determine whether the gradient starts in the mirrored or the non-mirrored area int gradient_start; float gradient_offset, gradient_mirror_offset; @@ -142,16 +142,16 @@ void StrafeHUD_DrawStrafeHUD(float startangle, float offsetangle, vector color, gradient_mirror_offset = 0; } - if(type == STRAFEHUD_STYLE_FAST_GRADIENT) + if(type == STRAFEHUD_STYLE_GRADIENT) { if(mirror_size.x > 0) - StrafeHUD_DrawGradientFast( + StrafeHUD_DrawGradient( color, autocvar_hud_panel_strafehud_bar_neutral_color, mirror_size, original_width, mirror_offset, alpha, gradient_mirror_offset, gradient_type, range); if(size.x > 0) - StrafeHUD_DrawGradientFast( + StrafeHUD_DrawGradient( color, autocvar_hud_panel_strafehud_bar_neutral_color, size, original_width, offset, alpha, gradient_offset, gradient_type, range); @@ -159,13 +159,13 @@ void StrafeHUD_DrawStrafeHUD(float startangle, float offsetangle, vector color, else { if(mirror_size.x > 0) - StrafeHUD_DrawGradient( + StrafeHUD_DrawSoftGradient( color, autocvar_hud_panel_strafehud_bar_neutral_color, mirror_size, original_width, mirror_offset, original_mirror_offset, alpha, gradient_mirror_offset, gradient_type, range); if(size.x > 0) - StrafeHUD_DrawGradient( + StrafeHUD_DrawSoftGradient( color, autocvar_hud_panel_strafehud_bar_neutral_color, size, original_width, offset, original_offset, alpha, gradient_offset, gradient_type, range); @@ -173,42 +173,8 @@ void StrafeHUD_DrawStrafeHUD(float startangle, float offsetangle, vector color, } } -// slow gradient, required for projection modes other than linear -void StrafeHUD_DrawGradient(vector color1, vector color2, vector size, float original_width, float offset, float original_offset, float alpha, float gradient_offset, int gradient_type, float range) -{ - float alpha1 = bound(0, alpha, 1); - float alpha2 = bound(0, autocvar_hud_panel_strafehud_bar_neutral_alpha * panel_fg_alpha, 1); - if((alpha1 + alpha2) == 0) return; - - float color_ratio = alpha1 / (alpha1 + alpha2); - vector segment_size = size; - for(int i = 0; i < size.x; ++i) - { - segment_size.x = min(size.x - i, 1); // each gradient segment is 1 unit wide except if there is less than 1 unit of gradient remaining - float segment_offset = offset + i; - float ratio_offset = segment_offset + segment_size.x / 2; - ratio_offset = StrafeHUD_ProjectOffset(ratio_offset, range, true); - ratio_offset += gradient_offset; - float ratio = (ratio_offset - original_offset) / original_width * (gradient_type == STRAFEHUD_GRADIENT_BOTH ? 2 : 1); - if(ratio > 1) ratio = 2 - ratio; - if(gradient_type != STRAFEHUD_GRADIENT_RIGHT) ratio = 1 - ratio; - float alpha_ratio = alpha1 - (alpha1 - alpha2) * ratio; - float combine_ratio1 = ratio * (1 - color_ratio); - float combine_ratio2 = (1 - ratio) * color_ratio; - ratio = (combine_ratio1 + combine_ratio2) == 0 ? 1 : combine_ratio1 / (combine_ratio1 + combine_ratio2); - - if(alpha_ratio > 0) - drawfill( - panel_pos + eX * segment_offset, - segment_size, - StrafeHUD_MixColors(color1, color2, ratio), - alpha_ratio, - DRAWFLAG_NORMAL); - } -} - -// optimized gradient, does not work with projection modes other than linear, decreased visual fidelity -void StrafeHUD_DrawGradientFast(vector color1, vector color2, vector size, float original_width, float offset, float alpha, float gradient_offset, int gradient_type, float range) +// accelerated gradient, does not support non-linear projection of the color and opacity within individual segments +void StrafeHUD_DrawGradient(vector color1, vector color2, vector size, float original_width, float offset, float alpha, float gradient_offset, int gradient_type, float range) { if(gradient_type == STRAFEHUD_GRADIENT_BOTH) { @@ -221,10 +187,10 @@ void StrafeHUD_DrawGradientFast(vector color1, vector color2, vector size, float size2.x = size.x - size1.x; if(size1.x > 0) - StrafeHUD_DrawGradientFast(color1, color2, size1, original_width, offset, alpha, gradient_offset, STRAFEHUD_GRADIENT_LEFT, range); + StrafeHUD_DrawGradient(color1, color2, size1, original_width, offset, alpha, gradient_offset, STRAFEHUD_GRADIENT_LEFT, range); if(size2.x > 0) - StrafeHUD_DrawGradientFast(color1, color2, size2, original_width, offset + size1.x, alpha, max(0, gradient_offset - original_width), STRAFEHUD_GRADIENT_RIGHT, range); + StrafeHUD_DrawGradient(color1, color2, size2, original_width, offset + size1.x, alpha, max(0, gradient_offset - original_width), STRAFEHUD_GRADIENT_RIGHT, range); return; } @@ -267,6 +233,40 @@ void StrafeHUD_DrawGradientFast(vector color1, vector color2, vector size, float R_EndPolygon(); } +// more expensive gradient rendering which does not rely on vertex gradients (required to properly render the color/opacity of individual segments in non-linear projection modes) +void StrafeHUD_DrawSoftGradient(vector color1, vector color2, vector size, float original_width, float offset, float original_offset, float alpha, float gradient_offset, int gradient_type, float range) +{ + float alpha1 = bound(0, alpha, 1); + float alpha2 = bound(0, autocvar_hud_panel_strafehud_bar_neutral_alpha * panel_fg_alpha, 1); + if((alpha1 + alpha2) == 0) return; + + float color_ratio = alpha1 / (alpha1 + alpha2); + vector segment_size = size; + for(int i = 0; i < size.x; ++i) + { + segment_size.x = min(size.x - i, 1); // each gradient segment is 1 unit wide except if there is less than 1 unit of gradient remaining + float segment_offset = offset + i; + float ratio_offset = segment_offset + segment_size.x / 2; + ratio_offset = StrafeHUD_ProjectOffset(ratio_offset, range, true); + ratio_offset += gradient_offset; + float ratio = (ratio_offset - original_offset) / original_width * (gradient_type == STRAFEHUD_GRADIENT_BOTH ? 2 : 1); + if(ratio > 1) ratio = 2 - ratio; + if(gradient_type != STRAFEHUD_GRADIENT_RIGHT) ratio = 1 - ratio; + float alpha_ratio = alpha1 - (alpha1 - alpha2) * ratio; + float combine_ratio1 = ratio * (1 - color_ratio); + float combine_ratio2 = (1 - ratio) * color_ratio; + ratio = (combine_ratio1 + combine_ratio2) == 0 ? 1 : combine_ratio1 / (combine_ratio1 + combine_ratio2); + + if(alpha_ratio > 0) + drawfill( + panel_pos + eX * segment_offset, + segment_size, + StrafeHUD_MixColors(color1, color2, ratio), + alpha_ratio, + DRAWFLAG_NORMAL); + } +} + // draw the strafe arrows (inspired by drawspritearrow() in common/mutators/mutator/waypoints/waypointsprites.qc) void StrafeHUD_DrawStrafeArrow(vector origin, float size, vector color, float alpha, bool flipped, float connection_width) { diff --git a/qcsrc/client/hud/panel/strafehud/draw.qh b/qcsrc/client/hud/panel/strafehud/draw.qh index 57b522bd4..d7412e41f 100644 --- a/qcsrc/client/hud/panel/strafehud/draw.qh +++ b/qcsrc/client/hud/panel/strafehud/draw.qh @@ -2,8 +2,8 @@ #include "../strafehud.qh" void StrafeHUD_DrawStrafeHUD(float, float, vector, float, int, int, bool, float); -void StrafeHUD_DrawGradient(vector, vector, vector, float, float, float, float, float, int, float); -void StrafeHUD_DrawGradientFast(vector, vector, vector, float, float, float, float, int, float); +void StrafeHUD_DrawGradient(vector, vector, vector, float, float, float, float, int, float); +void StrafeHUD_DrawSoftGradient(vector, vector, vector, float, float, float, float, float, int, float); void StrafeHUD_DrawStrafeArrow(vector, float, vector, float, bool, float); void StrafeHUD_DrawTextIndicator(string, float, vector, float, float, vector, float, float); vector StrafeHUD_CalculateTextIndicatorPosition(vector);