2013-11-06 18:17:18 -05:00
|
|
|
// SuperTuxKart - a fun racing game with go-kart
|
|
|
|
// Copyright (C) 2013 the SuperTuxKart team
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License
|
|
|
|
// as published by the Free Software Foundation; either version 3
|
|
|
|
// of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
2011-07-15 19:38:40 -04:00
|
|
|
// skinning.vert
|
2014-02-12 16:16:10 -05:00
|
|
|
#version 330 compatibility
|
2011-07-15 19:38:40 -04:00
|
|
|
#define MAX_JOINT_NUM 36
|
|
|
|
#define MAX_LIGHT_NUM 8
|
|
|
|
|
|
|
|
uniform mat4 JointTransform[MAX_JOINT_NUM];
|
|
|
|
|
2013-06-18 10:35:29 -04:00
|
|
|
void main()
|
2011-07-15 19:38:40 -04:00
|
|
|
{
|
|
|
|
int index;
|
|
|
|
vec4 ecPos;
|
|
|
|
vec3 normal;
|
|
|
|
vec3 light_dir;
|
|
|
|
float n_dot_l;
|
|
|
|
float dist;
|
|
|
|
|
|
|
|
mat4 ModelTransform = gl_ModelViewProjectionMatrix;
|
2013-06-18 10:35:29 -04:00
|
|
|
|
2011-07-15 19:38:40 -04:00
|
|
|
index = int(gl_Color.r * 255.99);
|
|
|
|
mat4 vertTran = JointTransform[index - 1];
|
2013-06-18 10:35:29 -04:00
|
|
|
|
2011-07-15 19:38:40 -04:00
|
|
|
index = int(gl_Color.g * 255.99);
|
|
|
|
if(index > 0)
|
|
|
|
vertTran += JointTransform[index - 1];
|
|
|
|
|
|
|
|
index = int(gl_Color.b * 255.99);
|
|
|
|
if(index > 0)
|
|
|
|
vertTran += JointTransform[index - 1];
|
2013-06-18 10:35:29 -04:00
|
|
|
|
2011-07-15 19:38:40 -04:00
|
|
|
index = int(gl_Color.a * 255.99);
|
|
|
|
if(index > 0)
|
|
|
|
vertTran += JointTransform[index - 1];
|
2013-06-18 10:35:29 -04:00
|
|
|
|
2011-07-15 19:38:40 -04:00
|
|
|
ecPos = gl_ModelViewMatrix * vertTran * gl_Vertex;
|
2013-06-18 10:34:59 -04:00
|
|
|
|
|
|
|
normal = (vertTran * vec4(gl_Normal, 0.0)).xyz;
|
|
|
|
normal = normalize(gl_NormalMatrix * normal);
|
2013-06-18 10:35:29 -04:00
|
|
|
|
2011-07-15 19:38:40 -04:00
|
|
|
gl_FrontColor = vec4(0,0,0,0);
|
|
|
|
for(int i = 0;i < MAX_LIGHT_NUM;i++)
|
|
|
|
{
|
|
|
|
light_dir = vec3(gl_LightSource[i].position-ecPos);
|
|
|
|
n_dot_l = max(dot(normal, normalize(light_dir)), 0.0);
|
|
|
|
dist = length(light_dir);
|
|
|
|
n_dot_l *= 1.0 / (gl_LightSource[0].constantAttenuation + gl_LightSource[0].linearAttenuation * dist);
|
|
|
|
gl_FrontColor += gl_LightSource[i].diffuse * n_dot_l;
|
|
|
|
}
|
|
|
|
gl_FrontColor = clamp(gl_FrontColor,0.3,1.0);
|
2013-06-18 10:35:29 -04:00
|
|
|
|
2011-07-15 19:38:40 -04:00
|
|
|
|
|
|
|
ModelTransform *= vertTran;
|
2013-06-18 10:35:29 -04:00
|
|
|
|
2011-07-15 19:38:40 -04:00
|
|
|
gl_Position = ModelTransform * gl_Vertex;
|
2013-12-19 18:58:26 -05:00
|
|
|
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
|
|
|
|
gl_TexCoord[1] = gl_TextureMatrix[1] * gl_MultiTexCoord1;
|
2013-06-18 10:35:29 -04:00
|
|
|
|
|
|
|
/*
|
2011-07-15 19:38:40 -04:00
|
|
|
// Reflections.
|
|
|
|
vec3 r = reflect( ecPos.xyz , normal );
|
|
|
|
float m = 2.0 * sqrt( r.x*r.x + r.y*r.y + (r.z+1.0)*(r.z+1.0) );
|
|
|
|
gl_TexCoord[1].s = r.x/m + 0.5;
|
|
|
|
gl_TexCoord[1].t = r.y/m + 0.5;
|
|
|
|
*/
|
|
|
|
}
|