mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 15:22:04 +00:00
Start using the new shader system.
So far, alias model rendering is the only victim, but things are working, even if only color map lookup and fog blending are broken out at this stage. I expect the effect naming scheme will go through some changes until I'm happy with it.
This commit is contained in:
parent
4bd82eb2b8
commit
b269338947
6 changed files with 180 additions and 80 deletions
|
@ -3,13 +3,13 @@ AUTOMAKE_OPTIONS= foreign
|
|||
AM_CFLAGS= @PREFER_PIC@
|
||||
AM_CPPFLAGS= -I$(top_srcdir)/include $(GLX_CFLAGS)
|
||||
|
||||
shader_src= \
|
||||
shader_src= quakeforge.glsl \
|
||||
iqm.frag iqm.vert \
|
||||
quake2d.frag quakebsp.frag quakebsp.vert quakeico.vert quakemdl.frag \
|
||||
quakemdl.vert quakepar.frag quakepar.vert quakepnt.frag quakepnt.vert \
|
||||
quakeskb.frag quakeski.frag quakesky.vert quakespr.frag quakespr.vert \
|
||||
quaketrb.frag quaketxt.vert
|
||||
shader_gen= \
|
||||
shader_gen= quakeforge.slc \
|
||||
iqm.fc iqm.vc \
|
||||
quake2d.fc quakebsp.fc quakebsp.vc quakeico.vc quakemdl.fc quakemdl.vc \
|
||||
quakepar.fc quakepar.vc quakepnt.fc quakepnt.vc quakeskb.fc quakeski.fc \
|
||||
|
@ -23,7 +23,9 @@ glsl_src = \
|
|||
noinst_LTLIBRARIES= libglsl.la
|
||||
BUILT_SOURCES= $(shader_gen)
|
||||
|
||||
SUFFICES=.frag .vert .fc .vc
|
||||
SUFFICES=.frag .vert .fc .vc .slc .glsl
|
||||
.glsl.slc:
|
||||
sed -e 's/^/"/' -e 's/$$/\\n"/' $< > $@
|
||||
.frag.fc:
|
||||
sed -e 's/^/"/' -e 's/$$/\\n"/' $< > $@
|
||||
.vert.vc:
|
||||
|
|
|
@ -55,13 +55,17 @@
|
|||
|
||||
#include "r_internal.h"
|
||||
|
||||
static const char quakemdl_vert[] =
|
||||
#include "quakemdl.vc"
|
||||
;
|
||||
static const char *alias_vert_effects[] =
|
||||
{
|
||||
"QuakeForge.Vertex.mdl",
|
||||
};
|
||||
|
||||
static const char quakemdl_frag[] =
|
||||
#include "quakemdl.fc"
|
||||
;
|
||||
static const char *alias_frag_effects[] =
|
||||
{
|
||||
"QuakeForge.Fragment.fog",
|
||||
"QuakeForge.Fragment.colormap",
|
||||
"QuakeForge.Fragment.mdl",
|
||||
};
|
||||
|
||||
static struct {
|
||||
int program;
|
||||
|
@ -110,12 +114,15 @@ static mat4_t alias_vp;
|
|||
void
|
||||
glsl_R_InitAlias (void)
|
||||
{
|
||||
shader_t *vert_shader, *frag_shader;
|
||||
int vert;
|
||||
int frag;
|
||||
|
||||
vert = GLSL_CompileShaderS ("quakemdl.vert", quakemdl_vert,
|
||||
vert_shader = GLSL_BuildShader (alias_vert_effects);
|
||||
frag_shader = GLSL_BuildShader (alias_frag_effects);
|
||||
vert = GLSL_CompileShader ("quakemdl.vert", vert_shader,
|
||||
GL_VERTEX_SHADER);
|
||||
frag = GLSL_CompileShaderS ("quakemdl.frag", quakemdl_frag,
|
||||
frag = GLSL_CompileShader ("quakemdl.frag", frag_shader,
|
||||
GL_FRAGMENT_SHADER);
|
||||
quake_mdl.program = GLSL_LinkProgram ("quakemdl", vert, frag);
|
||||
GLSL_ResolveShaderParam (quake_mdl.program, &quake_mdl.mvp_matrix);
|
||||
|
@ -136,6 +143,8 @@ glsl_R_InitAlias (void)
|
|||
GLSL_ResolveShaderParam (quake_mdl.program, &quake_mdl.shadelight);
|
||||
GLSL_ResolveShaderParam (quake_mdl.program, &quake_mdl.lightvec);
|
||||
GLSL_ResolveShaderParam (quake_mdl.program, &quake_mdl.fog);
|
||||
GLSL_FreeShader (vert_shader);
|
||||
GLSL_FreeShader (frag_shader);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
152
libs/video/renderer/glsl/quakeforge.glsl
Normal file
152
libs/video/renderer/glsl/quakeforge.glsl
Normal file
|
@ -0,0 +1,152 @@
|
|||
-- Math.const
|
||||
|
||||
const float PI = 3.14159265;
|
||||
const float E = 2.71828183;
|
||||
|
||||
-- Math.quaternion
|
||||
|
||||
vec3
|
||||
qmult (vec4 q, vec3 v)
|
||||
{
|
||||
float qc = q.w;
|
||||
vec3 qv = q.xyz;
|
||||
vec3 t = cross (qv, v);
|
||||
return (qs * qs) * v + 2.0 * qs * t + dot (qv, v) * qv + cross (qv, t);
|
||||
}
|
||||
|
||||
vec3
|
||||
dqtrans (vec4 q0, vec4 qe)
|
||||
{//2.0 * (q0.w * qe.xyz - qe.w * q0.xyz - cross (qe.xyz, q0.xyz));
|
||||
float qs = q0.w, Ts = qe.w;
|
||||
vec3 qv = -q0.xyz, Tv = qe.xyz;
|
||||
|
||||
return 2.0 * (Ts * qv + qs * Tv + cross (Tv, qv));
|
||||
}
|
||||
|
||||
-- Fragment.fog
|
||||
|
||||
uniform vec4 fog;
|
||||
|
||||
vec4
|
||||
fogBlend (vec4 color)
|
||||
{
|
||||
float fog_factor;
|
||||
float az = fog.a * gl_FragCoord.z / gl_FragCoord.w;
|
||||
vec4 fog_color = vec4 (fog.rgb, 1.0);
|
||||
|
||||
fog_factor = exp (-az * az);
|
||||
return vec4 (mix (fog_color.rgb, color.rgb, fog_factor), color.a);
|
||||
}
|
||||
|
||||
-- Fragment.colormap
|
||||
|
||||
uniform sampler2D colormap;
|
||||
|
||||
vec4
|
||||
mappedColor (float pix, float light)
|
||||
{
|
||||
return texture2D (colormap, vec2 (pix, light));
|
||||
}
|
||||
|
||||
-- Fragment.turb
|
||||
|
||||
const float SPEED = 20.0;
|
||||
const float CYCLE = 128.0;
|
||||
const float FACTOR = PI * 2.0 / CYCLE;
|
||||
const vec2 BIAS = vec2 (1.0, 1.0)
|
||||
const float SCALE = 8.0;
|
||||
|
||||
vec2
|
||||
turb_st (vec2 st, float time)
|
||||
{
|
||||
vec2 angle = st.ts * CYCLE / 2.0;
|
||||
vec2 phase = vec2 (time, time) * SPEED;
|
||||
return st + (sin ((angle + phase) * FACTOR) + BIAS) / SCALE;
|
||||
}
|
||||
|
||||
-- Fragment.skydome
|
||||
|
||||
uniform sampler2D palette;
|
||||
uniform sampler2D solid;
|
||||
uniform sampler2D trans;
|
||||
uniform float time
|
||||
varying vec3 direction
|
||||
|
||||
const float SCALE = 189.0 / 64.0;
|
||||
|
||||
vec4
|
||||
skydome (dir, time)
|
||||
{
|
||||
float len;
|
||||
float pix;
|
||||
vec2 flow = vec2 (1.0, 1.0);
|
||||
vec2 st, base;
|
||||
vec3 dir = direction;
|
||||
|
||||
dir.z *= 3.0;
|
||||
len = dot (dir, dir);
|
||||
len = SCALE * inversesqrt (len);
|
||||
|
||||
base = dir.yx * vec2(1.0, -1.0) * len;
|
||||
st = base + flow * time / 8.0;
|
||||
pix = texture2D (trans, st).r;
|
||||
if (pix == 0.0) {
|
||||
st = base + flow * realtime / 16.0;
|
||||
pix = texture2D (solid, st).r;
|
||||
}
|
||||
return texture2D (palette, pix);
|
||||
}
|
||||
|
||||
-- Vertex.mdl
|
||||
uniform mat4 mvp_mat;
|
||||
uniform mat3 norm_mat;
|
||||
uniform vec2 skin_size;
|
||||
uniform float blend;
|
||||
|
||||
attribute vec4 vcolora, vcolorb;
|
||||
attribute vec2 vsta, vstb;
|
||||
attribute vec3 vnormala, vnormalb;
|
||||
attribute vec3 vertexa, vertexb;
|
||||
|
||||
varying vec3 normal;
|
||||
varying vec2 st;
|
||||
varying vec4 color;
|
||||
|
||||
void
|
||||
main (void)
|
||||
{
|
||||
vec3 vertex;
|
||||
vec3 vnormal;
|
||||
|
||||
vertex = mix (vertexa, vertexb, blend);
|
||||
vnormal = mix (vnormala, vnormalb, blend);
|
||||
gl_Position = mvp_mat * vec4 (vertex, 1.0);
|
||||
st = mix (vsta, vstb, blend) / skin_size;
|
||||
normal = norm_mat * vnormal;
|
||||
color = mix (vcolora, vcolorb, blend);
|
||||
}
|
||||
-- Fragment.mdl
|
||||
uniform sampler2D skin;
|
||||
uniform float ambient;
|
||||
uniform float shadelight;
|
||||
uniform vec3 lightvec;
|
||||
|
||||
varying vec3 normal;
|
||||
varying vec2 st;
|
||||
varying vec4 color;
|
||||
|
||||
void
|
||||
main (void)
|
||||
{
|
||||
float pix = texture2D (skin, st).r;
|
||||
float light = ambient;
|
||||
float d, col;
|
||||
vec4 lit;
|
||||
|
||||
d = dot (normal, lightvec);
|
||||
d = min (d, 0.0);
|
||||
light = 255.0 - light;
|
||||
light += d * shadelight;
|
||||
lit = mappedColor (pix, light / 255.0);
|
||||
gl_FragColor = fogBlend (lit * color);
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
uniform sampler2D colormap;
|
||||
uniform sampler2D skin;
|
||||
uniform float ambient;
|
||||
uniform float shadelight;
|
||||
uniform vec3 lightvec;
|
||||
uniform vec4 fog;
|
||||
|
||||
varying vec3 normal;
|
||||
varying vec2 st;
|
||||
varying vec4 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)
|
||||
{
|
||||
float pix = texture2D (skin, st).r;
|
||||
float light = ambient;
|
||||
float d, col;
|
||||
vec4 lit;
|
||||
|
||||
d = dot (normal, lightvec);
|
||||
d = min (d, 0.0);
|
||||
light = 255.0 - light;
|
||||
light += d * shadelight;
|
||||
lit = texture2D (colormap, vec2 (pix, light / 255.0));
|
||||
gl_FragColor = fogBlend (lit * color);
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
uniform mat4 mvp_mat;
|
||||
uniform mat3 norm_mat;
|
||||
uniform vec2 skin_size;
|
||||
uniform float blend;
|
||||
|
||||
attribute vec4 vcolora, vcolorb;
|
||||
attribute vec2 vsta, vstb;
|
||||
attribute vec3 vnormala, vnormalb;
|
||||
attribute vec3 vertexa, vertexb;
|
||||
|
||||
varying vec3 normal;
|
||||
varying vec2 st;
|
||||
varying vec4 color;
|
||||
|
||||
void
|
||||
main (void)
|
||||
{
|
||||
vec3 vertex;
|
||||
vec3 vnormal;
|
||||
|
||||
vertex = mix (vertexa, vertexb, blend);
|
||||
vnormal = mix (vnormala, vnormalb, blend);
|
||||
gl_Position = mvp_mat * vec4 (vertex, 1.0);
|
||||
st = mix (vsta, vstb, blend) / skin_size;
|
||||
normal = norm_mat * vnormal;
|
||||
color = mix (vcolora, vcolorb, blend);
|
||||
}
|
|
@ -56,6 +56,10 @@
|
|||
#include "d_iface.h"
|
||||
#include "r_internal.h"
|
||||
|
||||
static const char quakeforge_effect[] =
|
||||
#include "quakeforge.slc"
|
||||
;
|
||||
|
||||
int glsl_palette;
|
||||
int glsl_colormap;
|
||||
|
||||
|
@ -181,6 +185,8 @@ GLSL_Init_Common (void)
|
|||
|
||||
qfeglEnable (GL_BLEND);
|
||||
qfeglBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
GLSL_RegisterEffect ("QuakeForge", quakeforge_effect);
|
||||
}
|
||||
|
||||
int
|
||||
|
|
Loading…
Reference in a new issue