Counter Strike : Global Offensive Source Code
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.

107 lines
3.3 KiB

  1. //========== Copyright (c) Valve Corporation, All rights reserved. ==========//
  2. // STATIC: "WIDEN_TIPS" "0..1"
  3. // DYNAMIC: "COMPRESSED_VERTS" "0..1"
  4. // Includes
  5. #include "common_vs_fxc.h"
  6. // Globals
  7. const float4 g_flWidthParams : register( SHADER_SPECIFIC_CONST_0 );
  8. #define g_flWidthExp g_flWidthParams.x
  9. #define g_flWidthScale g_flWidthParams.y
  10. #define g_flWidthBias g_flWidthParams.z
  11. #define g_flUVScale g_flWidthParams.w
  12. const float3 g_vEyePos : register( SHADER_SPECIFIC_CONST_1 );
  13. //#define g_flUVScale 0.05
  14. /*
  15. #define g_flWidthExp 4
  16. #define g_flWidthScale 5
  17. #define g_flWidthBias 0.2
  18. */
  19. /*
  20. #define g_flWidthExp 0.5
  21. #define g_flWidthScale 1.0
  22. #define g_flWidthBias 0.0
  23. */
  24. // Structs
  25. struct VS_INPUT
  26. {
  27. float4 vTexCoord0 : TEXCOORD0; // distance to arm root, V texcoord, rel. position along arm, and t
  28. float4 vBezierCage0 : TEXCOORD1; // Bezier positions. 4th position in w coords of the first 3
  29. float4 vBezierCage1 : TEXCOORD2;
  30. float4 vBezierCage2 : TEXCOORD3;
  31. float4 vColor : TEXCOORD4;
  32. };
  33. struct VS_OUTPUT
  34. {
  35. float4 vProjPosition : POSITION; // Projection-space position
  36. float4 vWorldNormal : TEXCOORD0; // w is proj. z coord (for depth stuff)
  37. float3 vWorldTangent : TEXCOORD1;
  38. float3 vWorldBinormal : TEXCOORD2;
  39. float3 vWorldPos : TEXCOORD3;
  40. float3 vUV : TEXCOORD4; // z is normalized dist from root
  41. float4 vColor : TEXCOORD5;
  42. };
  43. // Main
  44. VS_OUTPUT main( const VS_INPUT i )
  45. {
  46. VS_OUTPUT o;
  47. float3 vBezierCage3 = float3( i.vBezierCage0.w, i.vBezierCage1.w, i.vBezierCage2.w );
  48. // bezier evaluation
  49. float3 v0 = lerp( i.vBezierCage0.xyz, i.vBezierCage1.xyz, i.vTexCoord0.w );
  50. float3 v1 = lerp( i.vBezierCage1.xyz, i.vBezierCage2.xyz, i.vTexCoord0.w );
  51. float3 v2 = lerp( i.vBezierCage2.xyz, vBezierCage3.xyz, i.vTexCoord0.w );
  52. v0 = lerp( v0, v1, i.vTexCoord0.w );
  53. v1 = lerp( v1, v2, i.vTexCoord0.w );
  54. float3 vWorldPos = lerp( v0, v1, i.vTexCoord0.w ); // world position
  55. // eval bezier derivative to get a tangent
  56. v0 = lerp( i.vBezierCage1.xyz - i.vBezierCage0.xyz, i.vBezierCage2.xyz - i.vBezierCage1.xyz, i.vTexCoord0.w );
  57. v1 = lerp( i.vBezierCage2.xyz - i.vBezierCage1.xyz, vBezierCage3.xyz - i.vBezierCage2.xyz, i.vTexCoord0.w );
  58. v0 = lerp( v0, v1, i.vTexCoord0.w );
  59. float3 vWorldTan = normalize( v0 );
  60. float flDistAlongArm = i.vTexCoord0.z;
  61. //float flTotalArmLength = i.vTexCoord0.x / ( i.vTexCoord0.z - 1.0 );
  62. float flWidthScale = g_flWidthScale + i.vColor.a * 0.5;
  63. #if WIDEN_TIPS == 1
  64. float flWidth = g_flWidthBias + flWidthScale * pow( 1.0 - flDistAlongArm, g_flWidthExp );
  65. #else
  66. // regular tapering
  67. float flWidth = g_flWidthBias + flWidthScale * pow( flDistAlongArm, g_flWidthExp );
  68. #endif
  69. //flWidth = flDistAlongArm;
  70. // quad expansion
  71. float3 vView = normalize( g_vEyePos - vWorldPos );
  72. float3 vSpan = cross( vView, vWorldTan );
  73. vWorldPos += vSpan * flWidth * 2.0 * ( i.vTexCoord0.y - 0.5 );
  74. // Transform into projection space
  75. float4 vProjPosition = mul( float4( vWorldPos, 1.0f ), cViewProj );
  76. o.vProjPosition = vProjPosition;
  77. o.vColor = i.vColor;
  78. o.vWorldPos.xyz = vWorldPos.xyz;
  79. o.vWorldNormal.xyz = normalize( vView - dot( vView, vWorldTan ) * vWorldTan );
  80. o.vWorldTangent.xyz = vWorldTan;
  81. o.vWorldBinormal.xyz = vSpan;
  82. o.vWorldNormal.w = vProjPosition.z;
  83. o.vUV.xy = i.vTexCoord0.xy * float2( g_flUVScale, 1.0 );
  84. o.vUV.x = 1.0 - flDistAlongArm;
  85. o.vUV.z = flDistAlongArm;
  86. return o;
  87. }