mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 23:32:09 +00:00
Create and load the id sky shader.
This commit is contained in:
parent
89ae6eca8b
commit
f6f2e4f406
4 changed files with 88 additions and 2 deletions
|
@ -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 \
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
28
libs/video/renderer/glsl/quakeski.frag
Normal file
28
libs/video/renderer/glsl/quakeski.frag
Normal file
|
@ -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));
|
||||
}
|
17
libs/video/renderer/glsl/quakesky.vert
Normal file
17
libs/video/renderer/glsl/quakesky.vert
Normal file
|
@ -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;
|
||||
}
|
Loading…
Reference in a new issue