Fix specular.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4058 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
parent
a88b2274c7
commit
180432523d
1 changed files with 16 additions and 9 deletions
|
@ -36,13 +36,13 @@ void main ()
|
||||||
gl_Position = skeletaltransform_wnst(w,n,s,t);
|
gl_Position = skeletaltransform_wnst(w,n,s,t);
|
||||||
tcbase = v_texcoord; //pass the texture coords straight through
|
tcbase = v_texcoord; //pass the texture coords straight through
|
||||||
vec3 lightminusvertex = l_lightposition - w.xyz;
|
vec3 lightminusvertex = l_lightposition - w.xyz;
|
||||||
lightvector.x = dot(lightminusvertex, s.xyz);
|
lightvector.x = -dot(lightminusvertex, s.xyz);
|
||||||
lightvector.y = dot(lightminusvertex, t.xyz);
|
lightvector.y = dot(lightminusvertex, t.xyz);
|
||||||
lightvector.z = dot(lightminusvertex, n.xyz);
|
lightvector.z = dot(lightminusvertex, n.xyz);
|
||||||
#if defined(SPECULAR)||defined(OFFSETMAPPING)
|
#if defined(SPECULAR)||defined(OFFSETMAPPING)
|
||||||
vec3 eyeminusvertex = e_eyepos - w.xyz;
|
vec3 eyeminusvertex = e_eyepos - w.xyz;
|
||||||
eyevector.x = dot(eyeminusvertex, s.xyz);
|
eyevector.x = -dot(eyeminusvertex, s.xyz);
|
||||||
eyevector.y = -dot(eyeminusvertex, t.xyz);
|
eyevector.y = dot(eyeminusvertex, t.xyz);
|
||||||
eyevector.z = dot(eyeminusvertex, n.xyz);
|
eyevector.z = dot(eyeminusvertex, n.xyz);
|
||||||
#endif
|
#endif
|
||||||
#if defined(PCF) || defined(SPOT) || defined(PROJECTION) || defined(CUBE)
|
#if defined(PCF) || defined(SPOT) || defined(PROJECTION) || defined(CUBE)
|
||||||
|
@ -77,30 +77,37 @@ uniform vec3 l_lightcolourscale;
|
||||||
#endif
|
#endif
|
||||||
void main ()
|
void main ()
|
||||||
{
|
{
|
||||||
|
//read raw texture samples (offsetmapping munges the tex coords first)
|
||||||
#ifdef OFFSETMAPPING
|
#ifdef OFFSETMAPPING
|
||||||
vec2 tcoffsetmap = offsetmap(s_t1, tcbase, eyevector);
|
vec2 tcoffsetmap = offsetmap(s_t1, tcbase, eyevector);
|
||||||
#define tcbase tcoffsetmap
|
#define tcbase tcoffsetmap
|
||||||
#endif
|
#endif
|
||||||
vec3 bases = vec3(texture2D(s_t0, tcbase));
|
vec3 bases = vec3(texture2D(s_t0, tcbase));
|
||||||
#if defined(BUMP) || defined(SPECULAR)
|
#if defined(BUMP) || defined(SPECULAR)
|
||||||
vec3 bumps = vec3(texture2D(s_t1, tcbase)) - 0.5;
|
vec3 bumps = normalize(vec3(texture2D(s_t1, tcbase)) - 0.5);
|
||||||
#endif
|
#endif
|
||||||
#ifdef SPECULAR
|
#ifdef SPECULAR
|
||||||
vec4 specs = texture2D(s_t2, tcbase);
|
vec4 specs = texture2D(s_t2, tcbase);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
vec3 nl = normalize(lightvector);
|
vec3 nl = normalize(lightvector);
|
||||||
float colorscale = max(1.0 - dot(lightvector, lightvector)/(l_lightradius*l_lightradius), 0.0);
|
float colorscale = max(1.0 - (dot(lightvector, lightvector)/(l_lightradius*l_lightradius)), 0.0);
|
||||||
vec3 diff;
|
vec3 diff;
|
||||||
#ifdef BUMP
|
#ifdef BUMP
|
||||||
diff = bases * (l_lightcolourscale.x + l_lightcolourscale.y * max(dot(2.0*bumps, nl), 0.0));
|
diff = bases * (l_lightcolourscale.x + l_lightcolourscale.y * max(dot(bumps, nl), 0.0));
|
||||||
#else
|
#else
|
||||||
diff = bases * (l_lightcolourscale.x + l_lightcolourscale.y * max(dot(vec3(0.0, 0.0, 1.0), nl), 0.0));
|
diff = bases * (l_lightcolourscale.x + l_lightcolourscale.y * max(dot(vec3(0.0, 0.0, 1.0), nl), 0.0));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef SPECULAR
|
#ifdef SPECULAR
|
||||||
vec3 halfdir = normalize(lightvector - normalize(eyevector));
|
vec3 halfdir = normalize(normalize(eyevector) + nl);
|
||||||
float spec = pow(max(dot(halfdir, bumps), 0.0), 1.0 + 32.0 * specs.a);
|
float spec = pow(max(dot(halfdir, bumps), 0.0), 32.0 * specs.a);
|
||||||
diff += spec * specs.rgb * l_lightcolourscale.z;
|
diff += l_lightcolourscale.z * spec * specs.rgb;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef CUBE
|
#ifdef CUBE
|
||||||
diff *= textureCube(s_t3, vshadowcoord.xyz).rgb;
|
diff *= textureCube(s_t3, vshadowcoord.xyz).rgb;
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue