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.

152 lines
5.0 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: "STATIC_LIGHT" "0..1"
  8. // DYNAMIC: "MORPHING" "0..1" [vs30]
  9. // DYNAMIC: "NUM_LIGHTS" "0..2" [vs20]
  10. // If using static control flow on Direct3D, we should use the NUM_LIGHTS=0 combo
  11. // SKIP: $USE_STATIC_CONTROL_FLOW && ( $NUM_LIGHTS > 0 ) [vs20]
  12. #include "vortwarp_vs20_helper.h"
  13. static const int g_FogType = DOWATERFOG;
  14. static const bool g_bSkinning = SKINNING ? true : false;
  15. const float4 cTeethLighting : register( SHADER_SPECIFIC_CONST_0 );
  16. #if INTRO
  17. const float4 const4 : register( SHADER_SPECIFIC_CONST_1 );
  18. #define g_Time const4.w
  19. #define modelOrigin const4.xyz
  20. #endif
  21. #ifdef SHADER_MODEL_VS_3_0
  22. // NOTE: cMorphTargetTextureDim.xy = target dimensions,
  23. // cMorphTargetTextureDim.z = 4tuples/morph
  24. const float3 cMorphTargetTextureDim : register( SHADER_SPECIFIC_CONST_6 );
  25. const float4 cMorphSubrect : register( SHADER_SPECIFIC_CONST_7 );
  26. sampler2D morphSampler : register( D3DVERTEXTEXTURESAMPLER0, s0 );
  27. #endif
  28. struct VS_INPUT
  29. {
  30. // This is all of the stuff that we ever use.
  31. float4 vPos : POSITION;
  32. float4 vBoneWeights : BLENDWEIGHT;
  33. float4 vBoneIndices : BLENDINDICES;
  34. float4 vNormal : NORMAL;
  35. float2 vTexCoord0 : TEXCOORD0;
  36. float4 vUserData : TANGENT; // Sign for cross product in w
  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. float4 worldVertToEyeVector_Darkening : TEXCOORD1;
  52. float3x3 tangentSpaceTranspose : TEXCOORD2;
  53. // second row : TEXCOORD3;
  54. // third row : TEXCOORD4;
  55. float4 worldPos_projPosZ : TEXCOORD5;
  56. float2 lightAtten01 : TEXCOORD6;
  57. float2 lightAtten23 : TEXCOORD7;
  58. };
  59. VS_OUTPUT main( const VS_INPUT v )
  60. {
  61. VS_OUTPUT o = ( VS_OUTPUT )0;
  62. float4 vPosition = v.vPos;
  63. float3 vNormal;
  64. float4 vTangent;
  65. DecompressVertex_NormalTangent( v.vNormal, v.vUserData, vNormal, vTangent );
  66. #if !defined( SHADER_MODEL_VS_3_0 ) || !MORPHING
  67. ApplyMorph( v.vPosFlex, v.vNormalFlex, vPosition.xyz, vNormal, vTangent.xyz );
  68. #else
  69. ApplyMorph( morphSampler, cMorphTargetTextureDim, cMorphSubrect, v.vVertexID, float3( 0, 0, 0 ),
  70. vPosition.xyz, vNormal, vTangent.xyz );
  71. #endif
  72. // Perform skinning
  73. float3 worldNormal, worldPos, worldTangentS, worldTangentT;
  74. SkinPositionNormalAndTangentSpace( g_bSkinning, vPosition, vNormal, vTangent,
  75. v.vBoneWeights, v.vBoneIndices, worldPos,
  76. worldNormal, worldTangentS, worldTangentT );
  77. #if INTRO
  78. WorldSpaceVertexProcess( g_Time, modelOrigin, worldPos, worldNormal, worldTangentS, worldTangentT );
  79. #endif
  80. // Always normalize since flex path is controlled by runtime
  81. // constant not a shader combo and will always generate the normalization
  82. worldNormal = normalize( worldNormal );
  83. worldTangentS = normalize( worldTangentS );
  84. worldTangentT = normalize( worldTangentT );
  85. // Transform into projection space
  86. float4 vProjPos = mul( float4( worldPos, 1 ), cViewProj );
  87. o.projPos = vProjPos;
  88. vProjPos.z = dot( float4( worldPos, 1 ), cViewProjZ );
  89. o.worldPos_projPosZ = float4( worldPos, vProjPos.z );
  90. #if !defined( _X360 )
  91. // Set fixed-function fog factor
  92. o.fog = CalcFog( worldPos, vProjPos, g_FogType );
  93. #endif
  94. // Needed for specular
  95. o.worldVertToEyeVector_Darkening.xyz = cEyePos - worldPos;
  96. // Special darkening of lights for mouth open/close
  97. o.worldVertToEyeVector_Darkening.w = cTeethLighting.w * saturate( dot( worldNormal, cTeethLighting.xyz ) );;
  98. // Scalar light attenuation (mouth darkening applied in pixel shader)
  99. #if defined( SHADER_MODEL_VS_2_0 ) && ( !USE_STATIC_CONTROL_FLOW )
  100. o.lightAtten01.xy = float2(0,0);
  101. o.lightAtten23.xy = float2(0,0);
  102. #if ( NUM_LIGHTS > 0 )
  103. o.lightAtten01.x = GetVertexAttenForLight( worldPos, 0, false );
  104. #endif
  105. #if ( NUM_LIGHTS > 1 )
  106. o.lightAtten01.y = GetVertexAttenForLight( worldPos, 1, false );
  107. #endif
  108. #if ( NUM_LIGHTS > 2 )
  109. o.lightAtten23.x = GetVertexAttenForLight( worldPos, 2, false );
  110. #endif
  111. #if ( NUM_LIGHTS > 3 )
  112. o.lightAtten23.y = GetVertexAttenForLight( worldPos, 3, false );
  113. #endif
  114. #else
  115. o.lightAtten01.x = GetVertexAttenForLight( worldPos, 0, true );
  116. o.lightAtten01.y = GetVertexAttenForLight( worldPos, 1, true );
  117. o.lightAtten23.x = GetVertexAttenForLight( worldPos, 2, true );
  118. o.lightAtten23.y = GetVertexAttenForLight( worldPos, 3, true );
  119. #endif
  120. o.baseTexCoord = v.vTexCoord0;
  121. // Tangent space transform
  122. o.tangentSpaceTranspose[0] = float3( worldTangentS.x, worldTangentT.x, worldNormal.x );
  123. o.tangentSpaceTranspose[1] = float3( worldTangentS.y, worldTangentT.y, worldNormal.y );
  124. o.tangentSpaceTranspose[2] = float3( worldTangentS.z, worldTangentT.z, worldNormal.z );
  125. return o;
  126. }