2012-05-09 15:30:53 +00:00
|
|
|
!!permu FULLBRIGHT
|
|
|
|
!!permu UPPERLOWER
|
|
|
|
!!permu FRAMEBLEND
|
|
|
|
!!permu SKELETAL
|
|
|
|
!!permu FOG
|
2013-03-12 22:35:33 +00:00
|
|
|
!!cvarf r_glsl_offsetmapping_scale
|
|
|
|
!!cvarf gl_specular
|
2012-05-09 15:30:53 +00:00
|
|
|
|
|
|
|
//standard shader used for models.
|
|
|
|
//must support skeletal and 2-way vertex blending or Bad Things Will Happen.
|
|
|
|
//the vertex shader is responsible for calculating lighting values.
|
|
|
|
|
2013-03-12 22:35:33 +00:00
|
|
|
#ifdef UPPERLOWER
|
|
|
|
#define UPPER
|
|
|
|
#define LOWER
|
|
|
|
#endif
|
|
|
|
|
2012-05-09 15:30:53 +00:00
|
|
|
varying vec2 tc;
|
|
|
|
varying vec3 light;
|
2013-03-12 22:35:33 +00:00
|
|
|
#if defined(SPECULAR) || defined(OFFSETMAPPING)
|
|
|
|
varying vec3 eyevector;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-05-09 15:30:53 +00:00
|
|
|
#ifdef VERTEX_SHADER
|
|
|
|
#include "sys/skeletal.h"
|
|
|
|
attribute vec2 v_texcoord;
|
|
|
|
uniform vec3 e_light_dir;
|
|
|
|
uniform vec3 e_light_mul;
|
|
|
|
uniform vec3 e_light_ambient;
|
2013-03-12 22:35:33 +00:00
|
|
|
#if defined(SPECULAR) || defined(OFFSETMAPPING)
|
|
|
|
uniform vec3 e_eyepos;
|
|
|
|
#endif
|
2012-05-09 15:30:53 +00:00
|
|
|
void main ()
|
|
|
|
{
|
2013-03-12 22:35:33 +00:00
|
|
|
#if defined(SPECULAR)||defined(OFFSETMAPPING)
|
|
|
|
vec3 n, s, t, w;
|
|
|
|
gl_Position = skeletaltransform_wnst(w,n,s,t);
|
|
|
|
vec3 eyeminusvertex = e_eyepos - w.xyz;
|
|
|
|
eyevector.x = -dot(eyeminusvertex, s.xyz);
|
|
|
|
eyevector.y = dot(eyeminusvertex, t.xyz);
|
|
|
|
eyevector.z = dot(eyeminusvertex, n.xyz);
|
|
|
|
#else
|
2012-05-09 15:30:53 +00:00
|
|
|
vec3 n;
|
|
|
|
gl_Position = skeletaltransform_n(n);
|
2013-03-12 22:35:33 +00:00
|
|
|
#endif
|
|
|
|
|
2012-05-09 15:30:53 +00:00
|
|
|
light = e_light_ambient + (dot(n,e_light_dir)*e_light_mul);
|
|
|
|
tc = v_texcoord;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef FRAGMENT_SHADER
|
|
|
|
#include "sys/fog.h"
|
|
|
|
uniform sampler2D s_t0;
|
|
|
|
#ifdef LOWER
|
|
|
|
uniform sampler2D s_t1;
|
|
|
|
uniform vec3 e_lowercolour;
|
|
|
|
#endif
|
|
|
|
#ifdef UPPER
|
|
|
|
uniform sampler2D s_t2;
|
|
|
|
uniform vec3 e_uppercolour;
|
|
|
|
#endif
|
|
|
|
#ifdef FULLBRIGHT
|
|
|
|
uniform sampler2D s_t3;
|
|
|
|
#endif
|
2013-03-12 22:35:33 +00:00
|
|
|
|
|
|
|
#if defined(SPECULAR)
|
|
|
|
uniform sampler2D s_t4;
|
|
|
|
uniform sampler2D s_t5;
|
|
|
|
uniform float cvar_gl_specular;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef OFFSETMAPPING
|
|
|
|
#include "sys/offsetmapping.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-05-09 15:30:53 +00:00
|
|
|
uniform vec4 e_colourident;
|
|
|
|
void main ()
|
|
|
|
{
|
|
|
|
vec4 col, sp;
|
2013-03-12 22:35:33 +00:00
|
|
|
|
|
|
|
#ifdef OFFSETMAPPING
|
|
|
|
vec2 tcoffsetmap = offsetmap(s_t1, tcbase, eyevector);
|
|
|
|
#define tc tcoffsetmap
|
|
|
|
#endif
|
|
|
|
|
2012-05-09 15:30:53 +00:00
|
|
|
col = texture2D(s_t0, tc);
|
|
|
|
#ifdef UPPER
|
|
|
|
vec4 uc = texture2D(s_t2, tc);
|
2013-03-12 22:35:33 +00:00
|
|
|
col.rgb += uc.rgb*e_uppercolour*uc.a;
|
2012-05-09 15:30:53 +00:00
|
|
|
#endif
|
|
|
|
#ifdef LOWER
|
|
|
|
vec4 lc = texture2D(s_t1, tc);
|
2013-03-12 22:35:33 +00:00
|
|
|
col.rgb += lc.rgb*e_lowercolour*lc.a;
|
2012-05-09 15:30:53 +00:00
|
|
|
#endif
|
|
|
|
col.rgb *= light;
|
2013-03-12 22:35:33 +00:00
|
|
|
|
|
|
|
#if defined(SPECULAR)
|
|
|
|
vec3 bumps = normalize(vec3(texture2D(s_t4, tc)) - 0.5);
|
|
|
|
vec4 specs = texture2D(s_t5, tc);
|
|
|
|
|
|
|
|
vec3 halfdir = normalize(normalize(eyevector) + vec3(0.0, 0.0, 1.0));
|
|
|
|
float spec = pow(max(dot(halfdir, bumps), 0.0), 32.0 * specs.a);
|
|
|
|
col.rgb += cvar_gl_specular * spec * specs.rgb;
|
|
|
|
#endif
|
|
|
|
|
2012-05-09 15:30:53 +00:00
|
|
|
#ifdef FULLBRIGHT
|
|
|
|
vec4 fb = texture2D(s_t3, tc);
|
|
|
|
col.rgb = mix(col.rgb, fb.rgb, fb.a);
|
|
|
|
#endif
|
2013-03-12 22:35:33 +00:00
|
|
|
|
2012-05-09 15:30:53 +00:00
|
|
|
gl_FragColor = fog4(col * e_colourident);
|
|
|
|
}
|
|
|
|
#endif
|