Do not build VBOs on a dedicated server.
[xonotic/darkplaces.git] / r_sprites.c
index 133f3d1..5c621da 100644 (file)
@@ -8,6 +8,10 @@ extern cvar_t r_track_sprites;
 extern cvar_t r_track_sprites_flags;
 extern cvar_t r_track_sprites_scalew;
 extern cvar_t r_track_sprites_scaleh;
+extern cvar_t r_overheadsprites_perspective;
+extern cvar_t r_overheadsprites_pushback;
+extern cvar_t r_overheadsprites_scalex;
+extern cvar_t r_overheadsprites_scaley;
 
 #define TSF_ROTATE 1
 #define TSF_ROTATE_CONTINOUSLY 2
@@ -31,7 +35,7 @@ extern cvar_t r_track_sprites_scaleh;
 #define SIDE_BOTTOM 3
 #define SIDE_RIGHT 4
 
-void R_TrackSprite(const entity_render_t *ent, vec3_t origin, vec3_t left, vec3_t up, int *edge, float *dir_angle)
+static void R_TrackSprite(const entity_render_t *ent, vec3_t origin, vec3_t left, vec3_t up, int *edge, float *dir_angle)
 {
        float distance;
        vec3_t bCoord; // body coordinates of object
@@ -137,7 +141,7 @@ void R_TrackSprite(const entity_render_t *ent, vec3_t origin, vec3_t left, vec3_
        }
 }
 
