skinning.inc 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. float4 modelPosition = vertex.position;
  21. BRANCH if ( rpEnableSkinning.x > 0.0 ) {
  22. //--------------------------------------------------------------
  23. // GPU transformation of the normal / binormal / bitangent
  24. //
  25. // multiplying with 255.1 give us the same result and is faster than floor( w * 255 + 0.5 )
  26. //--------------------------------------------------------------
  27. const float w0 = vertex.color2.x;
  28. const float w1 = vertex.color2.y;
  29. const float w2 = vertex.color2.z;
  30. const float w3 = vertex.color2.w;
  31. float4 matX, matY, matZ; // must be float4 for vec4
  32. float joint = vertex.color.x * 255.1 * 3;
  33. matX = matrices[int(joint+0)] * w0;
  34. matY = matrices[int(joint+1)] * w0;
  35. matZ = matrices[int(joint+2)] * w0;
  36. joint = vertex.color.y * 255.1 * 3;
  37. matX += matrices[int(joint+0)] * w1;
  38. matY += matrices[int(joint+1)] * w1;
  39. matZ += matrices[int(joint+2)] * w1;
  40. joint = vertex.color.z * 255.1 * 3;
  41. matX += matrices[int(joint+0)] * w2;
  42. matY += matrices[int(joint+1)] * w2;
  43. matZ += matrices[int(joint+2)] * w2;
  44. joint = vertex.color.w * 255.1 * 3;
  45. matX += matrices[int(joint+0)] * w3;
  46. matY += matrices[int(joint+1)] * w3;
  47. matZ += matrices[int(joint+2)] * w3;
  48. modelPosition.x = dot4( matX, vertex.position );
  49. modelPosition.y = dot4( matY, vertex.position );
  50. modelPosition.z = dot4( matZ, vertex.position );
  51. modelPosition.w = 1.0;
  52. }
  53. result.position.x = dot4( modelPosition, rpMVPmatrixX );
  54. result.position.y = dot4( modelPosition, rpMVPmatrixY );
  55. result.position.z = dot4( modelPosition, rpMVPmatrixZ );
  56. result.position.w = dot4( modelPosition, rpMVPmatrixW );