From f6f2e4f406fd8547af378d6270c74caece736719 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Wed, 11 Jan 2012 16:02:20 +0900 Subject: [PATCH] Create and load the id sky shader. --- libs/video/renderer/glsl/Makefile.am | 5 ++-- libs/video/renderer/glsl/glsl_bsp.c | 40 ++++++++++++++++++++++++++ libs/video/renderer/glsl/quakeski.frag | 28 ++++++++++++++++++ libs/video/renderer/glsl/quakesky.vert | 17 +++++++++++ 4 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 libs/video/renderer/glsl/quakeski.frag create mode 100644 libs/video/renderer/glsl/quakesky.vert diff --git a/libs/video/renderer/glsl/Makefile.am b/libs/video/renderer/glsl/Makefile.am index e92acd94c..2e031d02f 100644 --- a/libs/video/renderer/glsl/Makefile.am +++ b/libs/video/renderer/glsl/Makefile.am @@ -5,10 +5,11 @@ INCLUDES= -I$(top_srcdir)/include $(GLX_CFLAGS) shader_src= \ quake2d.frag quakebsp.frag quakebsp.vert quakeico.vert quakemdl.frag \ - quakemdl.vert quakespr.frag quakespr.vert quaketrb.frag quaketxt.vert + quakemdl.vert quakeski.frag quakesky.vert quakespr.frag quakespr.vert \ + quaketrb.frag quaketxt.vert shader_gen= \ quake2d.fc quakebsp.fc quakebsp.vc quakeico.vc quakemdl.fc quakemdl.vc \ - quakespr.fc quakespr.vc quaketrb.fc quaketxt.vc + quakeski.fc quakesky.vc quakespr.fc quakespr.vc quaketrb.fc quaketxt.vc glsl_src = \ glsl_alias.c glsl_bsp.c glsl_draw.c glsl_lightmap.c glsl_main.c \ diff --git a/libs/video/renderer/glsl/glsl_bsp.c b/libs/video/renderer/glsl/glsl_bsp.c index 2e187dfd9..10e888399 100644 --- a/libs/video/renderer/glsl/glsl_bsp.c +++ b/libs/video/renderer/glsl/glsl_bsp.c @@ -104,6 +104,14 @@ static const char quaketurb_frag[] = #include "quaketrb.fc" ; +static const char quakesky_vert[] = +#include "quakesky.vc" +; + +static const char quakeskyid_frag[] = +#include "quakeski.fc" +; + static struct { int program; shaderparam_t mvp_matrix; @@ -142,6 +150,26 @@ static struct { {"realtime", 1}, }; +static struct { + int program; + shaderparam_t mvp_matrix; + shaderparam_t sky_matrix; + shaderparam_t vertex; + shaderparam_t palette; + shaderparam_t solid; + shaderparam_t trans; + shaderparam_t realtime; +} quake_skyid = { + 0, + {"mvp_mat", 1}, + {"sky_mat", 1}, + {"vertex", 0}, + {"palette", 1}, + {"solid", 1}, + {"trans", 1}, + {"realtime", 1}, +}; + #define CHAIN_SURF_F2B(surf,chain) \ do { \ instsurf_t *inst = (surf)->instsurf; \ @@ -961,4 +989,16 @@ R_InitBsp (void) GL_ResolveShaderParam (quake_turb.program, &quake_turb.palette); GL_ResolveShaderParam (quake_turb.program, &quake_turb.texture); GL_ResolveShaderParam (quake_turb.program, &quake_turb.realtime); + + vert = GL_CompileShader ("quakesky.vert", quakesky_vert, GL_VERTEX_SHADER); + frag = GL_CompileShader ("quakeski.frag", quakeskyid_frag, + GL_FRAGMENT_SHADER); + quake_skyid.program = GL_LinkProgram ("quakebsp", vert, frag); + GL_ResolveShaderParam (quake_skyid.program, &quake_skyid.mvp_matrix); + GL_ResolveShaderParam (quake_skyid.program, &quake_skyid.sky_matrix); + GL_ResolveShaderParam (quake_skyid.program, &quake_skyid.vertex); + GL_ResolveShaderParam (quake_skyid.program, &quake_skyid.palette); + GL_ResolveShaderParam (quake_skyid.program, &quake_skyid.solid); + GL_ResolveShaderParam (quake_skyid.program, &quake_skyid.trans); + GL_ResolveShaderParam (quake_skyid.program, &quake_skyid.realtime); } diff --git a/libs/video/renderer/glsl/quakeski.frag b/libs/video/renderer/glsl/quakeski.frag new file mode 100644 index 000000000..959c3ae5e --- /dev/null +++ b/libs/video/renderer/glsl/quakeski.frag @@ -0,0 +1,28 @@ +uniform sampler2D palette; +uniform sampler2D solid; +uniform sampler2D trans; +uniform float realtime; + +varying vec3 direction; + +const float SCALE = 189.0 / 64.0; + +void +main (void) +{ + float len; + float pix; + vec2 flow = vec2 (1.0, 1.0); + vec2 st; + + len = dot (direction, direction); + len = SCALE * inversesqrt (len); + + st = direction.xy * len + flow * realtime / 8.0; + pix = texture2D (trans, st).r; + if (pix == 1.0) { + st = direction.xy * len + flow * realtime / 8.0; + pix = texture2D (solid, st).r; + } + gl_FragColor = texture2D (palette, vec2 (pix, 0.5)); +} diff --git a/libs/video/renderer/glsl/quakesky.vert b/libs/video/renderer/glsl/quakesky.vert new file mode 100644 index 000000000..a779566e2 --- /dev/null +++ b/libs/video/renderer/glsl/quakesky.vert @@ -0,0 +1,17 @@ +uniform mat4 mvp_mat; +uniform mat4 sky_mat; + +attribute vec4 vertex; + +varying vec3 direction; + +void +main (void) +{ + vec3 dir; + float len; + vec2 offset = vec2 (1.0, 1.0); + + gl_Position = mvp_mat * vertex; + direction = (sky_mat * vertex).xyz; +}