Use the new shader system for point particles.

This commit is contained in:
Bill Currie 2014-01-28 12:08:53 +09:00
parent 3af6a640fe
commit 1a7b532927
5 changed files with 74 additions and 58 deletions

View file

@ -6,13 +6,13 @@ AM_CPPFLAGS= -I$(top_srcdir)/include $(GLX_CFLAGS)
shader_src= quakeforge.glsl \
iqm.frag iqm.vert \
quake2d.frag quakeico.vert \
quakepar.frag quakepar.vert quakepnt.frag quakepnt.vert \
quakepar.frag quakepar.vert \
quakespr.frag quakespr.vert \
quaketxt.vert
shader_gen= quakeforge.slc \
iqm.fc iqm.vc \
quake2d.fc quakeico.vc \
quakepar.fc quakepar.vc quakepnt.fc quakepnt.vc \
quakepar.fc quakepar.vc \
quakespr.fc quakespr.vc quaketxt.vc
glsl_src = \

View file

@ -78,13 +78,17 @@ static partvert_t *particleVertexArray;
static GLuint part_tex;
static const char quakepoint_vert[] =
#include "quakepnt.vc"
;
static const char *particle_point_vert_effects[] =
{
"QuakeForge.Vertex.particle.point",
0
};
static const char quakepoint_frag[] =
#include "quakepnt.fc"
;
static const char *particle_point_frag_effects[] =
{
"QuakeForge.Fragment.particle.point",
0
};
static const char quakepart_vert[] =
#include "quakepar.vc"
@ -210,6 +214,7 @@ glsl_R_ClearParticles (void)
void
glsl_R_InitParticles (void)
{
shader_t *vert_shader, *frag_shader;
unsigned i;
int vert;
int frag;
@ -223,9 +228,11 @@ glsl_R_InitParticles (void)
qfeglGetFloatv (GL_ALIASED_POINT_SIZE_RANGE, v);
Sys_MaskPrintf (SYS_GLSL, "point size: %g - %g\n", v[0], v[1]);
vert = GLSL_CompileShaderS ("quakepnt.vert", quakepoint_vert,
vert_shader = GLSL_BuildShader (particle_point_vert_effects);
frag_shader = GLSL_BuildShader (particle_point_frag_effects);
vert = GLSL_CompileShader ("quakepnt.vert", vert_shader,
GL_VERTEX_SHADER);
frag = GLSL_CompileShaderS ("quakepnt.frag", quakepoint_frag,
frag = GLSL_CompileShader ("quakepnt.frag", frag_shader,
GL_FRAGMENT_SHADER);
quake_point.program = GLSL_LinkProgram ("quakepoint", vert, frag);
GLSL_ResolveShaderParam (quake_point.program, &quake_point.mvp_matrix);
@ -233,6 +240,8 @@ glsl_R_InitParticles (void)
GLSL_ResolveShaderParam (quake_point.program, &quake_point.palette);
GLSL_ResolveShaderParam (quake_point.program, &quake_point.color);
GLSL_ResolveShaderParam (quake_point.program, &quake_point.fog);
GLSL_FreeShader (vert_shader);
GLSL_FreeShader (frag_shader);
vert = GLSL_CompileShaderS ("quakepar.vert", quakepart_vert,
GL_VERTEX_SHADER);

View file

@ -255,3 +255,58 @@ main (void)
vec4 c = sky_color (direction);
gl_FragColor = fogBlend (c);
}
-- Vertex.particle.point
uniform mat4 mvp_mat;
attribute float vcolor;
/** Vertex position.
x, y, z, c
c is the color of the point.
*/
attribute vec3 vertex;
varying float color;
void
main (void)
{
gl_Position = mvp_mat * vec4 (vertex, 1.0);
gl_PointSize = max (1.0, 1024.0 * abs (1.0 / gl_Position.z));
color = vcolor;
}
-- Fragment.particle.point
//precision mediump float;
uniform sampler2D palette;
uniform vec4 fog;
varying float color;
float
sqr (float x)
{
return x * x;
}
vec4
fogBlend (vec4 color)
{
float f;
vec4 fog_color = vec4 (fog.rgb, 1.0);
f = exp (-sqr (fog.a * gl_FragCoord.z / gl_FragCoord.w));
return vec4 (mix (fog_color.rgb, color.rgb, f), color.a);
}
void
main (void)
{
if (color == 1.0)
discard;
gl_FragColor = fogBlend (texture2D (palette, vec2 (color, 0.0)));
}

View file

@ -1,29 +0,0 @@
//precision mediump float;
uniform sampler2D palette;
uniform vec4 fog;
varying float color;
float
sqr (float x)
{
return x * x;
}
vec4
fogBlend (vec4 color)
{
float f;
vec4 fog_color = vec4 (fog.rgb, 1.0);
f = exp (-sqr (fog.a * gl_FragCoord.z / gl_FragCoord.w));
return vec4 (mix (fog_color.rgb, color.rgb, f), color.a);
}
void
main (void)
{
if (color == 1.0)
discard;
gl_FragColor = fogBlend (texture2D (palette, vec2 (color, 0.0)));
}

View file

@ -1,19 +0,0 @@
uniform mat4 mvp_mat;
attribute float vcolor;
/** Vertex position.
x, y, z, c
c is the color of the point.
*/
attribute vec3 vertex;
varying float color;
void
main (void)
{
gl_Position = mvp_mat * vec4 (vertex, 1.0);
gl_PointSize = max (1.0, 1024.0 * abs (1.0 / gl_Position.z));
color = vcolor;
}