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.

96 lines
2.3 KiB

  1. // STATIC: "HASALPHAMASK" "0..1"
  2. // STATIC: "HASSTATICTEXTURE" "0..1"
  3. // STATIC: "USEALTERNATEVIEW" "0..1"
  4. // DYNAMIC: "SKINNING" "0..1"
  5. // DYNAMIC: "ADDSTATIC" "0..1"
  6. #define USESTATICTEXTURE (((ADDSTATIC == 1) && (HASSTATICTEXTURE == 1))?(1):(0))
  7. #include "common_vs_fxc.h"
  8. static const bool g_bSkinning = SKINNING ? true : false;
  9. #if ( USEALTERNATEVIEW == 1 )
  10. const float4x4 g_CustomViewProj : register( SHADER_SPECIFIC_CONST_0 );
  11. #endif
  12. struct VS_INPUT
  13. {
  14. float4 vPos : POSITION;
  15. float4 vBoneWeights : BLENDWEIGHT;
  16. float4 vBoneIndices : BLENDINDICES;
  17. float2 vMappingTexCoord : TEXCOORD0;
  18. };
  19. struct VS_OUTPUT
  20. {
  21. float4 vProjPos : POSITION;
  22. float3 vPortalTexCoord : TEXCOORD0;
  23. # if( (HASALPHAMASK == 1) || (USESTATICTEXTURE == 1) )
  24. float2 vSecondaryTexCoord : TEXCOORD1;
  25. # if( (HASALPHAMASK == 1) && (USESTATICTEXTURE == 1) )
  26. float2 vTertiaryTexCoord : TEXCOORD2;
  27. # endif
  28. # endif
  29. # if !defined( _X360 )
  30. float vFog : FOG;
  31. # endif
  32. float4 worldPos_projPosZ : TEXCOORD7; // Necessary for pixel fog
  33. };
  34. VS_OUTPUT main( const VS_INPUT v )
  35. {
  36. VS_OUTPUT o = ( VS_OUTPUT )0;
  37. float3 worldPos;
  38. SkinPosition(
  39. g_bSkinning,
  40. v.vPos,
  41. v.vBoneWeights, v.vBoneIndices,
  42. worldPos );
  43. float4 vTextureProjectedPos;
  44. o.vProjPos = mul( float4( worldPos, 1 ), cViewProj );
  45. #if ( USEALTERNATEVIEW == 1 )
  46. vTextureProjectedPos = mul( float4( worldPos, 1 ), g_CustomViewProj );
  47. #else
  48. vTextureProjectedPos = o.vProjPos;
  49. #endif
  50. #if !defined( _X360 )
  51. o.vFog = CalcFog( worldPos, o.vProjPos.xyz, FOGTYPE_RANGE );
  52. #endif
  53. o.worldPos_projPosZ = float4( worldPos.xyz, o.vProjPos.z );
  54. //Screen coordinates mapped back to texture coordinates for the portal texture
  55. o.vPortalTexCoord.x = vTextureProjectedPos.x;
  56. o.vPortalTexCoord.y = -vTextureProjectedPos.y; // invert Y
  57. o.vPortalTexCoord.xy = (o.vPortalTexCoord.xy + vTextureProjectedPos.w) * 0.5f;
  58. o.vPortalTexCoord.z = vTextureProjectedPos.w;
  59. #if ( USEALTERNATEVIEW == 1 )
  60. o.vPortalTexCoord.xy = saturate( o.vPortalTexCoord.xy / vTextureProjectedPos.w ) * vTextureProjectedPos.w; //stretch instead of clipping.
  61. #endif
  62. # if( (HASALPHAMASK == 1) || (USESTATICTEXTURE == 1) )
  63. {
  64. o.vSecondaryTexCoord = v.vMappingTexCoord.xy;
  65. # if( (HASALPHAMASK == 1) && (USESTATICTEXTURE == 1) )
  66. o.vTertiaryTexCoord = v.vMappingTexCoord.xy;
  67. # endif
  68. }
  69. # endif
  70. return o;
  71. }