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.

185 lines
4.8 KiB

  1. // STATIC: "EFFECT" "0..3"
  2. // STATIC: "VERTEXCOLOR" "0..1"
  3. // STATIC: "HALFLAMBERT" "0..1"
  4. // STATIC: "VERTEX_LIT" "0..1"
  5. // STATIC: "FULLBRIGHT" "0..1"
  6. // STATIC: "USE_STATIC_CONTROL_FLOW" "0..1" [vs20]
  7. // STATIC: "BASETEXTURE2" "0..1"
  8. // STATIC: "STRIPES" "0..1"
  9. // STATIC: "STRIPES_USE_NORMAL2" "0..1"
  10. // DYNAMIC: "COMPRESSED_VERTS" "0..1"
  11. // DYNAMIC: "SKINNING" "0..1"
  12. // DYNAMIC: "DYNAMIC_LIGHT" "0..1"
  13. // DYNAMIC: "STATIC_LIGHT" "0..1"
  14. // DYNAMIC: "NUM_LIGHTS" "0..2" [vs20]
  15. // SKIP: ( STRIPES == 0 ) && ( STRIPES_USE_NORMAL2 == 1 )
  16. // SKIP: ( EFFECT == 2 || EFFECT == 3 ) && ( VERTEXCOLOR == 1 || HALFLAMBERT == 1 || VERTEX_LIT == 1 || FULLBRIGHT == 1 || USE_STATIC_CONTROL_FLOW == 1 || BASETEXTURE2 == 1 || STRIPES == 1 || STRIPES_USE_NORMAL2 == 1 )
  17. // SKIP: ( EFFECT == 2 || EFFECT == 3 ) && ( SKINNING == 1 || DYNAMIC_LIGHT == 1 || STATIC_LIGHT == 1 || NUM_LIGHTS != 0 )
  18. // SKIP: ( FULLBRIGHT == 1 ) && ( VERTEX_LIT == 0 || DYNAMIC_LIGHT == 1 || STATIC_LIGHT == 1 || NUM_LIGHTS != 0 )
  19. #include "common_vs_fxc.h"
  20. static const bool g_bSkinning = SKINNING ? true : false;
  21. static const bool g_bHalfLambert = HALFLAMBERT ? true : false;
  22. const float4 g_vPyroParms1 : register( SHADER_SPECIFIC_CONST_0 );
  23. #define g_vStripeScale g_vPyroParms1.xyz
  24. #define g_flUnused1 g_vPyroParms1.w
  25. #if EFFECT == 0 || EFFECT == 1
  26. const float4 g_vPyroParms2 : register( SHADER_SPECIFIC_CONST_1 );
  27. #define g_vCanvasScale g_vPyroParms2.xyz
  28. #define g_flUnused2 g_vPyroParms2.w
  29. #endif
  30. const float4 cBlendMaskTexCoordTransform[ 2 ] : register( SHADER_SPECIFIC_CONST_10 ); // not contiguous with the rest!
  31. struct VS_INPUT
  32. {
  33. float4 vPos : POSITION;
  34. float4 vBoneWeights : BLENDWEIGHT;
  35. float4 vBoneIndices : BLENDINDICES;
  36. #if ( VERTEX_LIT == 1 )
  37. float4 vNormal : NORMAL;
  38. #endif
  39. float2 vBaseTexCoord : TEXCOORD0;
  40. float2 vLightmapTexCoord : TEXCOORD1;
  41. float2 vLightmapTexCoordOffset : TEXCOORD2;
  42. float3 vTangentS : TANGENT;
  43. float3 vTangentT : BINORMAL;
  44. float4 vColor : COLOR0;
  45. float3 vSpecular : COLOR1;
  46. };
  47. struct VS_OUTPUT
  48. {
  49. float4 vProjPos : POSITION;
  50. #if EFFECT == 0 || EFFECT == 1
  51. float4 vBaseAndSeamlessTexCoord : TEXCOORD0;
  52. #if ( STRIPES == 1 )
  53. float2 vStripeSeamlessTexCoord : TEXCOORD1;
  54. #endif
  55. #if ( VERTEX_LIT == 0 )
  56. float2 vLightmapBlendTexCoord : TEXCOORD2;
  57. #endif
  58. #if BASETEXTURE2 == 1
  59. float3 vBlendFactor : TEXCOORD3;
  60. #endif
  61. float4 worldPos_projPosZ : TEXCOORD4;
  62. float3 vWorldNormal : TEXCOORD5;
  63. float4 vVertexColor : COLOR;
  64. #else
  65. float2 vBaseTexCoord : TEXCOORD0;
  66. #endif
  67. };
  68. VS_OUTPUT main( const VS_INPUT v )
  69. {
  70. VS_OUTPUT o;
  71. #if EFFECT == 0 || EFFECT == 1
  72. float4 vObjPosition = v.vPos;
  73. #if ( VERTEX_LIT == 1 )
  74. float3 vObjNormal;
  75. DecompressVertex_Normal( v.vNormal, vObjNormal );
  76. #else
  77. float3 vObjNormal = float3( 0.0, 0.0, 1.0 );
  78. #endif
  79. float3 vWorldNormal, vWorldPos;
  80. SkinPositionAndNormal( g_bSkinning, vObjPosition, vObjNormal, v.vBoneWeights, v.vBoneIndices, vWorldPos, vWorldNormal );
  81. float4 vProjPos = mul( float4( vWorldPos, 1 ), cViewProj );
  82. o.vProjPos = vProjPos;
  83. vProjPos.z = dot( float4( vWorldPos, 1 ), cViewProjZ );
  84. o.worldPos_projPosZ = float4( vWorldPos, vProjPos.z );
  85. #if 0
  86. if ( !g_bSkinning )
  87. {
  88. vWorldNormal = vObjNormal;
  89. }
  90. #endif
  91. vWorldNormal = normalize( vWorldNormal );
  92. o.vWorldNormal = vWorldNormal;
  93. o.vBaseAndSeamlessTexCoord.xy = v.vBaseTexCoord;
  94. float flZFactor = vWorldPos.z * g_vCanvasScale.z;
  95. o.vBaseAndSeamlessTexCoord.zw = float2( vWorldPos.x + flZFactor, vWorldPos.y - flZFactor ) * g_vCanvasScale.xy;
  96. #if ( STRIPES == 1 )
  97. float3 vWorldStripeCoord = vWorldPos * g_vStripeScale;
  98. o.vStripeSeamlessTexCoord.xy = vWorldStripeCoord.yz + vWorldStripeCoord.xz + vWorldStripeCoord.xy;
  99. #endif
  100. #if VERTEX_LIT == 0
  101. o.vLightmapBlendTexCoord.xy = v.vLightmapTexCoord;
  102. #endif
  103. #if BASETEXTURE2 == 1
  104. o.vBlendFactor.x = dot( v.vBaseTexCoord, cBlendMaskTexCoordTransform[ 0 ] ) + cBlendMaskTexCoordTransform[ 0 ].w;
  105. o.vBlendFactor.y = dot( v.vBaseTexCoord, cBlendMaskTexCoordTransform[ 1 ] ) + cBlendMaskTexCoordTransform[ 1 ].w;
  106. o.vBlendFactor.z = v.vColor.a;
  107. #endif
  108. #if VERTEXCOLOR == 1
  109. o.vVertexColor = v.vColor;
  110. #elif VERTEX_LIT == 1 && FULLBRIGHT == 0
  111. bool bDynamicLight = DYNAMIC_LIGHT ? true : false;
  112. bool bStaticLight = STATIC_LIGHT ? true : false;
  113. #if ( ( USE_STATIC_CONTROL_FLOW ) || defined ( SHADER_MODEL_VS_3_0 ) )
  114. {
  115. o.vVertexColor.xyz = DoLighting( vWorldPos, vWorldNormal, v.vSpecular, bStaticLight, bDynamicLight, g_bHalfLambert );
  116. }
  117. #else
  118. {
  119. o.vVertexColor.xyz = DoLightingUnrolled( vWorldPos, vWorldNormal, v.vSpecular, bStaticLight, bDynamicLight, g_bHalfLambert, NUM_LIGHTS );
  120. }
  121. #endif
  122. o.vVertexColor.a = 1.0f;
  123. #else
  124. o.vVertexColor = 1.0f;
  125. #endif
  126. #else
  127. o.vProjPos = v.vPos;
  128. o.vBaseTexCoord = v.vBaseTexCoord;
  129. #endif
  130. return o;
  131. }