2016-07-12 00:40:13 +00:00
|
|
|
!!ver 100 130
|
2012-05-09 15:30:53 +00:00
|
|
|
!!permu FULLBRIGHT
|
|
|
|
!!permu UPPERLOWER
|
|
|
|
!!permu FRAMEBLEND
|
|
|
|
!!permu SKELETAL
|
|
|
|
!!permu FOG
|
2013-03-12 23:14:57 +00:00
|
|
|
!!permu BUMP
|
2013-03-12 22:35:33 +00:00
|
|
|
!!cvarf r_glsl_offsetmapping_scale
|
|
|
|
!!cvarf gl_specular
|
2016-07-12 00:40:13 +00:00
|
|
|
!!cvardf gl_affinemodels=0
|
2012-05-09 15:30:53 +00:00
|
|
|
|
2015-03-03 00:14:43 +00:00
|
|
|
#include "sys/defs.h"
|
|
|
|
|
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.
|
|
|
|
|
2016-07-12 00:40:13 +00:00
|
|
|
#if gl_affinemodels==1 && __VERSION__ >= 130
|
|
|
|
noperspective
|
|
|
|
#endif
|
|
|
|
varying vec2 tc;
|
2012-05-09 15:30:53 +00:00
|
|
|
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"
|
|
|
|
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;
|
2014-01-13 02:42:25 +00:00
|
|
|
eyevector.x = dot(eyeminusvertex, s.xyz);
|
2013-03-12 22:35:33 +00:00
|
|
|
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
|
|
|
|
|
2014-08-15 02:20:41 +00:00
|
|
|
float d = dot(n,e_light_dir);
|
|
|
|
if (d < 0.0) //vertex shader. this might get ugly, but I don't really want to make it per vertex.
|
|
|
|
d = 0.0; //this avoids the dark side going below the ambient level.
|
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
|
2016-07-12 00:40:13 +00:00
|
|
|
|
2012-05-09 15:30:53 +00:00
|
|
|
#include "sys/fog.h"
|
2013-03-12 23:14:57 +00:00
|
|
|
|
|
|
|
#if defined(SPECULAR)
|
2013-03-12 22:35:33 +00:00
|
|
|
uniform float cvar_gl_specular;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef OFFSETMAPPING
|
|
|
|
#include "sys/offsetmapping.h"
|
|
|
|
#endif
|
|
|
|
|
2016-07-12 00:40:13 +00:00
|
|
|
#ifdef EIGHTBIT
|
|
|
|
#define s_colourmap s_t0
|
|
|
|
uniform sampler2D s_colourmap;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if __VERSION__ >= 130
|
|
|
|
#define gl_FragColor thecolour
|
|
|
|
out vec4 thecolour;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2012-05-09 15:30:53 +00:00
|
|
|
void main ()
|
|
|
|
{
|
|
|
|
vec4 col, sp;
|
2013-03-12 22:35:33 +00:00
|
|
|
|
|
|
|
#ifdef OFFSETMAPPING
|
2015-03-03 00:14:43 +00:00
|
|
|
vec2 tcoffsetmap = offsetmap(s_normalmap, tc, eyevector);
|
2013-03-12 22:35:33 +00:00
|
|
|
#define tc tcoffsetmap
|
|
|
|
#endif
|
|
|
|
|
2016-07-12 00:40:13 +00:00
|
|
|
#ifdef EIGHTBIT
|
|
|
|
vec3 lightlev = light;
|
|
|
|
//FIXME: with this extra flag, half the permutations are redundant.
|
|
|
|
lightlev *= 0.5; //counter the fact that the colourmap contains overbright values and logically ranges from 0 to 2 intead of to 1.
|
|
|
|
float pal = texture2D(s_paletted, tc).r; //the palette index. hopefully not interpolated.
|
|
|
|
lightlev -= 1.0 / 128.0; //software rendering appears to round down, so make sure we favour the lower values instead of rounding to the nearest
|
|
|
|
col.r = texture2D(s_colourmap, vec2(pal, 1.0-lightlev.r)).r; //do 3 lookups. this is to cope with lit files, would be a waste to not support those.
|
|
|
|
col.g = texture2D(s_colourmap, vec2(pal, 1.0-lightlev.g)).g; //its not very softwarey, but re-palettizing is ugly.
|
|
|
|
col.b = texture2D(s_colourmap, vec2(pal, 1.0-lightlev.b)).b; //without lits, it should be identical.
|
|
|
|
col.a = (pal<1.0)?1.0:0.0;
|
|
|
|
#else
|
2015-03-03 00:14:43 +00:00
|
|
|
col = texture2D(s_diffuse, tc);
|
2016-07-12 00:40:13 +00:00
|
|
|
#ifdef UPPER
|
|
|
|
vec4 uc = texture2D(s_upper, tc);
|
|
|
|
col.rgb += uc.rgb*e_uppercolour*uc.a;
|
|
|
|
#endif
|
|
|
|
#ifdef LOWER
|
|
|
|
vec4 lc = texture2D(s_lower, tc);
|
|
|
|
col.rgb += lc.rgb*e_lowercolour*lc.a;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(BUMP) && defined(SPECULAR)
|
|
|
|
vec3 bumps = normalize(vec3(texture2D(s_normalmap, tc)) - 0.5);
|
|
|
|
vec4 specs = texture2D(s_specular, 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
|
2013-03-12 22:35:33 +00:00
|
|
|
|
2014-10-05 20:04:11 +00:00
|
|
|
col.rgb *= light;
|
|
|
|
|
2016-07-12 00:40:13 +00:00
|
|
|
#ifdef FULLBRIGHT
|
|
|
|
vec4 fb = texture2D(s_fullbright, tc);
|
|
|
|
// col.rgb = mix(col.rgb, fb.rgb, fb.a);
|
|
|
|
col.rgb += fb.rgb * fb.a;
|
|
|
|
#endif
|
2012-05-09 15:30:53 +00:00
|
|
|
#endif
|
2013-03-12 22:35:33 +00:00
|
|
|
|
2012-05-09 15:30:53 +00:00
|
|
|
gl_FragColor = fog4(col * e_colourident);
|
|
|
|
}
|
|
|
|
#endif
|
2016-07-12 00:40:13 +00:00
|
|
|
|