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.

81 lines
2.6 KiB

  1. // DYNAMIC: "DOWATERFOG" "0..1"
  2. // DYNAMIC: "SKINNING" "0..1"
  3. #include "common_vs_fxc.h"
  4. static const bool g_bSkinning = SKINNING ? true : false;
  5. static const int g_FogType = DOWATERFOG;
  6. const float4 cShadowTextureMatrix[3] : register( SHADER_SPECIFIC_CONST_0 );
  7. const float4 cTexOrigin : register( SHADER_SPECIFIC_CONST_3 );
  8. const float4 cTexScale : register( SHADER_SPECIFIC_CONST_4 );
  9. // { Shadow falloff offset, 1/Shadow distance, Shadow scale, 0 }
  10. const float3 cShadowConstants : register( SHADER_SPECIFIC_CONST_5 );
  11. #define flShadowFalloffOffset cShadowConstants.x
  12. #define flOneOverShadowDist cShadowConstants.y
  13. #define flShadowScale cShadowConstants.z
  14. struct VS_INPUT
  15. {
  16. float4 vPos : POSITION;
  17. float3 vNormal : NORMAL;
  18. float4 vBoneWeights : BLENDWEIGHT;
  19. float4 vBoneIndices : BLENDINDICES;
  20. };
  21. struct VS_OUTPUT
  22. {
  23. float4 projPos : POSITION; // Projection-space position
  24. float3 T0 : TEXCOORD0; // PS wants this to be 4D but VS doesn't? (see original asm sources)
  25. float3 T1 : TEXCOORD1;
  26. float3 T2 : TEXCOORD2;
  27. float T3 : TEXCOORD3;
  28. float4 vColor : COLOR0;
  29. float fog : FOG;
  30. };
  31. VS_OUTPUT main( const VS_INPUT v )
  32. {
  33. VS_OUTPUT o;
  34. // Perform skinning
  35. float3 worldNormal, worldPos;
  36. SkinPositionAndNormal( g_bSkinning, v.vPos, v.vNormal, v.vBoneWeights, v.vBoneIndices, worldPos, worldNormal );
  37. // Transform into projection space
  38. o.projPos = mul( float4( worldPos, 1 ), cViewProj );
  39. // Compute fog
  40. o.fog = CalcFog( worldPos, o.projPos, g_FogType );
  41. // Transform position into texture space (from 0 to 1)
  42. float3 vTexturePos;
  43. vTexturePos.x = dot( worldPos.xyz, cShadowTextureMatrix[0].xyz );
  44. vTexturePos.y = dot( worldPos.xyz, cShadowTextureMatrix[1].xyz );
  45. vTexturePos.z = dot( worldPos.xyz, cShadowTextureMatrix[2].xyz );
  46. // Figure out the shadow fade amount
  47. float flShadowFade = ( vTexturePos.z - flShadowFalloffOffset ) * flOneOverShadowDist;
  48. // Offset it into the texture
  49. o.T0 = vTexturePos * cTexScale + cTexOrigin;
  50. // We're doing clipping by using texkill
  51. o.T1.xyz = vTexturePos.xyz; // Also clips when shadow z < 0 !
  52. o.T2.xyz = float3( 1.0f, 1.0f, 1.0f ) - vTexturePos.xyz;
  53. o.T2.z = 1.0f - flShadowFade; // Clips when shadow z > shadow distance
  54. // We're doing backface culling by using texkill also (wow yucky)
  55. // --------------------------------------------------------------
  56. // Transform z component of normal in texture space
  57. // If it's negative, then don't draw the pixel
  58. o.T3 = dot( worldNormal, -cShadowTextureMatrix[2] );
  59. // Shadow color, falloff
  60. o.vColor.xyz = cModulationColor.xyz;
  61. o.vColor.w = flShadowFade * flShadowScale;
  62. return o;
  63. }