- {
- // LordHavoc: only render if not too close
- if (DotProduct(p->org, vpn) < minparticledist)
- continue;
-
- // LordHavoc: check if it's in a visible leaf
- leaf = Mod_PointInLeaf(p->org, cl.worldmodel);
- if (leaf->visframe != r_framecount)
- continue;
-
- VectorCopy(p->org, org);
- orientation = (p->flags >> P_ORIENTATION_FIRSTBIT) & ((1 << P_ORIENTATION_BITS) - 1);
- texnum = (p->flags >> P_TEXNUM_FIRSTBIT) & ((1 << P_TEXNUM_BITS) - 1);
- dynlight = p->flags & P_DYNLIGHT;
- additive = p->flags & P_ADDITIVE;
- if (orientation == PARTICLE_BILLBOARD)
- {
- VectorScale(vright, p->scalex, right);
- VectorScale(vup, p->scaley, up);
- }
- else if (orientation == PARTICLE_UPRIGHT_FACING)
- {
- VectorScale(right2, p->scalex, right);
- VectorScale(up2, p->scaley, up);
- }
- else if (orientation == PARTICLE_ORIENTED_DOUBLESIDED)
- {
- // double-sided
- if (DotProduct(p->vel2, r_origin) > DotProduct(p->vel2, org))
- {
- VectorNegate(p->vel2, v);
- VectorVectors(v, right, up);
- }
- else
- VectorVectors(p->vel2, right, up);
- VectorScale(right, p->scalex, right);
- VectorScale(up, p->scaley, up);
- }
- else
- Host_Error("R_DrawParticles: unknown particle orientation %i\n", orientation);
-
- m.cr = p->color[0] * (1.0f / 255.0f);
- m.cg = p->color[1] * (1.0f / 255.0f);
- m.cb = p->color[2] * (1.0f / 255.0f);
- m.ca = p->alpha * (1.0f / 255.0f);
- if (lighting >= 1 && (dynlight || lighting >= 2))
- {
- R_CompleteLightPoint(v, org, true, leaf);
- m.cr *= v[0];
- m.cg *= v[1];
- m.cb *= v[2];
- }
-
- tex = &particletexture[texnum][0];
-
- tvxyz[0][0] = org[0] - right[0] - up[0];
- tvxyz[0][1] = org[1] - right[1] - up[1];
- tvxyz[0][2] = org[2] - right[2] - up[2];
- tvxyz[1][0] = org[0] - right[0] + up[0];
- tvxyz[1][1] = org[1] - right[1] + up[1];
- tvxyz[1][2] = org[2] - right[2] + up[2];
- tvxyz[2][0] = org[0] + right[0] + up[0];
- tvxyz[2][1] = org[1] + right[1] + up[1];
- tvxyz[2][2] = org[2] + right[2] + up[2];
- tvxyz[3][0] = org[0] + right[0] - up[0];
- tvxyz[3][1] = org[1] + right[1] - up[1];
- tvxyz[3][2] = org[2] + right[2] - up[2];
- tvst[0][0] = tex->s1;
- tvst[0][1] = tex->t1;
- tvst[1][0] = tex->s1;
- tvst[1][1] = tex->t2;
- tvst[2][0] = tex->s2;
- tvst[2][1] = tex->t2;
- tvst[3][0] = tex->s2;
- tvst[3][1] = tex->t1;
-
- if (additive)
- {
- m.blendfunc2 = GL_ONE;
- fog = 0;
- if (fogenabled)
- {
- texfog = &particletexture[texnum][1];
- VectorSubtract(org, r_origin, fogvec);
- ifog = 1 - exp(fogdensity/DotProduct(fogvec,fogvec));
- if (ifog < (1.0f - (1.0f / 64.0f)))
- {
- if (ifog >= (1.0f / 64.0f))
- {
- // partially fogged, darken it
- m.cr *= ifog;
- m.cg *= ifog;
- m.cb *= ifog;
- R_Mesh_Draw(&m);
- }
- }
- else
- R_Mesh_Draw(&m);
- }
- else
- R_Mesh_Draw(&m);
- }
- else
- {
- m.blendfunc2 = GL_ONE_MINUS_SRC_ALPHA;
- fog = 0;
- if (fogenabled)
- {
- texfog = &particletexture[texnum][1];
- VectorSubtract(org, r_origin, fogvec);
- fog = exp(fogdensity/DotProduct(fogvec,fogvec));
- if (fog >= (1.0f / 64.0f))
- {
- if (fog >= (1.0f - (1.0f / 64.0f)))
- {
- // fully fogged, just use the fog texture and render as alpha
- m.cr = fogcolor[0];
- m.cg = fogcolor[1];
- m.cb = fogcolor[2];
- tvst[0][0] = texfog->s1;
- tvst[0][1] = texfog->t1;
- tvst[1][0] = texfog->s1;
- tvst[1][1] = texfog->t2;
- tvst[2][0] = texfog->s2;
- tvst[2][1] = texfog->t2;
- tvst[3][0] = texfog->s2;
- tvst[3][1] = texfog->t1;
- R_Mesh_Draw(&m);
- }
- else
- {
- // partially fogged, darken the first pass
- ifog = 1 - fog;
- m.cr *= ifog;
- m.cg *= ifog;
- m.cb *= ifog;
- if (tex->s1 == texfog->s1 && tex->t1 == texfog->t1)
- {
- // fog texture is the same as the base, just change the color
- m.cr += fogcolor[0] * fog;
- m.cg += fogcolor[1] * fog;
- m.cb += fogcolor[2] * fog;
- R_Mesh_Draw(&m);
- }
- else
- {
- // render the first pass (alpha), then do additive fog
- R_Mesh_Draw(&m);
-
- m.blendfunc2 = GL_ONE;
- m.cr = fogcolor[0] * fog;
- m.cg = fogcolor[1] * fog;
- m.cb = fogcolor[2] * fog;
- tvst[0][0] = texfog->s1;
- tvst[0][1] = texfog->t1;
- tvst[1][0] = texfog->s1;
- tvst[1][1] = texfog->t2;
- tvst[2][0] = texfog->s2;
- tvst[2][1] = texfog->t2;
- tvst[3][0] = texfog->s2;
- tvst[3][1] = texfog->t1;
- R_Mesh_Draw(&m);
- }
- }
- }
- else
- R_Mesh_Draw(&m);
- }
- else
- R_Mesh_Draw(&m);
- }
- }