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.

91 lines
2.8 KiB

  1. //===================== Copyright (c) Valve Corporation. All Rights Reserved. ======================
  2. //
  3. // Example vertex shader that can be applied to models
  4. //
  5. //==================================================================================================
  6. // DYNAMIC: "COMPRESSED_VERTS" "0..1"
  7. // DYNAMIC: "DOWATERFOG" "0..1"
  8. // DYNAMIC: "SKINNING" "0..1"
  9. // DYNAMIC: "LIGHTING_PREVIEW" "0..1"
  10. // DYNAMIC: "NUM_LIGHTS" "0..4"
  11. #include "common_vs_fxc.h"
  12. static const bool g_bSkinning = SKINNING ? true : false;
  13. static const int g_FogType = DOWATERFOG;
  14. const float4 cBaseTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_0 );
  15. //-----------------------------------------------------------------------------
  16. // Input vertex format
  17. //-----------------------------------------------------------------------------
  18. struct VS_INPUT
  19. {
  20. // This is all of the stuff that we ever use.
  21. float4 vPos : POSITION;
  22. float4 vBoneWeights : BLENDWEIGHT;
  23. float4 vBoneIndices : BLENDINDICES;
  24. float4 vNormal : NORMAL;
  25. float2 vTexCoord0 : TEXCOORD0;
  26. };
  27. struct VS_OUTPUT
  28. {
  29. // Stuff that isn't seen by the pixel shader
  30. float4 projPosSetup : POSITION;
  31. float fog : FOG;
  32. // Stuff that is seen by the pixel shader
  33. float2 baseTexCoord : TEXCOORD0;
  34. float4 lightAtten : TEXCOORD1;
  35. float3 worldNormal : TEXCOORD2;
  36. float3 worldPos : TEXCOORD3;
  37. float3 projPos : TEXCOORD4;
  38. };
  39. //-----------------------------------------------------------------------------
  40. // Main shader entry point
  41. //-----------------------------------------------------------------------------
  42. VS_OUTPUT main( const VS_INPUT v )
  43. {
  44. VS_OUTPUT o = ( VS_OUTPUT )0;
  45. float3 vNormal;
  46. DecompressVertex_Normal( v.vNormal, vNormal );
  47. float3 worldNormal, worldPos;
  48. SkinPositionAndNormal( g_bSkinning, v.vPos, vNormal, v.vBoneWeights, v.vBoneIndices, worldPos, worldNormal );
  49. // Transform into projection space
  50. float4 vProjPos = mul( float4( worldPos, 1 ), cViewProj );
  51. o.projPosSetup = vProjPos;
  52. vProjPos.z = dot( float4( worldPos, 1 ), cViewProjZ );
  53. o.projPos = vProjPos.xyz;
  54. o.fog = CalcFog( worldPos, vProjPos.xyz, g_FogType );
  55. // Needed for water fog alpha and diffuse lighting
  56. o.worldPos = worldPos;
  57. o.worldNormal = normalize( worldNormal );
  58. // Scalar attenuations for four lights
  59. o.lightAtten.xyz = float4(0,0,0,0);
  60. #if ( NUM_LIGHTS > 0 )
  61. o.lightAtten.x = GetVertexAttenForLight( worldPos, 0, false );
  62. #endif
  63. #if ( NUM_LIGHTS > 1 )
  64. o.lightAtten.y = GetVertexAttenForLight( worldPos, 1, false );
  65. #endif
  66. #if ( NUM_LIGHTS > 2 )
  67. o.lightAtten.z = GetVertexAttenForLight( worldPos, 2, false );
  68. #endif
  69. #if ( NUM_LIGHTS > 3 )
  70. o.lightAtten.w = GetVertexAttenForLight( worldPos, 3, false );
  71. #endif
  72. // Base texture coordinate transform
  73. o.baseTexCoord.x = dot( v.vTexCoord0, cBaseTexCoordTransform[0] );
  74. o.baseTexCoord.y = dot( v.vTexCoord0, cBaseTexCoordTransform[1] );
  75. return o;
  76. }