Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
3.5 KiB

  1. //========= Copyright � 1996-2006, Valve Corporation, All rights reserved. ============//
  2. // DYNAMIC: "COMPRESSED_VERTS" "0..1"
  3. // DYNAMIC: "SKINNING" "0..1"
  4. // Includes
  5. #include "common_vs_fxc.h"
  6. // Globals
  7. static const bool g_bSkinning = SKINNING ? true : false;
  8. const float3 g_vTime : register( SHADER_SPECIFIC_CONST_0 );
  9. #define g_flTime1x g_vTime.x
  10. #define g_flTime2x g_vTime.y
  11. #define g_flTime4x g_vTime.z
  12. const float4 cBaseTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_1 );
  13. // Structs
  14. struct VS_INPUT
  15. {
  16. float4 vPos : POSITION; // Position
  17. float4 vNormal : NORMAL; // Normal
  18. float4 vBoneWeights : BLENDWEIGHT; // Skin weights
  19. float4 vBoneIndices : BLENDINDICES; // Skin indices
  20. float4 vTexCoord0 : TEXCOORD0; // Base texture coordinates
  21. float4 vUserData : TANGENT;
  22. };
  23. struct VS_OUTPUT
  24. {
  25. float4 vProjPosition : POSITION; // Projection-space position
  26. float4 v2DTangentViewVector01 : TEXCOORD0;
  27. float4 vUv01 : TEXCOORD1;
  28. float4 v2DTangentViewVector2_vUv2 : TEXCOORD2;
  29. };
  30. // Main
  31. VS_OUTPUT main( const VS_INPUT i )
  32. {
  33. VS_OUTPUT o;
  34. // Decompress compressed normal and tangent
  35. float4 vObjPosition = i.vPos.xyzw;
  36. float3 vObjNormal;
  37. float4 vObjTangent;
  38. DecompressVertex_NormalTangent( i.vNormal, i.vUserData, vObjNormal, vObjTangent );
  39. // Transform the position
  40. float3 vWorldPosition = { 0.0f, 0.0f, 0.0f };
  41. float3 vWorldNormal = { 0.0f, 0.0f, 0.0f };
  42. float3 vWorldTangent = { 0.0f, 0.0f, 0.0f };
  43. float3 vWorldBinormal = { 0.0f, 0.0f, 0.0f };
  44. SkinPositionNormalAndTangentSpace( g_bSkinning, vObjPosition, vObjNormal.xyz, vObjTangent.xyzw, i.vBoneWeights, i.vBoneIndices, vWorldPosition, vWorldNormal, vWorldTangent, vWorldBinormal );
  45. vWorldNormal.xyz = normalize( vWorldNormal.xyz );
  46. vWorldTangent.xyz = normalize( vWorldTangent.xyz );
  47. vWorldBinormal.xyz = normalize( vWorldBinormal.xyz );
  48. // Transform into projection space
  49. float4 vProjPosition = mul( float4( vWorldPosition, 1.0f ), cViewProj );
  50. o.vProjPosition = vProjPosition;
  51. // View vector
  52. float3 vWorldViewVector = normalize( vWorldPosition.xyz - cEyePos.xyz );
  53. float3 vTangentViewVector = Vec3WorldToTangentNormalized( vWorldViewVector.xyz, vWorldNormal.xyz, vWorldTangent.xyz, vWorldBinormal.xyz );
  54. // Texture coordinates
  55. float4 mRotate;
  56. float2 vBaseUv = i.vTexCoord0.xy;
  57. // Inner layer
  58. mRotate.x = cos( g_flTime4x );
  59. mRotate.y = -sin( g_flTime4x );
  60. mRotate.z = -mRotate.y;
  61. mRotate.w = mRotate.x;
  62. o.vUv01.xy = ( vBaseUv.xy - 0.5f ) * 1.0f;
  63. o.vUv01.xy = float2( dot( o.vUv01.xy, mRotate.xy ), dot( o.vUv01.xy, mRotate.zw ) );
  64. o.vUv01.xy += 0.5f;
  65. o.v2DTangentViewVector01.xy = float2( dot( vTangentViewVector.xy, mRotate.xy ), dot( vTangentViewVector.xy, mRotate.zw ) );
  66. // Middle layer
  67. mRotate.x = cos( g_flTime2x );
  68. mRotate.y = -sin( g_flTime2x );
  69. mRotate.z = -mRotate.y;
  70. mRotate.w = mRotate.x;
  71. o.vUv01.wz = ( vBaseUv.xy - 0.5f ) * 1.0f;
  72. o.vUv01.wz = float2( dot( o.vUv01.wz, mRotate.xy ), dot( o.vUv01.wz, mRotate.zw ) );
  73. o.vUv01.wz += 0.5f;
  74. o.v2DTangentViewVector01.wz = float2( dot( vTangentViewVector.xy, mRotate.xy ), dot( vTangentViewVector.xy, mRotate.zw ) );
  75. // Outer layer
  76. mRotate.x = cos( g_flTime1x );
  77. mRotate.y = -sin( g_flTime1x );
  78. mRotate.z = -mRotate.y;
  79. mRotate.w = mRotate.x;
  80. float2 vUv2 = ( vBaseUv.xy - 0.5f ) * 1.0f;
  81. vUv2.xy = float2( dot( vUv2.xy, mRotate.xy ), dot( vUv2.xy, mRotate.zw ) );
  82. vUv2.xy += 0.5f;
  83. o.v2DTangentViewVector2_vUv2.wz = vUv2.xy;
  84. o.v2DTangentViewVector2_vUv2.xy = float2( dot( vTangentViewVector.xy, mRotate.xy ), dot( vTangentViewVector.xy, mRotate.zw ) );
  85. return o;
  86. }