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.0 KiB

  1. // STATIC: "MODEL" "0..1"
  2. // DYNAMIC: "COMPRESSED_VERTS" "0..1"
  3. // DYNAMIC: "SKINNING" "0..1"
  4. #include "common_vs_fxc.h"
  5. static const bool g_bSkinning = SKINNING ? true : false;
  6. static const bool g_bModel = MODEL ? true : false;
  7. const float4 cBumpTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_1 );
  8. struct VS_INPUT
  9. {
  10. float4 vPos : POSITION;
  11. float4 vBoneWeights : BLENDWEIGHT;
  12. float4 vBoneIndices : BLENDINDICES;
  13. float4 vNormal : NORMAL;
  14. float4 vBaseTexCoord : TEXCOORD0;
  15. #if !MODEL
  16. float3 vTangentS : TANGENT;
  17. float3 vTangentT : BINORMAL0;
  18. #else
  19. float4 vUserData : TANGENT;
  20. #endif
  21. };
  22. struct VS_OUTPUT
  23. {
  24. float4 vProjPos_POSITION : POSITION;
  25. float vFog : FOG;
  26. float2 vBumpTexCoord : TEXCOORD0;
  27. float3 vTangentEyeVect : TEXCOORD1;
  28. float3x3 tangentSpaceTranspose : TEXCOORD2;
  29. float3 vRefractXYW : TEXCOORD5;
  30. float4 projNormal_screenCoordW : TEXCOORD6;
  31. float4 worldPos_projPosZ : TEXCOORD7;
  32. float4 fogFactorW : COLOR1;
  33. };
  34. VS_OUTPUT main( const VS_INPUT v )
  35. {
  36. VS_OUTPUT o = ( VS_OUTPUT )0;
  37. float3 worldNormal, worldPos, worldTangentS, worldTangentT;
  38. float3 vObjNormal;
  39. #if MODEL
  40. float4 vObjTangent;
  41. DecompressVertex_NormalTangent( v.vNormal, v.vUserData, vObjNormal, vObjTangent );
  42. SkinPositionNormalAndTangentSpace(
  43. g_bSkinning,
  44. v.vPos, vObjNormal, vObjTangent,
  45. v.vBoneWeights, v.vBoneIndices,
  46. worldPos, worldNormal, worldTangentS, worldTangentT );
  47. #else
  48. DecompressVertex_Normal( v.vNormal, vObjNormal );
  49. worldPos = mul( v.vPos, cModel[0] );
  50. worldTangentS = mul( v.vTangentS, ( const float3x3 )cModel[0] );
  51. worldTangentT = mul( v.vTangentT, ( const float3x3 )cModel[0] );
  52. worldNormal = mul( vObjNormal, ( float3x3 )cModel[0] );
  53. #endif
  54. // Projected position
  55. float4 vProjPos = mul( float4( worldPos, 1 ), cViewProj );
  56. o.vProjPos_POSITION = vProjPos;
  57. o.projNormal_screenCoordW.xyz = mul( worldNormal, cViewProj );
  58. o.worldPos_projPosZ = float4( worldPos.xyz, vProjPos.z );
  59. // Map projected position to the refraction texture
  60. float2 vRefractPos;
  61. vRefractPos.x = vProjPos.x;
  62. vRefractPos.y = -vProjPos.y; // invert Y
  63. vRefractPos = (vRefractPos + vProjPos.w) * 0.5f;
  64. // Refraction transform
  65. o.vRefractXYW = float3(vRefractPos.x, vRefractPos.y, vProjPos.w);
  66. // Compute fog based on the position
  67. float3 vWorldPos = mul( v.vPos, cModel[0] );
  68. o.fogFactorW = o.vFog = CalcFog( vWorldPos, vProjPos, FOGTYPE_RANGE );
  69. // Eye vector
  70. float3 vWorldEyeVect = cEyePos - vWorldPos;
  71. // Transform to the tangent space
  72. o.vTangentEyeVect.x = dot( vWorldEyeVect, worldTangentS );
  73. o.vTangentEyeVect.y = dot( vWorldEyeVect, worldTangentT );
  74. o.vTangentEyeVect.z = dot( vWorldEyeVect, worldNormal );
  75. // Tranform bump coordinates
  76. o.vBumpTexCoord.x = dot( v.vBaseTexCoord, cBumpTexCoordTransform[0] );
  77. o.vBumpTexCoord.y = dot( v.vBaseTexCoord, cBumpTexCoordTransform[1] );
  78. o.tangentSpaceTranspose[0] = worldTangentS;
  79. o.tangentSpaceTranspose[1] = worldTangentT;
  80. o.tangentSpaceTranspose[2] = worldNormal;
  81. return o;
  82. }