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.

117 lines
3.4 KiB

  1. // STATIC: "BASETEXTURE" "0..1"
  2. // STATIC: "MULTITEXTURE" "0..1"
  3. // SKIP: $MULTITEXTURE && $BASETEXTURE
  4. #include "common_vs_fxc.h"
  5. const float4 cBumpTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_1 );
  6. const float4 TexOffsets : register( SHADER_SPECIFIC_CONST_3 );
  7. struct VS_INPUT
  8. {
  9. float4 vPos : POSITION;
  10. float4 vNormal : NORMAL;
  11. float4 vBaseTexCoord : TEXCOORD0;
  12. float2 vLightmapTexCoord : TEXCOORD1;
  13. float2 vLightmapTexCoordOffset : TEXCOORD2;
  14. float3 vTangentS : TANGENT;
  15. float3 vTangentT : BINORMAL0;
  16. };
  17. struct VS_OUTPUT
  18. {
  19. float4 vProjPos_POSITION : POSITION;
  20. #if !defined( _X360 )
  21. float vFog : FOG;
  22. #endif
  23. float2 vBumpTexCoord : TEXCOORD0;
  24. float3 vTangentEyeVect : TEXCOORD1;
  25. float4 vReflectXY_vRefractYX : TEXCOORD2;
  26. float W : TEXCOORD3;
  27. float4 vProjPos : TEXCOORD4;
  28. float screenCoord : TEXCOORD5;
  29. #if MULTITEXTURE
  30. float4 vExtraBumpTexCoord : TEXCOORD6;
  31. #endif
  32. #if BASETEXTURE
  33. HALF4 lightmapTexCoord1And2 : TEXCOORD6;
  34. HALF4 lightmapTexCoord3 : TEXCOORD7;
  35. #endif
  36. float4 fogFactorW : COLOR1;
  37. };
  38. VS_OUTPUT main( const VS_INPUT v )
  39. {
  40. VS_OUTPUT o = ( VS_OUTPUT )0;
  41. float3 vObjNormal;
  42. DecompressVertex_Normal( v.vNormal, vObjNormal );
  43. // Projected position
  44. float4 vProjPos = mul( v.vPos, cModelViewProj );
  45. o.vProjPos = o.vProjPos_POSITION = vProjPos;
  46. // Project tangent basis
  47. float2 vProjTangentS = mul( v.vTangentS, cViewProj );
  48. float2 vProjTangentT = mul( v.vTangentT, cViewProj );
  49. // Map projected position to the reflection texture
  50. float2 vReflectPos;
  51. vReflectPos = (vProjPos.xy + vProjPos.w) * 0.5f;
  52. // Map projected position to the refraction texture
  53. float2 vRefractPos;
  54. vRefractPos.x = vProjPos.x;
  55. vRefractPos.y = -vProjPos.y; // invert Y
  56. vRefractPos = (vRefractPos + vProjPos.w) * 0.5f;
  57. // Reflection transform
  58. o.vReflectXY_vRefractYX = float4( vReflectPos.x, vReflectPos.y, vRefractPos.y, vRefractPos.x );
  59. o.W = vProjPos.w;
  60. o.screenCoord = vProjPos.x;
  61. // Compute fog based on the position
  62. float3 vWorldPos = mul( v.vPos, cModel[0] );
  63. o.fogFactorW = CalcFog( vWorldPos, vProjPos, FOGTYPE_RANGE );
  64. #if !defined( _X360 )
  65. o.vFog = o.fogFactorW;
  66. #endif
  67. // Eye vector
  68. float3 vWorldEyeVect = cEyePos - vWorldPos;
  69. // Transform to the tangent space
  70. o.vTangentEyeVect.x = dot( vWorldEyeVect, v.vTangentS );
  71. o.vTangentEyeVect.y = dot( vWorldEyeVect, v.vTangentT );
  72. o.vTangentEyeVect.z = dot( vWorldEyeVect, vObjNormal );
  73. // Tranform bump coordinates
  74. o.vBumpTexCoord.x = dot( v.vBaseTexCoord, cBumpTexCoordTransform[0] );
  75. o.vBumpTexCoord.y = dot( v.vBaseTexCoord, cBumpTexCoordTransform[1] );
  76. float f45x=v.vBaseTexCoord.x+v.vBaseTexCoord.y;
  77. float f45y=v.vBaseTexCoord.y-v.vBaseTexCoord.x;
  78. #if MULTITEXTURE
  79. o.vExtraBumpTexCoord.x=f45x*0.1+TexOffsets.x;
  80. o.vExtraBumpTexCoord.y=f45y*0.1+TexOffsets.y;
  81. o.vExtraBumpTexCoord.z=v.vBaseTexCoord.y*0.45+TexOffsets.z;
  82. o.vExtraBumpTexCoord.w=v.vBaseTexCoord.x*0.45+TexOffsets.w;
  83. #endif
  84. #if BASETEXTURE
  85. o.lightmapTexCoord1And2.xy = v.vLightmapTexCoord + v.vLightmapTexCoordOffset;
  86. float2 lightmapTexCoord2 = o.lightmapTexCoord1And2.xy + v.vLightmapTexCoordOffset;
  87. float2 lightmapTexCoord3 = lightmapTexCoord2 + v.vLightmapTexCoordOffset;
  88. // reversed component order
  89. o.lightmapTexCoord1And2.w = lightmapTexCoord2.x;
  90. o.lightmapTexCoord1And2.z = lightmapTexCoord2.y;
  91. o.lightmapTexCoord3.xy = lightmapTexCoord3;
  92. #endif
  93. return o;
  94. }