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.

455 lines
18 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================
  7. #include "BaseVSShader.h"
  8. #include "compositor_ps20.inc"
  9. #include "compositor_ps20b.inc"
  10. #include "materialsystem/combineoperations.h"
  11. #include "tier0/memdbgon.h"
  12. struct CompositorInfo_t
  13. {
  14. static const int cTextureCount = 4;
  15. static const int cSelectorCount = 16;
  16. CompositorInfo_t( ) { memset( this, -1, sizeof( *this ) ); }
  17. int m_nCombineMode;
  18. int m_nTextureInputCount;
  19. int m_nTexTransform[ cTextureCount ];
  20. int m_nTexAdjustLevels[ cTextureCount ];
  21. int m_nSrcTexture[ cTextureCount ];
  22. int m_nSelector[ cSelectorCount ];
  23. int m_nTexturesPerPass;
  24. int m_bDebug;
  25. };
  26. #ifdef STAGING_ONLY
  27. ConVar r_texcomp_debug_stickers( "r_texcomp_debug_stickers", "0" );
  28. #endif
  29. static void DrawCompositorStage_ps20( CBaseVSShader *pShader, IMaterialVar **params, IShaderShadow* pShaderShadow, IShaderDynamicAPI* pShaderAPI, VertexCompressionType_t vertexCompression, const CompositorInfo_t &info );
  30. static void DrawCompositorStage_ps20b( CBaseVSShader *pShader, IMaterialVar **params, IShaderShadow* pShaderShadow, IShaderDynamicAPI* pShaderAPI, VertexCompressionType_t vertexCompression, const CompositorInfo_t &info );
  31. BEGIN_VS_SHADER( Compositor, "Help for Compositor" )
  32. BEGIN_SHADER_PARAMS
  33. SHADER_PARAM( COMBINE_MODE, SHADER_PARAM_TYPE_INTEGER, "", "Which mode should the combiner operate in? 0: Mul, 1: Add, 2: Lerp, 3: Select" )
  34. SHADER_PARAM( TEXTUREINPUTCOUNT, SHADER_PARAM_TYPE_INTEGER, "", "" )
  35. SHADER_PARAM( TEXTRANSFORM0, SHADER_PARAM_TYPE_MATRIX4X2, "", "" )
  36. SHADER_PARAM( TEXTRANSFORM1, SHADER_PARAM_TYPE_MATRIX4X2, "", "" )
  37. SHADER_PARAM( TEXTRANSFORM2, SHADER_PARAM_TYPE_MATRIX4X2, "", "" )
  38. SHADER_PARAM( TEXTRANSFORM3, SHADER_PARAM_TYPE_MATRIX4X2, "", "" )
  39. SHADER_PARAM( TEXADJUSTLEVELS0, SHADER_PARAM_TYPE_VEC3, "", "" )
  40. SHADER_PARAM( TEXADJUSTLEVELS1, SHADER_PARAM_TYPE_VEC3, "", "" )
  41. SHADER_PARAM( TEXADJUSTLEVELS2, SHADER_PARAM_TYPE_VEC3, "", "" )
  42. SHADER_PARAM( TEXADJUSTLEVELS3, SHADER_PARAM_TYPE_VEC3, "", "" )
  43. SHADER_PARAM( SRCTEXTURE0, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  44. SHADER_PARAM( SRCTEXTURE1, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  45. SHADER_PARAM( SRCTEXTURE2, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  46. SHADER_PARAM( SRCTEXTURE3, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  47. SHADER_PARAM( SELECTOR0, SHADER_PARAM_TYPE_INTEGER, "", "" )
  48. SHADER_PARAM( SELECTOR1, SHADER_PARAM_TYPE_INTEGER, "", "" )
  49. SHADER_PARAM( SELECTOR2, SHADER_PARAM_TYPE_INTEGER, "", "" )
  50. SHADER_PARAM( SELECTOR3, SHADER_PARAM_TYPE_INTEGER, "", "" )
  51. SHADER_PARAM( SELECTOR4, SHADER_PARAM_TYPE_INTEGER, "", "" )
  52. SHADER_PARAM( SELECTOR5, SHADER_PARAM_TYPE_INTEGER, "", "" )
  53. SHADER_PARAM( SELECTOR6, SHADER_PARAM_TYPE_INTEGER, "", "" )
  54. SHADER_PARAM( SELECTOR7, SHADER_PARAM_TYPE_INTEGER, "", "" )
  55. SHADER_PARAM( SELECTOR8, SHADER_PARAM_TYPE_INTEGER, "", "" )
  56. SHADER_PARAM( SELECTOR9, SHADER_PARAM_TYPE_INTEGER, "", "" )
  57. SHADER_PARAM( SELECTOR10, SHADER_PARAM_TYPE_INTEGER, "", "" )
  58. SHADER_PARAM( SELECTOR11, SHADER_PARAM_TYPE_INTEGER, "", "" )
  59. SHADER_PARAM( SELECTOR12, SHADER_PARAM_TYPE_INTEGER, "", "" )
  60. SHADER_PARAM( SELECTOR13, SHADER_PARAM_TYPE_INTEGER, "", "" )
  61. SHADER_PARAM( SELECTOR14, SHADER_PARAM_TYPE_INTEGER, "", "" )
  62. SHADER_PARAM( SELECTOR15, SHADER_PARAM_TYPE_INTEGER, "", "" )
  63. SHADER_PARAM( DEBUG_MODE, SHADER_PARAM_TYPE_BOOL, "", "" )
  64. END_SHADER_PARAMS
  65. void SetupVarsCompositorInfo( CompositorInfo_t* pOutInfo )
  66. {
  67. Assert( pOutInfo != NULL );
  68. ( *pOutInfo ).m_nCombineMode = COMBINE_MODE;
  69. ( *pOutInfo ).m_nTextureInputCount = TEXTUREINPUTCOUNT;
  70. ( *pOutInfo ).m_nTexTransform[ 0 ] = TEXTRANSFORM0;
  71. ( *pOutInfo ).m_nTexTransform[ 1 ] = TEXTRANSFORM1;
  72. ( *pOutInfo ).m_nTexTransform[ 2 ] = TEXTRANSFORM2;
  73. ( *pOutInfo ).m_nTexTransform[ 3 ] = TEXTRANSFORM3;
  74. ( *pOutInfo ).m_nTexAdjustLevels[ 0 ] = TEXADJUSTLEVELS0;
  75. ( *pOutInfo ).m_nTexAdjustLevels[ 1 ] = TEXADJUSTLEVELS1;
  76. ( *pOutInfo ).m_nTexAdjustLevels[ 2 ] = TEXADJUSTLEVELS2;
  77. ( *pOutInfo ).m_nTexAdjustLevels[ 3 ] = TEXADJUSTLEVELS3;
  78. ( *pOutInfo ).m_nSrcTexture[ 0 ] = SRCTEXTURE0;
  79. ( *pOutInfo ).m_nSrcTexture[ 1 ] = SRCTEXTURE1;
  80. ( *pOutInfo ).m_nSrcTexture[ 2 ] = SRCTEXTURE2;
  81. ( *pOutInfo ).m_nSrcTexture[ 3 ] = SRCTEXTURE3;
  82. ( *pOutInfo ).m_nSelector[ 0 ] = SELECTOR0;
  83. ( *pOutInfo ).m_nSelector[ 1 ] = SELECTOR1;
  84. ( *pOutInfo ).m_nSelector[ 2 ] = SELECTOR2;
  85. ( *pOutInfo ).m_nSelector[ 3 ] = SELECTOR3;
  86. ( *pOutInfo ).m_nSelector[ 4 ] = SELECTOR4;
  87. ( *pOutInfo ).m_nSelector[ 5 ] = SELECTOR5;
  88. ( *pOutInfo ).m_nSelector[ 6 ] = SELECTOR6;
  89. ( *pOutInfo ).m_nSelector[ 7 ] = SELECTOR7;
  90. ( *pOutInfo ).m_nSelector[ 8 ] = SELECTOR8;
  91. ( *pOutInfo ).m_nSelector[ 9 ] = SELECTOR9;
  92. ( *pOutInfo ).m_nSelector[ 10 ] = SELECTOR10;
  93. ( *pOutInfo ).m_nSelector[ 11 ] = SELECTOR11;
  94. ( *pOutInfo ).m_nSelector[ 12 ] = SELECTOR12;
  95. ( *pOutInfo ).m_nSelector[ 13 ] = SELECTOR13;
  96. ( *pOutInfo ).m_nSelector[ 14 ] = SELECTOR14;
  97. ( *pOutInfo ).m_nSelector[ 15 ] = SELECTOR15;
  98. ( *pOutInfo ).m_bDebug = DEBUG_MODE;
  99. if ( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  100. ( *pOutInfo).m_nTexturesPerPass = 4;
  101. else
  102. ( *pOutInfo).m_nTexturesPerPass = 2;
  103. }
  104. SHADER_INIT
  105. {
  106. }
  107. SHADER_FALLBACK
  108. {
  109. // Requires DX9 + above
  110. if ( !g_pHardwareConfig->SupportsVertexAndPixelShaders() )
  111. {
  112. Assert( 0 );
  113. return "Wireframe";
  114. }
  115. return 0;
  116. }
  117. SHADER_DRAW
  118. {
  119. CompositorInfo_t info;
  120. SetupVarsCompositorInfo( &info );
  121. if ( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  122. DrawCompositorStage_ps20b( this, params, pShaderShadow, pShaderAPI, vertexCompression, info );
  123. else
  124. DrawCompositorStage_ps20( this, params, pShaderShadow, pShaderAPI, vertexCompression, info );
  125. }
  126. END_SHADER
  127. static void DrawCompositorStage_common( CBaseVSShader *pShader, IMaterialVar **params, IShaderShadow* pShaderShadow, IShaderDynamicAPI* pShaderAPI, VertexCompressionType_t vertexCompression, const CompositorInfo_t &info )
  128. {
  129. int nCombineMode = params[ info.m_nCombineMode ]->GetIntValue();
  130. SHADOW_STATE
  131. {
  132. pShader->SetInitialShadowState();
  133. // It's a quad, don't cull me bro.
  134. pShaderShadow->EnableCulling( false );
  135. pShaderShadow->EnablePolyOffset( SHADER_POLYOFFSET_DISABLE );
  136. pShaderShadow->EnableDepthWrites( false );
  137. pShaderShadow->EnableDepthTest( false );
  138. // In 2.0b shaders, we use the skin shader and alpha carries specular mask information--
  139. // so we need to write it
  140. // But with 2.0 shaders used by at least one customer in 2015, we fall back to
  141. // vertexlitgeneric and it doesn't do the same transforms as skin to the alpha shader
  142. // Since it won't be used anyways and it breaks the item model panel icons to write alpha
  143. // DON'T when we're running with 2.0 shaders.
  144. pShaderShadow->EnableAlphaWrites( g_pHardwareConfig->SupportsPixelShaders_2_b() );
  145. pShaderShadow->EnableSRGBWrite( true );
  146. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  147. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
  148. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, nCombineMode != ECO_Select );
  149. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, true );
  150. int fmt = VERTEX_POSITION;
  151. pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 );
  152. pShaderShadow->SetVertexShader( "compositor_vs20", 0 );
  153. }
  154. DYNAMIC_STATE
  155. {
  156. pShaderAPI->SetDefaultState();
  157. pShaderAPI->SetVertexShaderIndex( 0 );
  158. int textureCount = GetIntParam( info.m_nTextureInputCount, params );
  159. int textureCountThisPass = Min( textureCount, info.m_nTexturesPerPass );
  160. float f4TextureCountThisPass[] = { ( float ) textureCountThisPass, 0.0f, 0.0f, 0.0f };
  161. Assert( ARRAYSIZE( f4TextureCountThisPass ) == 4 );
  162. pShaderAPI->SetPixelShaderConstant( 6, f4TextureCountThisPass );
  163. if ( textureCountThisPass > 0 ) pShader->BindTexture( SHADER_SAMPLER0, info.m_nSrcTexture[0] );
  164. if ( textureCountThisPass > 0 ) pShader->SetVertexShaderMatrix2x4( 2, info.m_nTexTransform[0] );
  165. if ( nCombineMode == ECO_Select )
  166. {
  167. static const float cFac = 1.0f / 16.0f;
  168. float selectors[] =
  169. {
  170. cFac * GetIntParam( info.m_nSelector[ 0 ], params ),
  171. cFac * GetIntParam( info.m_nSelector[ 1 ], params ),
  172. cFac * GetIntParam( info.m_nSelector[ 2 ], params ),
  173. cFac * GetIntParam( info.m_nSelector[ 3 ], params ),
  174. cFac * GetIntParam( info.m_nSelector[ 4 ], params ),
  175. cFac * GetIntParam( info.m_nSelector[ 5 ], params ),
  176. cFac * GetIntParam( info.m_nSelector[ 6 ], params ),
  177. cFac * GetIntParam( info.m_nSelector[ 7 ], params ),
  178. cFac * GetIntParam( info.m_nSelector[ 8 ], params ),
  179. cFac * GetIntParam( info.m_nSelector[ 9 ], params ),
  180. cFac * GetIntParam( info.m_nSelector[ 10 ], params ),
  181. cFac * GetIntParam( info.m_nSelector[ 11 ], params ),
  182. cFac * GetIntParam( info.m_nSelector[ 12 ], params ),
  183. cFac * GetIntParam( info.m_nSelector[ 13 ], params ),
  184. cFac * GetIntParam( info.m_nSelector[ 14 ], params ),
  185. cFac * GetIntParam( info.m_nSelector[ 15 ], params )
  186. };
  187. pShaderAPI->SetPixelShaderConstant( 7, selectors, 4 );
  188. }
  189. }
  190. }
  191. // Helper function when using ps20 and performing multiply and add operations.
  192. static void DrawCompositorStage_ps20_muladdblend( CBaseVSShader *pShader, IMaterialVar **params, IShaderShadow* pShaderShadow, IShaderDynamicAPI* pShaderAPI, VertexCompressionType_t vertexCompression, const CompositorInfo_t &info )
  193. {
  194. int nCombineMode = params[ info.m_nCombineMode ]->GetIntValue();
  195. SHADOW_STATE
  196. {
  197. {
  198. DECLARE_STATIC_PIXEL_SHADER( compositor_ps20 );
  199. SET_STATIC_PIXEL_SHADER_COMBO( COMBINE_MODE, nCombineMode );
  200. SET_STATIC_PIXEL_SHADER( compositor_ps20 );
  201. }
  202. pShader->Draw();
  203. // We can blend on top for second and subsequent writes.
  204. pShaderShadow->EnableBlending( true );
  205. if ( nCombineMode == ECO_Multiply )
  206. pShaderShadow->BlendFunc( SHADER_BLEND_DST_COLOR, SHADER_BLEND_ZERO );
  207. else
  208. pShaderShadow->BlendFunc( SHADER_BLEND_ONE, SHADER_BLEND_ONE );
  209. pShader->Draw();
  210. }
  211. DYNAMIC_STATE
  212. {
  213. int textureCount = GetIntParam( info.m_nTextureInputCount, params );
  214. int textureCountThisPass = Min( textureCount, info.m_nTexturesPerPass );
  215. Assert( textureCount > 0 ); // Valid, but would be really weird.
  216. Assert( textureCountThisPass > 0 ); // That's bogus
  217. if ( textureCountThisPass > 0 ) pShader->SetPixelShaderConstantGammaToLinear( 2, info.m_nTexAdjustLevels[ 0 ] );
  218. if ( textureCountThisPass > 1 ) pShader->BindTexture( SHADER_SAMPLER1, info.m_nSrcTexture[ 1 ] );
  219. if ( textureCountThisPass > 1 ) pShader->SetVertexShaderMatrix2x4( 4, info.m_nTexTransform[ 1 ] );
  220. if ( textureCountThisPass > 1 ) pShader->SetPixelShaderConstantGammaToLinear( 3, info.m_nTexAdjustLevels[ 1 ] );
  221. {
  222. DECLARE_DYNAMIC_PIXEL_SHADER( compositor_ps20 );
  223. SET_DYNAMIC_PIXEL_SHADER_COMBO( DEBUG_MODE, 0 );
  224. SET_DYNAMIC_PIXEL_SHADER( compositor_ps20 );
  225. }
  226. pShader->Draw();
  227. textureCountThisPass = Max( 0, textureCount - textureCountThisPass );
  228. Assert( textureCountThisPass <= info.m_nTexturesPerPass );
  229. float f4TextureCountThisPass[] = { (float)textureCountThisPass, 0.0f, 0.0f, 0.0f };
  230. Assert( ARRAYSIZE( f4TextureCountThisPass ) == 4 );
  231. pShaderAPI->SetPixelShaderConstant( 6, f4TextureCountThisPass );
  232. if ( textureCountThisPass > 0 ) pShader->BindTexture( SHADER_SAMPLER0, info.m_nSrcTexture[ 2 ] );
  233. if ( textureCountThisPass > 0 ) pShader->SetVertexShaderMatrix2x4( 2, info.m_nTexTransform[ 2 ] );
  234. if ( textureCountThisPass > 0 ) pShader->SetPixelShaderConstantGammaToLinear( 2, info.m_nTexAdjustLevels[ 2 ] );
  235. if ( textureCountThisPass > 1 ) pShader->BindTexture( SHADER_SAMPLER1, info.m_nSrcTexture[ 3 ] );
  236. if ( textureCountThisPass > 1 ) pShader->SetVertexShaderMatrix2x4( 4, info.m_nTexTransform[ 3 ] );
  237. if ( textureCountThisPass > 1 ) pShader->SetPixelShaderConstantGammaToLinear( 3, info.m_nTexAdjustLevels[ 3 ] );
  238. pShader->Draw( textureCountThisPass > 0 );
  239. }
  240. }
  241. // Helper function when using ps20 and performing lerp operations.
  242. static void DrawCompositorStage_ps20_lerp( CBaseVSShader *pShader, IMaterialVar **params, IShaderShadow* pShaderShadow, IShaderDynamicAPI* pShaderAPI, VertexCompressionType_t vertexCompression, const CompositorInfo_t &info )
  243. {
  244. SHADOW_STATE
  245. {
  246. {
  247. DECLARE_STATIC_PIXEL_SHADER( compositor_ps20 );
  248. SET_STATIC_PIXEL_SHADER_COMBO( COMBINE_MODE, ECO_Legacy_Lerp_FirstPass );
  249. SET_STATIC_PIXEL_SHADER( compositor_ps20 );
  250. }
  251. pShader->Draw();
  252. // We can blend on top for second write.
  253. pShaderShadow->EnableBlending( true );
  254. pShaderShadow->BlendFunc( SHADER_BLEND_ONE, SHADER_BLEND_ONE );
  255. {
  256. DECLARE_STATIC_PIXEL_SHADER( compositor_ps20 );
  257. SET_STATIC_PIXEL_SHADER_COMBO( COMBINE_MODE, ECO_Legacy_Lerp_SecondPass );
  258. SET_STATIC_PIXEL_SHADER( compositor_ps20 );
  259. }
  260. pShader->Draw();
  261. }
  262. DYNAMIC_STATE
  263. {
  264. Assert( GetIntParam( info.m_nTextureInputCount, params ) == 3 );
  265. pShader->SetPixelShaderConstantGammaToLinear( 2, info.m_nTexAdjustLevels[ 0 ] );
  266. pShader->BindTexture( SHADER_SAMPLER1, info.m_nSrcTexture[ 2 ] );
  267. pShader->SetVertexShaderMatrix2x4( 4, info.m_nTexTransform[ 2 ] );
  268. pShader->SetPixelShaderConstantGammaToLinear( 3, info.m_nTexAdjustLevels[ 2 ] );
  269. {
  270. DECLARE_DYNAMIC_PIXEL_SHADER( compositor_ps20 );
  271. SET_DYNAMIC_PIXEL_SHADER_COMBO( DEBUG_MODE, 0 );
  272. SET_DYNAMIC_PIXEL_SHADER( compositor_ps20 );
  273. }
  274. pShader->Draw();
  275. pShader->BindTexture( SHADER_SAMPLER0, info.m_nSrcTexture[ 1 ] );
  276. pShader->SetVertexShaderMatrix2x4( 2, info.m_nTexTransform[ 1 ] );
  277. pShader->SetPixelShaderConstantGammaToLinear( 2, info.m_nTexAdjustLevels[ 1 ] );
  278. pShader->Draw();
  279. }
  280. }
  281. // Helper function when using ps20 and performing lerp operations.
  282. static void DrawCompositorStage_ps20_select( CBaseVSShader *pShader, IMaterialVar **params, IShaderShadow* pShaderShadow, IShaderDynamicAPI* pShaderAPI, VertexCompressionType_t vertexCompression, const CompositorInfo_t &info )
  283. {
  284. int nCombineMode = params[ info.m_nCombineMode ]->GetIntValue();
  285. SHADOW_STATE
  286. {
  287. {
  288. DECLARE_STATIC_PIXEL_SHADER( compositor_ps20 );
  289. SET_STATIC_PIXEL_SHADER_COMBO( COMBINE_MODE, nCombineMode );
  290. SET_STATIC_PIXEL_SHADER( compositor_ps20 );
  291. }
  292. pShader->Draw();
  293. }
  294. DYNAMIC_STATE
  295. {
  296. Assert( GetIntParam( info.m_nTextureInputCount, params ) == 1 );
  297. pShader->SetPixelShaderConstantGammaToLinear( 2, info.m_nTexAdjustLevels[ 0 ] );
  298. {
  299. DECLARE_DYNAMIC_PIXEL_SHADER( compositor_ps20 );
  300. SET_DYNAMIC_PIXEL_SHADER_COMBO( DEBUG_MODE, 0 );
  301. SET_DYNAMIC_PIXEL_SHADER( compositor_ps20 );
  302. }
  303. pShader->Draw();
  304. }
  305. }
  306. static void DrawCompositorStage_ps20( CBaseVSShader *pShader, IMaterialVar **params, IShaderShadow* pShaderShadow, IShaderDynamicAPI* pShaderAPI, VertexCompressionType_t vertexCompression, const CompositorInfo_t &info )
  307. {
  308. DrawCompositorStage_common( pShader, params, pShaderShadow, pShaderAPI, vertexCompression, info );
  309. int nCombineMode = params[ info.m_nCombineMode ]->GetIntValue();
  310. switch ( nCombineMode )
  311. {
  312. case ECO_Multiply:
  313. case ECO_Add:
  314. case ECO_Blend:
  315. DrawCompositorStage_ps20_muladdblend( pShader, params, pShaderShadow, pShaderAPI, vertexCompression, info );
  316. return;
  317. case ECO_Lerp:
  318. DrawCompositorStage_ps20_lerp( pShader, params, pShaderShadow, pShaderAPI, vertexCompression, info );
  319. return;
  320. case ECO_Select:
  321. DrawCompositorStage_ps20_select( pShader, params, pShaderShadow, pShaderAPI, vertexCompression, info );
  322. return;
  323. default:
  324. Assert( !"Need to update DrawCompositoreStage_ps20 with how to draw this mode." );
  325. break;
  326. }
  327. }
  328. static void DrawCompositorStage_ps20b( CBaseVSShader *pShader, IMaterialVar **params, IShaderShadow* pShaderShadow, IShaderDynamicAPI* pShaderAPI, VertexCompressionType_t vertexCompression, const CompositorInfo_t &info )
  329. {
  330. int nCombineMode = params[ info.m_nCombineMode ]->GetIntValue();
  331. DrawCompositorStage_common( pShader, params, pShaderShadow, pShaderAPI, vertexCompression, info );
  332. SHADOW_STATE
  333. {
  334. pShaderShadow->EnableTexture( SHADER_SAMPLER2, true );
  335. pShaderShadow->EnableTexture( SHADER_SAMPLER3, true );
  336. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER2, true );
  337. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER3, true );
  338. DECLARE_STATIC_PIXEL_SHADER( compositor_ps20b );
  339. SET_STATIC_PIXEL_SHADER_COMBO( COMBINE_MODE, nCombineMode );
  340. SET_STATIC_PIXEL_SHADER( compositor_ps20b );
  341. pShader->Draw();
  342. }
  343. DYNAMIC_STATE
  344. {
  345. int textureCount = GetIntParam( info.m_nTextureInputCount, params );
  346. int textureCountThisPass = Min( textureCount, info.m_nTexturesPerPass );
  347. Assert( textureCount > 0 ); // Valid, but would be really weird.
  348. Assert( textureCountThisPass > 0 ); // That's bogus
  349. // Slot 0 is mostly already handled by common
  350. if ( textureCountThisPass > 0 ) pShader->SetPixelShaderConstant( 2, info.m_nTexAdjustLevels[ 0 ] );
  351. if ( textureCountThisPass > 1 ) pShader->BindTexture( SHADER_SAMPLER1, info.m_nSrcTexture[ 1 ] );
  352. if ( textureCountThisPass > 1 ) pShader->SetVertexShaderMatrix2x4( 4, info.m_nTexTransform[ 1 ] );
  353. if ( textureCountThisPass > 1 ) pShader->SetPixelShaderConstant( 3, info.m_nTexAdjustLevels[ 1 ] );
  354. if ( textureCountThisPass > 2 ) pShader->BindTexture( SHADER_SAMPLER2, info.m_nSrcTexture[ 2 ] );
  355. if ( textureCountThisPass > 2 ) pShader->SetVertexShaderMatrix2x4( 6, info.m_nTexTransform[ 2 ] );
  356. if ( textureCountThisPass > 2 ) pShader->SetPixelShaderConstant( 4, info.m_nTexAdjustLevels[ 2 ] );
  357. if ( textureCountThisPass > 3 ) pShader->BindTexture( SHADER_SAMPLER3, info.m_nSrcTexture[ 3 ] );
  358. if ( textureCountThisPass > 3 ) pShader->SetVertexShaderMatrix2x4( 8, info.m_nTexTransform[ 3 ] );
  359. if ( textureCountThisPass > 3 ) pShader->SetPixelShaderConstant( 5, info.m_nTexAdjustLevels[ 3 ] );
  360. DECLARE_DYNAMIC_PIXEL_SHADER( compositor_ps20b );
  361. #ifdef STAGING_ONLY
  362. SET_DYNAMIC_PIXEL_SHADER_COMBO( DEBUG_MODE, r_texcomp_debug_stickers.GetBool() ? 1 : 0 );
  363. #else
  364. SET_DYNAMIC_PIXEL_SHADER_COMBO( DEBUG_MODE, 0 );
  365. #endif
  366. SET_DYNAMIC_PIXEL_SHADER( compositor_ps20b );
  367. pShader->Draw();
  368. }
  369. }