cvar_t r_mipsprites = {CVAR_SAVE, "r_mipsprites", "1", "mipmaps sprites so they render faster in the distance and do not display noise artifacts"};
cvar_t r_picmipsprites = {CVAR_SAVE, "r_picmipsprites", "1", "make gl_picmip affect sprites too (saves some graphics memory in sprite heavy games)"};
+cvar_t r_labelsprites_scale = {CVAR_SAVE, "r_labelsprites_scale", "1", "global scale to apply to label sprites before conversion to HUD coordinates"};
+cvar_t r_labelsprites_roundtopixels = {CVAR_SAVE, "r_labelsprites_roundtopixels", "1", "try to make label sprites sharper by rounding their size to 0.5x or 1x and by rounding their position to whole pixels if possible"};
/*
===============
{
Cvar_RegisterVariable(&r_mipsprites);
Cvar_RegisterVariable(&r_picmipsprites);
+ Cvar_RegisterVariable(&r_labelsprites_scale);
+ Cvar_RegisterVariable(&r_labelsprites_roundtopixels);
}
static void Mod_SpriteSetupTexture(texture_t *texture, skinframe_t *skinframe, qboolean fullbright, qboolean additive)
#include "quakedef.h"
#include "r_shadow.h"
+extern cvar_t r_labelsprites_scale;
+extern cvar_t r_labelsprites_roundtopixels;
+
void R_Model_Sprite_Draw_TransparentCallback(const entity_render_t *ent, const rtlight_t *rtlight, int numsurfaces, int *surfacelist)
{
int i;
model_t *model = ent->model;
- vec3_t left, up, org, mforward, mleft, mup;
- float scale;
+ vec3_t left, up, org, mforward, mleft, mup, middle;
+ float scale, dx, dy, hud_vs_screen;
// nudge it toward the view to make sure it isn't in a wall
Matrix4x4_ToVectors(&ent->matrix, mforward, mleft, mup, org);
VectorScale(r_view.left, ent->scale, left);
VectorScale(r_view.up, ent->scale, up);
break;
+ case SPR_LABEL_SCALE:
+ // normal sprite
+ // faces view plane
+ // fixed HUD pixel size specified in sprite
+ // honors scale
+ // honors a global label scaling cvar
+
+ scale = 2 * ent->scale * (DotProduct(r_view.forward, org) - DotProduct(r_view.forward, r_view.origin)) * r_labelsprites_scale.value;
+ VectorScale(r_view.left, scale * r_view.frustum_x / vid_conwidth.integer, left); // 1px
+ VectorScale(r_view.up, scale * r_view.frustum_y / vid_conheight.integer, up); // 1px
+ break;
+ case SPR_LABEL:
+ // normal sprite
+ // faces view plane
+ // fixed pixel size specified in sprite
+ // tries to get the right size in HUD units, if possible
+ // ignores scale
+ // honors a global label scaling cvar before the rounding
+ // FIXME assumes that 1qu is 1 pixel in the sprite like in SPR32 format. Should not do that, but instead query the source image! This bug only applies to the roundtopixels case, though.
+
+ scale = 2 * (DotProduct(r_view.forward, org) - DotProduct(r_view.forward, r_view.origin));
+
+ if(r_labelsprites_roundtopixels.integer)
+ {
+ hud_vs_screen = max(
+ vid_conwidth.integer / (float) r_view.width,
+ vid_conheight.integer / (float) r_view.height
+ ) / max(0.125, r_labelsprites_scale.value);
+
+ // snap to "good sizes"
+ // 1 for (0.6, 1.41]
+ // 2 for (1.8, 3.33]
+ if(hud_vs_screen <= 0.6)
+ hud_vs_screen = 0; // don't, use real HUD pixels
+ else if(hud_vs_screen <= 1.41)
+ hud_vs_screen = 1;
+ else if(hud_vs_screen <= 3.33)
+ hud_vs_screen = 2;
+ else
+ hud_vs_screen = 0; // don't, use real HUD pixels
+
+ if(hud_vs_screen)
+ {
+ // use screen pixels
+ VectorScale(r_view.left, scale * r_view.frustum_x / (r_view.width * hud_vs_screen), left); // 1px
+ VectorScale(r_view.up, scale * r_view.frustum_y / (r_view.height * hud_vs_screen), up); // 1px
+ }
+ else
+ {
+ // use HUD pixels
+ VectorScale(r_view.left, scale * r_view.frustum_x / vid_conwidth.integer * r_labelsprites_scale.value, left); // 1px
+ VectorScale(r_view.up, scale * r_view.frustum_y / vid_conheight.integer * r_labelsprites_scale.value, up); // 1px
+ }
+
+ if(hud_vs_screen == 1)
+ {
+ VectorMA(r_view.origin, scale, r_view.forward, middle); // center of screen in distance scale
+ dx = 0.5 - fmod(r_view.width * 0.5 + (DotProduct(org, left) - DotProduct(middle, left)) / DotProduct(left, left) + 0.5, 1.0);
+ dy = 0.5 - fmod(r_view.height * 0.5 + (DotProduct(org, up) - DotProduct(middle, up)) / DotProduct(up, up) + 0.5, 1.0);
+ VectorMAMAM(1, org, dx, left, dy, up, org);
+ }
+ }
+ else
+ {
+ // use HUD pixels
+ VectorScale(r_view.left, scale * r_view.frustum_x / vid_conwidth.integer * r_labelsprites_scale.value, left); // 1px
+ VectorScale(r_view.up, scale * r_view.frustum_y / vid_conheight.integer * r_labelsprites_scale.value, up); // 1px
+ }
+ break;
case SPR_ORIENTED:
// bullet marks on walls
// ignores viewer entirely