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.

68 lines
1.8 KiB

  1. //========= Copyright � 1996-2006, Valve Corporation, All rights reserved. ============//
  2. // DYNAMIC: "COMPRESSED_VERTS" "0..1"
  3. // DYNAMIC: "SKINNING" "0..1"
  4. // DYNAMIC: "MORPHING" "0..1" [vs30]
  5. // Includes
  6. #include "common_vs_fxc.h"
  7. // Globals
  8. static const bool g_bSkinning = SKINNING ? true : false;
  9. #ifdef SHADER_MODEL_VS_3_0
  10. // NOTE: cMorphTargetTextureDim.xy = target dimensions,
  11. // cMorphTargetTextureDim.z = 4tuples/morph
  12. const float3 cMorphTargetTextureDim : register( SHADER_SPECIFIC_CONST_6 );
  13. const float4 cMorphSubrect : register( SHADER_SPECIFIC_CONST_7 );
  14. sampler2D morphSampler : register( D3DVERTEXTEXTURESAMPLER0, s0 );
  15. #endif
  16. // Structs
  17. struct VS_INPUT
  18. {
  19. float4 vPos : POSITION; // Position
  20. float4 vBoneWeights : BLENDWEIGHT; // Skin weights
  21. float4 vBoneIndices : BLENDINDICES; // Skin indices
  22. float4 vTexCoord0 : TEXCOORD0; // Base texture coordinates
  23. float3 vPosFlex : POSITION1; // Delta positions for flexing
  24. #ifdef SHADER_MODEL_VS_3_0
  25. float vVertexID : POSITION2;
  26. #endif
  27. };
  28. struct VS_OUTPUT
  29. {
  30. float4 vProjPosition : POSITION; // Projection-space position
  31. float2 vTexCoord0 : TEXCOORD0;
  32. };
  33. // Main
  34. VS_OUTPUT main( const VS_INPUT i )
  35. {
  36. VS_OUTPUT o;
  37. float4 vObjPosition = i.vPos;
  38. #if !defined( SHADER_MODEL_VS_3_0 ) || !MORPHING
  39. ApplyMorph( i.vPosFlex, vObjPosition.xyz );
  40. #else
  41. ApplyMorph( morphSampler, cMorphTargetTextureDim, cMorphSubrect, i.vVertexID, float3( 0, 0, 0 ), vObjPosition.xyz );
  42. #endif
  43. // Transform the position
  44. float3 vWorldPosition = { 0.0f, 0.0f, 0.0f };
  45. SkinPosition( g_bSkinning, vObjPosition, i.vBoneWeights, i.vBoneIndices, vWorldPosition );
  46. // Transform into projection space
  47. float4 vProjPosition = mul( float4( vWorldPosition, 1.0f ), cViewProj );
  48. o.vProjPosition = vProjPosition;
  49. // Pass through tex coords
  50. o.vTexCoord0.xy = i.vTexCoord0.xy;
  51. return o;
  52. }