6 static int R_SpriteSetup (entity_render_t *ent, int type, float org[3], float left[3], float up[3])
8 float matrix1[3][3], matrix2[3][3], matrix3[3][3];
10 VectorCopy(ent->origin, org);
13 case SPR_VP_PARALLEL_UPRIGHT:
15 // vertical beam sprite, faces view plane
16 VectorNegate(vpn, matrix3[0]);
18 VectorNormalizeFast(matrix3[0]);
19 matrix3[1][0] = matrix3[0][1];
20 matrix3[1][1] = -matrix3[0][0];
26 case SPR_FACING_UPRIGHT:
28 // vertical beam sprite, faces viewer's origin (not the view plane)
29 VectorSubtract(ent->origin, r_origin, matrix3[0]);
31 VectorNormalizeFast(matrix3[0]);
32 matrix3[1][0] = matrix3[0][1];
33 matrix3[1][1] = -matrix3[0][0];
40 Con_Printf("R_SpriteSetup: unknown sprite type %i\n", type);
41 // fall through to normal sprite
45 VectorCopy(vpn, matrix3[0]);
46 VectorNegate(vright, matrix3[1]);
47 VectorCopy(vup, matrix3[2]);
50 // bullet marks on walls
51 // ignores viewer entirely
52 AngleVectorsFLU (ent->angles, matrix3[0], matrix3[1], matrix3[2]);
53 // nudge it toward the view, so it will be infront of the wall
54 VectorSubtract(org, vpn, org);
56 case SPR_VP_PARALLEL_ORIENTED:
57 // I have no idea what people would use this for
58 // oriented relative to view space
59 // FIXME: test this and make sure it mimicks software
60 AngleVectorsFLU (ent->angles, matrix1[0], matrix1[1], matrix1[2]);
61 VectorCopy(vpn, matrix2[0]);
62 VectorNegate(vright, matrix2[1]);
63 VectorCopy(vup, matrix2[2]);
64 R_ConcatRotations (matrix1[0], matrix2[0], matrix3[0]);
70 VectorScale(matrix3[1], ent->scale, left);
71 VectorScale(matrix3[2], ent->scale, up);
75 VectorCopy(matrix3[1], left);
76 VectorCopy(matrix3[2], up);
81 static void R_DrawSpriteImage (int wantoverbright, int additive, mspriteframe_t *frame, int texture, vec3_t origin, vec3_t up, vec3_t left, float red, float green, float blue, float alpha)
84 memset(&m, 0, sizeof(m));
85 m.blendfunc1 = GL_SRC_ALPHA;
86 m.blendfunc2 = GL_ONE_MINUS_SRC_ALPHA;
88 m.blendfunc2 = GL_ONE;
92 if (R_Mesh_Draw_GetBuffer(&m, wantoverbright))
100 m.color[0] = m.color[4] = m.color[8] = m.color[12] = red * m.colorscale;
101 m.color[1] = m.color[5] = m.color[9] = m.color[13] = green * m.colorscale;
102 m.color[2] = m.color[6] = m.color[10] = m.color[14] = blue * m.colorscale;
103 m.color[3] = m.color[7] = m.color[11] = m.color[15] = alpha;
104 m.texcoords[0][0] = 0;
105 m.texcoords[0][1] = 1;
106 m.texcoords[0][2] = 0;
107 m.texcoords[0][3] = 0;
108 m.texcoords[0][4] = 1;
109 m.texcoords[0][5] = 0;
110 m.texcoords[0][6] = 1;
111 m.texcoords[0][7] = 1;
112 // FIXME: negate left and right in loader
113 m.vertex[0] = origin[0] + frame->down * up[0] - frame->left * left[0];
114 m.vertex[1] = origin[1] + frame->down * up[1] - frame->left * left[1];
115 m.vertex[2] = origin[2] + frame->down * up[2] - frame->left * left[2];
116 m.vertex[4] = origin[0] + frame->up * up[0] - frame->left * left[0];
117 m.vertex[5] = origin[1] + frame->up * up[1] - frame->left * left[1];
118 m.vertex[6] = origin[2] + frame->up * up[2] - frame->left * left[2];
119 m.vertex[8] = origin[0] + frame->up * up[0] - frame->right * left[0];
120 m.vertex[9] = origin[1] + frame->up * up[1] - frame->right * left[1];
121 m.vertex[10] = origin[2] + frame->up * up[2] - frame->right * left[2];
122 m.vertex[12] = origin[0] + frame->down * up[0] - frame->right * left[0];
123 m.vertex[13] = origin[1] + frame->down * up[1] - frame->right * left[1];
124 m.vertex[14] = origin[2] + frame->down * up[2] - frame->right * left[2];
129 void R_DrawSpriteModelCallback(void *calldata1, int calldata2)
131 entity_render_t *ent;
132 int i, wantoverbright;
133 vec3_t left, up, org, color;
134 mspriteframe_t *frame;
139 if (R_SpriteSetup(ent, ent->model->sprnum_type, org, left, up))
142 if ((ent->model->flags & EF_FULLBRIGHT) || (ent->effects & EF_FULLBRIGHT))
144 color[0] = color[1] = color[2] = 1;
145 wantoverbright = false;
149 R_CompleteLightPoint(color, ent->origin, true, NULL);
150 wantoverbright = color[0] > 1 || color[1] > 1 || color[2] > 1;
155 VectorSubtract(ent->origin, r_origin, diff);
156 fog = exp(fogdensity/DotProduct(diff,diff));
165 // LordHavoc: interpolated sprite rendering
166 for (i = 0;i < 4;i++)
168 if (ent->frameblend[i].lerp >= 0.01f)
170 frame = ent->model->sprdata_frames + ent->frameblend[i].frame;
171 R_DrawSpriteImage(wantoverbright, (ent->effects & EF_ADDITIVE) || (ent->model->flags & EF_ADDITIVE), frame, R_GetTexture(frame->texture), org, up, left, color[0] * ifog, color[1] * ifog, color[2] * ifog, ent->alpha * ent->frameblend[i].lerp);
172 if (fog * ent->frameblend[i].lerp >= 0.01f)
173 R_DrawSpriteImage(false, true, frame, R_GetTexture(frame->fogtexture), org, up, left, fogcolor[0],fogcolor[1],fogcolor[2], fog * ent->alpha * ent->frameblend[i].lerp);
177 // LordHavoc: no interpolation
179 for (i = 0;i < 4 && ent->frameblend[i].lerp;i++)
180 frame = ent->model->sprdata_frames + ent->frameblend[i].frame;
182 R_DrawSpriteImage(wantoverbright, (ent->effects & EF_ADDITIVE) || (ent->model->flags & EF_ADDITIVE), frame, R_GetTexture(frame->texture), org, up, left, color[0] * ifog, color[1] * ifog, color[2] * ifog, ent->alpha);
183 if (fog * ent->frameblend[i].lerp >= 0.01f)
184 R_DrawSpriteImage(false, true, frame, R_GetTexture(frame->fogtexture), org, up, left, fogcolor[0],fogcolor[1],fogcolor[2], fog * ent->alpha);
193 void R_DrawSpriteModel (entity_render_t *ent)
195 if (ent->frameblend[0].frame < 0)
200 R_MeshQueue_AddTransparent(ent->origin, R_DrawSpriteModelCallback, ent, 0);