environment_skinned.vertex 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. #include "global.inc"
  21. uniform matrices_ubo { float4 matrices[408]; };
  22. struct VS_IN {
  23. float4 position : POSITION;
  24. float2 texcoord : TEXCOORD0;
  25. float4 normal : NORMAL;
  26. float4 color : COLOR0;
  27. float4 color2 : COLOR1;
  28. };
  29. struct VS_OUT {
  30. float4 position : POSITION;
  31. float3 texcoord0 : TEXCOORD0;
  32. float3 texcoord1 : TEXCOORD1;
  33. float4 color : COLOR0;
  34. };
  35. void main( VS_IN vertex, out VS_OUT result ) {
  36. float4 vNormal = vertex.normal * 2.0 - 1.0;
  37. //--------------------------------------------------------------
  38. // GPU transformation of the normal / binormal / bitangent
  39. //
  40. // multiplying with 255.1 give us the same result and is faster than floor( w * 255 + 0.5 )
  41. //--------------------------------------------------------------
  42. const float w0 = vertex.color2.x;
  43. const float w1 = vertex.color2.y;
  44. const float w2 = vertex.color2.z;
  45. const float w3 = vertex.color2.w;
  46. float4 matX, matY, matZ; // must be float4 for vec4
  47. float joint = vertex.color.x * 255.1 * 3;
  48. matX = matrices[int(joint+0)] * w0;
  49. matY = matrices[int(joint+1)] * w0;
  50. matZ = matrices[int(joint+2)] * w0;
  51. joint = vertex.color.y * 255.1 * 3;
  52. matX += matrices[int(joint+0)] * w1;
  53. matY += matrices[int(joint+1)] * w1;
  54. matZ += matrices[int(joint+2)] * w1;
  55. joint = vertex.color.z * 255.1 * 3;
  56. matX += matrices[int(joint+0)] * w2;
  57. matY += matrices[int(joint+1)] * w2;
  58. matZ += matrices[int(joint+2)] * w2;
  59. joint = vertex.color.w * 255.1 * 3;
  60. matX += matrices[int(joint+0)] * w3;
  61. matY += matrices[int(joint+1)] * w3;
  62. matZ += matrices[int(joint+2)] * w3;
  63. float3 vNormalSkinned;
  64. vNormalSkinned.x = dot3( matX, vNormal );
  65. vNormalSkinned.y = dot3( matY, vNormal );
  66. vNormalSkinned.z = dot3( matZ, vNormal );
  67. vNormalSkinned = normalize( vNormalSkinned );
  68. float4 modelPosition;
  69. modelPosition.x = dot4( matX, vertex.position );
  70. modelPosition.y = dot4( matY, vertex.position );
  71. modelPosition.z = dot4( matZ, vertex.position );
  72. modelPosition.w = 1.0;
  73. result.position.x = dot4( modelPosition, rpMVPmatrixX );
  74. result.position.y = dot4( modelPosition, rpMVPmatrixY );
  75. result.position.z = dot4( modelPosition, rpMVPmatrixZ );
  76. result.position.w = dot4( modelPosition, rpMVPmatrixW );
  77. float4 toEye = rpLocalViewOrigin - modelPosition;
  78. result.texcoord0 = toEye.xyz;
  79. result.texcoord1 = vNormalSkinned.xyz;
  80. result.color = rpColor;
  81. }