quakeforge/libs/video/renderer/glsl/quakeski.frag

49 lines
926 B
GLSL
Raw Normal View History

2012-01-11 07:02:20 +00:00
uniform sampler2D palette;
uniform sampler2D solid;
uniform sampler2D trans;
uniform float realtime;
uniform vec4 fog;
2012-01-11 07:02:20 +00:00
varying vec3 direction;
const float SCALE = 189.0 / 64.0;
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);
}
2012-01-11 07:02:20 +00:00
void
main (void)
{
float len;
float pix;
vec2 flow = vec2 (1.0, 1.0);
vec2 st, base;
2012-01-11 12:26:12 +00:00
vec3 dir = direction;
2012-01-11 07:02:20 +00:00
2012-01-11 12:26:12 +00:00
dir.z *= 3.0;
len = dot (dir, dir);
2012-01-11 07:02:20 +00:00
len = SCALE * inversesqrt (len);
base = direction.yx * vec2(1.0, -1.0) * len;
st = base + flow * realtime / 8.0;
2012-01-11 07:02:20 +00:00
pix = texture2D (trans, st).r;
2012-01-11 12:26:12 +00:00
if (pix == 0.0) {
st = base + flow * realtime / 16.0;
2012-01-11 07:02:20 +00:00
pix = texture2D (solid, st).r;
}
gl_FragColor = fogBlend (texture2D (palette, vec2 (pix, 0.0)));
2012-01-11 07:02:20 +00:00
}