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.

661 lines
28 KiB

  1. //===== Copyright (c) 1996-2007, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose: shader for drawing sprites as cards, with animation frame lerping
  4. //
  5. // $Header: $
  6. // $NoKeywords: $
  7. //===========================================================================//
  8. #include "BaseVSShader.h"
  9. #include "convar.h"
  10. // STDSHADER_DX9_DLL_EXPORT
  11. #include "spritecard_ps20.inc"
  12. #include "spritecard_ps20b.inc"
  13. #include "spritecard_vs20.inc"
  14. #include "splinecard_vs20.inc"
  15. #include "common_hlsl_cpp_consts.h"
  16. #include "tier0/icommandline.h" //command line
  17. // memdbgon must be the last include file in a .cpp file!!!
  18. #include "tier0/memdbgon.h"
  19. #define DEFAULT_PARTICLE_FEATHERING_ENABLED 1
  20. static ConVar mat_depthfeather_enable( "mat_depthfeather_enable", "1", FCVAR_DEVELOPMENTONLY );
  21. #if defined( CSTRIKE15 ) && defined( _X360 )
  22. static ConVar r_shader_srgbread( "r_shader_srgbread", "1", 0, "1 = use shader srgb texture reads, 0 = use HW" );
  23. #else
  24. static ConVar r_shader_srgbread( "r_shader_srgbread", "0", 0, "1 = use shader srgb texture reads, 0 = use HW" );
  25. #endif
  26. int GetDefaultDepthFeatheringValue( void ) //Allow the command-line to go against the default soft-particle value
  27. {
  28. static int iRetVal = -1;
  29. if ( iRetVal == -1 )
  30. {
  31. #if ( DEFAULT_PARTICLE_FEATHERING_ENABLED == 1 )
  32. {
  33. if ( CommandLine()->CheckParm( "-softparticlesdefaultoff" ) )
  34. iRetVal = 0;
  35. else
  36. iRetVal = 1;
  37. }
  38. #else
  39. {
  40. if ( CommandLine()->CheckParm( "-softparticlesdefaulton" ) )
  41. iRetVal = 1;
  42. else
  43. iRetVal = 0;
  44. }
  45. #endif
  46. }
  47. // On low end parts on the Mac, we reduce particles and shut off depth blending here
  48. static ConVarRef mat_reduceparticles( "mat_reduceparticles" );
  49. if ( mat_reduceparticles.GetBool() )
  50. {
  51. iRetVal = 0;
  52. }
  53. return iRetVal;
  54. }
  55. BEGIN_VS_SHADER_FLAGS( Spritecard, "Help for Spritecard", SHADER_NOT_EDITABLE )
  56. BEGIN_SHADER_PARAMS
  57. SHADER_PARAM( DEPTHBLEND, SHADER_PARAM_TYPE_INTEGER, "0", "fade at intersection boundaries" )
  58. SHADER_PARAM( SCENEDEPTH, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  59. SHADER_PARAM( DEPTHBLENDSCALE, SHADER_PARAM_TYPE_FLOAT, "50.0", "Amplify or reduce DEPTHBLEND fading. Lower values make harder edges." )
  60. SHADER_PARAM( INVERSEDEPTHBLEND, SHADER_PARAM_TYPE_BOOL, "0", "calculate 1-depthblendalpha so that sprites appear when they are near geometry" )
  61. SHADER_PARAM( ORIENTATION, SHADER_PARAM_TYPE_INTEGER, "0", "0 = always face camera, 1 = rotate around z, 2= parallel to ground 3=use normal 4=face camera POS" )
  62. SHADER_PARAM( AIMATCAMERA, SHADER_PARAM_TYPE_BOOL, "0", "Aim at camera using orientation type 1" )
  63. SHADER_PARAM( ADDBASETEXTURE2, SHADER_PARAM_TYPE_FLOAT, "0.0", "amount to blend second texture into frame by" )
  64. SHADER_PARAM( OVERBRIGHTFACTOR, SHADER_PARAM_TYPE_FLOAT, "1.0", "overbright factor for texture. For HDR effects.")
  65. SHADER_PARAM( DUALSEQUENCE, SHADER_PARAM_TYPE_INTEGER, "0", "blend two separate animated sequences.")
  66. SHADER_PARAM( SEQUENCE_BLEND_MODE, SHADER_PARAM_TYPE_INTEGER, "0", "defines the blend mode between the images un dual sequence particles. 0 = avg, 1=alpha from first, rgb from 2nd, 2= first over second" )
  67. SHADER_PARAM( MAXLUMFRAMEBLEND1, SHADER_PARAM_TYPE_INTEGER, "0", "instead of blending between animation frames for the first sequence, select pixels based upon max luminance" )
  68. SHADER_PARAM( MAXLUMFRAMEBLEND2, SHADER_PARAM_TYPE_INTEGER, "0", "instead of blending between animation frames for the 2nd sequence, select pixels based upon max luminance" )
  69. SHADER_PARAM( RAMPTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "if specified, then the red value of the image is used to index this ramp to produce the output color" )
  70. SHADER_PARAM( ZOOMANIMATESEQ2, SHADER_PARAM_TYPE_FLOAT, "1.0", "amount to gradually zoom between frames on the second sequence. 2.0 will double the size of a frame over its lifetime.")
  71. SHADER_PARAM( EXTRACTGREENALPHA, SHADER_PARAM_TYPE_INTEGER, "0", "grayscale data sitting in green/alpha channels")
  72. SHADER_PARAM( ADDOVERBLEND, SHADER_PARAM_TYPE_INTEGER, "0", "use ONE:INVSRCALPHA blending")
  73. SHADER_PARAM( ADDSELF, SHADER_PARAM_TYPE_FLOAT, "0.0", "amount of base texture to additively blend in" )
  74. SHADER_PARAM( BLENDFRAMES, SHADER_PARAM_TYPE_BOOL, "1", "whether or not to smoothly blend between animated frames" )
  75. SHADER_PARAM( MINSIZE, SHADER_PARAM_TYPE_FLOAT, "0.0", "minimum screen fractional size of particle")
  76. SHADER_PARAM( STARTFADESIZE, SHADER_PARAM_TYPE_FLOAT, "10.0", "screen fractional size to start fading particle out")
  77. SHADER_PARAM( ENDFADESIZE, SHADER_PARAM_TYPE_FLOAT, "20.0", "screen fractional size to finish fading particle out")
  78. SHADER_PARAM( MAXSIZE, SHADER_PARAM_TYPE_FLOAT, "20.0", "maximum screen fractional size of particle")
  79. SHADER_PARAM( USEINSTANCING, SHADER_PARAM_TYPE_BOOL, "1", "whether to use GPU vertex instancing (submit 1 vert per particle quad)")
  80. SHADER_PARAM( SPLINETYPE, SHADER_PARAM_TYPE_INTEGER, "0", "spline type 0 = none, 1=ctamull rom")
  81. SHADER_PARAM( MAXDISTANCE, SHADER_PARAM_TYPE_FLOAT, "100000.0", "maximum distance to draw particles at")
  82. SHADER_PARAM( FARFADEINTERVAL, SHADER_PARAM_TYPE_FLOAT, "400.0", "interval over which to fade out far away particles")
  83. SHADER_PARAM( SHADERSRGBREAD360, SHADER_PARAM_TYPE_BOOL, "0", "Simulate srgb read in shader code")
  84. SHADER_PARAM( ORIENTATIONMATRIX, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "Matrix used to orient in orientation mode #2" )
  85. SHADER_PARAM( MOD2X, SHADER_PARAM_TYPE_BOOL, "0", "whether or not to multiply the result of the pixel shader * 2 against the framebuffer" )
  86. SHADER_PARAM( ALPHATRAILFADE, SHADER_PARAM_TYPE_FLOAT, "1", "Amount to scale alpha by between start and end of trail/rope" )
  87. SHADER_PARAM( RADIUSTRAILFADE, SHADER_PARAM_TYPE_FLOAT, "1", "Amount to scale radis by between start and end of trail/rope" )
  88. SHADER_PARAM( SHADOWDEPTH,SHADER_PARAM_TYPE_INTEGER, "0", "writing to a shadow depth buffer" )
  89. SHADER_PARAM( OPAQUE, SHADER_PARAM_TYPE_BOOL, "0", "Are we opaque? (defaults to 0)" )
  90. SHADER_PARAM( CROPFACTOR,SHADER_PARAM_TYPE_VEC2, "[1 1]", "writing to a shadow depth buffer" )
  91. SHADER_PARAM( VERTEXCOLORLERP, SHADER_PARAM_TYPE_BOOL, "0", "Enable computing vertex color by interpolating two color based on vertex r color channel" )
  92. SHADER_PARAM( LERPCOLOR1, SHADER_PARAM_TYPE_VEC3, "[1 0 0]", "Lerp color 1" )
  93. SHADER_PARAM( LERPCOLOR2, SHADER_PARAM_TYPE_VEC3, "[0 1 0]", "Lerp color 2" )
  94. SHADER_PARAM( VERTEXFOGAMOUNT, SHADER_PARAM_TYPE_FLOAT, "1", "Amount of vertex fog to apply" )
  95. // distance outline control
  96. SHADER_PARAM( DISTANCEALPHA, SHADER_PARAM_TYPE_BOOL, "0", "Use distance-coded alpha generated from hi-res texture by vtex.")
  97. SHADER_PARAM( SOFTEDGES, SHADER_PARAM_TYPE_BOOL, "0", "Enable soft edges to distance coded textures.")
  98. SHADER_PARAM( EDGESOFTNESSSTART, SHADER_PARAM_TYPE_FLOAT, "0.6", "Start value for soft edges for distancealpha.");
  99. SHADER_PARAM( EDGESOFTNESSEND, SHADER_PARAM_TYPE_FLOAT, "0.5", "End value for soft edges for distancealpha.");
  100. SHADER_PARAM( OUTLINE, SHADER_PARAM_TYPE_BOOL, "0", "Enable outline for distance coded textures.")
  101. SHADER_PARAM( OUTLINECOLOR, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "color of outline for distance coded images." )
  102. SHADER_PARAM( OUTLINEALPHA, SHADER_PARAM_TYPE_FLOAT, "0.0", "alpha value for outline")
  103. SHADER_PARAM( OUTLINESTART0, SHADER_PARAM_TYPE_FLOAT, "0.0", "outer start value for outline")
  104. SHADER_PARAM( OUTLINESTART1, SHADER_PARAM_TYPE_FLOAT, "0.0", "inner start value for outline")
  105. SHADER_PARAM( OUTLINEEND0, SHADER_PARAM_TYPE_FLOAT, "0.0", "inner end value for outline")
  106. SHADER_PARAM( OUTLINEEND1, SHADER_PARAM_TYPE_FLOAT, "0.0", "outer end value for outline")
  107. SHADER_PARAM( PERPARTICLEOUTLINE, SHADER_PARAM_TYPE_BOOL, "0", "Allow per particle outline control" )
  108. SHADER_PARAM( MULOUTPUTBYALPHA, SHADER_PARAM_TYPE_BOOL, "0", "Multiply output RGB by output alpha to avoid precision problems" );
  109. SHADER_PARAM( INTENSITY, SHADER_PARAM_TYPE_FLOAT, "1.0", "Multiply output RGB by intensity factor" );
  110. END_SHADER_PARAMS
  111. SHADER_INIT_PARAMS()
  112. {
  113. INIT_FLOAT_PARM( MAXDISTANCE, 100000.0 );
  114. INIT_FLOAT_PARM( FARFADEINTERVAL, 400.0 );
  115. INIT_FLOAT_PARM( MAXSIZE, 20.0 );
  116. INIT_FLOAT_PARM( ENDFADESIZE, 20.0 );
  117. INIT_FLOAT_PARM( STARTFADESIZE, 10.0 );
  118. INIT_FLOAT_PARM( DEPTHBLENDSCALE, 50.0 );
  119. INIT_FLOAT_PARM( OVERBRIGHTFACTOR, 1.0 );
  120. INIT_FLOAT_PARM( ADDBASETEXTURE2, 0.0 );
  121. INIT_FLOAT_PARM( ADDSELF, 0.0 );
  122. INIT_FLOAT_PARM( ZOOMANIMATESEQ2, 0.0 );
  123. INIT_FLOAT_PARM( ALPHATRAILFADE, 1. );
  124. INIT_FLOAT_PARM( RADIUSTRAILFADE, 1. );
  125. INIT_FLOAT_PARM( VERTEXFOGAMOUNT, 0.0f );
  126. INIT_FLOAT_PARM( OUTLINEALPHA, 1.0 );
  127. if ( !params[ORIENTATIONMATRIX]->IsDefined() )
  128. {
  129. VMatrix mat;
  130. MatrixSetIdentity( mat );
  131. params[ORIENTATIONMATRIX]->SetMatrixValue( mat );
  132. }
  133. if ( !params[CROPFACTOR]->IsDefined() )
  134. {
  135. params[CROPFACTOR]->SetVecValue( 1.0f, 1.0f );
  136. }
  137. if ( !params[DEPTHBLEND]->IsDefined() )
  138. {
  139. params[ DEPTHBLEND ]->SetIntValue( GetDefaultDepthFeatheringValue() );
  140. }
  141. if ( !g_pHardwareConfig->SupportsPixelShaders_2_b() )
  142. {
  143. params[ DEPTHBLEND ]->SetIntValue( 0 );
  144. }
  145. InitIntParam( DUALSEQUENCE, params, 0 );
  146. InitIntParam( MAXLUMFRAMEBLEND1, params, 0 );
  147. InitIntParam( MAXLUMFRAMEBLEND2, params, 0 );
  148. InitIntParam( EXTRACTGREENALPHA, params, 0 );
  149. InitIntParam( ADDOVERBLEND, params, 0 );
  150. InitIntParam( BLENDFRAMES, params, 1 );
  151. InitIntParam( DISTANCEALPHA, params, 0 );
  152. InitIntParam( OUTLINE, params, 0 );
  153. InitIntParam( SOFTEDGES, params, 0 );
  154. InitIntParam( PERPARTICLEOUTLINE, params, 0 );
  155. InitIntParam( MULOUTPUTBYALPHA, params, 0 );
  156. InitFloatParam( INTENSITY, params, 1.0f );
  157. if ( !params[USEINSTANCING]->IsDefined() )
  158. {
  159. params[ USEINSTANCING ]->SetIntValue( IsX360() ? 1 : 0 );
  160. }
  161. // srgb read 360
  162. InitIntParam( SHADERSRGBREAD360, params, 0 );
  163. // default to being translucent since that's what we always were for historical reasons.
  164. InitIntParam( OPAQUE, params, 0 );
  165. InitIntParam( VERTEXCOLORLERP, params, 0 );
  166. if ( !params[LERPCOLOR1]->IsDefined() )
  167. {
  168. params[LERPCOLOR1]->SetVecValue( 1.0f, 0.0f, 0.0f );
  169. }
  170. if ( !params[LERPCOLOR2]->IsDefined() )
  171. {
  172. params[LERPCOLOR2]->SetVecValue( 0.0f, 1.0f, 0.0f );
  173. }
  174. if ( params[OPAQUE]->GetIntValue() != 0 )
  175. {
  176. // none of these make sense if we have $opaque 1:
  177. params[ADDBASETEXTURE2]->SetFloatValue( 0.0f );
  178. params[DUALSEQUENCE]->SetIntValue( 0 );
  179. params[SEQUENCE_BLEND_MODE]->SetIntValue( 0 );
  180. params[MAXLUMFRAMEBLEND1]->SetIntValue( 0 );
  181. params[MAXLUMFRAMEBLEND2]->SetIntValue( 0 );
  182. params[EXTRACTGREENALPHA]->SetIntValue( 0 );
  183. params[RAMPTEXTURE]->SetUndefined();
  184. params[ZOOMANIMATESEQ2]->SetIntValue( 0 );
  185. params[ADDOVERBLEND]->SetIntValue( 0 );
  186. params[ADDSELF]->SetIntValue( 0 );
  187. params[BLENDFRAMES]->SetIntValue( 0 );
  188. params[DEPTHBLEND]->SetIntValue( 0 );
  189. params[INVERSEDEPTHBLEND]->SetIntValue( 0 );
  190. }
  191. if ( IsPS3() && !params[SCENEDEPTH]->IsDefined() )
  192. {
  193. params[SCENEDEPTH]->SetStringValue( "^PS3^DEPTHBUFFER" );
  194. }
  195. if ( g_pHardwareConfig->HasFullResolutionDepthTexture() )
  196. {
  197. params[SCENEDEPTH]->SetStringValue( "_rt_FullFrameDepth" );
  198. }
  199. SET_FLAGS2( MATERIAL_VAR2_IS_SPRITECARD );
  200. }
  201. SHADER_FALLBACK
  202. {
  203. return 0;
  204. }
  205. SHADER_INIT
  206. {
  207. SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT );
  208. if ( params[BASETEXTURE]->IsDefined() )
  209. {
  210. bool bExtractGreenAlpha = false;
  211. if ( params[EXTRACTGREENALPHA]->IsDefined() )
  212. {
  213. bExtractGreenAlpha = params[EXTRACTGREENALPHA]->GetIntValue() != 0;
  214. }
  215. LoadTexture( BASETEXTURE, bExtractGreenAlpha ? 0 : TEXTUREFLAGS_SRGB );
  216. }
  217. if ( params[RAMPTEXTURE]->IsDefined() )
  218. {
  219. LoadTexture( RAMPTEXTURE, TEXTUREFLAGS_SRGB );
  220. }
  221. if( IsPS3() && params[SCENEDEPTH]->IsDefined() )
  222. {
  223. LoadTexture( SCENEDEPTH, 0 );
  224. }
  225. if ( g_pHardwareConfig->HasFullResolutionDepthTexture() )
  226. {
  227. LoadTexture( SCENEDEPTH, 0 );
  228. }
  229. }
  230. SHADER_DRAW
  231. {
  232. bool bUseRampTexture = ( params[RAMPTEXTURE]->IsDefined() );
  233. bool bZoomSeq2 = ( ( params[ZOOMANIMATESEQ2]->GetFloatValue()) > 1.0 );
  234. bool bDepthBlend = false;
  235. if ( g_pHardwareConfig->HasFullResolutionDepthTexture() )
  236. {
  237. // If we didn't create the depth texture. We are looking at not using depth feathering to save memory.
  238. static bool bNoDepthTexture = ( CommandLine()->FindParm( "-nodepthtexture" ) ) ? true : false;
  239. if ( !bNoDepthTexture )
  240. {
  241. bDepthBlend = ( params[DEPTHBLEND]->GetIntValue() != 0 ) && mat_depthfeather_enable.GetBool();
  242. }
  243. }
  244. bool bInverseDepthBlend = ( params[INVERSEDEPTHBLEND]->GetIntValue() != 0 );
  245. bool bAdditive2ndTexture = params[ADDBASETEXTURE2]->GetFloatValue() != 0.0;
  246. bool bExtractGreenAlpha = ( params[EXTRACTGREENALPHA]->GetIntValue() != 0 );
  247. int nSplineType = params[SPLINETYPE]->GetIntValue();
  248. bool bUseInstancing = IsX360() ? ( params[ USEINSTANCING ]->GetIntValue() != 0 ) : false;
  249. #if defined( CSTRIKE15 )
  250. bool bShaderSrgbRead = IsX360() && r_shader_srgbread.GetBool();
  251. #else
  252. bool bShaderSrgbRead = ( IsX360() && IS_PARAM_DEFINED( SHADERSRGBREAD360 ) && params[SHADERSRGBREAD360]->GetIntValue() );
  253. #endif
  254. bool bCrop = ( params[CROPFACTOR]->GetVecValue()[0] != 1.0f ) || ( params[CROPFACTOR]->GetVecValue()[1] != 1.0f );
  255. bool bSecondSequence = params[DUALSEQUENCE]->GetIntValue() != 0;
  256. bool bBlendFrames = ( params[BLENDFRAMES]->GetIntValue() != 0 );
  257. bool bDistanceAlpha = ( params[DISTANCEALPHA]->GetIntValue() != 0 );
  258. bool bOutLine = bDistanceAlpha && ( params[OUTLINE]->GetIntValue() != 0 );
  259. bool bSoftEdges = bDistanceAlpha && ( params[OUTLINE]->GetIntValue() != 0 );
  260. bool bPerParticleOutline = bDistanceAlpha && ( !bSecondSequence ) && ( params[PERPARTICLEOUTLINE]->GetIntValue() );
  261. float flIntensity = params[INTENSITY]->GetFloatValue();
  262. if ( nSplineType )
  263. {
  264. bDepthBlend = false; //splinecard_vsxx.fxc doesn't output all the data necessary for depth blending
  265. bUseInstancing = false;
  266. bBlendFrames = false;
  267. }
  268. bool bColorLerpPS = ( params[VERTEXCOLORLERP]->GetIntValue() != 0 );
  269. bool bPackedInterpolator = bColorLerpPS && !( bExtractGreenAlpha || bSecondSequence || bBlendFrames || params[MAXLUMFRAMEBLEND1]->GetIntValue() );
  270. bool bFog = params[VERTEXFOGAMOUNT]->GetFloatValue() != 0;
  271. SHADOW_STATE
  272. {
  273. bool bAddOverBlend = params[ADDOVERBLEND]->GetIntValue() != 0;
  274. bool bMod2X = params[MOD2X]->GetIntValue() != 0;
  275. bool bShadowDepth = ( params[SHADOWDEPTH]->GetIntValue() != 0 );
  276. bool bAddSelf = params[ADDSELF]->GetFloatValue() != 0.0;
  277. if ( bFog )
  278. {
  279. pShaderShadow->FogMode( SHADER_FOGMODE_FOGCOLOR, true );
  280. }
  281. // draw back-facing because of yaw spin
  282. pShaderShadow->EnableCulling( false );
  283. // Don't write to dest alpha.
  284. pShaderShadow->EnableAlphaWrites( false );
  285. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  286. if ( bUseRampTexture )
  287. {
  288. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
  289. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, !bShaderSrgbRead );
  290. }
  291. if ( bDepthBlend )
  292. {
  293. pShaderShadow->EnableTexture( SHADER_SAMPLER2, true );
  294. }
  295. if ( bAdditive2ndTexture || bAddSelf )
  296. pShaderShadow->EnableAlphaTest( false );
  297. else
  298. pShaderShadow->EnableAlphaTest( true );
  299. pShaderShadow->AlphaFunc( SHADER_ALPHAFUNC_GREATER, 1 / 255 );
  300. if ( bMod2X )
  301. {
  302. EnableAlphaBlending( SHADER_BLEND_DST_COLOR, SHADER_BLEND_SRC_COLOR );
  303. }
  304. else if ( bAdditive2ndTexture || bAddOverBlend || bAddSelf )
  305. {
  306. EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
  307. }
  308. else
  309. {
  310. if ( IS_FLAG_SET(MATERIAL_VAR_ADDITIVE) )
  311. {
  312. EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE );
  313. }
  314. else
  315. {
  316. EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
  317. }
  318. }
  319. bool bUseNormal = ( params[ORIENTATION]->GetIntValue() == 3 );
  320. unsigned int flags = VERTEX_POSITION | VERTEX_COLOR;
  321. static int s_TexCoordSize[8]={4, // 0 = sheet bounding uvs, frame0
  322. 4, // 1 = sheet bounding uvs, frame 1
  323. 4, // 2 = frame blend, rot, radius, ???
  324. 2, // 3 = corner identifier ( 0/0,1/0,1/1, 1/0 )
  325. 4, // 4 = texture 2 bounding uvs
  326. 4, // 5 = second sequence bounding uvs, frame0.. or glow tint, or normal
  327. 4, // 6 = second sequence bounding uvs, frame1
  328. 4, // 7 = second sequence frame blend, ?,?,?
  329. };
  330. static int s_TexCoordSizeSpline[]={4, // 0 = xyz rad pt0
  331. 4, // 1 = xyz rad pt1
  332. 4, // 2 = xyz rad pt2
  333. 4, // 3 = xyz rad pt3
  334. 4, // 4 = texture range u0,v0-u1,v1
  335. 4, // 5 = rgba pt1
  336. 3, // 6 = normal0
  337. 3, // 7 = normal1
  338. };
  339. int numTexCoords = 5;
  340. if ( nSplineType )
  341. {
  342. numTexCoords += 1; // need second rope color
  343. if ( bUseNormal )
  344. numTexCoords += 2; // need normal vectors
  345. }
  346. else
  347. {
  348. if ( bPerParticleOutline || bUseNormal )
  349. {
  350. numTexCoords = 6;
  351. }
  352. else
  353. {
  354. if ( bSecondSequence )
  355. {
  356. // the whole shebang - 2 sequences, with a possible multi-image sequence first
  357. numTexCoords = 8;
  358. }
  359. }
  360. }
  361. pShaderShadow->VertexShaderVertexFormat( flags,
  362. numTexCoords,
  363. nSplineType? s_TexCoordSizeSpline : s_TexCoordSize, 0 );
  364. if ( nSplineType )
  365. {
  366. DECLARE_STATIC_VERTEX_SHADER( splinecard_vs20 );
  367. SET_STATIC_VERTEX_SHADER_COMBO( ADDBASETEXTURE2, 0 );
  368. SET_STATIC_VERTEX_SHADER_COMBO( EXTRACTGREENALPHA, 0 );
  369. SET_STATIC_VERTEX_SHADER_COMBO( DUALSEQUENCE, 0 );
  370. SET_STATIC_VERTEX_SHADER_COMBO( DEPTHBLEND, 0 );
  371. SET_STATIC_VERTEX_SHADER_COMBO( PACKED_INTERPOLATOR, 0 );
  372. SET_STATIC_VERTEX_SHADER_COMBO( ANIMBLEND_OR_MAXLUMFRAMEBLEND1, bBlendFrames || ( params[MAXLUMFRAMEBLEND1]->GetIntValue() != 0 ) );
  373. SET_STATIC_VERTEX_SHADER( splinecard_vs20 );
  374. }
  375. else
  376. {
  377. DECLARE_STATIC_VERTEX_SHADER( spritecard_vs20 );
  378. SET_STATIC_VERTEX_SHADER_COMBO( SPRITECARDVERTEXFOG, bFog );
  379. SET_STATIC_VERTEX_SHADER_COMBO( DUALSEQUENCE, bSecondSequence );
  380. SET_STATIC_VERTEX_SHADER_COMBO( ZOOM_ANIMATE_SEQ2, bZoomSeq2 );
  381. SET_STATIC_VERTEX_SHADER_COMBO( ADDBASETEXTURE2, bAdditive2ndTexture );
  382. SET_STATIC_VERTEX_SHADER_COMBO( EXTRACTGREENALPHA, bExtractGreenAlpha );
  383. SET_STATIC_VERTEX_SHADER_COMBO( DEPTHBLEND, bDepthBlend );
  384. SET_STATIC_VERTEX_SHADER_COMBO( ANIMBLEND_OR_MAXLUMFRAMEBLEND1, bBlendFrames || ( params[MAXLUMFRAMEBLEND1]->GetIntValue() != 0 ) );
  385. SET_STATIC_VERTEX_SHADER_COMBO( CROP, bCrop );
  386. SET_STATIC_VERTEX_SHADER_COMBO( PACKED_INTERPOLATOR, bPackedInterpolator );
  387. SET_STATIC_VERTEX_SHADER_COMBO( HARDWAREFOGBLEND, !IsX360() && bFog && ( g_pHardwareConfig->GetDXSupportLevel() <= 90 ) );
  388. SET_STATIC_VERTEX_SHADER_COMBO( PERPARTICLEOUTLINE, bPerParticleOutline );
  389. SET_STATIC_VERTEX_SHADER( spritecard_vs20 );
  390. }
  391. bool bMulOutputByAlpha = params[MULOUTPUTBYALPHA]->GetIntValue() != 0;
  392. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  393. {
  394. DECLARE_STATIC_PIXEL_SHADER( spritecard_ps20b );
  395. SET_STATIC_PIXEL_SHADER_COMBO( ADDBASETEXTURE2, bAdditive2ndTexture );
  396. SET_STATIC_PIXEL_SHADER_COMBO( ADDSELF, bAddSelf );
  397. SET_STATIC_PIXEL_SHADER_COMBO( ANIMBLEND, bBlendFrames );
  398. SET_STATIC_PIXEL_SHADER_COMBO( DUALSEQUENCE, bSecondSequence );
  399. SET_STATIC_PIXEL_SHADER_COMBO( SEQUENCE_BLEND_MODE, bSecondSequence ? params[SEQUENCE_BLEND_MODE]->GetIntValue() : 0 );
  400. SET_STATIC_PIXEL_SHADER_COMBO( MAXLUMFRAMEBLEND1, params[MAXLUMFRAMEBLEND1]->GetIntValue() );
  401. SET_STATIC_PIXEL_SHADER_COMBO( MAXLUMFRAMEBLEND2, bSecondSequence? params[MAXLUMFRAMEBLEND1]->GetIntValue() : 0 );
  402. SET_STATIC_PIXEL_SHADER_COMBO( COLORRAMP, bUseRampTexture );
  403. SET_STATIC_PIXEL_SHADER_COMBO( EXTRACTGREENALPHA, bExtractGreenAlpha );
  404. SET_STATIC_PIXEL_SHADER_COMBO( DEPTHBLEND, bDepthBlend );
  405. SET_STATIC_PIXEL_SHADER_COMBO( INVERSEDEPTHBLEND, bInverseDepthBlend );
  406. SET_STATIC_PIXEL_SHADER_COMBO( SHADER_SRGB_READ, bShaderSrgbRead );
  407. SET_STATIC_PIXEL_SHADER_COMBO( MOD2X, bMod2X );
  408. SET_STATIC_PIXEL_SHADER_COMBO( PACKED_INTERPOLATOR, bPackedInterpolator );
  409. SET_STATIC_PIXEL_SHADER_COMBO( COLOR_LERP_PS, bColorLerpPS );
  410. SET_STATIC_PIXEL_SHADER_COMBO( DISTANCEALPHA, bDistanceAlpha );
  411. SET_STATIC_PIXEL_SHADER_COMBO( OUTLINE, bOutLine );
  412. SET_STATIC_PIXEL_SHADER_COMBO( SOFTEDGES, bSoftEdges );
  413. SET_STATIC_PIXEL_SHADER_COMBO( MULOUTPUTBYALPHA, bMulOutputByAlpha );
  414. SET_STATIC_PIXEL_SHADER( spritecard_ps20b );
  415. }
  416. else
  417. {
  418. DECLARE_STATIC_PIXEL_SHADER( spritecard_ps20 );
  419. SET_STATIC_PIXEL_SHADER_COMBO( ADDBASETEXTURE2, bAdditive2ndTexture );
  420. SET_STATIC_PIXEL_SHADER_COMBO( DUALSEQUENCE, bSecondSequence );
  421. SET_STATIC_PIXEL_SHADER_COMBO( ADDSELF, bAddSelf );
  422. SET_STATIC_PIXEL_SHADER_COMBO( ANIMBLEND, bBlendFrames );
  423. SET_STATIC_PIXEL_SHADER_COMBO( SEQUENCE_BLEND_MODE, bSecondSequence ? params[SEQUENCE_BLEND_MODE]->GetIntValue() : 0 );
  424. SET_STATIC_PIXEL_SHADER_COMBO( MAXLUMFRAMEBLEND1, params[MAXLUMFRAMEBLEND1]->GetIntValue() );
  425. SET_STATIC_PIXEL_SHADER_COMBO( MAXLUMFRAMEBLEND2, bSecondSequence? params[MAXLUMFRAMEBLEND1]->GetIntValue() : 0 );
  426. SET_STATIC_PIXEL_SHADER_COMBO( COLORRAMP, bUseRampTexture );
  427. SET_STATIC_PIXEL_SHADER_COMBO( EXTRACTGREENALPHA, bExtractGreenAlpha );
  428. SET_STATIC_PIXEL_SHADER_COMBO( INVERSEDEPTHBLEND, bInverseDepthBlend );
  429. SET_STATIC_PIXEL_SHADER_COMBO( SHADER_SRGB_READ, bShaderSrgbRead );
  430. SET_STATIC_PIXEL_SHADER_COMBO( MOD2X, bMod2X );
  431. SET_STATIC_PIXEL_SHADER_COMBO( DEPTHBLEND, bDepthBlend );
  432. SET_STATIC_PIXEL_SHADER_COMBO( PACKED_INTERPOLATOR, bPackedInterpolator );
  433. SET_STATIC_PIXEL_SHADER_COMBO( COLOR_LERP_PS, bColorLerpPS );
  434. SET_STATIC_PIXEL_SHADER_COMBO( DISTANCEALPHA, bDistanceAlpha );
  435. SET_STATIC_PIXEL_SHADER_COMBO( OUTLINE, bOutLine );
  436. SET_STATIC_PIXEL_SHADER_COMBO( SOFTEDGES, bSoftEdges );
  437. SET_STATIC_PIXEL_SHADER_COMBO( MULOUTPUTBYALPHA, bMulOutputByAlpha );
  438. SET_STATIC_PIXEL_SHADER( spritecard_ps20 );
  439. }
  440. if ( bShadowDepth )
  441. {
  442. pShaderShadow->EnableColorWrites( false );
  443. pShaderShadow->EnableAlphaWrites( false );
  444. pShaderShadow->EnablePolyOffset( SHADER_POLYOFFSET_SHADOW_BIAS );
  445. }
  446. pShaderShadow->EnableSRGBWrite( true );
  447. if( !bExtractGreenAlpha )
  448. {
  449. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, !bShaderSrgbRead );
  450. }
  451. }
  452. DYNAMIC_STATE
  453. {
  454. BindTexture( SHADER_SAMPLER0, SRGBReadMask( (! bExtractGreenAlpha ) && ( ! bShaderSrgbRead ) ), BASETEXTURE, FRAME );
  455. if ( bUseRampTexture )
  456. {
  457. BindTexture( SHADER_SAMPLER1, SRGBReadMask( !bShaderSrgbRead ), RAMPTEXTURE, FRAME );
  458. }
  459. if ( bDepthBlend )
  460. {
  461. BindTexture( SHADER_SAMPLER2, TEXTURE_BINDFLAGS_NONE, SCENEDEPTH, -1 );
  462. }
  463. int nOrientation = params[ORIENTATION]->GetIntValue();
  464. nOrientation = clamp( nOrientation, 0, 4 );
  465. if ( nOrientation == 1 && params[AIMATCAMERA]->GetIntValue() > 0 )
  466. nOrientation = 4;
  467. switch ( nOrientation )
  468. {
  469. case 0:
  470. // We need these only when screen-orienting
  471. LoadModelViewMatrixIntoVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0 );
  472. LoadProjectionMatrixIntoVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_3 );
  473. break;
  474. case 2:
  475. // We need this only when doing fixed orientation
  476. SetVertexShaderMatrix3x4( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, ORIENTATIONMATRIX );
  477. break;
  478. }
  479. if ( bZoomSeq2 || bFog )
  480. {
  481. float flZScale=1.0/(params[ZOOMANIMATESEQ2]->GetFloatValue());
  482. float C0[4]={ 0.5*(1.0+flZScale), flZScale, params[VERTEXFOGAMOUNT]->GetFloatValue(), 0 };
  483. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_7, C0, ARRAYSIZE(C0)/4 );
  484. }
  485. // set fade constants in vsconsts 8 and 9
  486. float flMaxDistance = params[MAXDISTANCE]->GetFloatValue();
  487. float flStartFade = MAX( 1.0, flMaxDistance - params[FARFADEINTERVAL]->GetFloatValue() );
  488. float VC0[8]={ params[MINSIZE]->GetFloatValue(), params[MAXSIZE]->GetFloatValue(),
  489. params[STARTFADESIZE]->GetFloatValue(), params[ENDFADESIZE]->GetFloatValue(),
  490. flStartFade, 1.0/(flMaxDistance-flStartFade),
  491. params[ALPHATRAILFADE]->GetFloatValue(),
  492. params[RADIUSTRAILFADE]->GetFloatValue() };
  493. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_8, VC0, ARRAYSIZE(VC0)/4 );
  494. if ( bDepthBlend )
  495. {
  496. pShaderAPI->SetDepthFeatheringShaderConstants( 2, params[DEPTHBLENDSCALE]->GetFloatValue() );
  497. }
  498. // Get viewport and render target dimensions and set shader constant to do a 2D mad
  499. int nViewportX, nViewportY, nViewportWidth, nViewportHeight;
  500. pShaderAPI->GetCurrentViewport( nViewportX, nViewportY, nViewportWidth, nViewportHeight );
  501. int nRtWidth, nRtHeight;
  502. pShaderAPI->GetCurrentRenderTargetDimensions( nRtWidth, nRtHeight );
  503. float vViewportMad[4];
  504. // Compute viewport mad that takes projection space coords (post divide by W) into normalized screenspace, taking into account the currently set viewport.
  505. vViewportMad[0] = .5f * ( ( float )nViewportWidth / ( float )nRtWidth );
  506. vViewportMad[1] = -.5f * ( ( float )nViewportHeight / ( float )nRtHeight );
  507. vViewportMad[2] = vViewportMad[0] + ( ( float )nViewportX / ( float )nRtWidth );
  508. vViewportMad[3] = -vViewportMad[1] + ( ( float )nViewportY / ( float )nRtHeight );
  509. pShaderAPI->SetPixelShaderConstant( DEPTH_FEATHER_VIEWPORT_MAD, vViewportMad, 1 );
  510. if ( bCrop )
  511. {
  512. float vCropFactors[4];
  513. params[CROPFACTOR]->GetVecValue( vCropFactors, 2 );
  514. vCropFactors[2] = -0.5f * vCropFactors[0] + 0.5f;
  515. vCropFactors[3] = -0.5f * vCropFactors[1] + 0.5f;
  516. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_11, vCropFactors, 1 );
  517. }
  518. if ( bColorLerpPS )
  519. {
  520. float vLerpColors[8];
  521. params[LERPCOLOR1]->GetVecValue( vLerpColors, 3 );
  522. params[LERPCOLOR2]->GetVecValue( vLerpColors+4, 3 );
  523. vLerpColors[3] = 1.0f;
  524. vLerpColors[7] = 1.0f;
  525. SetPixelShaderConstantGammaToLinear( 5, vLerpColors, 2 );
  526. }
  527. float C0[4]={ params[ADDBASETEXTURE2]->GetFloatValue(), params[OVERBRIGHTFACTOR]->GetFloatValue(), params[ADDSELF]->GetFloatValue(), flIntensity };
  528. BOOL nBoolShaderConstant = bUseInstancing ? 1 : 0; // Convert to BOOL, which is int
  529. pShaderAPI->SetBooleanVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_BOOL_CONST_0, &nBoolShaderConstant, 1 );
  530. pShaderAPI->SetPixelShaderConstant( 0, C0, ARRAYSIZE(C0)/4 );
  531. // Set Mod2xIdentity to be 0.5 if we blend in linear space, or 0.5 Gamma->Linear if we blend in gamma space
  532. float vPsConst1[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  533. vPsConst1[0] = g_pHardwareConfig->UsesSRGBCorrectBlending() ? 0.5f : SrgbGammaToLinear( 0.5f );
  534. pShaderAPI->SetPixelShaderConstant( 1, vPsConst1, 1 );
  535. // set up distance-coding constants
  536. if ( bDistanceAlpha )
  537. {
  538. float vDistanceConstants[4 * 3]; // c7, c8,c9
  539. params[OUTLINECOLOR]->GetVecValue( vDistanceConstants, 3 );
  540. vDistanceConstants[3] = params[OUTLINEALPHA]->GetFloatValue();
  541. vDistanceConstants[4] = params[OUTLINESTART0]->GetFloatValue();
  542. vDistanceConstants[5] = params[OUTLINESTART1]->GetFloatValue();
  543. vDistanceConstants[6] = params[OUTLINEEND0]->GetFloatValue();
  544. vDistanceConstants[7] = params[OUTLINEEND1]->GetFloatValue();
  545. vDistanceConstants[8] = params[EDGESOFTNESSSTART]->GetFloatValue();
  546. vDistanceConstants[9] = params[EDGESOFTNESSEND]->GetFloatValue();
  547. vDistanceConstants[10] = 0;
  548. vDistanceConstants[11] = 0;
  549. pShaderAPI->SetPixelShaderConstant( 7, vDistanceConstants, ARRAYSIZE( vDistanceConstants ) / 4 );
  550. }
  551. if ( nSplineType )
  552. {
  553. DECLARE_DYNAMIC_VERTEX_SHADER( splinecard_vs20 );
  554. SET_DYNAMIC_VERTEX_SHADER_COMBO( ORIENTATION, nOrientation );
  555. SET_DYNAMIC_VERTEX_SHADER( splinecard_vs20 );
  556. }
  557. else
  558. {
  559. DECLARE_DYNAMIC_VERTEX_SHADER( spritecard_vs20 );
  560. SET_DYNAMIC_VERTEX_SHADER_COMBO( ORIENTATION, nOrientation );
  561. SET_DYNAMIC_VERTEX_SHADER( spritecard_vs20 );
  562. }
  563. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  564. {
  565. DECLARE_DYNAMIC_PIXEL_SHADER( spritecard_ps20b );
  566. SET_DYNAMIC_PIXEL_SHADER( spritecard_ps20b );
  567. }
  568. else
  569. {
  570. DECLARE_DYNAMIC_PIXEL_SHADER( spritecard_ps20 );
  571. SET_DYNAMIC_PIXEL_SHADER( spritecard_ps20 );
  572. }
  573. }
  574. Draw( );
  575. }
  576. END_SHADER