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.

145 lines
5.2 KiB

  1. //======= Copyright � 1996-2006, Valve Corporation, All rights reserved. ======
  2. // $SHADER_SPECIFIC_CONST_0 = eyeball origin
  3. // $SHADER_SPECIFIC_CONST_1 = eyeball up * 0.5
  4. // $SHADER_SPECIFIC_CONST_2 = iris projection U
  5. // $SHADER_SPECIFIC_CONST_3 = iris projection V
  6. // $SHADER_SPECIFIC_CONST_4 = glint projection U
  7. // $SHADER_SPECIFIC_CONST_5 = glint projection V
  8. //=============================================================================
  9. // STATIC: "INTRO" "0..1"
  10. // STATIC: "HALFLAMBERT" "0..1"
  11. // STATIC: "USE_STATIC_CONTROL_FLOW" "0..1" [vs20]
  12. // DYNAMIC: "COMPRESSED_VERTS" "0..1"
  13. // DYNAMIC: "SKINNING" "0..1"
  14. // DYNAMIC: "DOWATERFOG" "0..1"
  15. // DYNAMIC: "DYNAMIC_LIGHT" "0..1"
  16. // DYNAMIC: "STATIC_LIGHT" "0..1"
  17. // DYNAMIC: "MORPHING" "0..1" [vs30]
  18. // DYNAMIC: "NUM_LIGHTS" "0..2" [vs20]
  19. // If using static control flow on Direct3D, we should use the NUM_LIGHTS=0 combo
  20. // SKIP: $USE_STATIC_CONTROL_FLOW && ( $NUM_LIGHTS > 0 ) [vs20]
  21. #include "vortwarp_vs20_helper.h"
  22. static const int g_bSkinning = SKINNING ? true : false;
  23. static const int g_FogType = DOWATERFOG;
  24. static const bool g_bHalfLambert = HALFLAMBERT ? true : false;
  25. const float3 cEyeOrigin : register( SHADER_SPECIFIC_CONST_0 );
  26. const float3 cHalfEyeballUp : register( SHADER_SPECIFIC_CONST_1 );
  27. const float4 cIrisProjectionU : register( SHADER_SPECIFIC_CONST_2 );
  28. const float4 cIrisProjectionV : register( SHADER_SPECIFIC_CONST_3 );
  29. const float4 cGlintProjectionU : register( SHADER_SPECIFIC_CONST_4 );
  30. const float4 cGlintProjectionV : register( SHADER_SPECIFIC_CONST_5 );
  31. #if INTRO
  32. const float4 const4 : register( SHADER_SPECIFIC_CONST_6 );
  33. #define g_Time const4.w
  34. #define modelOrigin const4.xyz
  35. #endif
  36. #ifdef SHADER_MODEL_VS_3_0
  37. // NOTE: cMorphTargetTextureDim.xy = target dimensions,
  38. // cMorphTargetTextureDim.z = 4tuples/morph
  39. const float3 cMorphTargetTextureDim : register( SHADER_SPECIFIC_CONST_7 );
  40. const float4 cMorphSubrect : register( SHADER_SPECIFIC_CONST_8 );
  41. sampler2D morphSampler : register( D3DVERTEXTEXTURESAMPLER0, s0 );
  42. #endif
  43. struct VS_INPUT
  44. {
  45. float4 vPos : POSITION; // Position
  46. float4 vBoneWeights : BLENDWEIGHT; // Skin weights
  47. float4 vBoneIndices : BLENDINDICES; // Skin indices
  48. float4 vTexCoord0 : TEXCOORD0; // Base (sclera) texture coordinates
  49. float3 vPosFlex : POSITION1; // Delta positions for flexing
  50. #ifdef SHADER_MODEL_VS_3_0
  51. float vVertexID : POSITION2;
  52. #endif
  53. };
  54. struct VS_OUTPUT
  55. {
  56. float4 projPos : POSITION; // Projection-space position
  57. #if !defined( _X360 )
  58. float fog : FOG; // Fixed-function fog factor
  59. #endif
  60. float2 baseTC : TEXCOORD0; // Base texture coordinate
  61. float2 irisTC : TEXCOORD1; // Iris texture coordinates
  62. float2 glintTC : TEXCOORD2; // Glint texture coordinates
  63. float3 vColor : TEXCOORD3; // Vertex-lit color
  64. float4 worldPos_projPosZ : TEXCOORD7; // Necessary for pixel fog
  65. };
  66. VS_OUTPUT main( const VS_INPUT v )
  67. {
  68. VS_OUTPUT o;
  69. bool bDynamicLight = DYNAMIC_LIGHT ? true : false;
  70. bool bStaticLight = STATIC_LIGHT ? true : false;
  71. float4 vPosition = v.vPos;
  72. float3 dummy = v.vPos.xyz; // dummy values that can't be optimized out
  73. #if !defined( SHADER_MODEL_VS_3_0 ) || !MORPHING
  74. ApplyMorph( v.vPosFlex, vPosition.xyz );
  75. #else
  76. ApplyMorph( morphSampler, cMorphTargetTextureDim, cMorphSubrect, v.vVertexID, dummy, vPosition.xyz );
  77. #endif
  78. // Transform the position and dummy normal (not doing the dummy normal causes invariance issues with the flashlight!)
  79. float3 worldNormal, worldPos;
  80. SkinPositionAndNormal(
  81. g_bSkinning,
  82. vPosition, dummy,
  83. v.vBoneWeights, v.vBoneIndices,
  84. worldPos, worldNormal );
  85. #if INTRO
  86. WorldSpaceVertexProcess( g_Time, modelOrigin, worldPos, dummy, dummy, dummy );
  87. #endif
  88. // Transform into projection space
  89. float4 vProjPos = mul( float4( worldPos, 1 ), cViewProj );
  90. o.projPos = vProjPos;
  91. vProjPos.z = dot( float4( worldPos, 1 ), cViewProjZ );
  92. o.worldPos_projPosZ = float4( worldPos.xyz, vProjPos.z );
  93. #if !defined( _X360 )
  94. // Set fixed-function fog factor
  95. o.fog = CalcFog( worldPos, vProjPos, g_FogType );
  96. #endif
  97. // Normal = (Pos - Eye origin) - just step on dummy normal created above
  98. worldNormal = worldPos - cEyeOrigin;
  99. // Normal -= 0.5f * (Normal dot Eye Up) * Eye Up
  100. float normalDotUp = -dot( worldNormal, cHalfEyeballUp) * 0.5f;
  101. worldNormal = normalize(normalDotUp * cHalfEyeballUp + worldNormal);
  102. // Vertex lighting
  103. #if ( USE_STATIC_CONTROL_FLOW || defined ( SHADER_MODEL_VS_3_0 ) )
  104. o.vColor = DoLighting( worldPos, worldNormal, float3(0.0f, 0.0f, 0.0f), bStaticLight, bDynamicLight, g_bHalfLambert );
  105. #else
  106. o.vColor = DoLightingUnrolled( worldPos, worldNormal, float3(0.0f, 0.0f, 0.0f), bStaticLight, bDynamicLight, g_bHalfLambert, NUM_LIGHTS );
  107. #endif
  108. // Texture 0 is the base texture
  109. // Texture 1 is a planar projection used for the iris
  110. // Texture 2 is a planar projection used for the glint
  111. o.baseTC = v.vTexCoord0;
  112. o.irisTC.x = dot( cIrisProjectionU, float4(worldPos, 1) );
  113. o.irisTC.y = dot( cIrisProjectionV, float4(worldPos, 1) );
  114. o.glintTC.x = dot( cGlintProjectionU, float4(worldPos, 1) );
  115. o.glintTC.y = dot( cGlintProjectionV, float4(worldPos, 1) );
  116. return o;
  117. }