From 1a7b532927e550fcec363b1246cd5d78ab76add6 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Tue, 28 Jan 2014 12:08:53 +0900 Subject: [PATCH] Use the new shader system for point particles. --- libs/video/renderer/glsl/Makefile.am | 4 +- libs/video/renderer/glsl/glsl_particles.c | 25 +++++++---- libs/video/renderer/glsl/quakeforge.glsl | 55 +++++++++++++++++++++++ libs/video/renderer/glsl/quakepnt.frag | 29 ------------ libs/video/renderer/glsl/quakepnt.vert | 19 -------- 5 files changed, 74 insertions(+), 58 deletions(-) delete mode 100644 libs/video/renderer/glsl/quakepnt.frag delete mode 100644 libs/video/renderer/glsl/quakepnt.vert diff --git a/libs/video/renderer/glsl/Makefile.am b/libs/video/renderer/glsl/Makefile.am index d28c62454..7c1b1869c 100644 --- a/libs/video/renderer/glsl/Makefile.am +++ b/libs/video/renderer/glsl/Makefile.am @@ -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 = \ diff --git a/libs/video/renderer/glsl/glsl_particles.c b/libs/video/renderer/glsl/glsl_particles.c index 4d870623f..902fef2c0 100644 --- a/libs/video/renderer/glsl/glsl_particles.c +++ b/libs/video/renderer/glsl/glsl_particles.c @@ -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); diff --git a/libs/video/renderer/glsl/quakeforge.glsl b/libs/video/renderer/glsl/quakeforge.glsl index c8d0da2c2..cbde9ac81 100644 --- a/libs/video/renderer/glsl/quakeforge.glsl +++ b/libs/video/renderer/glsl/quakeforge.glsl @@ -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))); +} diff --git a/libs/video/renderer/glsl/quakepnt.frag b/libs/video/renderer/glsl/quakepnt.frag deleted file mode 100644 index 3ae6bebbc..000000000 --- a/libs/video/renderer/glsl/quakepnt.frag +++ /dev/null @@ -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))); -} diff --git a/libs/video/renderer/glsl/quakepnt.vert b/libs/video/renderer/glsl/quakepnt.vert deleted file mode 100644 index 2a1ca43b6..000000000 --- a/libs/video/renderer/glsl/quakepnt.vert +++ /dev/null @@ -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; -}