2011-12-25 22:50:05 +00:00
|
|
|
/*
|
2021-12-19 05:47:25 +00:00
|
|
|
glsl_particles.c
|
2011-12-25 22:50:05 +00:00
|
|
|
|
2012-01-19 01:38:05 +00:00
|
|
|
OpenGL particle system.
|
2011-12-25 22:50:05 +00:00
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
#define NH_DEFINE
|
|
|
|
#include "namehack.h"
|
|
|
|
|
2011-12-25 22:50:05 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
2012-01-19 01:38:05 +00:00
|
|
|
# include <string.h>
|
2011-12-25 22:50:05 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
2012-01-19 01:38:05 +00:00
|
|
|
# include <strings.h>
|
2011-12-25 22:50:05 +00:00
|
|
|
#endif
|
|
|
|
|
2012-01-19 01:38:05 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "QF/cmd.h"
|
2011-12-25 22:50:05 +00:00
|
|
|
#include "QF/cvar.h"
|
2012-01-21 10:51:18 +00:00
|
|
|
#include "QF/image.h"
|
2013-01-21 11:06:54 +00:00
|
|
|
#include "QF/mersenne.h"
|
2012-01-19 01:38:05 +00:00
|
|
|
#include "QF/qargs.h"
|
|
|
|
#include "QF/quakefs.h"
|
2011-12-25 22:50:05 +00:00
|
|
|
#include "QF/render.h"
|
2012-01-19 01:38:05 +00:00
|
|
|
#include "QF/sys.h"
|
|
|
|
#include "QF/va.h"
|
2021-07-24 05:19:52 +00:00
|
|
|
|
|
|
|
#include "QF/scene/entity.h"
|
|
|
|
|
2011-12-26 07:08:55 +00:00
|
|
|
#include "QF/GLSL/defines.h"
|
|
|
|
#include "QF/GLSL/funcs.h"
|
2012-01-19 01:38:05 +00:00
|
|
|
//#include "QF/GL/qf_explosions.h"
|
|
|
|
#include "QF/GLSL/qf_particles.h"
|
|
|
|
#include "QF/GLSL/qf_textures.h"
|
|
|
|
#include "QF/GLSL/qf_vid.h"
|
2011-12-25 22:50:05 +00:00
|
|
|
|
2012-02-14 08:28:09 +00:00
|
|
|
#include "r_internal.h"
|
2011-12-25 22:50:05 +00:00
|
|
|
|
2012-01-21 12:54:36 +00:00
|
|
|
//FIXME not part of GLES, but needed for GL
|
|
|
|
#ifndef GL_VERTEX_PROGRAM_POINT_SIZE
|
|
|
|
# define GL_VERTEX_PROGRAM_POINT_SIZE 0x8642
|
|
|
|
#endif
|
|
|
|
|
2012-01-19 01:38:05 +00:00
|
|
|
static GLushort *pVAindices;
|
|
|
|
static partvert_t *particleVertexArray;
|
|
|
|
|
2012-01-21 10:51:18 +00:00
|
|
|
static GLuint part_tex;
|
2012-01-19 01:38:05 +00:00
|
|
|
|
2014-01-28 03:08:53 +00:00
|
|
|
static const char *particle_point_vert_effects[] =
|
|
|
|
{
|
|
|
|
"QuakeForge.Vertex.particle.point",
|
|
|
|
0
|
|
|
|
};
|
2012-01-19 01:38:05 +00:00
|
|
|
|
2014-01-28 03:08:53 +00:00
|
|
|
static const char *particle_point_frag_effects[] =
|
|
|
|
{
|
2014-01-28 04:00:28 +00:00
|
|
|
"QuakeForge.Fragment.fog",
|
|
|
|
"QuakeForge.Fragment.palette",
|
2014-01-28 03:08:53 +00:00
|
|
|
"QuakeForge.Fragment.particle.point",
|
|
|
|
0
|
|
|
|
};
|
2012-01-19 01:38:05 +00:00
|
|
|
|
2014-01-28 03:16:52 +00:00
|
|
|
static const char *particle_textured_vert_effects[] =
|
|
|
|
{
|
|
|
|
"QuakeForge.Vertex.particle.textured",
|
|
|
|
0
|
|
|
|
};
|
2012-01-21 10:51:18 +00:00
|
|
|
|
2014-01-28 03:16:52 +00:00
|
|
|
static const char *particle_textured_frag_effects[] =
|
|
|
|
{
|
2014-01-28 04:00:28 +00:00
|
|
|
"QuakeForge.Fragment.fog",
|
|
|
|
"QuakeForge.Fragment.palette",
|
2014-01-28 03:16:52 +00:00
|
|
|
"QuakeForge.Fragment.particle.textured",
|
|
|
|
0
|
|
|
|
};
|
2012-01-21 10:51:18 +00:00
|
|
|
|
2012-01-19 01:38:05 +00:00
|
|
|
static struct {
|
|
|
|
int program;
|
|
|
|
shaderparam_t mvp_matrix;
|
|
|
|
shaderparam_t vertex;
|
|
|
|
shaderparam_t palette;
|
|
|
|
shaderparam_t color;
|
2012-01-29 01:27:28 +00:00
|
|
|
shaderparam_t fog;
|
2012-01-19 01:38:05 +00:00
|
|
|
} quake_point = {
|
|
|
|
0,
|
|
|
|
{"mvp_mat", 1},
|
|
|
|
{"vertex", 0},
|
|
|
|
{"palette", 1},
|
|
|
|
{"vcolor", 0},
|
2012-01-29 01:35:23 +00:00
|
|
|
{"fog", 1},
|
2012-01-19 01:38:05 +00:00
|
|
|
};
|
|
|
|
|
2012-01-21 10:51:18 +00:00
|
|
|
static struct {
|
|
|
|
int program;
|
|
|
|
shaderparam_t mvp_matrix;
|
|
|
|
shaderparam_t st;
|
|
|
|
shaderparam_t vertex;
|
|
|
|
shaderparam_t color;
|
|
|
|
shaderparam_t texture;
|
2012-01-29 01:27:28 +00:00
|
|
|
shaderparam_t fog;
|
2012-01-21 10:51:18 +00:00
|
|
|
} quake_part = {
|
|
|
|
0,
|
|
|
|
{"mvp_mat", 1},
|
|
|
|
{"vst", 0},
|
|
|
|
{"vertex", 0},
|
|
|
|
{"vcolor", 0},
|
|
|
|
{"texture", 1},
|
2012-01-29 01:35:23 +00:00
|
|
|
{"fog", 1},
|
2012-01-21 10:51:18 +00:00
|
|
|
};
|
|
|
|
|
2011-12-25 22:50:05 +00:00
|
|
|
void
|
2012-02-22 07:32:34 +00:00
|
|
|
glsl_R_InitParticles (void)
|
2011-12-25 22:50:05 +00:00
|
|
|
{
|
2014-01-28 03:08:53 +00:00
|
|
|
shader_t *vert_shader, *frag_shader;
|
2012-01-19 01:38:05 +00:00
|
|
|
unsigned i;
|
|
|
|
int vert;
|
|
|
|
int frag;
|
2012-01-21 06:48:21 +00:00
|
|
|
float v[2] = {0, 0};
|
2012-01-21 10:51:18 +00:00
|
|
|
byte data[64][64][2];
|
|
|
|
tex_t *tex;
|
2012-01-21 06:48:21 +00:00
|
|
|
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglEnable (GL_VERTEX_PROGRAM_POINT_SIZE);
|
|
|
|
qfeglGetFloatv (GL_ALIASED_POINT_SIZE_RANGE, v);
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_glsl, "point size: %g - %g\n", v[0], v[1]);
|
2012-01-19 01:38:05 +00:00
|
|
|
|
2014-01-28 03:08:53 +00:00
|
|
|
vert_shader = GLSL_BuildShader (particle_point_vert_effects);
|
|
|
|
frag_shader = GLSL_BuildShader (particle_point_frag_effects);
|
|
|
|
vert = GLSL_CompileShader ("quakepnt.vert", vert_shader,
|
2012-02-17 09:57:13 +00:00
|
|
|
GL_VERTEX_SHADER);
|
2014-01-28 03:08:53 +00:00
|
|
|
frag = GLSL_CompileShader ("quakepnt.frag", frag_shader,
|
2012-02-17 09:57:13 +00:00
|
|
|
GL_FRAGMENT_SHADER);
|
|
|
|
quake_point.program = GLSL_LinkProgram ("quakepoint", vert, frag);
|
|
|
|
GLSL_ResolveShaderParam (quake_point.program, &quake_point.mvp_matrix);
|
|
|
|
GLSL_ResolveShaderParam (quake_point.program, &quake_point.vertex);
|
|
|
|
GLSL_ResolveShaderParam (quake_point.program, &quake_point.palette);
|
|
|
|
GLSL_ResolveShaderParam (quake_point.program, &quake_point.color);
|
|
|
|
GLSL_ResolveShaderParam (quake_point.program, &quake_point.fog);
|
2014-01-28 03:08:53 +00:00
|
|
|
GLSL_FreeShader (vert_shader);
|
|
|
|
GLSL_FreeShader (frag_shader);
|
2012-02-17 09:57:13 +00:00
|
|
|
|
2014-01-28 03:16:52 +00:00
|
|
|
vert_shader = GLSL_BuildShader (particle_textured_vert_effects);
|
|
|
|
frag_shader = GLSL_BuildShader (particle_textured_frag_effects);
|
|
|
|
vert = GLSL_CompileShader ("quakepar.vert", vert_shader,
|
2012-02-17 09:57:13 +00:00
|
|
|
GL_VERTEX_SHADER);
|
2014-01-28 03:16:52 +00:00
|
|
|
frag = GLSL_CompileShader ("quakepar.frag", frag_shader,
|
2012-02-17 09:57:13 +00:00
|
|
|
GL_FRAGMENT_SHADER);
|
|
|
|
quake_part.program = GLSL_LinkProgram ("quakepart", vert, frag);
|
|
|
|
GLSL_ResolveShaderParam (quake_part.program, &quake_part.mvp_matrix);
|
|
|
|
GLSL_ResolveShaderParam (quake_part.program, &quake_part.st);
|
|
|
|
GLSL_ResolveShaderParam (quake_part.program, &quake_part.vertex);
|
|
|
|
GLSL_ResolveShaderParam (quake_part.program, &quake_part.color);
|
|
|
|
GLSL_ResolveShaderParam (quake_part.program, &quake_part.texture);
|
|
|
|
GLSL_ResolveShaderParam (quake_part.program, &quake_part.fog);
|
2014-01-28 03:16:52 +00:00
|
|
|
GLSL_FreeShader (vert_shader);
|
|
|
|
GLSL_FreeShader (frag_shader);
|
2012-01-21 10:51:18 +00:00
|
|
|
|
|
|
|
memset (data, 0, sizeof (data));
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglGenTextures (1, &part_tex);
|
|
|
|
qfeglBindTexture (GL_TEXTURE_2D, part_tex);
|
|
|
|
qfeglTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
qfeglTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
qfeglTexImage2D (GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, 64, 64, 0,
|
2012-01-21 10:51:18 +00:00
|
|
|
GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, data);
|
|
|
|
tex = R_DotParticleTexture ();
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, 32, 32, GL_LUMINANCE_ALPHA,
|
2012-01-21 10:51:18 +00:00
|
|
|
GL_UNSIGNED_BYTE, tex->data);
|
|
|
|
free (tex);
|
|
|
|
tex = R_SparkParticleTexture ();
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglTexSubImage2D (GL_TEXTURE_2D, 0, 32, 0, 32, 32, GL_LUMINANCE_ALPHA,
|
2012-01-21 10:51:18 +00:00
|
|
|
GL_UNSIGNED_BYTE, tex->data);
|
|
|
|
free (tex);
|
|
|
|
tex = R_SmokeParticleTexture ();
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglTexSubImage2D (GL_TEXTURE_2D, 0, 0, 32, 32, 32, GL_LUMINANCE_ALPHA,
|
2012-01-21 10:51:18 +00:00
|
|
|
GL_UNSIGNED_BYTE, tex->data);
|
|
|
|
free (tex);
|
|
|
|
|
2012-01-19 01:38:05 +00:00
|
|
|
if (particleVertexArray)
|
|
|
|
free (particleVertexArray);
|
2021-12-19 05:47:25 +00:00
|
|
|
particleVertexArray = calloc (r_psystem.maxparticles * 4,
|
|
|
|
sizeof (partvert_t));
|
2012-01-19 01:38:05 +00:00
|
|
|
|
|
|
|
if (pVAindices)
|
|
|
|
free (pVAindices);
|
2021-12-19 05:47:25 +00:00
|
|
|
pVAindices = calloc (r_psystem.maxparticles * 6, sizeof (GLushort));
|
|
|
|
for (i = 0; i < r_psystem.maxparticles; i++) {
|
2012-01-19 01:38:05 +00:00
|
|
|
pVAindices[i * 6 + 0] = i * 4 + 0;
|
|
|
|
pVAindices[i * 6 + 1] = i * 4 + 1;
|
|
|
|
pVAindices[i * 6 + 2] = i * 4 + 2;
|
|
|
|
pVAindices[i * 6 + 3] = i * 4 + 0;
|
|
|
|
pVAindices[i * 6 + 4] = i * 4 + 2;
|
|
|
|
pVAindices[i * 6 + 5] = i * 4 + 3;
|
|
|
|
}
|
2011-12-25 22:50:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-01-19 01:38:05 +00:00
|
|
|
draw_qf_particles (void)
|
2011-12-25 22:50:05 +00:00
|
|
|
{
|
2012-01-19 01:38:05 +00:00
|
|
|
byte *at;
|
2021-12-18 16:21:39 +00:00
|
|
|
int vacount;
|
2012-01-19 01:38:05 +00:00
|
|
|
float minparticledist, scale;
|
|
|
|
vec3_t up_scale, right_scale, up_right_scale, down_right_scale;
|
|
|
|
partvert_t *VA;
|
2021-03-09 14:52:40 +00:00
|
|
|
mat4f_t vp_mat;
|
2012-01-29 01:27:28 +00:00
|
|
|
quat_t fog;
|
2012-01-21 10:51:18 +00:00
|
|
|
|
2021-03-09 14:52:40 +00:00
|
|
|
mmulf (vp_mat, glsl_projection, glsl_view);
|
2012-01-21 10:51:18 +00:00
|
|
|
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglDepthMask (GL_FALSE);
|
|
|
|
qfeglUseProgram (quake_part.program);
|
|
|
|
qfeglEnableVertexAttribArray (quake_part.vertex.location);
|
|
|
|
qfeglEnableVertexAttribArray (quake_part.color.location);
|
|
|
|
qfeglEnableVertexAttribArray (quake_part.st.location);
|
2012-01-21 10:51:18 +00:00
|
|
|
|
2022-03-07 17:10:47 +00:00
|
|
|
Fog_GetColor (fog);
|
|
|
|
fog[3] = Fog_GetDensity () / 64.0;
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglUniform4fv (quake_part.fog.location, 1, fog);
|
2012-01-29 01:27:28 +00:00
|
|
|
|
2021-03-09 14:52:40 +00:00
|
|
|
qfeglUniformMatrix4fv (quake_part.mvp_matrix.location, 1, false,
|
|
|
|
&vp_mat[0][0]);
|
2012-01-21 10:51:18 +00:00
|
|
|
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglUniform1i (quake_part.texture.location, 0);
|
|
|
|
qfeglActiveTexture (GL_TEXTURE0 + 0);
|
|
|
|
qfeglEnable (GL_TEXTURE_2D);
|
|
|
|
qfeglBindTexture (GL_TEXTURE_2D, part_tex);
|
2012-01-19 01:38:05 +00:00
|
|
|
|
|
|
|
// LordHavoc: particles should not affect zbuffer
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglDepthMask (GL_FALSE);
|
2012-01-19 01:38:05 +00:00
|
|
|
|
2021-03-19 11:18:45 +00:00
|
|
|
minparticledist = DotProduct (r_refdef.viewposition, vpn) +
|
2012-01-19 01:38:05 +00:00
|
|
|
r_particles_nearclip->value;
|
|
|
|
|
|
|
|
vacount = 0;
|
|
|
|
VA = particleVertexArray;
|
|
|
|
|
2021-12-19 05:47:25 +00:00
|
|
|
for (unsigned i = 0; i < r_psystem.numparticles; i++) {
|
|
|
|
particle_t *p = &r_psystem.particles[i];
|
2012-01-19 01:38:05 +00:00
|
|
|
// Don't render particles too close to us.
|
|
|
|
// Note, we must still do physics and such on them.
|
2021-12-18 16:21:39 +00:00
|
|
|
if (!(DotProduct (p->pos, vpn) < minparticledist)) {
|
|
|
|
at = (byte *) &d_8to24table[(byte) p->icolor];
|
2012-01-19 01:38:05 +00:00
|
|
|
VA[0].color[0] = at[0];
|
|
|
|
VA[0].color[1] = at[1];
|
|
|
|
VA[0].color[2] = at[2];
|
2021-12-18 16:21:39 +00:00
|
|
|
VA[0].color[3] = p->alpha * 255;
|
2012-01-19 01:38:05 +00:00
|
|
|
memcpy (VA[1].color, VA[0].color, sizeof (VA[0].color));
|
|
|
|
memcpy (VA[2].color, VA[0].color, sizeof (VA[0].color));
|
|
|
|
memcpy (VA[3].color, VA[0].color, sizeof (VA[0].color));
|
|
|
|
|
2021-12-18 16:21:39 +00:00
|
|
|
switch (p->tex) {
|
2012-01-19 01:38:05 +00:00
|
|
|
case part_tex_dot:
|
|
|
|
VA[0].texcoord[0] = 0.0;
|
|
|
|
VA[0].texcoord[1] = 0.0;
|
|
|
|
VA[1].texcoord[0] = 0.5;
|
|
|
|
VA[1].texcoord[1] = 0.0;
|
|
|
|
VA[2].texcoord[0] = 0.5;
|
|
|
|
VA[2].texcoord[1] = 0.5;
|
|
|
|
VA[3].texcoord[0] = 0.0;
|
|
|
|
VA[3].texcoord[1] = 0.5;
|
|
|
|
break;
|
|
|
|
case part_tex_spark:
|
|
|
|
VA[0].texcoord[0] = 0.5;
|
|
|
|
VA[0].texcoord[1] = 0.0;
|
|
|
|
VA[1].texcoord[0] = 1.0;
|
|
|
|
VA[1].texcoord[1] = 0.0;
|
|
|
|
VA[2].texcoord[0] = 1.0;
|
|
|
|
VA[2].texcoord[1] = 0.5;
|
|
|
|
VA[3].texcoord[0] = 0.5;
|
|
|
|
VA[3].texcoord[1] = 0.5;
|
|
|
|
break;
|
|
|
|
case part_tex_smoke:
|
|
|
|
VA[0].texcoord[0] = 0.0;
|
|
|
|
VA[0].texcoord[1] = 0.5;
|
|
|
|
VA[1].texcoord[0] = 0.5;
|
|
|
|
VA[1].texcoord[1] = 0.5;
|
|
|
|
VA[2].texcoord[0] = 0.5;
|
|
|
|
VA[2].texcoord[1] = 1.0;
|
|
|
|
VA[3].texcoord[0] = 0.0;
|
|
|
|
VA[3].texcoord[1] = 1.0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-12-18 16:21:39 +00:00
|
|
|
scale = p->scale;
|
2012-01-19 01:38:05 +00:00
|
|
|
|
|
|
|
VectorScale (vup, scale, up_scale);
|
|
|
|
VectorScale (vright, scale, right_scale);
|
|
|
|
|
|
|
|
VectorAdd (right_scale, up_scale, up_right_scale);
|
|
|
|
VectorSubtract (right_scale, up_scale, down_right_scale);
|
|
|
|
|
2021-12-18 16:21:39 +00:00
|
|
|
VectorAdd (p->pos, down_right_scale, VA[0].vertex);
|
|
|
|
VectorSubtract (p->pos, up_right_scale, VA[1].vertex);
|
|
|
|
VectorSubtract (p->pos, down_right_scale, VA[2].vertex);
|
|
|
|
VectorAdd (p->pos, up_right_scale, VA[3].vertex);
|
2012-01-19 01:38:05 +00:00
|
|
|
|
|
|
|
VA += 4;
|
2012-01-21 11:16:18 +00:00
|
|
|
vacount += 6;
|
2012-01-19 01:38:05 +00:00
|
|
|
}
|
|
|
|
}
|
2021-12-18 16:21:39 +00:00
|
|
|
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglVertexAttribPointer (quake_part.vertex.location, 3, GL_FLOAT,
|
2012-01-21 10:51:18 +00:00
|
|
|
0, sizeof (partvert_t),
|
|
|
|
&particleVertexArray[0].vertex);
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglVertexAttribPointer (quake_part.color.location, 4, GL_UNSIGNED_BYTE,
|
2012-01-21 10:51:18 +00:00
|
|
|
1, sizeof (partvert_t),
|
|
|
|
&particleVertexArray[0].color);
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglVertexAttribPointer (quake_part.st.location, 2, GL_FLOAT,
|
2012-01-21 10:51:18 +00:00
|
|
|
0, sizeof (partvert_t),
|
|
|
|
&particleVertexArray[0].texcoord);
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglDrawElements (GL_TRIANGLES, vacount, GL_UNSIGNED_SHORT, pVAindices);
|
2012-01-19 01:38:05 +00:00
|
|
|
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglDepthMask (GL_TRUE);
|
|
|
|
qfeglDisableVertexAttribArray (quake_part.vertex.location);
|
|
|
|
qfeglDisableVertexAttribArray (quake_part.color.location);
|
|
|
|
qfeglDisableVertexAttribArray (quake_part.st.location);
|
|
|
|
qfeglActiveTexture (GL_TEXTURE0 + 0);
|
|
|
|
qfeglDisable (GL_TEXTURE_2D);
|
2011-12-25 22:50:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-01-19 01:38:05 +00:00
|
|
|
draw_id_particles (void)
|
2011-12-25 22:50:05 +00:00
|
|
|
{
|
2021-12-18 16:21:39 +00:00
|
|
|
int vacount;
|
2012-01-19 01:38:05 +00:00
|
|
|
float minparticledist;
|
|
|
|
partvert_t *VA;
|
2021-03-09 14:52:40 +00:00
|
|
|
mat4f_t vp_mat;
|
2012-01-29 01:27:28 +00:00
|
|
|
quat_t fog;
|
2012-01-19 01:38:05 +00:00
|
|
|
|
2021-03-09 14:52:40 +00:00
|
|
|
mmulf (vp_mat, glsl_projection, glsl_view);
|
2012-01-19 01:38:05 +00:00
|
|
|
|
|
|
|
// LordHavoc: particles should not affect zbuffer
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglDepthMask (GL_FALSE);
|
|
|
|
qfeglUseProgram (quake_point.program);
|
|
|
|
qfeglEnableVertexAttribArray (quake_point.vertex.location);
|
|
|
|
qfeglEnableVertexAttribArray (quake_point.color.location);
|
2012-01-19 01:38:05 +00:00
|
|
|
|
2021-03-09 14:52:40 +00:00
|
|
|
qfeglUniformMatrix4fv (quake_point.mvp_matrix.location, 1, false,
|
|
|
|
&vp_mat[0][0]);
|
2012-01-19 01:38:05 +00:00
|
|
|
|
2022-03-07 17:10:47 +00:00
|
|
|
Fog_GetColor (fog);
|
|
|
|
fog[3] = Fog_GetDensity () / 64.0;
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglUniform4fv (quake_point.fog.location, 1, fog);
|
2012-01-29 01:27:28 +00:00
|
|
|
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglUniform1i (quake_point.palette.location, 0);
|
|
|
|
qfeglActiveTexture (GL_TEXTURE0 + 0);
|
|
|
|
qfeglEnable (GL_TEXTURE_2D);
|
|
|
|
qfeglBindTexture (GL_TEXTURE_2D, glsl_palette);
|
2012-01-19 01:38:05 +00:00
|
|
|
|
2021-03-19 11:18:45 +00:00
|
|
|
minparticledist = DotProduct (r_refdef.viewposition, vpn) +
|
2012-01-19 01:38:05 +00:00
|
|
|
r_particles_nearclip->value;
|
|
|
|
|
|
|
|
vacount = 0;
|
|
|
|
VA = particleVertexArray;
|
|
|
|
|
2021-12-19 05:47:25 +00:00
|
|
|
for (unsigned i = 0; i < r_psystem.numparticles; i++) {
|
|
|
|
particle_t *p = &r_psystem.particles[i];
|
2012-01-19 01:38:05 +00:00
|
|
|
// Don't render particles too close to us.
|
|
|
|
// Note, we must still do physics and such on them.
|
2021-12-18 16:21:39 +00:00
|
|
|
if (!(DotProduct (p->pos, vpn) < minparticledist)) {
|
|
|
|
VA[0].color[0] = (byte) p->icolor;
|
|
|
|
VectorCopy (p->pos, VA[0].vertex);
|
2012-01-19 01:38:05 +00:00
|
|
|
VA++;
|
|
|
|
vacount++;
|
|
|
|
}
|
|
|
|
}
|
2021-12-18 16:21:39 +00:00
|
|
|
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglVertexAttribPointer (quake_point.vertex.location, 3, GL_FLOAT,
|
2012-01-19 01:38:05 +00:00
|
|
|
0, sizeof (partvert_t),
|
|
|
|
&particleVertexArray[0].vertex);
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglVertexAttribPointer (quake_point.color.location, 1, GL_UNSIGNED_BYTE,
|
2012-01-21 07:16:48 +00:00
|
|
|
1, sizeof (partvert_t),
|
2012-01-19 01:38:05 +00:00
|
|
|
&particleVertexArray[0].color);
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglDrawArrays (GL_POINTS, 0, vacount);
|
2012-01-19 01:38:05 +00:00
|
|
|
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglDepthMask (GL_TRUE);
|
|
|
|
qfeglDisableVertexAttribArray (quake_point.vertex.location);
|
|
|
|
qfeglDisableVertexAttribArray (quake_point.color.location);
|
|
|
|
qfeglActiveTexture (GL_TEXTURE0 + 0);
|
|
|
|
qfeglDisable (GL_TEXTURE_2D);
|
2012-01-19 01:38:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-22 07:32:34 +00:00
|
|
|
glsl_R_DrawParticles (void)
|
2012-01-19 01:38:05 +00:00
|
|
|
{
|
2021-12-19 05:47:25 +00:00
|
|
|
if (!r_particles->int_val || !r_psystem.numparticles)
|
2012-01-19 01:38:05 +00:00
|
|
|
return;
|
2021-12-19 04:38:50 +00:00
|
|
|
R_RunParticles (vr_data.frametime);
|
2021-12-19 05:47:25 +00:00
|
|
|
if (!r_psystem.points_only) {
|
2012-01-19 01:38:05 +00:00
|
|
|
draw_qf_particles ();
|
|
|
|
} else {
|
|
|
|
draw_id_particles ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-11 13:45:23 +00:00
|
|
|
static void
|
|
|
|
r_particles_nearclip_f (cvar_t *var)
|
|
|
|
{
|
|
|
|
Cvar_SetValue (r_particles_nearclip, bound (r_nearclip->value, var->value,
|
|
|
|
r_farclip->value));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
r_particles_f (cvar_t *var)
|
|
|
|
{
|
|
|
|
R_MaxParticlesCheck (var, r_particles_max);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
r_particles_max_f (cvar_t *var)
|
|
|
|
{
|
|
|
|
R_MaxParticlesCheck (r_particles, var);
|
|
|
|
}
|
|
|
|
|
2012-02-18 13:28:42 +00:00
|
|
|
void
|
2012-02-22 07:32:34 +00:00
|
|
|
glsl_R_Particles_Init_Cvars (void)
|
2012-01-19 01:38:05 +00:00
|
|
|
{
|
2012-04-11 13:45:23 +00:00
|
|
|
r_particles = Cvar_Get ("r_particles", "1", CVAR_ARCHIVE, r_particles_f,
|
|
|
|
"Toggles drawing of particles.");
|
|
|
|
r_particles_max = Cvar_Get ("r_particles_max", "2048", CVAR_ARCHIVE,
|
|
|
|
r_particles_max_f, "Maximum amount of "
|
|
|
|
"particles to display. No maximum, minimum "
|
|
|
|
"is 0.");
|
|
|
|
r_particles_nearclip = Cvar_Get ("r_particles_nearclip", "32",
|
|
|
|
CVAR_ARCHIVE, r_particles_nearclip_f,
|
|
|
|
"Distance of the particle near clipping "
|
|
|
|
"plane from the player.");
|
2012-01-19 01:38:05 +00:00
|
|
|
}
|
2021-12-19 05:47:25 +00:00
|
|
|
|
|
|
|
psystem_t * __attribute__((const))//FIXME
|
|
|
|
glsl_ParticleSystem (void)
|
|
|
|
{
|
|
|
|
return &r_psystem;
|
|
|
|
}
|