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.

130 lines
4.1 KiB

  1. #include "common_vs_fxc.h"
  2. #include "spline_fxc.h"
  3. // These are "0..0" for the splinecard case. We only use these combos in the spritecard case.
  4. // STATIC: "ADDBASETEXTURE2" "0..0"
  5. // STATIC: "EXTRACTGREENALPHA" "0..0"
  6. // STATIC: "DUALSEQUENCE" "0..0"
  7. // STATIC: "DEPTHBLEND" "0..0"
  8. // STATIC: "PACKED_INTERPOLATOR" "0..0"
  9. // These determine the format of VS_OUTPUT:
  10. // STATIC: "ANIMBLEND_OR_MAXLUMFRAMEBLEND1" "0..1"
  11. // DYNAMIC: "ORIENTATION" "0..3"
  12. #define ANIMBLEND ANIMBLEND_OR_MAXLUMFRAMEBLEND1
  13. #define MAXLUMFRAMEBLEND1 ANIMBLEND_OR_MAXLUMFRAMEBLEND1
  14. const float4x3 cModelView : register(SHADER_SPECIFIC_CONST_0);
  15. const float4x4 cProj : register(SHADER_SPECIFIC_CONST_3);
  16. const float4 SizeParms : register(SHADER_SPECIFIC_CONST_8);
  17. const float4 SizeParms2 : register(SHADER_SPECIFIC_CONST_9);
  18. #define MINIMUM_SIZE_FACTOR (SizeParms.x)
  19. #define MAXIMUM_SIZE_FACTOR (SizeParms.y)
  20. #define START_FADE_SIZE_FACTOR (SizeParms.z)
  21. #define END_FADE_SIZE_FACTOR (SizeParms.w)
  22. // alpha fade w/ distance
  23. #define START_FAR_FADE ( SizeParms2.x )
  24. #define FAR_FADE_FACTOR ( SizeParms2.y ) // alpha = 1-min(1,max(0, (dist-start_fade)*factor))
  25. #define ALPHATFADE ( SizeParms2.z )
  26. #define RADIUSTFADE ( SizeParms2.w )
  27. struct VS_INPUT
  28. {
  29. // This is all of the stuff that we ever use.
  30. float4 vTint : COLOR;
  31. float4 vParms : POSITION; // T V side_id
  32. float4 vSplinePt0 : TEXCOORD0; // x y z rad
  33. float4 vSplinePt1 : TEXCOORD1; // x y z rad
  34. float4 vSplinePt2 : TEXCOORD2; // x y z rad
  35. float4 vSplinePt3 : TEXCOORD3; // x y z rad
  36. float4 vTexCoordRange : TEXCOORD4; // u0 v0 u1 v1
  37. float4 vEndPointColor : TEXCOORD5; // r g b a at p1
  38. #if ORIENTATION == 3
  39. float3 vNormal0 : TEXCOORD6; // normal at p0
  40. float3 vNormal1 : TEXCOORD7; // normal at p1
  41. #endif
  42. };
  43. // VS_OUTPUT in a common file.
  44. #include "common_spritecard_fxc.h"
  45. // #define P0 float4( 0,0,0,40)
  46. // #define P1 float4( 0,0,100,40)
  47. // #define P2 float4( 0,0,200,40)
  48. // #define P3 float4( 0,0,300,40)
  49. #define P0 (v.vSplinePt0)
  50. #define P1 (v.vSplinePt1)
  51. #define P2 (v.vSplinePt2)
  52. #define P3 (v.vSplinePt3)
  53. VS_OUTPUT main( const VS_INPUT v )
  54. {
  55. VS_OUTPUT o;
  56. o.vecOutlineTint = 1;
  57. // posrad.xyz is worldspace position and posrad.w is worldspace diameter.
  58. float4 posrad =
  59. CatmullRomSpline( P0, P1, P2, P3, v.vParms.x );
  60. posrad.w *= lerp( 1, RADIUSTFADE, v.vParms.x );
  61. float3 v2p = float3( 0, 0, 1 );
  62. if ( ORIENTATION == 0 )
  63. {
  64. v2p = posrad.xyz - cEyePos; // screen aligned
  65. }
  66. #if ( ORIENTATION == 3 ) // use normal
  67. v2p = lerp( v.vNormal0, v.vNormal1, v.vParms.x );
  68. #endif
  69. float3 tangent = DCatmullRomSpline3( P0, P1, P2, P3, v.vParms.x );
  70. float3 ofs = normalize( cross( v2p, normalize( tangent ) ) );
  71. posrad.xyz += ofs * ( posrad.w * ( v.vParms.z - .5 ) );
  72. o.projPos = mul( float4(posrad.xyz, 1.0f), cViewProj );
  73. #ifdef _PS3
  74. // Account for OpenGL's flipped y coordinate and expanded z range [-1,1] instead of [0,1]
  75. o.projPos.y = -o.projPos.y;
  76. o.projPos.z = 2.0f * o.projPos.z - o.projPos.w;
  77. #endif // _PS3
  78. o.texCoord0_1.wz = o.texCoord0_1.xy = float2( lerp( v.vTexCoordRange.z, v.vTexCoordRange.x, v.vParms.z ), lerp( v.vTexCoordRange.y, v.vTexCoordRange.w, v.vParms.y ) );
  79. float4 color1 = float4( GammaToLinear( v.vTint.rgb ), v.vTint.a );
  80. float4 color2 = float4( GammaToLinear( v.vEndPointColor.rgb ), v.vEndPointColor.a );
  81. o.argbcolor = lerp( color1, color2, v.vParms.x );
  82. o.argbcolor.a *= lerp( 1, ALPHATFADE, v.vParms.x );
  83. // Don't really need these in the splinecard case, but since we aren't typically fillrate limited with
  84. // spline cards (are we?), then go ahead and send it through.
  85. #if HAS_BLENDFACTOR0
  86. o.blendfactor0.xyzw = float4( 0.0f, 0.0f, 0.0f, 0.0f );
  87. #endif
  88. #if DEPTHBLEND
  89. #if defined( REVERSE_DEPTH_ON_X360 )
  90. o.vScreenPos_ReverseZ.xyzw = float4( 0.0f, 0.0f, 0.0f, 0.0f );
  91. #else
  92. o.vScreenPos.xyzw = float4( 0.0f, 0.0f, 0.0f, 0.0f );
  93. #endif
  94. #endif
  95. #if !defined( _X360 ) && !defined( SHADER_MODEL_VS_3_0 )
  96. {
  97. o.fog = CalcFixedFunctionFog( posrad.xyz, 0 );
  98. }
  99. #endif
  100. return o;
  101. }