skinning.vert 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // SuperTuxKart - a fun racing game with go-kart
  2. // Copyright (C) 2013 the SuperTuxKart team
  3. //
  4. // This program is free software; you can redistribute it and/or
  5. // modify it under the terms of the GNU General Public License
  6. // as published by the Free Software Foundation; either version 3
  7. // of the License, or (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program; if not, write to the Free Software
  16. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. // skinning.vert
  18. #version 330 compatibility
  19. #define MAX_JOINT_NUM 36
  20. #define MAX_LIGHT_NUM 8
  21. uniform mat4 JointTransform[MAX_JOINT_NUM];
  22. void main()
  23. {
  24. int index;
  25. vec4 ecPos;
  26. vec3 normal;
  27. vec3 light_dir;
  28. float n_dot_l;
  29. float dist;
  30. mat4 ModelTransform = gl_ModelViewProjectionMatrix;
  31. index = int(gl_Color.r * 255.99);
  32. mat4 vertTran = JointTransform[index - 1];
  33. index = int(gl_Color.g * 255.99);
  34. if(index > 0)
  35. vertTran += JointTransform[index - 1];
  36. index = int(gl_Color.b * 255.99);
  37. if(index > 0)
  38. vertTran += JointTransform[index - 1];
  39. index = int(gl_Color.a * 255.99);
  40. if(index > 0)
  41. vertTran += JointTransform[index - 1];
  42. ecPos = gl_ModelViewMatrix * vertTran * gl_Vertex;
  43. normal = (vertTran * vec4(gl_Normal, 0.0)).xyz;
  44. normal = normalize(gl_NormalMatrix * normal);
  45. gl_FrontColor = vec4(0,0,0,0);
  46. for(int i = 0;i < MAX_LIGHT_NUM;i++)
  47. {
  48. light_dir = vec3(gl_LightSource[i].position-ecPos);
  49. n_dot_l = max(dot(normal, normalize(light_dir)), 0.0);
  50. dist = length(light_dir);
  51. n_dot_l *= 1.0 / (gl_LightSource[0].constantAttenuation + gl_LightSource[0].linearAttenuation * dist);
  52. gl_FrontColor += gl_LightSource[i].diffuse * n_dot_l;
  53. }
  54. gl_FrontColor = clamp(gl_FrontColor,0.3,1.0);
  55. ModelTransform *= vertTran;
  56. gl_Position = ModelTransform * gl_Vertex;
  57. gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
  58. gl_TexCoord[1] = gl_TextureMatrix[1] * gl_MultiTexCoord1;
  59. /*
  60. // Reflections.
  61. vec3 r = reflect( ecPos.xyz , normal );
  62. float m = 2.0 * sqrt( r.x*r.x + r.y*r.y + (r.z+1.0)*(r.z+1.0) );
  63. gl_TexCoord[1].s = r.x/m + 0.5;
  64. gl_TexCoord[1].t = r.y/m + 0.5;
  65. */
  66. }