2017-02-11 16:14:06 +00:00
|
|
|
!!ver 100 150
|
|
|
|
!!permu TESS
|
2012-05-09 15:30:53 +00:00
|
|
|
!!permu BUMP
|
2013-10-08 14:28:11 +00:00
|
|
|
!!permu FRAMEBLEND
|
2012-05-09 15:30:53 +00:00
|
|
|
!!permu SKELETAL
|
2013-03-12 22:35:33 +00:00
|
|
|
!!permu UPPERLOWER
|
2012-05-09 15:30:53 +00:00
|
|
|
!!permu FOG
|
2015-05-03 19:57:46 +00:00
|
|
|
!!permu REFLECTCUBEMASK
|
2012-05-09 15:30:53 +00:00
|
|
|
!!cvarf r_glsl_offsetmapping_scale
|
2013-10-08 14:28:11 +00:00
|
|
|
!!cvardf r_glsl_pcf
|
2017-02-19 00:15:42 +00:00
|
|
|
!!cvardf r_tessellation_level=5
|
|
|
|
!!samps shadowmap diffuse normalmap specular upper lower reflectcube reflectmask
|
2013-10-08 14:28:11 +00:00
|
|
|
|
2017-02-11 16:14:06 +00:00
|
|
|
#include "sys/defs.h"
|
2012-05-09 15:30:53 +00:00
|
|
|
|
|
|
|
//this is the main shader responsible for realtime dlights.
|
|
|
|
|
|
|
|
//texture units:
|
|
|
|
//s0=diffuse, s1=normal, s2=specular, s3=shadowmap
|
|
|
|
//custom modifiers:
|
|
|
|
//PCF(shadowmap)
|
2013-10-08 14:28:11 +00:00
|
|
|
//CUBEPROJ(projected cubemap)
|
2012-08-04 01:35:52 +00:00
|
|
|
//SPOT(projected circle
|
|
|
|
//CUBESHADOW
|
|
|
|
|
|
|
|
#if 0 && defined(GL_ARB_texture_gather) && defined(PCF)
|
|
|
|
#extension GL_ARB_texture_gather : enable
|
|
|
|
#endif
|
2012-05-09 15:30:53 +00:00
|
|
|
|
2013-03-12 22:35:33 +00:00
|
|
|
#ifdef UPPERLOWER
|
|
|
|
#define UPPER
|
|
|
|
#define LOWER
|
|
|
|
#endif
|
|
|
|
|
2014-10-05 20:04:11 +00:00
|
|
|
//if there's no vertex normals known, disable some stuff.
|
|
|
|
//FIXME: this results in dupe permutations.
|
|
|
|
#ifdef NOBUMP
|
|
|
|
#undef SPECULAR
|
|
|
|
#undef BUMP
|
|
|
|
#undef OFFSETMAPPING
|
|
|
|
#endif
|
|
|
|
|
2017-02-11 16:14:06 +00:00
|
|
|
#if !defined(TESS_CONTROL_SHADER)
|
|
|
|
varying vec2 tcbase;
|
|
|
|
varying vec3 lightvector;
|
|
|
|
#if defined(SPECULAR) || defined(OFFSETMAPPING) || defined(REFLECTCUBEMASK)
|
|
|
|
varying vec3 eyevector;
|
|
|
|
#endif
|
|
|
|
#ifdef REFLECTCUBEMASK
|
|
|
|
varying mat3 invsurface;
|
|
|
|
#endif
|
|
|
|
#if defined(PCF) || defined(CUBE) || defined(SPOT)
|
|
|
|
varying vec4 vtexprojcoord;
|
|
|
|
#endif
|
2012-08-04 01:35:52 +00:00
|
|
|
#endif
|
2014-08-27 08:41:31 +00:00
|
|
|
|
|
|
|
|
2012-05-09 15:30:53 +00:00
|
|
|
#ifdef VERTEX_SHADER
|
2017-02-11 16:14:06 +00:00
|
|
|
#ifdef TESS
|
|
|
|
varying vec3 vertex, normal;
|
2014-08-27 08:41:31 +00:00
|
|
|
#endif
|
2012-05-09 15:30:53 +00:00
|
|
|
#include "sys/skeletal.h"
|
|
|
|
void main ()
|
|
|
|
{
|
|
|
|
vec3 n, s, t, w;
|
|
|
|
gl_Position = skeletaltransform_wnst(w,n,s,t);
|
|
|
|
tcbase = v_texcoord; //pass the texture coords straight through
|
|
|
|
vec3 lightminusvertex = l_lightposition - w.xyz;
|
2014-10-05 20:04:11 +00:00
|
|
|
#ifdef NOBUMP
|
|
|
|
//the only important thing is distance
|
|
|
|
lightvector = lightminusvertex;
|
|
|
|
#else
|
|
|
|
//the light direction relative to the surface normal, for bumpmapping.
|
2014-01-13 02:42:25 +00:00
|
|
|
lightvector.x = dot(lightminusvertex, s.xyz);
|
2012-05-09 15:30:53 +00:00
|
|
|
lightvector.y = dot(lightminusvertex, t.xyz);
|
|
|
|
lightvector.z = dot(lightminusvertex, n.xyz);
|
2014-10-05 20:04:11 +00:00
|
|
|
#endif
|
2015-05-03 19:57:46 +00:00
|
|
|
#if defined(SPECULAR)||defined(OFFSETMAPPING) || defined(REFLECTCUBEMASK)
|
2012-05-09 15:30:53 +00:00
|
|
|
vec3 eyeminusvertex = e_eyepos - w.xyz;
|
2014-01-13 02:42:25 +00:00
|
|
|
eyevector.x = dot(eyeminusvertex, s.xyz);
|
2012-07-05 13:09:44 +00:00
|
|
|
eyevector.y = dot(eyeminusvertex, t.xyz);
|
2012-05-09 15:30:53 +00:00
|
|
|
eyevector.z = dot(eyeminusvertex, n.xyz);
|
|
|
|
#endif
|
2015-05-03 19:57:46 +00:00
|
|
|
#ifdef REFLECTCUBEMASK
|
|
|
|
invsurface[0] = v_svector;
|
|
|
|
invsurface[1] = v_tvector;
|
|
|
|
invsurface[2] = v_normal;
|
|
|
|
#endif
|
2013-06-26 00:39:13 +00:00
|
|
|
#if defined(PCF) || defined(SPOT) || defined(CUBE)
|
2012-08-04 01:35:52 +00:00
|
|
|
//for texture projections/shadowmapping on dlights
|
|
|
|
vtexprojcoord = (l_cubematrix*vec4(w.xyz, 1.0));
|
2012-05-09 15:30:53 +00:00
|
|
|
#endif
|
2017-02-11 16:14:06 +00:00
|
|
|
|
|
|
|
#ifdef TESS
|
|
|
|
vertex = w;
|
|
|
|
normal = n;
|
|
|
|
#endif
|
2012-05-09 15:30:53 +00:00
|
|
|
}
|
|
|
|
#endif
|
2012-08-04 01:35:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-02-11 16:14:06 +00:00
|
|
|
|
|
|
|
#if defined(TESS_CONTROL_SHADER)
|
|
|
|
layout(vertices = 3) out;
|
|
|
|
|
|
|
|
in vec3 vertex[];
|
|
|
|
out vec3 t_vertex[];
|
|
|
|
in vec3 normal[];
|
|
|
|
out vec3 t_normal[];
|
|
|
|
in vec2 tcbase[];
|
|
|
|
out vec2 t_tcbase[];
|
|
|
|
in vec3 lightvector[];
|
|
|
|
out vec3 t_lightvector[];
|
|
|
|
#if defined(SPECULAR) || defined(OFFSETMAPPING) || defined(REFLECTCUBEMASK)
|
|
|
|
in vec3 eyevector[];
|
|
|
|
out vec3 t_eyevector[];
|
2012-05-09 15:30:53 +00:00
|
|
|
#endif
|
2017-02-11 16:14:06 +00:00
|
|
|
void main()
|
|
|
|
{
|
|
|
|
//the control shader needs to pass stuff through
|
|
|
|
#define id gl_InvocationID
|
|
|
|
t_vertex[id] = vertex[id];
|
|
|
|
t_normal[id] = normal[id];
|
|
|
|
t_tcbase[id] = tcbase[id];
|
|
|
|
t_lightvector[id] = lightvector[id];
|
|
|
|
#if defined(SPECULAR) || defined(OFFSETMAPPING) || defined(REFLECTCUBEMASK)
|
|
|
|
t_eyevector[id] = eyevector[id];
|
2012-08-04 01:35:52 +00:00
|
|
|
#endif
|
2017-02-11 16:14:06 +00:00
|
|
|
|
2017-02-19 00:15:42 +00:00
|
|
|
gl_TessLevelOuter[0] = float(r_tessellation_level);
|
|
|
|
gl_TessLevelOuter[1] = float(r_tessellation_level);
|
|
|
|
gl_TessLevelOuter[2] = float(r_tessellation_level);
|
|
|
|
gl_TessLevelInner[0] = float(r_tessellation_level);
|
2017-02-11 16:14:06 +00:00
|
|
|
}
|
2012-05-09 15:30:53 +00:00
|
|
|
#endif
|
2017-02-11 16:14:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(TESS_EVALUATION_SHADER)
|
|
|
|
layout(triangles) in;
|
|
|
|
|
|
|
|
in vec3 t_vertex[];
|
|
|
|
in vec3 t_normal[];
|
|
|
|
in vec2 t_tcbase[];
|
|
|
|
in vec3 t_lightvector[];
|
|
|
|
#if defined(SPECULAR) || defined(OFFSETMAPPING) || defined(REFLECTCUBEMASK)
|
|
|
|
in vec3 t_eyevector[];
|
2012-05-09 15:30:53 +00:00
|
|
|
#endif
|
2017-02-11 16:14:06 +00:00
|
|
|
|
|
|
|
#define LERP(a) (gl_TessCoord.x*a[0] + gl_TessCoord.y*a[1] + gl_TessCoord.z*a[2])
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
#define factor 1.0
|
|
|
|
tcbase = LERP(t_tcbase);
|
|
|
|
vec3 w = LERP(t_vertex);
|
|
|
|
|
|
|
|
vec3 t0 = w - dot(w-t_vertex[0],t_normal[0])*t_normal[0];
|
|
|
|
vec3 t1 = w - dot(w-t_vertex[1],t_normal[1])*t_normal[1];
|
|
|
|
vec3 t2 = w - dot(w-t_vertex[2],t_normal[2])*t_normal[2];
|
|
|
|
w = w*(1.0-factor) + factor*(gl_TessCoord.x*t0+gl_TessCoord.y*t1+gl_TessCoord.z*t2);
|
|
|
|
|
|
|
|
#if defined(PCF) || defined(SPOT) || defined(CUBE)
|
|
|
|
//for texture projections/shadowmapping on dlights
|
|
|
|
vtexprojcoord = (l_cubematrix*vec4(w.xyz, 1.0));
|
2013-03-12 22:35:33 +00:00
|
|
|
#endif
|
2017-02-11 16:14:06 +00:00
|
|
|
|
|
|
|
//FIXME: we should be recalcing these here, instead of just lerping them
|
|
|
|
lightvector = LERP(t_lightvector);
|
|
|
|
#if defined(SPECULAR) || defined(OFFSETMAPPING) || defined(REFLECTCUBEMASK)
|
|
|
|
eyevector = LERP(t_eyevector);
|
2013-03-12 22:35:33 +00:00
|
|
|
#endif
|
2012-08-04 01:35:52 +00:00
|
|
|
|
2017-02-11 16:14:06 +00:00
|
|
|
gl_Position = m_modelviewprojection * vec4(w,1.0);
|
|
|
|
}
|
2015-05-03 19:57:46 +00:00
|
|
|
#endif
|
|
|
|
|
2012-08-04 01:35:52 +00:00
|
|
|
|
2017-02-11 16:14:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef FRAGMENT_SHADER
|
|
|
|
|
|
|
|
#include "sys/fog.h"
|
2017-03-06 14:06:12 +00:00
|
|
|
#include "sys/pcf.h"
|
2012-05-09 15:30:53 +00:00
|
|
|
#ifdef OFFSETMAPPING
|
|
|
|
#include "sys/offsetmapping.h"
|
|
|
|
#endif
|
2013-10-29 17:38:22 +00:00
|
|
|
|
2012-05-09 15:30:53 +00:00
|
|
|
void main ()
|
|
|
|
{
|
2017-03-06 14:06:12 +00:00
|
|
|
float colorscale = max(1.0 - (dot(lightvector, lightvector)/(l_lightradius*l_lightradius)), 0.0);
|
|
|
|
#ifdef PCF
|
|
|
|
/*filter the light by the shadowmap. logically a boolean, but we allow fractions for softer shadows*/
|
|
|
|
colorscale *= ShadowmapFilter(s_shadowmap);
|
|
|
|
#endif
|
|
|
|
#if defined(SPOT)
|
|
|
|
/*filter the colour by the spotlight. discard anything behind the light so we don't get a mirror image*/
|
|
|
|
if (vtexprojcoord.w < 0.0) discard;
|
|
|
|
vec2 spot = ((vtexprojcoord.st)/vtexprojcoord.w);
|
|
|
|
colorscale*=1.0-(dot(spot,spot));
|
|
|
|
#endif
|
|
|
|
|
2012-07-05 13:09:44 +00:00
|
|
|
//read raw texture samples (offsetmapping munges the tex coords first)
|
2012-05-09 15:30:53 +00:00
|
|
|
#ifdef OFFSETMAPPING
|
2015-08-10 18:28:23 +00:00
|
|
|
vec2 tcoffsetmap = offsetmap(s_normalmap, tcbase, eyevector);
|
2012-05-09 15:30:53 +00:00
|
|
|
#define tcbase tcoffsetmap
|
|
|
|
#endif
|
2015-08-10 18:28:23 +00:00
|
|
|
#if defined(FLAT)
|
2017-02-21 20:22:07 +00:00
|
|
|
vec3 bases = vec3(FLAT);
|
2015-08-10 18:28:23 +00:00
|
|
|
#else
|
|
|
|
vec3 bases = vec3(texture2D(s_diffuse, tcbase));
|
|
|
|
#endif
|
2013-03-12 22:35:33 +00:00
|
|
|
#ifdef UPPER
|
2015-08-10 18:28:23 +00:00
|
|
|
vec4 uc = texture2D(s_upper, tcbase);
|
2013-03-12 22:35:33 +00:00
|
|
|
bases.rgb += uc.rgb*e_uppercolour*uc.a;
|
|
|
|
#endif
|
|
|
|
#ifdef LOWER
|
2015-08-10 18:28:23 +00:00
|
|
|
vec4 lc = texture2D(s_lower, tcbase);
|
2013-03-12 22:35:33 +00:00
|
|
|
bases.rgb += lc.rgb*e_lowercolour*lc.a;
|
|
|
|
#endif
|
2015-05-03 19:57:46 +00:00
|
|
|
#if defined(BUMP) || defined(SPECULAR) || defined(REFLECTCUBEMASK)
|
2015-08-10 18:28:23 +00:00
|
|
|
vec3 bumps = normalize(vec3(texture2D(s_normalmap, tcbase)) - 0.5);
|
2015-05-03 19:57:46 +00:00
|
|
|
#elif defined(REFLECTCUBEMASK)
|
|
|
|
vec3 bumps = vec3(0.0,0.0,1.0);
|
2012-05-09 15:30:53 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SPECULAR
|
2015-08-10 18:28:23 +00:00
|
|
|
vec4 specs = texture2D(s_specular, tcbase);
|
2012-05-09 15:30:53 +00:00
|
|
|
#endif
|
2012-07-05 13:09:44 +00:00
|
|
|
|
2012-05-09 15:30:53 +00:00
|
|
|
vec3 diff;
|
2014-10-05 20:04:11 +00:00
|
|
|
#ifdef NOBUMP
|
|
|
|
//surface can only support ambient lighting, even for lights that try to avoid it.
|
|
|
|
diff = bases * (l_lightcolourscale.x+l_lightcolourscale.y);
|
2012-05-09 15:30:53 +00:00
|
|
|
#else
|
2014-10-05 20:04:11 +00:00
|
|
|
vec3 nl = normalize(lightvector);
|
|
|
|
#ifdef BUMP
|
|
|
|
diff = bases * (l_lightcolourscale.x + l_lightcolourscale.y * max(dot(bumps, nl), 0.0));
|
|
|
|
#else
|
|
|
|
//we still do bumpmapping even without bumps to ensure colours are always sane. light.exe does it too.
|
|
|
|
diff = bases * (l_lightcolourscale.x + l_lightcolourscale.y * max(dot(vec3(0.0, 0.0, 1.0), nl), 0.0));
|
|
|
|
#endif
|
2012-05-09 15:30:53 +00:00
|
|
|
#endif
|
2012-07-05 13:09:44 +00:00
|
|
|
|
|
|
|
|
2012-05-09 15:30:53 +00:00
|
|
|
#ifdef SPECULAR
|
2012-07-05 13:09:44 +00:00
|
|
|
vec3 halfdir = normalize(normalize(eyevector) + nl);
|
|
|
|
float spec = pow(max(dot(halfdir, bumps), 0.0), 32.0 * specs.a);
|
|
|
|
diff += l_lightcolourscale.z * spec * specs.rgb;
|
2012-05-09 15:30:53 +00:00
|
|
|
#endif
|
2012-07-05 13:09:44 +00:00
|
|
|
|
2015-05-03 19:57:46 +00:00
|
|
|
#ifdef REFLECTCUBEMASK
|
|
|
|
vec3 rtc = reflect(-eyevector, bumps);
|
|
|
|
rtc = rtc.x*invsurface[0] + rtc.y*invsurface[1] + rtc.z*invsurface[2];
|
|
|
|
rtc = (m_model * vec4(rtc.xyz,0.0)).xyz;
|
|
|
|
diff += texture2D(s_reflectmask, tcbase).rgb * textureCube(s_reflectcube, rtc).rgb;
|
|
|
|
#endif
|
2012-07-05 13:09:44 +00:00
|
|
|
|
2013-06-26 00:39:13 +00:00
|
|
|
#ifdef CUBE
|
2012-08-04 01:35:52 +00:00
|
|
|
/*filter the colour by the cubemap projection*/
|
2015-08-10 18:28:23 +00:00
|
|
|
diff *= textureCube(s_projectionmap, vtexprojcoord.xyz).rgb;
|
2012-05-09 15:30:53 +00:00
|
|
|
#endif
|
2012-08-04 01:35:52 +00:00
|
|
|
|
2012-05-09 15:30:53 +00:00
|
|
|
#if defined(PROJECTION)
|
2012-08-04 01:35:52 +00:00
|
|
|
/*2d projection, not used*/
|
2015-08-10 18:28:23 +00:00
|
|
|
// diff *= texture2d(s_projectionmap, shadowcoord);
|
2012-05-09 15:30:53 +00:00
|
|
|
#endif
|
2012-08-04 01:35:52 +00:00
|
|
|
|
2012-05-09 15:30:53 +00:00
|
|
|
gl_FragColor.rgb = fog3additive(diff*colorscale*l_lightcolour);
|
2015-05-03 19:57:46 +00:00
|
|
|
|
2012-05-09 15:30:53 +00:00
|
|
|
}
|
|
|
|
#endif
|
2014-08-27 08:41:31 +00:00
|
|
|
|