]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - r_sprites.c
use bigger prime numbers in calculating vertex hash indices to improve
[xonotic/darkplaces.git] / r_sprites.c
index ae19bdeacbc8c27d64b2b21026fae86d13d0cef9..c514b81246cae0fcf538e5141aee1db00077a82e 100644 (file)
@@ -2,12 +2,15 @@
 #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);
@@ -45,6 +48,75 @@ void R_Model_Sprite_Draw_TransparentCallback(const entity_render_t *ent, const r
                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
@@ -87,6 +159,6 @@ void R_Model_Sprite_Draw(entity_render_t *ent)
                return;
 
        Matrix4x4_OriginFromMatrix(&ent->matrix, org);
-       R_MeshQueue_AddTransparent(ent->effects & EF_NODEPTHTEST ? r_view.origin : org, R_Model_Sprite_Draw_TransparentCallback, ent, 0, r_shadow_rtlight);
+       R_MeshQueue_AddTransparent(ent->effects & EF_NODEPTHTEST ? r_view.origin : org, R_Model_Sprite_Draw_TransparentCallback, ent, 0, rsurface.rtlight);
 }