4 static int R_SpriteSetup (const entity_render_t *ent, int type, float org[3], float left[3], float up[3])
8 // nudge it toward the view to make sure it isn't in a wall
9 org[0] = ent->matrix.m[0][3] - r_viewforward[0];
10 org[1] = ent->matrix.m[1][3] - r_viewforward[1];
11 org[2] = ent->matrix.m[2][3] - r_viewforward[2];
14 case SPR_VP_PARALLEL_UPRIGHT:
16 // vertical beam sprite, faces view plane
17 scale = ent->scale / sqrt(r_viewforward[0]*r_viewforward[0]+r_viewforward[1]*r_viewforward[1]);
18 left[0] = -r_viewforward[1] * scale;
19 left[1] = r_viewforward[0] * scale;
25 case SPR_FACING_UPRIGHT:
27 // vertical beam sprite, faces viewer's origin (not the view plane)
28 scale = ent->scale / sqrt((org[0] - r_vieworigin[0])*(org[0] - r_vieworigin[0])+(org[1] - r_vieworigin[1])*(org[1] - r_vieworigin[1]));
29 left[0] = (org[1] - r_vieworigin[1]) * scale;
30 left[1] = -(org[0] - r_vieworigin[0]) * scale;
37 Con_Printf("R_SpriteSetup: unknown sprite type %i\n", type);
38 // fall through to normal sprite
42 left[0] = r_viewleft[0] * ent->scale;
43 left[1] = r_viewleft[1] * ent->scale;
44 left[2] = r_viewleft[2] * ent->scale;
45 up[0] = r_viewup[0] * ent->scale;
46 up[1] = r_viewup[1] * ent->scale;
47 up[2] = r_viewup[2] * ent->scale;
50 // bullet marks on walls
51 // ignores viewer entirely
52 left[0] = ent->matrix.m[0][1];
53 left[1] = ent->matrix.m[1][1];
54 left[2] = ent->matrix.m[2][1];
55 up[0] = ent->matrix.m[0][2];
56 up[1] = ent->matrix.m[1][2];
57 up[2] = ent->matrix.m[2][2];
59 case SPR_VP_PARALLEL_ORIENTED:
60 // I have no idea what people would use this for...
61 // oriented relative to view space
62 // FIXME: test this and make sure it mimicks software
63 left[0] = ent->matrix.m[0][1] * r_viewforward[0] + ent->matrix.m[1][1] * r_viewleft[0] + ent->matrix.m[2][1] * r_viewup[0];
64 left[1] = ent->matrix.m[0][1] * r_viewforward[1] + ent->matrix.m[1][1] * r_viewleft[1] + ent->matrix.m[2][1] * r_viewup[1];
65 left[2] = ent->matrix.m[0][1] * r_viewforward[2] + ent->matrix.m[1][1] * r_viewleft[2] + ent->matrix.m[2][1] * r_viewup[2];
66 up[0] = ent->matrix.m[0][2] * r_viewforward[0] + ent->matrix.m[1][2] * r_viewleft[0] + ent->matrix.m[2][2] * r_viewup[0];
67 up[1] = ent->matrix.m[0][2] * r_viewforward[1] + ent->matrix.m[1][2] * r_viewleft[1] + ent->matrix.m[2][2] * r_viewup[1];
68 up[2] = ent->matrix.m[0][2] * r_viewforward[2] + ent->matrix.m[1][2] * r_viewleft[2] + ent->matrix.m[2][2] * r_viewup[2];
74 static void R_DrawSpriteImage (int additive, int depthdisable, mspriteframe_t *frame, rtexture_t *texture, vec3_t origin, vec3_t up, vec3_t left, float red, float green, float blue, float alpha)
76 // FIXME: negate left and right in loader
77 R_DrawSprite(GL_SRC_ALPHA, additive ? GL_ONE : GL_ONE_MINUS_SRC_ALPHA, texture, depthdisable, origin, left, up, frame->left, frame->right, frame->down, frame->up, red, green, blue, alpha);
80 void R_DrawSpriteModelCallback(const void *calldata1, int calldata2)
82 const entity_render_t *ent = calldata1;
84 vec3_t left, up, org, color, diffusecolor, diffusenormal;
85 mspriteframe_t *frame;
89 if (R_SpriteSetup(ent, ent->model->sprite.sprnum_type, org, left, up))
92 R_Mesh_Matrix(&r_identitymatrix);
94 if (!(ent->flags & RENDER_LIGHT))
95 color[0] = color[1] = color[2] = 1;
98 R_CompleteLightPoint(color, diffusecolor, diffusenormal, ent->origin, true);
99 VectorMA(color, 0.5f, diffusecolor, color);
101 color[0] *= ent->colormod[0];
102 color[1] *= ent->colormod[1];
103 color[2] *= ent->colormod[2];
107 VectorSubtract(ent->origin, r_vieworigin, diff);
108 fog = exp(fogdensity/DotProduct(diff,diff));
116 if (r_lerpsprites.integer)
118 // LordHavoc: interpolated sprite rendering
119 for (i = 0;i < 4;i++)
121 if (ent->frameblend[i].lerp >= 0.01f)
123 frame = ent->model->sprite.sprdata_frames + ent->frameblend[i].frame;
124 R_DrawSpriteImage((ent->effects & EF_ADDITIVE), (ent->effects & EF_NODEPTHTEST), frame, frame->texture, org, up, left, color[0] * ifog, color[1] * ifog, color[2] * ifog, ent->alpha * ent->frameblend[i].lerp);
125 if (fog * ent->frameblend[i].lerp >= 0.01f)
126 R_DrawSpriteImage(true, (ent->effects & EF_NODEPTHTEST), frame, frame->fogtexture, org, up, left, fogcolor[0],fogcolor[1],fogcolor[2], fog * ent->alpha * ent->frameblend[i].lerp);
132 // LordHavoc: no interpolation
134 for (i = 0;i < 4 && ent->frameblend[i].lerp;i++)
135 frame = ent->model->sprite.sprdata_frames + ent->frameblend[i].frame;
139 R_DrawSpriteImage((ent->effects & EF_ADDITIVE), (ent->effects & EF_NODEPTHTEST), frame, frame->texture, org, up, left, color[0] * ifog, color[1] * ifog, color[2] * ifog, ent->alpha);
140 if (fog * ent->frameblend[i].lerp >= 0.01f)
141 R_DrawSpriteImage(true, (ent->effects & EF_NODEPTHTEST), frame, frame->fogtexture, org, up, left, fogcolor[0],fogcolor[1],fogcolor[2], fog * ent->alpha);
146 void R_Model_Sprite_Draw(entity_render_t *ent)
148 if (ent->frameblend[0].frame < 0)
153 R_MeshQueue_AddTransparent(ent->effects & EF_NODEPTHTEST ? r_vieworigin : ent->origin, R_DrawSpriteModelCallback, ent, 0);