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.

106 lines
3.2 KiB

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