-void R_RotateSprite(const mspriteframe_t *frame, vec3_t origin, vec3_t left, vec3_t up, int edge, float dir_angle)
+static void R_RotateSprite(const mspriteframe_t *frame, vec3_t origin, vec3_t left, vec3_t up, int edge, float dir_angle)
 {
        if(!(r_track_sprites_flags.integer & TSF_ROTATE))
        {
@@ -201,7 +205,7 @@ void R_RotateSprite(const mspriteframe_t *frame, vec3_t origin, vec3_t left, vec
 
 static float spritetexcoord2f[4*2] = {0, 1, 0, 0, 1, 0, 1, 1};
 
-void R_Model_Sprite_Draw_TransparentCallback(const entity_render_t *ent, const rtlight_t *rtlight, int numsurfaces, int *surfacelist)
+static void R_Model_Sprite_Draw_TransparentCallback(const entity_render_t *ent, const rtlight_t *rtlight, int numsurfaces, int *surfacelist)
 {
        int i;
        dp_model_t *model = ent->model;
@@ -254,7 +258,7 @@ void R_Model_Sprite_Draw_TransparentCallback(const entity_render_t *ent, const r
                // honors scale
                // honors a global label scaling cvar
        
-               if(r_waterstate.renderingscene) // labels are considered HUD items, and don't appear in reflections
+               if(r_fb.water.renderingscene) // labels are considered HUD items, and don't appear in reflections
                        return;
 
                // See the R_TrackSprite definition for a reason for this copying
@@ -277,7 +281,7 @@ void R_Model_Sprite_Draw_TransparentCallback(const entity_render_t *ent, const r
                // 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.
 
-               if(r_waterstate.renderingscene) // labels are considered HUD items, and don't appear in reflections
+               if(r_fb.water.renderingscene) // labels are considered HUD items, and don't appear in reflections
                        return;
 
                // See the R_TrackSprite definition for a reason for this copying
@@ -354,16 +358,26 @@ void R_Model_Sprite_Draw_TransparentCallback(const entity_render_t *ent, const r
                up[2] = mup[0] * r_refdef.view.forward[2] + mup[1] * r_refdef.view.left[2] + mup[2] * r_refdef.view.up[2];
                break;
        case SPR_OVERHEAD:
-               VectorScale(r_refdef.view.left, ent->scale, left);
-               VectorScale(r_refdef.view.up, ent->scale, up);
-               // offset
-               VectorSubtract(r_refdef.view.origin, org, middle);
+               // Overhead games sprites, have some special hacks to look good
+               VectorScale(r_refdef.view.left, ent->scale * r_overheadsprites_scalex.value, left);
+               VectorScale(r_refdef.view.up, ent->scale * r_overheadsprites_scaley.value, up);
+               VectorSubtract(org, r_refdef.view.origin, middle);
                VectorNormalize(middle);
-               org[0] = org[0] + middle[0]*17;
-               org[1] = org[1] + middle[1]*17;
-               org[2] = org[2] + middle[2]*17;
-               // simlulate a bit of perspective effect
-               up[2] = up[2] + 0.15;
+               // offset and rotate
+               dir_angle = r_overheadsprites_perspective.value * (1 - fabs(DotProduct(middle, r_refdef.view.forward)));
+               up[2] = up[2] + dir_angle;
+               VectorNormalize(up);
+               VectorScale(up, ent->scale * r_overheadsprites_scaley.value, up);
+               // offset (move nearer to player, yz is camera plane)
+               org[0] = org[0] - middle[0]*r_overheadsprites_pushback.value;
+               org[1] = org[1] - middle[1]*r_overheadsprites_pushback.value;
+               org[2] = org[2] - middle[2]*r_overheadsprites_pushback.value;
+               // little perspective effect
+               up[2] = up[2] + dir_angle * 0.3;
+               // a bit of counter-camera rotation
+               up[0] = up[0] + r_refdef.view.forward[0] * 0.07;
+               up[1] = up[1] + r_refdef.view.forward[1] * 0.07;
+               up[2] = up[2] + r_refdef.view.forward[2] * 0.07;
                break;
        }
 
@@ -377,6 +391,16 @@ void R_Model_Sprite_Draw_TransparentCallback(const entity_render_t *ent, const r
                        RSurf_ActiveCustomEntity(&identitymatrix, &identitymatrix, ent->flags, 0, ent->colormod[0], ent->colormod[1], ent->colormod[2], ent->alpha * ent->frameblend[i].lerp, 4, vertex3f, spritetexcoord2f, NULL, NULL, NULL, NULL, 2, polygonelement3i, polygonelement3s, false, false);
                        frame = model->sprite.sprdata_frames + ent->frameblend[i].subframe;
                        texture = R_GetCurrentTexture(model->data_textures + ent->frameblend[i].subframe);
+               
+                       // sprites are fullbright by default, but if this one is not fullbright we
+                       // need to combine the lighting into ambient as sprite lighting is not
+                       // directional
+                       if (!(texture->currentmaterialflags & MATERIALFLAG_FULLBRIGHT))
+                       {
+                               VectorMAM(1.0f, texture->render_modellight_ambient, 0.25f, texture->render_modellight_diffuse, texture->render_modellight_ambient);
+                               VectorClear(texture->render_modellight_diffuse);
+                               VectorClear(texture->render_modellight_specular);
+                       }
 
                        // SPR_LABEL should not use depth test AT ALL
                        if(model->sprite.sprnum_type == SPR_LABEL || model->sprite.sprnum_type == SPR_LABEL_SCALE)
@@ -392,6 +416,10 @@ void R_Model_Sprite_Draw_TransparentCallback(const entity_render_t *ent, const r
 
                        R_CalcSprite_Vertex3f(vertex3f, org, left, up, frame->left, frame->right, frame->down, frame->up);
 
+                       if (r_showspriteedges.integer)
+                               for (i = 0; i < 4; i++)
+                                       R_DebugLine(vertex3f + i * 3, vertex3f + ((i + 1) % 4) * 3);
+
                        R_DrawCustomSurface_Texture(texture, &identitymatrix, texture->currentmaterialflags, 0, 4, 0, 2, false, false);
                }
        }
@@ -406,6 +434,6 @@ void R_Model_Sprite_Draw(entity_render_t *ent)
                return;
 
        Matrix4x4_OriginFromMatrix(&ent->matrix, org);
-       R_MeshQueue_AddTransparent(ent->flags & RENDER_NODEPTHTEST ? r_refdef.view.origin : org, R_Model_Sprite_Draw_TransparentCallback, ent, 0, rsurface.rtlight);
+       R_MeshQueue_AddTransparent((ent->flags & RENDER_WORLDOBJECT) ? TRANSPARENTSORT_SKY : (ent->flags & RENDER_NODEPTHTEST) ? TRANSPARENTSORT_HUD : TRANSPARENTSORT_DISTANCE, org, R_Model_Sprite_Draw_TransparentCallback, ent, 0, rsurface.rtlight);
 }