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.

680 lines
22 KiB

  1. //=============== Copyright � Valve Corporation, All rights reserved. =================//
  2. //
  3. //=====================================================================================//
  4. #include "BaseVSShader.h"
  5. #include "customcharacter_vs30.inc"
  6. #include "customcharacter_ps30.inc"
  7. #include "../materialsystem_global.h"
  8. // NOTE: This has to be the last file included!
  9. #include "tier0/memdbgon.h"
  10. BEGIN_VS_SHADER( CustomCharacter, "Help for CustomCharacter Shader" )
  11. BEGIN_SHADER_PARAMS
  12. // Original material samplers
  13. SHADER_PARAM( BUMPMAP, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  14. SHADER_PARAM( MASKS1, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  15. SHADER_PARAM( BASEALPHAPHONGMASK, SHADER_PARAM_TYPE_BOOL, "", "" )
  16. SHADER_PARAM( BASEALPHAENVMASK, SHADER_PARAM_TYPE_BOOL, "", "" )
  17. SHADER_PARAM( BUMPALPHAENVMASK, SHADER_PARAM_TYPE_BOOL, "", "" )
  18. // Composite Samplers
  19. SHADER_PARAM( MATERIALMASK, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  20. SHADER_PARAM( AO, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  21. SHADER_PARAM( DETAIL, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  22. SHADER_PARAM( DETAILNORMAL, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  23. SHADER_PARAM( GRUNGE, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  24. SHADER_PARAM( GRUNGETEXTURETRANSFORM, SHADER_PARAM_TYPE_MATRIX, "", "" )
  25. SHADER_PARAM( NOISE, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  26. // Composite Parameters Per-Material
  27. SHADER_PARAM( DETAILSCALE, SHADER_PARAM_TYPE_VEC4, "", "" )
  28. SHADER_PARAM( DETAILPHONGBOOST, SHADER_PARAM_TYPE_VEC4, "", "" )
  29. SHADER_PARAM( WEARDETAILPHONGBOOST, SHADER_PARAM_TYPE_VEC4, "", "" )
  30. SHADER_PARAM( DAMAGEDETAILPHONGBOOST, SHADER_PARAM_TYPE_VEC4, "", "" )
  31. SHADER_PARAM( DETAILENVBOOST, SHADER_PARAM_TYPE_VEC4, "", "" )
  32. SHADER_PARAM( WEARDETAILENVBOOST, SHADER_PARAM_TYPE_VEC4, "", "" )
  33. SHADER_PARAM( DAMAGEDETAILENVBOOST, SHADER_PARAM_TYPE_VEC4, "", "" )
  34. SHADER_PARAM( DETAILPHONGALBEDOTINT, SHADER_PARAM_TYPE_VEC4, "", "" )
  35. SHADER_PARAM( DAMAGEDETAILSATURATION, SHADER_PARAM_TYPE_VEC4, "", "" )
  36. SHADER_PARAM( DAMAGEDETAILBRIGHTNESSADJUSTMENT, SHADER_PARAM_TYPE_VEC4, "", "" )
  37. SHADER_PARAM( DETAILWARPINDEX, SHADER_PARAM_TYPE_VEC4, "", "" )
  38. SHADER_PARAM( DETAILMETALNESS, SHADER_PARAM_TYPE_VEC4, "", "" )
  39. SHADER_PARAM( DETAILNORMALDEPTH, SHADER_PARAM_TYPE_VEC4, "", "" )
  40. SHADER_PARAM( DAMAGENORMALEDGEDEPTH, SHADER_PARAM_TYPE_VEC4, "", "" )
  41. SHADER_PARAM( DAMAGEEDGEPHONGBOOST, SHADER_PARAM_TYPE_VEC4, "", "" )
  42. SHADER_PARAM( DAMAGEEDGEENVBOOST, SHADER_PARAM_TYPE_VEC4, "", "" )
  43. SHADER_PARAM( CURVATUREWEARBOOST, SHADER_PARAM_TYPE_VEC4, "", "" )
  44. SHADER_PARAM( CURVATUREWEARPOWER, SHADER_PARAM_TYPE_VEC4, "", "" )
  45. SHADER_PARAM( GRIME, SHADER_PARAM_TYPE_VEC4, "", "" )
  46. SHADER_PARAM( GRIMESATURATION, SHADER_PARAM_TYPE_VEC4, "", "" )
  47. SHADER_PARAM( GRIMEBRIGHTNESSADJUSTMENT, SHADER_PARAM_TYPE_VEC4, "", "" )
  48. SHADER_PARAM( DAMAGEGRUNGE, SHADER_PARAM_TYPE_VEC4, "", "" )
  49. SHADER_PARAM( DETAILGRUNGE, SHADER_PARAM_TYPE_VEC4, "", "" )
  50. SHADER_PARAM( GRUNGEMAX, SHADER_PARAM_TYPE_VEC4, "", "" )
  51. SHADER_PARAM( DAMAGELEVELS1, SHADER_PARAM_TYPE_VEC2, "", "" )
  52. SHADER_PARAM( DAMAGELEVELS2, SHADER_PARAM_TYPE_VEC2, "", "" )
  53. SHADER_PARAM( DAMAGELEVELS3, SHADER_PARAM_TYPE_VEC2, "", "" )
  54. SHADER_PARAM( DAMAGELEVELS4, SHADER_PARAM_TYPE_VEC2, "", "" )
  55. // Composite Pattern Parameters
  56. SHADER_PARAM( PATTERN, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  57. SHADER_PARAM( PATTERNTEXTURETRANSFORM, SHADER_PARAM_TYPE_MATRIX, "", "" )
  58. SHADER_PARAM( PATTERNREPLACEINDEX, SHADER_PARAM_TYPE_INTEGER, "", "" )
  59. SHADER_PARAM( PATTERNCOLORINDICES, SHADER_PARAM_TYPE_VEC4, "", "" )
  60. SHADER_PARAM( PATTERNDETAILINFLUENCE, SHADER_PARAM_TYPE_FLOAT, "", "" )
  61. SHADER_PARAM( PATTERNPHONGFACTOR, SHADER_PARAM_TYPE_FLOAT, "", "" )
  62. SHADER_PARAM( PATTERNPAINTTHICKNESS, SHADER_PARAM_TYPE_FLOAT, "", "" )
  63. SHADER_PARAM( FLIPFIXUP, SHADER_PARAM_TYPE_FLOAT, "", "" )
  64. // Composite Parameters
  65. SHADER_PARAM( PALETTECOLOR1, SHADER_PARAM_TYPE_COLOR, "", "" )
  66. SHADER_PARAM( PALETTECOLOR2, SHADER_PARAM_TYPE_COLOR, "", "" )
  67. SHADER_PARAM( PALETTECOLOR3, SHADER_PARAM_TYPE_COLOR, "", "" )
  68. SHADER_PARAM( PALETTECOLOR4, SHADER_PARAM_TYPE_COLOR, "", "" )
  69. SHADER_PARAM( PALETTECOLOR5, SHADER_PARAM_TYPE_COLOR, "", "" )
  70. SHADER_PARAM( PALETTECOLOR6, SHADER_PARAM_TYPE_COLOR, "", "" )
  71. SHADER_PARAM( PALETTECOLOR7, SHADER_PARAM_TYPE_COLOR, "", "" )
  72. SHADER_PARAM( PALETTECOLOR8, SHADER_PARAM_TYPE_COLOR, "", "" )
  73. SHADER_PARAM( CUSTOMPAINTJOB, SHADER_PARAM_TYPE_BOOL, "", "" )
  74. SHADER_PARAM( ALLOVERPAINTJOB, SHADER_PARAM_TYPE_BOOL, "", "" )
  75. SHADER_PARAM( WEARPROGRESS, SHADER_PARAM_TYPE_FLOAT, "", "" )
  76. SHADER_PARAM( WEAREXPONENT, SHADER_PARAM_TYPE_FLOAT, "", "" )
  77. SHADER_PARAM( GRUNGETEXTUREROTATION, SHADER_PARAM_TYPE_MATRIX, "", "" )
  78. SHADER_PARAM( PATTERNTEXTUREROTATION, SHADER_PARAM_TYPE_MATRIX, "", "")
  79. END_SHADER_PARAMS
  80. SHADER_INIT_PARAMS()
  81. {
  82. if ( !params[BASEALPHAPHONGMASK]->IsDefined() )
  83. {
  84. params[BASEALPHAPHONGMASK]->SetIntValue( 0 );
  85. }
  86. if ( !params[BASEALPHAENVMASK]->IsDefined() )
  87. {
  88. params[BASEALPHAENVMASK]->SetIntValue( 0 );
  89. }
  90. if ( !params[BUMPALPHAENVMASK]->IsDefined() )
  91. {
  92. params[BUMPALPHAENVMASK]->SetIntValue( 0 );
  93. }
  94. if ( !params[DETAILSCALE]->IsDefined() )
  95. {
  96. params[DETAILSCALE]->SetFloatValue( 4.0f );
  97. }
  98. if ( !params[DETAILPHONGBOOST]->IsDefined() )
  99. {
  100. params[DETAILPHONGBOOST]->SetVecValue( 1.0f, 1.0f, 1.0f, 1.0f );
  101. }
  102. if ( !params[WEARDETAILPHONGBOOST]->IsDefined() )
  103. {
  104. params[WEARDETAILPHONGBOOST]->SetVecValue( 0.0f, 0.0f, 0.0f, 0.0f );
  105. }
  106. if ( !params[DAMAGEDETAILPHONGBOOST]->IsDefined() )
  107. {
  108. params[DAMAGEDETAILPHONGBOOST]->SetVecValue( 1.0f, 1.0f, 1.0f, 1.0f );
  109. }
  110. if ( !params[DETAILENVBOOST]->IsDefined() )
  111. {
  112. params[DETAILENVBOOST]->SetVecValue( 1.0f, 1.0f, 1.0f, 1.0f );
  113. }
  114. if ( !params[WEARDETAILENVBOOST]->IsDefined() )
  115. {
  116. params[WEARDETAILENVBOOST]->SetVecValue( 0.0f, 0.0f, 0.0f, 0.0f );
  117. }
  118. if ( !params[DAMAGEDETAILENVBOOST]->IsDefined() )
  119. {
  120. params[DAMAGEDETAILENVBOOST]->SetVecValue( 0.0f, 0.0f, 0.0f, 0.0f );
  121. }
  122. if ( !params[DETAILPHONGALBEDOTINT]->IsDefined() )
  123. {
  124. params[DETAILPHONGALBEDOTINT]->SetVecValue( 0.0f, 0.0f, 0.0f, 0.0f );
  125. }
  126. if ( !params[DETAILWARPINDEX]->IsDefined() )
  127. {
  128. params[DETAILWARPINDEX]->SetVecValue( 0.0f, 0.0f, 0.0f, 0.0f );
  129. }
  130. // Metalness is just a multiply on the albedo, so invert the defined amount to get the multiplier
  131. if ( !params[DETAILMETALNESS]->IsDefined() )
  132. {
  133. params[DETAILMETALNESS]->SetVecValue( 1.0f, 1.0f, 1.0f, 1.0f );
  134. }
  135. else
  136. {
  137. float vParams[4] = { 0, 0, 0, 0 };
  138. params[DETAILMETALNESS]->GetVecValue( vParams, 4 );
  139. for ( int i = 0; i < 4; i++ )
  140. {
  141. vParams[i] = clamp( vParams[i], 0.0f, 1.0f );
  142. }
  143. params[DETAILMETALNESS]->SetVecValue( vParams, 4 );
  144. }
  145. if ( !params[DETAILNORMALDEPTH]->IsDefined() )
  146. {
  147. params[DETAILNORMALDEPTH]->SetVecValue( 1.0f, 1.0f, 1.0f, 1.0f );
  148. }
  149. if ( !params[DAMAGENORMALEDGEDEPTH]->IsDefined() )
  150. {
  151. params[DAMAGENORMALEDGEDEPTH]->SetVecValue( 1.0f, 1.0f, 1.0f, 1.0f );
  152. }
  153. if ( !params[DAMAGEEDGEPHONGBOOST]->IsDefined() )
  154. {
  155. params[DAMAGEEDGEPHONGBOOST]->SetVecValue( 0.0f, 0.0f, 0.0f, 0.0f );
  156. }
  157. if ( !params[DAMAGEEDGEENVBOOST]->IsDefined() )
  158. {
  159. params[DAMAGEEDGEENVBOOST]->SetVecValue( 0.0f, 0.0f, 0.0f, 0.0f );
  160. }
  161. if ( !params[DAMAGELEVELS1]->IsDefined() )
  162. {
  163. params[DAMAGELEVELS1]->SetVecValue( 0.0f, 1.0f );
  164. }
  165. if ( !params[DAMAGELEVELS2]->IsDefined() )
  166. {
  167. params[DAMAGELEVELS2]->SetVecValue( 0.0f, 1.0f );
  168. }
  169. if ( !params[DAMAGELEVELS3]->IsDefined() )
  170. {
  171. params[DAMAGELEVELS3]->SetVecValue( 0.0f, 1.0f );
  172. }
  173. if ( !params[DAMAGELEVELS4]->IsDefined() )
  174. {
  175. params[DAMAGELEVELS4]->SetVecValue( 0.0f, 1.0f );
  176. }
  177. if ( !params[CUSTOMPAINTJOB]->IsDefined() )
  178. {
  179. params[CUSTOMPAINTJOB]->SetIntValue( 0 );
  180. }
  181. if ( !params[PATTERNDETAILINFLUENCE]->IsDefined() )
  182. {
  183. params[PATTERNDETAILINFLUENCE]->SetFloatValue( 32.0f );
  184. }
  185. if ( !params[ALLOVERPAINTJOB]->IsDefined() )
  186. {
  187. params[ALLOVERPAINTJOB]->SetIntValue( 0 );
  188. }
  189. if ( !params[CURVATUREWEARBOOST]->IsDefined() )
  190. {
  191. params[CURVATUREWEARBOOST]->SetVecValue( 0.0f, 0.0f, 0.0f, 0.0f );
  192. }
  193. if ( !params[CURVATUREWEARPOWER]->IsDefined() )
  194. {
  195. params[CURVATUREWEARPOWER]->SetVecValue( 1.0f, 1.0f, 1.0f, 1.0f );
  196. }
  197. if ( !params[DAMAGEDETAILSATURATION]->IsDefined() )
  198. {
  199. params[DAMAGEDETAILSATURATION]->SetVecValue( 0.0f, 0.0f, 0.0f, 0.0f );
  200. }
  201. if (!params[DAMAGEDETAILBRIGHTNESSADJUSTMENT]->IsDefined())
  202. {
  203. params[DAMAGEDETAILBRIGHTNESSADJUSTMENT]->SetVecValue(0.0f, 0.0f, 0.0f, 0.0f);
  204. }
  205. if ( !params[GRIME]->IsDefined() )
  206. {
  207. params[GRIME]->SetVecValue( 0.25f, 0.25f, 0.25f, 0.25f );
  208. }
  209. if ( !params[GRIMESATURATION]->IsDefined() )
  210. {
  211. params[GRIMESATURATION]->SetVecValue( 0.0f, 0.0f, 0.0f, 0.0f );
  212. }
  213. if ( !params[GRIMEBRIGHTNESSADJUSTMENT]->IsDefined() )
  214. {
  215. params[GRIMEBRIGHTNESSADJUSTMENT]->SetVecValue( 0.0f, 0.0f, 0.0f, 0.0f );
  216. }
  217. if ( !params[DAMAGEGRUNGE]->IsDefined() )
  218. {
  219. params[DAMAGEGRUNGE]->SetVecValue( 0.25f, 0.25f, 0.25f, 0.25f );
  220. }
  221. if ( !params[DETAILGRUNGE]->IsDefined() )
  222. {
  223. params[DETAILGRUNGE]->SetVecValue( 0.0f, 0.0f, 0.0f, 0.0f );
  224. }
  225. if (!params[GRUNGEMAX]->IsDefined())
  226. {
  227. params[GRUNGEMAX]->SetVecValue( 1.0f, 1.0f, 1.0f, 1.0f );
  228. }
  229. if (!params[WEARPROGRESS]->IsDefined())
  230. {
  231. params[WEARPROGRESS]->SetFloatValue(0.0f);
  232. }
  233. if (!params[WEAREXPONENT]->IsDefined())
  234. {
  235. params[WEAREXPONENT]->SetFloatValue(1.0f);
  236. }
  237. if ( !params[PATTERNCOLORINDICES]->IsDefined() )
  238. {
  239. params[PATTERNCOLORINDICES]->SetVecValue( 1, 2, 3, 4 );
  240. }
  241. if ( !params[PATTERNREPLACEINDEX]->IsDefined() )
  242. {
  243. params[PATTERNREPLACEINDEX]->SetIntValue( 1 );
  244. }
  245. if (!params[NOISE]->IsDefined())
  246. {
  247. params[NOISE]->SetStringValue("models/weapons/customization/materials/noise");
  248. }
  249. if (!params[PATTERNPHONGFACTOR]->IsDefined())
  250. {
  251. params[PATTERNPHONGFACTOR]->SetFloatValue(0.0f);
  252. }
  253. if (!params[PATTERNPAINTTHICKNESS]->IsDefined())
  254. {
  255. params[PATTERNPAINTTHICKNESS]->SetFloatValue(0.0f);
  256. }
  257. if (!params[FLIPFIXUP]->IsDefined())
  258. {
  259. params[FLIPFIXUP]->SetFloatValue(1.0f);
  260. }
  261. }
  262. SHADER_FALLBACK
  263. {
  264. return 0;
  265. }
  266. SHADER_INIT
  267. {
  268. if ( params[BUMPMAP]->IsDefined() )
  269. {
  270. LoadTexture( BUMPMAP );
  271. }
  272. if ( params[MASKS1]->IsDefined() )
  273. {
  274. LoadTexture( MASKS1 );
  275. }
  276. if ( params[MATERIALMASK]->IsDefined() )
  277. {
  278. LoadTexture( MATERIALMASK );
  279. }
  280. if ( params[AO]->IsDefined() )
  281. {
  282. LoadTexture( AO );
  283. }
  284. if ( params[GRUNGE]->IsDefined() )
  285. {
  286. LoadTexture( GRUNGE );
  287. }
  288. if ( params[DETAIL]->IsDefined() )
  289. {
  290. LoadTexture( DETAIL );
  291. }
  292. if ( params[DETAILNORMAL]->IsDefined() )
  293. {
  294. LoadTexture( DETAILNORMAL );
  295. }
  296. if ( params[PATTERN]->IsDefined() )
  297. {
  298. LoadTexture( PATTERN );
  299. }
  300. LoadTexture( NOISE );
  301. }
  302. SHADER_DRAW
  303. {
  304. bool bHasBumpMap = IsTextureSet( BUMPMAP, params );
  305. bool bHasMasks1 = IsTextureSet( MASKS1, params );
  306. // Phong mask uses bump alpha by default, but can use base alpha if specified
  307. bool bBaseAlphaPhongMask = params[BASEALPHAPHONGMASK]->IsDefined() && ( params[BASEALPHAPHONGMASK]->GetIntValue() > 0 );
  308. // Envmap uses same mask as spec
  309. bool bBaseAlphaEnvMask = bBaseAlphaPhongMask;
  310. bool bBumpAlphaEnvMask = !bBaseAlphaPhongMask;
  311. // Unless we've specified it should be different.
  312. bBaseAlphaEnvMask = ( bBaseAlphaEnvMask || ( ( params[BASEALPHAENVMASK]->IsDefined() && ( params[BASEALPHAENVMASK]->GetIntValue() > 0 ) ) ) );
  313. bBumpAlphaEnvMask = ( params[BUMPALPHAENVMASK]->IsDefined() && ( params[BUMPALPHAENVMASK]->GetIntValue() > 0 ) );
  314. // Can't have both.
  315. bBaseAlphaEnvMask = bBaseAlphaEnvMask && !bBumpAlphaEnvMask;
  316. bool bGenerateNormalMap = bHasBumpMap;
  317. bool bGenerateMasks1 = !bHasBumpMap && bHasMasks1;
  318. bool bGenerateBaseTexture = !bGenerateNormalMap && !bGenerateMasks1;
  319. bool bPattern = ( bGenerateBaseTexture || bGenerateNormalMap ) && IsTextureSet( PATTERN, params );
  320. bool bHasCustomPaint = bGenerateBaseTexture && params[CUSTOMPAINTJOB]->IsDefined() && ( params[CUSTOMPAINTJOB]->GetIntValue() > 0 );
  321. bool bHasAlloverPaint = bGenerateBaseTexture && params[ALLOVERPAINTJOB]->IsDefined() && ( params[ALLOVERPAINTJOB]->GetIntValue() > 0 );
  322. bool bHasAO = !bGenerateMasks1 && IsTextureSet( AO, params );
  323. bool bHasMaterialMask = IsTextureSet( MATERIALMASK, params );
  324. bool bHasGrunge = !bGenerateMasks1 && IsTextureSet( GRUNGE, params );
  325. bool bHasDetail = !bGenerateMasks1 && IsTextureSet( DETAIL, params );
  326. bool bHasDetailNormal = bGenerateNormalMap && IsTextureSet( DETAILNORMAL, params );
  327. SHADOW_STATE
  328. {
  329. SetInitialShadowState();
  330. unsigned int flags = VERTEX_POSITION;
  331. int nTexCoordCount = 1;
  332. pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, 0 );
  333. // Vertex Shader
  334. DECLARE_STATIC_VERTEX_SHADER( customcharacter_vs30 );
  335. SET_STATIC_VERTEX_SHADER( customcharacter_vs30 );
  336. // Pixel Shader
  337. DECLARE_STATIC_PIXEL_SHADER( customcharacter_ps30 );
  338. SET_STATIC_PIXEL_SHADER_COMBO( GENERATEBASETEXTURE, bGenerateBaseTexture );
  339. SET_STATIC_PIXEL_SHADER_COMBO( GENERATENORMAL, bGenerateNormalMap );
  340. SET_STATIC_PIXEL_SHADER_COMBO( GENERATEMASKS1, bGenerateMasks1 );
  341. SET_STATIC_PIXEL_SHADER_COMBO( CHEAPFILTERING, !bGenerateBaseTexture && !bGenerateNormalMap );
  342. SET_STATIC_PIXEL_SHADER_COMBO( BASEALPHAPHONGMASK, bBaseAlphaPhongMask );
  343. SET_STATIC_PIXEL_SHADER_COMBO( BASEALPHAENVMASK, bBaseAlphaEnvMask );
  344. SET_STATIC_PIXEL_SHADER_COMBO( BUMPALPHAENVMASK, bBumpAlphaEnvMask );
  345. SET_STATIC_PIXEL_SHADER_COMBO( USEPATTERN, bPattern + bHasCustomPaint + ( 2 * bHasAlloverPaint ) );
  346. SET_STATIC_PIXEL_SHADER( customcharacter_ps30 );
  347. if ( bHasBumpMap )
  348. {
  349. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  350. }
  351. if ( bHasMasks1 )
  352. {
  353. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
  354. }
  355. if ( bHasMaterialMask )
  356. {
  357. pShaderShadow->EnableTexture( SHADER_SAMPLER9, true );
  358. }
  359. if ( bHasAO )
  360. {
  361. pShaderShadow->EnableTexture( SHADER_SAMPLER10, true );
  362. }
  363. if ( bHasGrunge )
  364. {
  365. pShaderShadow->EnableTexture( SHADER_SAMPLER11, true );
  366. }
  367. if ( bHasDetail )
  368. {
  369. pShaderShadow->EnableTexture( SHADER_SAMPLER12, true );
  370. }
  371. if ( bHasDetailNormal )
  372. {
  373. pShaderShadow->EnableTexture( SHADER_SAMPLER13, true );
  374. }
  375. pShaderShadow->EnableTexture( SHADER_SAMPLER15, true );
  376. pShaderShadow->EnableAlphaWrites( true );
  377. pShaderShadow->EnableSRGBWrite( bGenerateBaseTexture );
  378. }
  379. DYNAMIC_STATE
  380. {
  381. pShaderAPI->SetDefaultState();
  382. if ( bHasBumpMap )
  383. {
  384. BindTexture( SHADER_SAMPLER0, TEXTURE_BINDFLAGS_NONE, BUMPMAP, -1 );
  385. }
  386. if ( bHasMasks1 )
  387. {
  388. BindTexture( SHADER_SAMPLER1, TEXTURE_BINDFLAGS_NONE, MASKS1, -1 );
  389. }
  390. if ( bHasMaterialMask )
  391. {
  392. BindTexture( SHADER_SAMPLER9, TEXTURE_BINDFLAGS_NONE, MATERIALMASK, -1 );
  393. }
  394. if ( bHasAO )
  395. {
  396. BindTexture( SHADER_SAMPLER10, TEXTURE_BINDFLAGS_NONE, AO, -1 );
  397. }
  398. if ( bHasGrunge )
  399. {
  400. BindTexture( SHADER_SAMPLER11, TEXTURE_BINDFLAGS_SRGBREAD, GRUNGE, -1 );
  401. }
  402. if ( bHasDetail )
  403. {
  404. BindTexture( SHADER_SAMPLER12, TEXTURE_BINDFLAGS_NONE, DETAIL, -1 );
  405. }
  406. if ( bHasDetailNormal )
  407. {
  408. BindTexture( SHADER_SAMPLER13, TEXTURE_BINDFLAGS_NONE, DETAILNORMAL, -1 );
  409. }
  410. if ( bPattern )
  411. {
  412. BindTexture( SHADER_SAMPLER14, bHasCustomPaint ? TEXTURE_BINDFLAGS_SRGBREAD : TEXTURE_BINDFLAGS_NONE, PATTERN, -1 );
  413. }
  414. BindTexture(SHADER_SAMPLER15, TEXTURE_BINDFLAGS_NONE, NOISE, -1);
  415. // Vertex Shader
  416. DECLARE_DYNAMIC_VERTEX_SHADER( customcharacter_vs30 );
  417. SET_DYNAMIC_VERTEX_SHADER( customcharacter_vs30 );
  418. // Pixel Shader
  419. DECLARE_DYNAMIC_PIXEL_SHADER( customcharacter_ps30 );
  420. SET_DYNAMIC_PIXEL_SHADER( customcharacter_ps30 );
  421. float vParams[4] = { 0, 0, 0, 0 };
  422. params[DETAILSCALE]->GetVecValue(vParams, 4);
  423. pShaderAPI->SetPixelShaderConstant(108, vParams, 1);
  424. params[DETAILPHONGBOOST]->GetVecValue(vParams, 4);
  425. pShaderAPI->SetPixelShaderConstant(32, vParams, 1);
  426. params[DAMAGEDETAILPHONGBOOST]->GetVecValue(vParams, 4);
  427. pShaderAPI->SetPixelShaderConstant(100, vParams, 1);
  428. params[DETAILENVBOOST]->GetVecValue(vParams, 4);
  429. pShaderAPI->SetPixelShaderConstant(34, vParams, 1);
  430. params[DAMAGEDETAILENVBOOST]->GetVecValue(vParams, 4);
  431. pShaderAPI->SetPixelShaderConstant(35, vParams, 1);
  432. params[DETAILPHONGALBEDOTINT]->GetVecValue(vParams, 4);
  433. pShaderAPI->SetPixelShaderConstant(36, vParams, 1);
  434. params[DETAILWARPINDEX]->GetVecValue(vParams, 4);
  435. pShaderAPI->SetPixelShaderConstant(37, vParams, 1);
  436. params[DETAILMETALNESS]->GetVecValue(vParams, 4);
  437. pShaderAPI->SetPixelShaderConstant(38, vParams, 1);
  438. params[DETAILNORMALDEPTH]->GetVecValue(vParams, 4);
  439. pShaderAPI->SetPixelShaderConstant(39, vParams, 1);
  440. params[DAMAGENORMALEDGEDEPTH]->GetVecValue(vParams, 4);
  441. pShaderAPI->SetPixelShaderConstant(40, vParams, 1);
  442. float vParams2[2] = { 0, 0 };
  443. params[DAMAGELEVELS1]->GetVecValue(vParams, 2);
  444. params[DAMAGELEVELS2]->GetVecValue(vParams2, 2);
  445. vParams[2] = vParams2[0];
  446. vParams[3] = vParams2[1];
  447. pShaderAPI->SetPixelShaderConstant(41, vParams, 1);
  448. params[DAMAGELEVELS3]->GetVecValue(vParams, 2);
  449. params[DAMAGELEVELS4]->GetVecValue(vParams2, 2);
  450. vParams[2] = vParams2[0];
  451. vParams[3] = vParams2[1];
  452. pShaderAPI->SetPixelShaderConstant(42, vParams, 1);
  453. SetPixelShaderTextureTransform(43, PATTERNTEXTURETRANSFORM); // 43-44
  454. params[PATTERNCOLORINDICES]->GetVecValue(vParams, 4);
  455. vParams[0] = clamp(vParams[0] - 1, 0, 7);
  456. vParams[1] = clamp(vParams[1] - 1, 0, 7);
  457. vParams[2] = clamp(vParams[2] - 1, 0, 7);
  458. vParams[3] = clamp(vParams[3] - 1, 0, 7);
  459. pShaderAPI->SetPixelShaderConstant(45, vParams, 1);
  460. vParams[0] = pow(params[WEARPROGRESS]->GetFloatValue(), params[WEAREXPONENT]->GetFloatValue());
  461. vParams[1] = params[PATTERNDETAILINFLUENCE]->GetFloatValue();
  462. if (bPattern)
  463. {
  464. vParams[2] = clamp(params[PATTERNREPLACEINDEX]->GetIntValue() - 1, 0, 7);
  465. }
  466. else
  467. {
  468. vParams[2] = -1;
  469. }
  470. vParams[3] = 1.0f / 1024.0f; // assuming texture size of 2048. Should be dynamic?
  471. pShaderAPI->SetPixelShaderConstant(46, vParams, 1);
  472. float vParams3[3] = { 0, 0, 0 };
  473. params[PALETTECOLOR4]->GetVecValue(vParams3, 3);
  474. vParams3[0] = SrgbGammaToLinear(vParams3[0] / 255.0f);
  475. vParams3[1] = SrgbGammaToLinear(vParams3[1] / 255.0f);
  476. vParams3[2] = SrgbGammaToLinear(vParams3[2] / 255.0f);
  477. params[PALETTECOLOR1]->GetVecValue(vParams, 3);
  478. vParams[0] = SrgbGammaToLinear(vParams[0] / 255.0f);
  479. vParams[1] = SrgbGammaToLinear(vParams[1] / 255.0f);
  480. vParams[2] = SrgbGammaToLinear(vParams[2] / 255.0f);
  481. vParams[3] = vParams3[0];
  482. pShaderAPI->SetPixelShaderConstant(47, vParams, 1);
  483. params[PALETTECOLOR2]->GetVecValue(vParams, 3);
  484. vParams[0] = SrgbGammaToLinear(vParams[0] / 255.0f);
  485. vParams[1] = SrgbGammaToLinear(vParams[1] / 255.0f);
  486. vParams[2] = SrgbGammaToLinear(vParams[2] / 255.0f);
  487. vParams[3] = vParams3[1];
  488. pShaderAPI->SetPixelShaderConstant(48, vParams, 1);
  489. params[PALETTECOLOR3]->GetVecValue(vParams, 3);
  490. vParams[0] = SrgbGammaToLinear(vParams[0] / 255.0f);
  491. vParams[1] = SrgbGammaToLinear(vParams[1] / 255.0f);
  492. vParams[2] = SrgbGammaToLinear(vParams[2] / 255.0f);
  493. vParams[3] = vParams3[2];
  494. pShaderAPI->SetPixelShaderConstant(49, vParams, 1);
  495. params[PALETTECOLOR8]->GetVecValue(vParams3, 3);
  496. vParams3[0] = SrgbGammaToLinear(vParams3[0] / 255.0f);
  497. vParams3[1] = SrgbGammaToLinear(vParams3[1] / 255.0f);
  498. vParams3[2] = SrgbGammaToLinear(vParams3[2] / 255.0f);
  499. params[PALETTECOLOR5]->GetVecValue(vParams, 3);
  500. vParams[0] = SrgbGammaToLinear(vParams[0] / 255.0f);
  501. vParams[1] = SrgbGammaToLinear(vParams[1] / 255.0f);
  502. vParams[2] = SrgbGammaToLinear(vParams[2] / 255.0f);
  503. vParams[3] = vParams3[0];
  504. pShaderAPI->SetPixelShaderConstant(50, vParams, 1);
  505. params[PALETTECOLOR6]->GetVecValue(vParams, 3);
  506. vParams[0] = SrgbGammaToLinear(vParams[0] / 255.0f);
  507. vParams[1] = SrgbGammaToLinear(vParams[1] / 255.0f);
  508. vParams[2] = SrgbGammaToLinear(vParams[2] / 255.0f);
  509. vParams[3] = vParams3[1];
  510. pShaderAPI->SetPixelShaderConstant(51, vParams, 1);
  511. params[PALETTECOLOR7]->GetVecValue(vParams, 3);
  512. vParams[0] = SrgbGammaToLinear(vParams[0] / 255.0f);
  513. vParams[1] = SrgbGammaToLinear(vParams[1] / 255.0f);
  514. vParams[2] = SrgbGammaToLinear(vParams[2] / 255.0f);
  515. vParams[3] = vParams3[2];
  516. pShaderAPI->SetPixelShaderConstant(52, vParams, 1);
  517. SetPixelShaderTextureTransform(53, GRUNGETEXTURETRANSFORM); // 53-54
  518. params[GRIME]->GetVecValue(vParams, 4);
  519. pShaderAPI->SetPixelShaderConstant(55, vParams, 1);
  520. params[WEARDETAILPHONGBOOST]->GetVecValue(vParams, 4);
  521. pShaderAPI->SetPixelShaderConstant(56, vParams, 1);
  522. params[WEARDETAILENVBOOST]->GetVecValue(vParams, 4);
  523. pShaderAPI->SetPixelShaderConstant(57, vParams, 1);
  524. params[DAMAGEEDGEPHONGBOOST]->GetVecValue(vParams, 4);
  525. pShaderAPI->SetPixelShaderConstant(58, vParams, 1);
  526. params[DAMAGEEDGEENVBOOST]->GetVecValue(vParams, 4);
  527. pShaderAPI->SetPixelShaderConstant(59, vParams, 1);
  528. params[CURVATUREWEARBOOST]->GetVecValue(vParams, 4);
  529. pShaderAPI->SetPixelShaderConstant(60, vParams, 1);
  530. params[CURVATUREWEARPOWER]->GetVecValue(vParams, 4);
  531. pShaderAPI->SetPixelShaderConstant(61, vParams, 1);
  532. params[DAMAGEDETAILSATURATION]->GetVecValue(vParams, 4);
  533. pShaderAPI->SetPixelShaderConstant(62, vParams, 1);
  534. params[DAMAGEGRUNGE]->GetVecValue(vParams, 4);
  535. pShaderAPI->SetPixelShaderConstant(63, vParams, 1);
  536. params[DETAILGRUNGE]->GetVecValue(vParams, 4);
  537. pShaderAPI->SetPixelShaderConstant(90, vParams, 1);
  538. vParams[0] = params[PATTERNPHONGFACTOR]->GetFloatValue();
  539. vParams[1] = params[PATTERNPAINTTHICKNESS]->GetFloatValue();
  540. vParams[2] = params[FLIPFIXUP]->GetFloatValue();
  541. vParams[3] = 0;
  542. pShaderAPI->SetPixelShaderConstant(91, vParams, 1);
  543. params[DAMAGEDETAILBRIGHTNESSADJUSTMENT]->GetVecValue(vParams, 4);
  544. pShaderAPI->SetPixelShaderConstant(92, vParams, 1);
  545. params[GRUNGEMAX]->GetVecValue(vParams, 4);
  546. pShaderAPI->SetPixelShaderConstant(93, vParams, 1);
  547. // c68-89 used by csms
  548. params[GRIMESATURATION]->GetVecValue(vParams, 4);
  549. pShaderAPI->SetPixelShaderConstant(94, vParams, 1);
  550. params[GRIMEBRIGHTNESSADJUSTMENT]->GetVecValue(vParams, 4);
  551. pShaderAPI->SetPixelShaderConstant(95, vParams, 1);
  552. SetPixelShaderTextureTransform( 96, GRUNGETEXTUREROTATION );
  553. SetPixelShaderTextureTransform( 98, PATTERNTEXTUREROTATION );
  554. }
  555. Draw();
  556. }
  557. END_SHADER