interaction.vertex 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. struct VS_IN {
  22. float4 position : POSITION;
  23. float2 texcoord : TEXCOORD0;
  24. float4 normal : NORMAL;
  25. float4 tangent : TANGENT;
  26. float4 color : COLOR0;
  27. };
  28. struct VS_OUT {
  29. float4 position : POSITION;
  30. float4 texcoord0 : TEXCOORD0;
  31. float4 texcoord1 : TEXCOORD1;
  32. float4 texcoord2 : TEXCOORD2;
  33. float4 texcoord3 : TEXCOORD3;
  34. float4 texcoord4 : TEXCOORD4;
  35. float4 texcoord5 : TEXCOORD5;
  36. float4 texcoord6 : TEXCOORD6;
  37. float4 color : COLOR0;
  38. };
  39. void main( VS_IN vertex, out VS_OUT result ) {
  40. float3 vNormal = vertex.normal.xyz * 2.0 - 1.0;
  41. float4 vTangent = vertex.tangent * 2.0 - 1.0;
  42. float3 vBinormal = cross( vNormal.xyz, vTangent.xyz ) * vTangent.w;
  43. result.position.x = dot4( vertex.position, rpMVPmatrixX );
  44. result.position.y = dot4( vertex.position, rpMVPmatrixY );
  45. result.position.z = dot4( vertex.position, rpMVPmatrixZ );
  46. result.position.w = dot4( vertex.position, rpMVPmatrixW );
  47. float4 defaultTexCoord = float4( 0.0f, 0.5f, 0.0f, 1.0f );
  48. //calculate vector to light in R0
  49. float4 toLight = rpLocalLightOrigin - vertex.position;
  50. //result.texcoord0
  51. result.texcoord0.x = dot3( vTangent.xyz, toLight );
  52. result.texcoord0.y = dot3( vBinormal, toLight );
  53. result.texcoord0.z = dot3( vNormal, toLight );
  54. result.texcoord0.w = 1.0f;
  55. //textures 1 takes the base coordinates by the texture matrix
  56. result.texcoord1 = defaultTexCoord;
  57. result.texcoord1.x = dot4( vertex.texcoord.xy, rpBumpMatrixS );
  58. result.texcoord1.y = dot4( vertex.texcoord.xy, rpBumpMatrixT );
  59. //# texture 2 has one texgen
  60. result.texcoord2 = defaultTexCoord;
  61. result.texcoord2.x = dot4( vertex.position, rpLightFalloffS );
  62. //# texture 3 has three texgens
  63. result.texcoord3.x = dot4( vertex.position, rpLightProjectionS );
  64. result.texcoord3.y = dot4( vertex.position, rpLightProjectionT );
  65. result.texcoord3.z = 0.0f;
  66. result.texcoord3.w = dot4( vertex.position, rpLightProjectionQ );
  67. //# textures 4 takes the base coordinates by the texture matrix
  68. result.texcoord4 = defaultTexCoord;
  69. result.texcoord4.x = dot4( vertex.texcoord.xy, rpDiffuseMatrixS );
  70. result.texcoord4.y = dot4( vertex.texcoord.xy, rpDiffuseMatrixT );
  71. //# textures 5 takes the base coordinates by the texture matrix
  72. result.texcoord5 = defaultTexCoord;
  73. result.texcoord5.x = dot4( vertex.texcoord.xy, rpSpecularMatrixS );
  74. result.texcoord5.y = dot4( vertex.texcoord.xy, rpSpecularMatrixT );
  75. //# texture 6's texcoords will be the halfangle in texture space
  76. //# calculate normalized vector to light in R0
  77. toLight = normalize( toLight );
  78. //# calculate normalized vector to viewer in R1
  79. float4 toView = normalize( rpLocalViewOrigin - vertex.position );
  80. //# add together to become the half angle vector in object space (non-normalized)
  81. float4 halfAngleVector = toLight + toView;
  82. //# put into texture space
  83. result.texcoord6.x = dot3( vTangent.xyz, halfAngleVector );
  84. result.texcoord6.y = dot3( vBinormal, halfAngleVector );
  85. result.texcoord6.z = dot3( vNormal, halfAngleVector );
  86. result.texcoord6.w = 1.0f;
  87. //# generate the vertex color, which can be 1.0, color, or 1.0 - color
  88. //# for 1.0 : env[16] = 0, env[17] = 1
  89. //# for color : env[16] = 1, env[17] = 0
  90. //# for 1.0-color : env[16] = -1, env[17] = 1
  91. result.color = ( swizzleColor( vertex.color ) * rpVertexColorModulate ) + rpVertexColorAdd;
  92. }