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.

127 lines
3.8 KiB

  1. //======= Copyright � 1996-2006, Valve Corporation, All rights reserved. ======
  2. // STATIC: "INTRO" "0..1"
  3. // STATIC: "USE_STATIC_CONTROL_FLOW" "0..1" [vs20]
  4. // DYNAMIC: "COMPRESSED_VERTS" "0..1"
  5. // DYNAMIC: "DOWATERFOG" "0..1"
  6. // DYNAMIC: "SKINNING" "0..1"
  7. // DYNAMIC: "DYNAMIC_LIGHT" "0..1"
  8. // DYNAMIC: "STATIC_LIGHT" "0..1"
  9. // DYNAMIC: "MORPHING" "0..1" [vs30]
  10. // DYNAMIC: "NUM_LIGHTS" "0..2" [vs20]
  11. // If using static control flow on Direct3D, we should use the NUM_LIGHTS=0 combo
  12. // SKIP: $USE_STATIC_CONTROL_FLOW && ( $NUM_LIGHTS > 0 ) [vs20]
  13. #include "vortwarp_vs20_helper.h"
  14. static const int g_FogType = DOWATERFOG;
  15. static const bool g_bSkinning = SKINNING ? true : false;
  16. const float4 cTeethLighting : register( SHADER_SPECIFIC_CONST_0 );
  17. #if INTRO
  18. const float4 const4 : register( SHADER_SPECIFIC_CONST_1 );
  19. #define g_Time const4.w
  20. #define modelOrigin const4.xyz
  21. #endif
  22. #ifdef SHADER_MODEL_VS_3_0
  23. // NOTE: cMorphTargetTextureDim.xy = target dimensions,
  24. // cMorphTargetTextureDim.z = 4tuples/morph
  25. const float3 cMorphTargetTextureDim : register( SHADER_SPECIFIC_CONST_6 );
  26. const float4 cMorphSubrect : register( SHADER_SPECIFIC_CONST_7 );
  27. sampler2D morphSampler : register( D3DVERTEXTEXTURESAMPLER0, s0 );
  28. #endif
  29. struct VS_INPUT
  30. {
  31. // This is all of the stuff that we ever use.
  32. float4 vPos : POSITION;
  33. float4 vBoneWeights : BLENDWEIGHT;
  34. float4 vBoneIndices : BLENDINDICES;
  35. float4 vNormal : NORMAL;
  36. float2 vTexCoord0 : TEXCOORD0;
  37. // Position and normal/tangent deltas
  38. float3 vPosFlex : POSITION1;
  39. float3 vNormalFlex : NORMAL1;
  40. #ifdef SHADER_MODEL_VS_3_0
  41. float vVertexID : POSITION2;
  42. #endif
  43. };
  44. struct VS_OUTPUT
  45. {
  46. float4 projPos : POSITION;
  47. #if !defined( _X360 )
  48. float fog : FOG;
  49. #endif
  50. float2 baseTexCoord : TEXCOORD0;
  51. float3 vertAtten : TEXCOORD1;
  52. float4 worldPos_projPosZ : TEXCOORD7; // Necessary for pixel fog
  53. };
  54. VS_OUTPUT main( const VS_INPUT v )
  55. {
  56. VS_OUTPUT o = ( VS_OUTPUT )0;
  57. bool bDynamicLight = DYNAMIC_LIGHT ? true : false;
  58. bool bStaticLight = STATIC_LIGHT ? true : false;
  59. float4 vPosition = v.vPos;
  60. float3 vNormal;
  61. DecompressVertex_Normal( v.vNormal, vNormal );
  62. #if !defined( SHADER_MODEL_VS_3_0 ) || !MORPHING
  63. ApplyMorph( v.vPosFlex, v.vNormalFlex, vPosition.xyz, vNormal );
  64. #else
  65. ApplyMorph( morphSampler, cMorphTargetTextureDim, cMorphSubrect, v.vVertexID, float3( 0, 0, 0 ), vPosition.xyz, vNormal );
  66. #endif
  67. // Normalize the flexed normal
  68. vNormal.xyz = normalize( vNormal.xyz );
  69. // Transform the position
  70. float3 worldPos, worldNormal;
  71. SkinPositionAndNormal( g_bSkinning, vPosition, vNormal, v.vBoneWeights, v.vBoneIndices, worldPos, worldNormal );
  72. #if INTRO
  73. float3 dummy = float3( 0.0f, 0.0f, 0.0f );
  74. WorldSpaceVertexProcess( g_Time, modelOrigin, worldPos, worldNormal, dummy, dummy );
  75. #endif
  76. // Transform into projection space
  77. float4 vProjPos = mul( float4( worldPos, 1 ), cViewProj );
  78. o.projPos = vProjPos;
  79. vProjPos.z = dot( float4( worldPos, 1 ), cViewProjZ );
  80. o.worldPos_projPosZ = float4( worldPos.xyz, vProjPos.z );
  81. #if !defined( _X360 )
  82. // Set fixed-function fog factor
  83. o.fog = CalcFog( worldPos, vProjPos, g_FogType );
  84. #endif
  85. // Compute lighting
  86. #if ( USE_STATIC_CONTROL_FLOW ) || defined ( SHADER_MODEL_VS_3_0 )
  87. float3 linearColor = DoLighting( worldPos, worldNormal, float3(0.0f, 0.0f, 0.0f), bStaticLight, bDynamicLight, false );
  88. #else
  89. float3 linearColor = DoLightingUnrolled( worldPos, worldNormal, float3(0.0f, 0.0f, 0.0f), bStaticLight, bDynamicLight, false, NUM_LIGHTS );
  90. #endif
  91. // Forward vector
  92. float3 vForward = cTeethLighting.xyz;
  93. float fIllumFactor = cTeethLighting.w;
  94. // Darken by forward dot normal and illumination factor
  95. linearColor *= fIllumFactor * saturate( dot( worldNormal, vForward ) );
  96. o.vertAtten = linearColor;
  97. o.baseTexCoord = v.vTexCoord0;
  98. return o;
  99. }