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.

1242 lines
42 KiB

  1. //=============== Copyright © Valve Corporation, All rights reserved. =================//
  2. //
  3. //=====================================================================================//
  4. #include "BaseVSShader.h"
  5. #include "shaderlib/commandbuilder.h"
  6. #include "character_vs30.inc"
  7. #include "character_ps30.inc"
  8. #include "character_vs20.inc"
  9. #include "character_ps20b.inc"
  10. #include "../materialsystem_global.h"
  11. // NOTE: This has to be the last file included!
  12. #include "tier0/memdbgon.h"
  13. //#define CHARACTER_LIMIT_LIGHTS_WITH_PHONGWARP 1
  14. BEGIN_VS_SHADER( Character, "Help for Character Shader" )
  15. BEGIN_SHADER_PARAMS
  16. SHADER_PARAM( BUMPMAP, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  17. SHADER_PARAM( MASKS1, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  18. SHADER_PARAM( METALNESS, SHADER_PARAM_TYPE_FLOAT, "", "" )
  19. SHADER_PARAM( WARPINDEX, SHADER_PARAM_TYPE_FLOAT, "", "" )
  20. // Phong terms
  21. SHADER_PARAM( PHONGBOOST, SHADER_PARAM_TYPE_FLOAT, "", "" )
  22. SHADER_PARAM( PHONGALBEDOBOOST, SHADER_PARAM_TYPE_FLOAT, "", "" )
  23. SHADER_PARAM( PHONGTINT, SHADER_PARAM_TYPE_COLOR, "", "" )
  24. SHADER_PARAM( PHONGWARPTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  25. SHADER_PARAM( PHONGEXPONENT, SHADER_PARAM_TYPE_FLOAT, "", "" )
  26. SHADER_PARAM( BASEALPHAPHONGMASK, SHADER_PARAM_TYPE_BOOL, "", "" )
  27. // Envmap terms
  28. SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  29. SHADER_PARAM( ENVMAPCONTRAST, SHADER_PARAM_TYPE_FLOAT, "", "" )
  30. SHADER_PARAM( ENVMAPSATURATION, SHADER_PARAM_TYPE_FLOAT, "", "" )
  31. SHADER_PARAM( ENVMAPTINT, SHADER_PARAM_TYPE_COLOR, "", "" )
  32. SHADER_PARAM( BASEALPHAENVMASK, SHADER_PARAM_TYPE_BOOL, "", "" )
  33. SHADER_PARAM( BUMPALPHAENVMASK, SHADER_PARAM_TYPE_BOOL, "", "" )
  34. SHADER_PARAM( ENVMAPLIGHTSCALE, SHADER_PARAM_TYPE_FLOAT, "", "" )
  35. SHADER_PARAM( ENVMAPLIGHTSCALEMINMAX, SHADER_PARAM_TYPE_VEC2, "", "" )
  36. // Phong and envmap
  37. SHADER_PARAM( FRESNELRANGESTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  38. SHADER_PARAM( FRESNELRANGES, SHADER_PARAM_TYPE_VEC3, "", "" )
  39. SHADER_PARAM( MASKS2, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  40. SHADER_PARAM( ANISOTROPYAMOUNT, SHADER_PARAM_TYPE_FLOAT, "", "" )
  41. // Rim lighting terms
  42. SHADER_PARAM( RIMLIGHTEXPONENT, SHADER_PARAM_TYPE_FLOAT, "4.0", "Exponent for rim lights" )
  43. SHADER_PARAM( RIMLIGHTBOOST, SHADER_PARAM_TYPE_FLOAT, "1.0", "Boost for rim lights" )
  44. SHADER_PARAM( RIMLIGHTALBEDO, SHADER_PARAM_TYPE_FLOAT, "0.0", "" )
  45. SHADER_PARAM( RIMLIGHTTINT, SHADER_PARAM_TYPE_COLOR, "", "" )
  46. SHADER_PARAM( SHADOWRIMBOOST, SHADER_PARAM_TYPE_FLOAT, "2.0f", "Extra boost for rim lights in shadow" )
  47. SHADER_PARAM( FAKERIMBOOST, SHADER_PARAM_TYPE_FLOAT, "", "" )
  48. SHADER_PARAM( FAKERIMTINT, SHADER_PARAM_TYPE_COLOR, "", "" )
  49. SHADER_PARAM( RIMHALOBOOST, SHADER_PARAM_TYPE_FLOAT, "", "" )
  50. SHADER_PARAM( RIMHALOBOUNDS, SHADER_PARAM_TYPE_VEC4, "", "" )
  51. // Ambient reflection terms
  52. SHADER_PARAM( AMBIENTREFLECTIONBOOST, SHADER_PARAM_TYPE_FLOAT, "", "" )
  53. SHADER_PARAM( AMBIENTREFLECTIONBOUNCECOLOR, SHADER_PARAM_TYPE_COLOR, "", "" )
  54. SHADER_PARAM( AMBIENTREFLECTIONBOUNCECENTER, SHADER_PARAM_TYPE_VEC3, "", "" )
  55. // Diffuse shading params
  56. SHADER_PARAM( SHADOWSATURATION, SHADER_PARAM_TYPE_FLOAT, "", "" )
  57. SHADER_PARAM( SHADOWSATURATIONBOUNDS, SHADER_PARAM_TYPE_VEC4, "", "" )
  58. SHADER_PARAM( SHADOWTINT, SHADER_PARAM_TYPE_VEC4, "", "Color and alpha" )
  59. SHADER_PARAM( SHADOWCONTRAST, SHADER_PARAM_TYPE_FLOAT, "", "" )
  60. // Self-illum
  61. SHADER_PARAM( SELFILLUMBOOST, SHADER_PARAM_TYPE_FLOAT, "", "" )
  62. SHADER_PARAM( BASEALPHASELFILLUMMASK, SHADER_PARAM_TYPE_BOOL, "", "" )
  63. // Composite Preview
  64. SHADER_PARAM( PREVIEW, SHADER_PARAM_TYPE_BOOL, "", "" )
  65. // Composite Preview Samplers
  66. SHADER_PARAM( MATERIALMASK, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  67. SHADER_PARAM( AO, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  68. SHADER_PARAM( DETAIL, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  69. SHADER_PARAM( DETAILNORMAL, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  70. SHADER_PARAM( GRUNGE, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  71. SHADER_PARAM( GRUNGETEXTURETRANSFORM, SHADER_PARAM_TYPE_MATRIX, "", "" )
  72. SHADER_PARAM( NOISE, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  73. // Composite Preview Parameters Per-Material
  74. SHADER_PARAM( DETAILSCALE, SHADER_PARAM_TYPE_VEC4, "", "" )
  75. SHADER_PARAM( DETAILPHONGBOOST, SHADER_PARAM_TYPE_VEC4, "", "" )
  76. SHADER_PARAM( WEARDETAILPHONGBOOST, SHADER_PARAM_TYPE_VEC4, "", "" )
  77. SHADER_PARAM( DAMAGEDETAILPHONGBOOST, SHADER_PARAM_TYPE_VEC4, "", "" )
  78. SHADER_PARAM( DETAILENVBOOST, SHADER_PARAM_TYPE_VEC4, "", "" )
  79. SHADER_PARAM( WEARDETAILENVBOOST, SHADER_PARAM_TYPE_VEC4, "", "" )
  80. SHADER_PARAM( DAMAGEDETAILENVBOOST, SHADER_PARAM_TYPE_VEC4, "", "" )
  81. SHADER_PARAM( DETAILPHONGALBEDOTINT, SHADER_PARAM_TYPE_VEC4, "", "" )
  82. SHADER_PARAM( DAMAGEDETAILSATURATION, SHADER_PARAM_TYPE_VEC4, "", "" )
  83. SHADER_PARAM( DAMAGEDETAILBRIGHTNESSADJUSTMENT, SHADER_PARAM_TYPE_VEC4, "", "" )
  84. SHADER_PARAM( DETAILWARPINDEX, SHADER_PARAM_TYPE_VEC4, "", "" )
  85. SHADER_PARAM( DETAILMETALNESS, SHADER_PARAM_TYPE_VEC4, "", "" )
  86. SHADER_PARAM( DETAILNORMALDEPTH, SHADER_PARAM_TYPE_VEC4, "", "" )
  87. SHADER_PARAM( DAMAGENORMALEDGEDEPTH, SHADER_PARAM_TYPE_VEC4, "", "" )
  88. SHADER_PARAM( DAMAGEEDGEPHONGBOOST, SHADER_PARAM_TYPE_VEC4, "", "" )
  89. SHADER_PARAM( DAMAGEEDGEENVBOOST, SHADER_PARAM_TYPE_VEC4, "", "" )
  90. SHADER_PARAM( CURVATUREWEARBOOST, SHADER_PARAM_TYPE_VEC4, "", "" )
  91. SHADER_PARAM( CURVATUREWEARPOWER, SHADER_PARAM_TYPE_VEC4, "", "" )
  92. SHADER_PARAM( GRIME, SHADER_PARAM_TYPE_VEC4, "", "" )
  93. SHADER_PARAM( GRIMESATURATION, SHADER_PARAM_TYPE_VEC4, "", "" )
  94. SHADER_PARAM( GRIMEBRIGHTNESSADJUSTMENT, SHADER_PARAM_TYPE_VEC4, "", "" )
  95. SHADER_PARAM( DAMAGEGRUNGE, SHADER_PARAM_TYPE_VEC4, "", "" )
  96. SHADER_PARAM( DETAILGRUNGE, SHADER_PARAM_TYPE_VEC4, "", "" )
  97. SHADER_PARAM( GRUNGEMAX, SHADER_PARAM_TYPE_VEC4, "", "" )
  98. SHADER_PARAM( DAMAGELEVELS1, SHADER_PARAM_TYPE_VEC2, "", "" )
  99. SHADER_PARAM( DAMAGELEVELS2, SHADER_PARAM_TYPE_VEC2, "", "" )
  100. SHADER_PARAM( DAMAGELEVELS3, SHADER_PARAM_TYPE_VEC2, "", "" )
  101. SHADER_PARAM( DAMAGELEVELS4, SHADER_PARAM_TYPE_VEC2, "", "" )
  102. // Composite Preview Pattern Parameters
  103. SHADER_PARAM( PATTERN, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  104. SHADER_PARAM( PATTERNTEXTURETRANSFORM, SHADER_PARAM_TYPE_MATRIX, "", "" )
  105. SHADER_PARAM( PATTERNREPLACEINDEX, SHADER_PARAM_TYPE_INTEGER, "", "" )
  106. SHADER_PARAM( PATTERNCOLORINDICES, SHADER_PARAM_TYPE_VEC4, "", "" )
  107. SHADER_PARAM( PATTERNDETAILINFLUENCE, SHADER_PARAM_TYPE_FLOAT, "", "" )
  108. SHADER_PARAM( PATTERNPHONGFACTOR, SHADER_PARAM_TYPE_FLOAT, "", "" )
  109. SHADER_PARAM( PATTERNPAINTTHICKNESS, SHADER_PARAM_TYPE_FLOAT, "", "" )
  110. // Composite Preview Parameters
  111. SHADER_PARAM( PALETTECOLOR1, SHADER_PARAM_TYPE_COLOR, "", "" )
  112. SHADER_PARAM( PALETTECOLOR2, SHADER_PARAM_TYPE_COLOR, "", "" )
  113. SHADER_PARAM( PALETTECOLOR3, SHADER_PARAM_TYPE_COLOR, "", "" )
  114. SHADER_PARAM( PALETTECOLOR4, SHADER_PARAM_TYPE_COLOR, "", "" )
  115. SHADER_PARAM( PALETTECOLOR5, SHADER_PARAM_TYPE_COLOR, "", "" )
  116. SHADER_PARAM( PALETTECOLOR6, SHADER_PARAM_TYPE_COLOR, "", "" )
  117. SHADER_PARAM( PALETTECOLOR7, SHADER_PARAM_TYPE_COLOR, "", "" )
  118. SHADER_PARAM( PALETTECOLOR8, SHADER_PARAM_TYPE_COLOR, "", "" )
  119. SHADER_PARAM( CUSTOMPAINTJOB, SHADER_PARAM_TYPE_BOOL, "", "" )
  120. SHADER_PARAM( ALLOVERPAINTJOB, SHADER_PARAM_TYPE_BOOL, "", "" )
  121. SHADER_PARAM( WEARPROGRESS, SHADER_PARAM_TYPE_FLOAT, "", "" )
  122. SHADER_PARAM( WEAREXPONENT, SHADER_PARAM_TYPE_FLOAT, "", "" )
  123. SHADER_PARAM(GRUNGETEXTUREROTATION, SHADER_PARAM_TYPE_MATRIX, "", "")
  124. SHADER_PARAM(PATTERNTEXTUREROTATION, SHADER_PARAM_TYPE_MATRIX, "", "")
  125. SHADER_PARAM( ENTITYORIGIN, SHADER_PARAM_TYPE_VEC3, "", "" )
  126. END_SHADER_PARAMS
  127. SHADER_INIT_PARAMS()
  128. {
  129. if ( !params[PHONGBOOST]->IsDefined() )
  130. {
  131. params[PHONGBOOST]->SetFloatValue( 1.0f );
  132. }
  133. if ( !params[PHONGEXPONENT]->IsDefined() )
  134. {
  135. params[PHONGEXPONENT]->SetFloatValue( 1.0f );
  136. }
  137. if ( !params[PHONGALBEDOBOOST]->IsDefined() )
  138. {
  139. params[PHONGALBEDOBOOST]->SetFloatValue( 1.0f );
  140. }
  141. if ( !params[PHONGTINT]->IsDefined() )
  142. {
  143. params[PHONGTINT]->SetVecValue( 1.0f, 1.0f, 1.0f );
  144. }
  145. if ( !params[BASEALPHAPHONGMASK]->IsDefined() )
  146. {
  147. params[BASEALPHAPHONGMASK]->SetIntValue( 0 );
  148. }
  149. if ( !params[ENVMAPCONTRAST]->IsDefined() )
  150. {
  151. params[ENVMAPCONTRAST]->SetFloatValue( 0.0f );
  152. }
  153. if ( !params[ENVMAPSATURATION]->IsDefined() )
  154. {
  155. params[ENVMAPSATURATION]->SetFloatValue( 0.0 );
  156. }
  157. if ( !params[ENVMAPTINT]->IsDefined() )
  158. {
  159. params[ENVMAPTINT]->SetVecValue( 1.0f, 1.0f, 1.0f );
  160. }
  161. if ( !params[BASEALPHAENVMASK]->IsDefined() )
  162. {
  163. params[BASEALPHAENVMASK]->SetIntValue( 0 );
  164. }
  165. if ( !params[BUMPALPHAENVMASK]->IsDefined() )
  166. {
  167. params[BUMPALPHAENVMASK]->SetIntValue( 0 );
  168. }
  169. if ( !params[SHADOWSATURATION]->IsDefined() )
  170. {
  171. params[SHADOWSATURATION]->SetFloatValue( 0.0f );
  172. }
  173. if ( !params[SHADOWSATURATIONBOUNDS]->IsDefined() )
  174. {
  175. params[SHADOWSATURATIONBOUNDS]->SetVecValue( 0.4f, 0.5f, 0.5f, 0.6f );
  176. }
  177. if ( !params[SHADOWTINT]->IsDefined() )
  178. {
  179. params[SHADOWTINT]->SetVecValue( 1.0f, 1.0f, 1.0f );
  180. }
  181. if ( !params[RIMLIGHTEXPONENT]->IsDefined() )
  182. {
  183. params[RIMLIGHTEXPONENT]->SetFloatValue( 4.0f );
  184. }
  185. if ( !params[RIMLIGHTBOOST]->IsDefined() )
  186. {
  187. params[RIMLIGHTBOOST]->SetFloatValue( 0.0f );
  188. }
  189. if ( !params[RIMLIGHTALBEDO]->IsDefined() )
  190. {
  191. params[RIMLIGHTALBEDO]->SetFloatValue( 0.0f );
  192. }
  193. if ( !params[AMBIENTREFLECTIONBOOST]->IsDefined() )
  194. {
  195. params[AMBIENTREFLECTIONBOOST]->SetFloatValue( 0.0f );
  196. }
  197. if ( !params[AMBIENTREFLECTIONBOUNCECOLOR]->IsDefined() )
  198. {
  199. params[AMBIENTREFLECTIONBOUNCECOLOR]->SetVecValue( 0.0f, 0.0f, 0.0f );
  200. }
  201. if ( !params[AMBIENTREFLECTIONBOUNCECENTER]->IsDefined() )
  202. {
  203. params[AMBIENTREFLECTIONBOUNCECENTER]->SetVecValue( 0.0f, 42.0f, 0.0f );
  204. }
  205. if ( !params[FRESNELRANGES]->IsDefined() )
  206. {
  207. params[FRESNELRANGES]->SetVecValue( 1.0f, 1.0f, 1.0f );
  208. }
  209. // Metalness is just a multiply on the albedo, so invert the defined amount to get the multiplier
  210. if ( !params[METALNESS]->IsDefined() )
  211. {
  212. params[METALNESS]->SetFloatValue( 1.0f );
  213. }
  214. else
  215. {
  216. params[METALNESS]->SetFloatValue( 1 - clamp( params[METALNESS]->GetFloatValue(), 0.0f, 1.0f ) );
  217. }
  218. if ( !params[ENVMAPLIGHTSCALE]->IsDefined() )
  219. {
  220. params[ENVMAPLIGHTSCALE]->SetFloatValue( 0.0f );
  221. }
  222. if ( !params[ENVMAPLIGHTSCALEMINMAX]->IsDefined() )
  223. {
  224. params[ENVMAPLIGHTSCALEMINMAX]->SetVecValue( 0.0f, 1.0f );
  225. }
  226. if ( !params[RIMLIGHTTINT]->IsDefined() )
  227. {
  228. params[RIMLIGHTTINT]->SetVecValue( 1.0f, 1.0f, 1.0f );
  229. }
  230. if ( !params[WARPINDEX]->IsDefined() )
  231. {
  232. params[WARPINDEX]->SetFloatValue( 0.0f );
  233. }
  234. if ( !params[SHADOWCONTRAST]->IsDefined() )
  235. {
  236. params[SHADOWCONTRAST]->SetFloatValue( 0.0f );
  237. }
  238. if ( !params[FAKERIMTINT]->IsDefined() )
  239. {
  240. params[FAKERIMTINT]->SetVecValue( 1.0f, 1.0f, 1.0f );
  241. }
  242. if ( !params[RIMHALOBOOST]->IsDefined() )
  243. {
  244. params[RIMHALOBOOST]->SetFloatValue( 0.0f );
  245. }
  246. if ( !params[RIMHALOBOUNDS]->IsDefined() )
  247. {
  248. params[RIMHALOBOUNDS]->SetVecValue( 0.4f, 0.5f, 0.5f, 0.6f );
  249. }
  250. if ( !params[PREVIEW]->IsDefined() )
  251. {
  252. params[PREVIEW]->SetIntValue( 0 );
  253. }
  254. if ( !params[SHADOWRIMBOOST]->IsDefined() )
  255. {
  256. params[SHADOWRIMBOOST]->SetIntValue( 2.0f );
  257. }
  258. if ( params[PREVIEW]->GetIntValue() > 0 )
  259. {
  260. if ( !params[DETAILSCALE]->IsDefined() )
  261. {
  262. params[DETAILSCALE]->SetFloatValue( 4.0f );
  263. }
  264. if ( !params[DETAILPHONGBOOST]->IsDefined() )
  265. {
  266. params[DETAILPHONGBOOST]->SetVecValue( 1.0f, 1.0f, 1.0f, 1.0f );
  267. }
  268. if ( !params[WEARDETAILPHONGBOOST]->IsDefined() )
  269. {
  270. params[WEARDETAILPHONGBOOST]->SetVecValue( 0.0f, 0.0f, 0.0f, 0.0f );
  271. }
  272. if ( !params[DAMAGEDETAILPHONGBOOST]->IsDefined() )
  273. {
  274. params[DAMAGEDETAILPHONGBOOST]->SetVecValue( 1.0f, 1.0f, 1.0f, 1.0f );
  275. }
  276. if ( !params[DETAILENVBOOST]->IsDefined() )
  277. {
  278. params[DETAILENVBOOST]->SetVecValue( 1.0f, 1.0f, 1.0f, 1.0f );
  279. }
  280. if ( !params[WEARDETAILENVBOOST]->IsDefined() )
  281. {
  282. params[WEARDETAILENVBOOST]->SetVecValue( 0.0f, 0.0f, 0.0f, 0.0f );
  283. }
  284. if ( !params[DAMAGEDETAILENVBOOST]->IsDefined() )
  285. {
  286. params[DAMAGEDETAILENVBOOST]->SetVecValue( 0.0f, 0.0f, 0.0f, 0.0f );
  287. }
  288. if ( !params[DETAILPHONGALBEDOTINT]->IsDefined() )
  289. {
  290. params[DETAILPHONGALBEDOTINT]->SetVecValue( 0.0f, 0.0f, 0.0f, 0.0f );
  291. }
  292. if ( !params[DETAILWARPINDEX]->IsDefined() )
  293. {
  294. params[DETAILWARPINDEX]->SetVecValue( 0.0f, 0.0f, 0.0f, 0.0f );
  295. }
  296. // Metalness is just a multiply on the albedo, so invert the defined amount to get the multiplier
  297. if ( !params[DETAILMETALNESS]->IsDefined() )
  298. {
  299. params[DETAILMETALNESS]->SetVecValue( 1.0f, 1.0f, 1.0f, 1.0f );
  300. }
  301. if ( !params[DETAILNORMALDEPTH]->IsDefined() )
  302. {
  303. params[DETAILNORMALDEPTH]->SetVecValue( 1.0f, 1.0f, 1.0f, 1.0f );
  304. }
  305. if ( !params[DAMAGENORMALEDGEDEPTH]->IsDefined() )
  306. {
  307. params[DAMAGENORMALEDGEDEPTH]->SetVecValue( 1.0f, 1.0f, 1.0f, 1.0f );
  308. }
  309. if ( !params[DAMAGEEDGEPHONGBOOST]->IsDefined() )
  310. {
  311. params[DAMAGEEDGEPHONGBOOST]->SetVecValue( 0.0f, 0.0f, 0.0f, 0.0f );
  312. }
  313. if ( !params[DAMAGEEDGEENVBOOST]->IsDefined() )
  314. {
  315. params[DAMAGEEDGEENVBOOST]->SetVecValue( 0.0f, 0.0f, 0.0f, 0.0f );
  316. }
  317. if ( !params[DAMAGELEVELS1]->IsDefined() )
  318. {
  319. params[DAMAGELEVELS1]->SetVecValue( 0.0f, 1.0f );
  320. }
  321. if ( !params[DAMAGELEVELS2]->IsDefined() )
  322. {
  323. params[DAMAGELEVELS2]->SetVecValue( 0.0f, 1.0f );
  324. }
  325. if ( !params[DAMAGELEVELS3]->IsDefined() )
  326. {
  327. params[DAMAGELEVELS3]->SetVecValue( 0.0f, 1.0f );
  328. }
  329. if ( !params[DAMAGELEVELS4]->IsDefined() )
  330. {
  331. params[DAMAGELEVELS4]->SetVecValue( 0.0f, 1.0f );
  332. }
  333. if ( !params[CUSTOMPAINTJOB]->IsDefined() )
  334. {
  335. params[CUSTOMPAINTJOB]->SetIntValue( 0 );
  336. }
  337. if ( !params[PATTERNDETAILINFLUENCE]->IsDefined() )
  338. {
  339. params[PATTERNDETAILINFLUENCE]->SetFloatValue( 32.0f );
  340. }
  341. if ( !params[ALLOVERPAINTJOB]->IsDefined() )
  342. {
  343. params[ALLOVERPAINTJOB]->SetIntValue( 0 );
  344. }
  345. if ( !params[CURVATUREWEARBOOST]->IsDefined() )
  346. {
  347. params[CURVATUREWEARBOOST]->SetVecValue( 0.0f, 0.0f, 0.0f, 0.0f );
  348. }
  349. if ( !params[CURVATUREWEARPOWER]->IsDefined() )
  350. {
  351. params[CURVATUREWEARPOWER]->SetVecValue( 1.0f, 1.0f, 1.0f, 1.0f );
  352. }
  353. if ( !params[DAMAGEDETAILSATURATION]->IsDefined() )
  354. {
  355. params[DAMAGEDETAILSATURATION]->SetVecValue( 0.0f, 0.0f, 0.0f, 0.0f );
  356. }
  357. if (!params[DAMAGEDETAILBRIGHTNESSADJUSTMENT]->IsDefined())
  358. {
  359. params[DAMAGEDETAILBRIGHTNESSADJUSTMENT]->SetVecValue(0.0f, 0.0f, 0.0f, 0.0f);
  360. }
  361. if ( !params[GRIME]->IsDefined() )
  362. {
  363. params[GRIME]->SetVecValue( 0.25f, 0.25f, 0.25f, 0.25f );
  364. }
  365. if ( !params[GRIMESATURATION]->IsDefined() )
  366. {
  367. params[GRIMESATURATION]->SetVecValue( 0.0f, 0.0f, 0.0f, 0.0f );
  368. }
  369. if ( !params[GRIMEBRIGHTNESSADJUSTMENT]->IsDefined() )
  370. {
  371. params[GRIMEBRIGHTNESSADJUSTMENT]->SetVecValue( 0.0f, 0.0f, 0.0f, 0.0f );
  372. }
  373. if ( !params[DAMAGEGRUNGE]->IsDefined() )
  374. {
  375. params[DAMAGEGRUNGE]->SetVecValue( 0.25f, 0.25f, 0.25f, 0.25f );
  376. }
  377. if ( !params[DETAILGRUNGE]->IsDefined() )
  378. {
  379. params[DETAILGRUNGE]->SetVecValue( 0.0f, 0.0f, 0.0f, 0.0f );
  380. }
  381. if (!params[GRUNGEMAX]->IsDefined())
  382. {
  383. params[GRUNGEMAX]->SetVecValue( 1.0f, 1.0f, 1.0f, 1.0f );
  384. }
  385. if ( !params[WEARPROGRESS]->IsDefined() )
  386. {
  387. params[WEARPROGRESS]->SetFloatValue( 0.0f );
  388. }
  389. if ( !params[WEAREXPONENT]->IsDefined() )
  390. {
  391. params[WEAREXPONENT]->SetFloatValue( 1.0f );
  392. }
  393. if ( !params[PATTERNCOLORINDICES]->IsDefined() )
  394. {
  395. params[PATTERNCOLORINDICES]->SetVecValue( 1, 2, 3, 4 );
  396. }
  397. if ( !params[PATTERNREPLACEINDEX]->IsDefined() )
  398. {
  399. params[PATTERNREPLACEINDEX]->SetIntValue( 1 );
  400. }
  401. if ( !params[NOISE]->IsDefined() )
  402. {
  403. params[NOISE]->SetStringValue( "models/weapons/customization/materials/noise" );
  404. }
  405. if (!params[PATTERNPHONGFACTOR]->IsDefined())
  406. {
  407. params[PATTERNPHONGFACTOR]->SetFloatValue( 0.0f );
  408. }
  409. if (!params[PATTERNPAINTTHICKNESS]->IsDefined())
  410. {
  411. params[PATTERNPAINTTHICKNESS]->SetFloatValue(0.0f);
  412. }
  413. if (!params[PATTERNTEXTURETRANSFORM]->IsDefined())
  414. {
  415. params[PATTERNTEXTURETRANSFORM]->SetStringValue( "scale 1 1 translate 0 0 rotate 0" );
  416. }
  417. if (!params[GRUNGETEXTURETRANSFORM]->IsDefined())
  418. {
  419. params[GRUNGETEXTURETRANSFORM]->SetStringValue( "scale 1 1 translate 0 0 rotate 0" );
  420. }
  421. if (!params[GRUNGETEXTUREROTATION]->IsDefined())
  422. {
  423. params[GRUNGETEXTUREROTATION]->SetStringValue("scale 1 1 translate 0 0 rotate 0");
  424. }
  425. if (!params[PATTERNTEXTUREROTATION]->IsDefined())
  426. {
  427. params[PATTERNTEXTUREROTATION]->SetStringValue("scale 1 1 translate 0 0 rotate 0");
  428. }
  429. }
  430. SET_FLAGS2( MATERIAL_VAR2_NEEDS_TANGENT_SPACES );
  431. SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING );
  432. SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT );
  433. }
  434. SHADER_FALLBACK
  435. {
  436. return 0;
  437. }
  438. SHADER_INIT
  439. {
  440. LoadTexture( BASETEXTURE );
  441. if ( params[BUMPMAP]->IsDefined() )
  442. {
  443. LoadTexture( BUMPMAP );
  444. }
  445. if ( params[MASKS1]->IsDefined() )
  446. {
  447. LoadTexture( MASKS1 );
  448. }
  449. if ( params[PHONGWARPTEXTURE]->IsDefined() )
  450. {
  451. LoadTexture( PHONGWARPTEXTURE );
  452. }
  453. if ( params[FRESNELRANGESTEXTURE]->IsDefined() )
  454. {
  455. LoadTexture( FRESNELRANGESTEXTURE );
  456. }
  457. if ( params[MASKS2]->IsDefined() )
  458. {
  459. LoadTexture( MASKS2 );
  460. }
  461. if ( params[ENVMAP]->IsDefined() )
  462. {
  463. LoadCubeMap( ENVMAP );
  464. }
  465. bool bPreview = params[PREVIEW]->IsDefined() && ( params[PREVIEW]->GetIntValue() > 0 );
  466. if ( bPreview && params[MATERIALMASK]->IsDefined() )
  467. {
  468. LoadTexture( MATERIALMASK );
  469. }
  470. if ( bPreview && params[AO]->IsDefined() )
  471. {
  472. LoadTexture( AO );
  473. }
  474. if ( bPreview && params[GRUNGE]->IsDefined() )
  475. {
  476. LoadTexture( GRUNGE );
  477. }
  478. if ( bPreview && params[DETAIL]->IsDefined() )
  479. {
  480. LoadTexture( DETAIL );
  481. }
  482. if ( bPreview && params[DETAILNORMAL]->IsDefined() )
  483. {
  484. LoadTexture( DETAILNORMAL );
  485. }
  486. if ( bPreview && params[PATTERN]->IsDefined() )
  487. {
  488. LoadTexture( PATTERN );
  489. }
  490. if ( bPreview )
  491. {
  492. LoadTexture( NOISE );
  493. }
  494. }
  495. SHADER_DRAW
  496. {
  497. bool bIsTranslucent = IS_FLAG_SET( MATERIAL_VAR_TRANSLUCENT ) != 0;
  498. bool bHasMasks1 = IsTextureSet( MASKS1, params );
  499. bool bHasFresnelRangesTexture = IsTextureSet( FRESNELRANGESTEXTURE, params );
  500. bool bHasPhongWarpTexture = IsTextureSet( PHONGWARPTEXTURE, params );
  501. bool bHasBumpMap = IsTextureSet( BUMPMAP, params );
  502. bool bHasEnvmap = params[ENVMAP]->IsDefined();
  503. bool bHasAmbientReflection = params[AMBIENTREFLECTIONBOOST]->IsDefined() && ( params[AMBIENTREFLECTIONBOOST]->GetFloatValue() > 0 );
  504. bool bHasBounceColor = bHasAmbientReflection && params[AMBIENTREFLECTIONBOUNCECOLOR]->IsDefined();
  505. //bool bHasRim = params[RIMLIGHTBOOST]->IsDefined() && ( params[RIMLIGHTBOOST]->GetFloatValue() > 0 );
  506. bool bBaseAlphaSelfIllumMask = !bIsTranslucent && params[BASEALPHASELFILLUMMASK]->IsDefined() && ( params[BASEALPHASELFILLUMMASK]->GetIntValue() > 0 );
  507. // Phong mask uses bump alpha by default, but can use base alpha if specified
  508. bool bBaseAlphaPhongMask = !bBaseAlphaSelfIllumMask && !bIsTranslucent && params[BASEALPHAPHONGMASK]->IsDefined() && ( params[BASEALPHAPHONGMASK]->GetIntValue() > 0 );
  509. bool bHasAnisotropy = params[ANISOTROPYAMOUNT]->IsDefined() && ( params[ANISOTROPYAMOUNT]->GetFloatValue() > 0 );
  510. bool bHasShadowSaturation = params[SHADOWSATURATION]->IsDefined() && ( params[SHADOWSATURATION]->GetFloatValue() > 0 );
  511. bool bHasMasks2 = IsTextureSet( MASKS2, params ) && ( bHasEnvmap || bHasShadowSaturation || bHasAnisotropy );
  512. // Envmap uses same mask as spec
  513. bool bBaseAlphaEnvMask = bHasEnvmap && bBaseAlphaPhongMask;
  514. bool bBumpAlphaEnvMask = bHasEnvmap && !bBaseAlphaPhongMask;
  515. // Unless we've specified it should be different.
  516. bBaseAlphaEnvMask = !bBaseAlphaSelfIllumMask && ( bBaseAlphaEnvMask || ( bHasEnvmap && !bIsTranslucent && ( params[BASEALPHAENVMASK]->IsDefined() && ( params[BASEALPHAENVMASK]->GetIntValue() > 0 ) ) ) );
  517. bBumpAlphaEnvMask = bHasEnvmap && bHasBumpMap && ( params[BUMPALPHAENVMASK]->IsDefined() && ( params[BUMPALPHAENVMASK]->GetIntValue() > 0 ) );
  518. // Can't have both.
  519. bBaseAlphaEnvMask = bBaseAlphaEnvMask && !bBumpAlphaEnvMask;
  520. bool bHasFakeRim = params[FAKERIMBOOST]->IsDefined() && ( params[FAKERIMBOOST]->GetFloatValue() > 0 );
  521. bool bPreview = params[PREVIEW]->IsDefined() && ( params[PREVIEW]->GetIntValue() > 0 );
  522. bool bPattern = bPreview && IsTextureSet( PATTERN, params );
  523. bool bHasCustomPaint = bPattern && params[CUSTOMPAINTJOB]->IsDefined() && ( params[CUSTOMPAINTJOB]->GetIntValue() > 0 );
  524. bool bHasAlloverPaint = bPattern && params[ALLOVERPAINTJOB]->IsDefined() && ( params[ALLOVERPAINTJOB]->GetIntValue() > 0 );
  525. bool bHasAO = bPreview && IsTextureSet( AO, params );
  526. bool bHasMaterialMask = bPreview && IsTextureSet( MATERIALMASK, params );
  527. bool bHasGrunge = bPreview && IsTextureSet( GRUNGE, params );
  528. bool bHasDetail = bPreview && IsTextureSet( DETAIL, params );
  529. bool bHasDetailNormal = bPreview && IsTextureSet( DETAILNORMAL, params );
  530. bool bHasFlashlight = UsingFlashlight( params );
  531. if ( bPreview )
  532. // need to turn off some features for shadercompile to complete, otherwise it runs out of memory before all combos are compiled
  533. {
  534. bHasBounceColor = false;
  535. bBaseAlphaSelfIllumMask = false;
  536. bHasFakeRim = false;
  537. bHasFlashlight = false;
  538. }
  539. bool bSupportsCSM = g_pHardwareConfig->SupportsCascadedShadowMapping();
  540. // need to turn off some features for shadercompile to complete, otherwise it runs out of memory before all combos are compiled
  541. if ( bHasFlashlight )
  542. bSupportsCSM = false;
  543. if ( bPreview )
  544. bSupportsCSM = false;
  545. int nCSMQualityComboValue = 0;
  546. if ( bSupportsCSM )
  547. nCSMQualityComboValue = g_pHardwareConfig->GetCSMShaderMode( materials->GetCurrentConfigForVideoCard().GetCSMQualityMode() );
  548. bool bUseStaticControlFlow = g_pHardwareConfig->SupportsStaticControlFlow();
  549. SHADOW_STATE
  550. {
  551. SetInitialShadowState();
  552. // Set stream format
  553. int userDataSize = 4; // tangent S
  554. unsigned int flags = VERTEX_POSITION | VERTEX_NORMAL | VERTEX_FORMAT_COMPRESSED;
  555. int nTexCoordCount = 1;
  556. pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize );
  557. ShadowFilterMode_t nShadowFilterMode = SHADOWFILTERMODE_DEFAULT;
  558. if ( bHasFlashlight )
  559. {
  560. nShadowFilterMode = g_pHardwareConfig->GetShadowFilterMode( false, true ); // Based upon vendor and device dependent formats
  561. }
  562. // Vertex Shader
  563. DECLARE_STATIC_VERTEX_SHADER( character_vs30 );
  564. SET_STATIC_VERTEX_SHADER_COMBO( USEBOUNCECOLOR, bHasBounceColor );
  565. SET_STATIC_VERTEX_SHADER_COMBO( FLASHLIGHT, bHasFlashlight );
  566. SET_STATIC_VERTEX_SHADER_COMBO( FLATTEN_STATIC_CONTROL_FLOW, !bUseStaticControlFlow );
  567. SET_STATIC_VERTEX_SHADER( character_vs30 );
  568. // Pixel Shader
  569. DECLARE_STATIC_PIXEL_SHADER( character_ps30 );
  570. SET_STATIC_PIXEL_SHADER_COMBO( MASKS1, bHasMasks1 );
  571. SET_STATIC_PIXEL_SHADER_COMBO( MASKS2, bHasMasks2 );
  572. SET_STATIC_PIXEL_SHADER_COMBO( FRESNELRANGESTEXTURE, bHasFresnelRangesTexture );
  573. SET_STATIC_PIXEL_SHADER_COMBO( PHONGWARPTEXTURE, bHasPhongWarpTexture );
  574. SET_STATIC_PIXEL_SHADER_COMBO( ENVMAP, bHasEnvmap );
  575. SET_STATIC_PIXEL_SHADER_COMBO( AMBIENTREFLECTION, bHasAmbientReflection );
  576. SET_STATIC_PIXEL_SHADER_COMBO( USEBOUNCECOLOR, bHasBounceColor );
  577. SET_STATIC_PIXEL_SHADER_COMBO( ANISOTROPY, bHasAnisotropy );
  578. SET_STATIC_PIXEL_SHADER_COMBO( BASEALPHAPHONGMASK, bBaseAlphaPhongMask );
  579. SET_STATIC_PIXEL_SHADER_COMBO( BASEALPHAENVMASK, bBaseAlphaEnvMask );
  580. SET_STATIC_PIXEL_SHADER_COMBO( BUMPALPHAENVMASK, bBumpAlphaEnvMask );
  581. SET_STATIC_PIXEL_SHADER_COMBO( SHADOWSATURATION, bHasShadowSaturation );
  582. SET_STATIC_PIXEL_SHADER_COMBO( BASEALPHASELFILLUMMASK, bBaseAlphaSelfIllumMask );
  583. SET_STATIC_PIXEL_SHADER_COMBO( FAKERIM, bHasFakeRim && !bHasFlashlight );
  584. SET_STATIC_PIXEL_SHADER_COMBO( CASCADED_SHADOW_MAPPING, bSupportsCSM );
  585. SET_STATIC_PIXEL_SHADER_COMBO( CSM_MODE, nCSMQualityComboValue);
  586. SET_STATIC_PIXEL_SHADER_COMBO( DOPREVIEW, bPreview );
  587. SET_STATIC_PIXEL_SHADER_COMBO( USEPATTERN, bPattern + bHasCustomPaint + ( 2 * bHasAlloverPaint ) );
  588. SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHT, bHasFlashlight );
  589. SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHTDEPTHFILTERMODE, nShadowFilterMode );
  590. SET_STATIC_PIXEL_SHADER( character_ps30 );
  591. // Base texture
  592. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  593. // Bump map
  594. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
  595. if ( bHasMasks2 )
  596. {
  597. pShaderShadow->EnableTexture( SHADER_SAMPLER3, true );
  598. }
  599. if ( bHasFresnelRangesTexture )
  600. {
  601. pShaderShadow->EnableTexture( SHADER_SAMPLER4, true );
  602. }
  603. if ( bHasPhongWarpTexture )
  604. {
  605. pShaderShadow->EnableTexture( SHADER_SAMPLER7, true );
  606. }
  607. if ( bHasEnvmap )
  608. {
  609. pShaderShadow->EnableTexture( SHADER_SAMPLER6, true );
  610. }
  611. // Normalize sampler
  612. pShaderShadow->EnableTexture( SHADER_SAMPLER5, true );
  613. // CSM sampler
  614. pShaderShadow->EnableTexture( SHADER_SAMPLER8, true );
  615. if ( bHasMaterialMask )
  616. {
  617. pShaderShadow->EnableTexture( SHADER_SAMPLER9, true );
  618. }
  619. if ( bPreview )
  620. {
  621. if ( bHasMasks1 )
  622. {
  623. pShaderShadow->EnableTexture(SHADER_SAMPLER2, true);
  624. }
  625. if ( bHasAO )
  626. {
  627. pShaderShadow->EnableTexture( SHADER_SAMPLER10, true );
  628. }
  629. if ( bHasGrunge )
  630. {
  631. pShaderShadow->EnableTexture( SHADER_SAMPLER11, true );
  632. }
  633. if ( bHasDetail )
  634. {
  635. pShaderShadow->EnableTexture( SHADER_SAMPLER12, true );
  636. }
  637. if ( bHasDetailNormal )
  638. {
  639. pShaderShadow->EnableTexture( SHADER_SAMPLER13, true );
  640. }
  641. if ( bPattern )
  642. {
  643. pShaderShadow->EnableTexture( SHADER_SAMPLER14, true );
  644. }
  645. // noise for color modulation
  646. pShaderShadow->EnableTexture( SHADER_SAMPLER15, true );
  647. }
  648. else
  649. {
  650. if ( bHasMasks1 )
  651. {
  652. pShaderShadow->EnableTexture( SHADER_SAMPLER10, true );
  653. }
  654. if ( bHasFlashlight )
  655. {
  656. pShaderShadow->EnableTexture( SHADER_SAMPLER11, true );
  657. }
  658. }
  659. if ( bIsTranslucent || IsAlphaModulating() )
  660. {
  661. EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
  662. }
  663. else
  664. {
  665. pShaderShadow->EnableAlphaWrites( false );
  666. pShaderShadow->EnableDepthWrites( true );
  667. }
  668. pShaderShadow->EnableAlphaTest( IS_FLAG_SET(MATERIAL_VAR_ALPHATEST) );
  669. pShaderShadow->EnableSRGBWrite( true );
  670. DefaultFog();
  671. bool bFullyOpaque = !bIsTranslucent && !( IS_FLAG_SET( MATERIAL_VAR_ALPHATEST ) );
  672. // HACK HACK HACK - enable alpha writes all the time so that we have them for underwater stuff
  673. pShaderShadow->EnableAlphaWrites( bFullyOpaque );
  674. PI_BeginCommandBuffer();
  675. PI_SetPixelShaderAmbientLightCube( PSREG_AMBIENT_CUBE );
  676. PI_SetVertexShaderAmbientLightCube();
  677. PI_SetPixelShaderLocalLighting( PSREG_LIGHT_INFO_ARRAY );
  678. PI_SetModulationPixelShaderDynamicState_LinearColorSpace( 1 );
  679. PI_EndCommandBuffer();
  680. }
  681. DYNAMIC_STATE
  682. {
  683. pShaderAPI->SetDefaultState();
  684. bool bCSMEnabled = bSupportsCSM && pShaderAPI->IsCascadedShadowMapping();
  685. // need to turn off some features for shadercompile to complete, otherwise it runs out of memory before all combos are compiled
  686. if ( bPreview )
  687. bCSMEnabled = false;
  688. BindTexture( SHADER_SAMPLER0, TEXTURE_BINDFLAGS_SRGBREAD, BASETEXTURE, -1 );
  689. ShaderApiFast( pShaderAPI )->BindStandardTexture( SHADER_SAMPLER5, TEXTURE_BINDFLAGS_NONE, TEXTURE_NORMALIZATION_CUBEMAP_SIGNED );
  690. if ( bHasBumpMap )
  691. {
  692. BindTexture( SHADER_SAMPLER1, TEXTURE_BINDFLAGS_NONE, BUMPMAP, -1 );
  693. }
  694. else
  695. {
  696. pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_BINDFLAGS_NONE, TEXTURE_NORMALMAP_FLAT );
  697. }
  698. if ( bHasMasks1 )
  699. {
  700. if ( bPreview )
  701. {
  702. BindTexture( SHADER_SAMPLER2, TEXTURE_BINDFLAGS_NONE, MASKS1, -1 );
  703. }
  704. else
  705. {
  706. BindTexture(SHADER_SAMPLER10, TEXTURE_BINDFLAGS_NONE, MASKS1, -1);
  707. }
  708. }
  709. if ( bHasMasks2 )
  710. {
  711. BindTexture( SHADER_SAMPLER3, TEXTURE_BINDFLAGS_NONE, MASKS2, -1 );
  712. }
  713. if ( bHasFresnelRangesTexture )
  714. {
  715. BindTexture( SHADER_SAMPLER4, TEXTURE_BINDFLAGS_NONE, FRESNELRANGESTEXTURE, -1 );
  716. }
  717. if ( bHasPhongWarpTexture )
  718. {
  719. BindTexture( SHADER_SAMPLER7, TEXTURE_BINDFLAGS_SRGBREAD, PHONGWARPTEXTURE, -1 );
  720. }
  721. if ( bHasEnvmap )
  722. {
  723. bool bHdr = ( g_pHardwareConfig->GetHDRType() != HDR_TYPE_NONE );
  724. if ( params[ENVMAP]->IsTextureValueInternalEnvCubemap() )
  725. {
  726. pShaderAPI->BindStandardTexture( SHADER_SAMPLER6, bHdr ? TEXTURE_BINDFLAGS_NONE : TEXTURE_BINDFLAGS_SRGBREAD, TEXTURE_LOCAL_ENV_CUBEMAP );
  727. }
  728. else
  729. {
  730. BindTexture( SHADER_SAMPLER6, bHdr ? TEXTURE_BINDFLAGS_NONE : TEXTURE_BINDFLAGS_SRGBREAD, ENVMAP, -1 );
  731. }
  732. }
  733. if ( bCSMEnabled )
  734. {
  735. ITexture *pDepthTextureAtlas = NULL;
  736. const CascadedShadowMappingState_t &cascadeState = pShaderAPI->GetCascadedShadowMappingState( &pDepthTextureAtlas );
  737. if ( pDepthTextureAtlas )
  738. {
  739. BindTexture( SHADER_SAMPLER8, TEXTURE_BINDFLAGS_SHADOWDEPTH, pDepthTextureAtlas, 0 );
  740. pShaderAPI->SetPixelShaderConstant( 64, &cascadeState.m_vLightColor.x, CASCADED_SHADOW_MAPPING_CONSTANT_BUFFER_SIZE );
  741. }
  742. else
  743. {
  744. bCSMEnabled = false;
  745. }
  746. }
  747. else if ( bHasFlashlight )
  748. {
  749. CBCmdSetPixelShaderFlashlightState_t state;
  750. state.m_LightSampler = SHADER_SAMPLER8;
  751. state.m_DepthSampler = SHADER_SAMPLER11;
  752. state.m_ShadowNoiseSampler = SHADER_SAMPLER5;
  753. state.m_nColorConstant = PSREG_FLASHLIGHT_COLOR;
  754. state.m_nAttenConstant = PSREG_FLASHLIGHT_ATTENUATION;
  755. state.m_nOriginConstant = PSREG_FLASHLIGHT_POSITION_RIM_BOOST;
  756. state.m_nDepthTweakConstant = 109;
  757. state.m_nScreenScaleConstant = PSREG_FLASHLIGHT_SCREEN_SCALE;
  758. state.m_nWorldToTextureConstant = PSREG_FLASHLIGHT_TO_WORLD_TEXTURE;
  759. state.m_bFlashlightNoLambert = false;
  760. state.m_bSinglePassFlashlight = true;
  761. CCommandBufferBuilder< CFixedCommandStorageBuffer< 256 > > DynamicCmdsOut;
  762. DynamicCmdsOut.SetPixelShaderFlashlightState( state );
  763. DynamicCmdsOut.End();
  764. pShaderAPI->ExecuteCommandBuffer(DynamicCmdsOut.Base());
  765. }
  766. if ( bHasMaterialMask )
  767. {
  768. BindTexture( SHADER_SAMPLER9, TEXTURE_BINDFLAGS_NONE, MATERIALMASK, -1 );
  769. }
  770. if ( bHasAO )
  771. {
  772. BindTexture( SHADER_SAMPLER10, TEXTURE_BINDFLAGS_NONE, AO, -1 );
  773. }
  774. if ( bHasGrunge )
  775. {
  776. BindTexture( SHADER_SAMPLER11, TEXTURE_BINDFLAGS_SRGBREAD, GRUNGE, -1 );
  777. }
  778. if ( bHasDetail )
  779. {
  780. BindTexture( SHADER_SAMPLER12, TEXTURE_BINDFLAGS_NONE, DETAIL, -1 );
  781. }
  782. if ( bHasDetailNormal )
  783. {
  784. BindTexture( SHADER_SAMPLER13, TEXTURE_BINDFLAGS_NONE, DETAILNORMAL, -1 );
  785. }
  786. if ( bPattern )
  787. {
  788. BindTexture( SHADER_SAMPLER14, bHasCustomPaint ? TEXTURE_BINDFLAGS_SRGBREAD : TEXTURE_BINDFLAGS_NONE, PATTERN, -1 );
  789. }
  790. if ( bPreview )
  791. {
  792. BindTexture( SHADER_SAMPLER15, TEXTURE_BINDFLAGS_NONE, NOISE, -1 );
  793. }
  794. int numBones = ShaderApiFast( pShaderAPI )->GetCurrentNumBones();
  795. LightState_t lightState = { 0, false, false };
  796. ShaderApiFast( pShaderAPI )->GetDX9LightState( &lightState );
  797. MaterialFogMode_t fogType = ShaderApiFast( pShaderAPI )->GetSceneFogMode();
  798. bool bWriteDepthToAlpha;
  799. bool bWriteWaterFogToAlpha;
  800. bool bFullyOpaque = !bIsTranslucent && !( IS_FLAG_SET( MATERIAL_VAR_VERTEXALPHA ) ) && !( IS_FLAG_SET( MATERIAL_VAR_ALPHATEST ) );
  801. if( bFullyOpaque )
  802. {
  803. bWriteDepthToAlpha = false;
  804. bWriteWaterFogToAlpha = (fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z);
  805. AssertMsg( !(bWriteDepthToAlpha && bWriteWaterFogToAlpha), "Can't write two values to alpha at the same time." );
  806. }
  807. else
  808. {
  809. //can't write a special value to dest alpha if we're actually using as-intended alpha
  810. bWriteDepthToAlpha = false;
  811. bWriteWaterFogToAlpha = false;
  812. }
  813. int nNumLights = lightState.m_nNumLights;
  814. nNumLights = bUseStaticControlFlow ? nNumLights : MIN( 2, nNumLights );
  815. // need to turn off some features for shadercompile to complete, otherwise it runs out of memory before all combos are compiled
  816. if ( bPreview )
  817. nNumLights = clamp( nNumLights, 0, 1 );
  818. #if defined( CHARACTER_LIMIT_LIGHTS_WITH_PHONGWARP )
  819. if ( bHasPhongWarpTexture )
  820. nNumLights = clamp( nNumLights, 0, 3 );
  821. #endif
  822. // Vertex Shader
  823. DECLARE_DYNAMIC_VERTEX_SHADER( character_vs30 );
  824. SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, numBones > 0 );
  825. SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression );
  826. SET_DYNAMIC_VERTEX_SHADER_COMBO( NUM_LIGHTS, nNumLights );
  827. SET_DYNAMIC_VERTEX_SHADER( character_vs30 );
  828. SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, AMBIENTREFLECTIONBOUNCECENTER );
  829. SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, ENTITYORIGIN );
  830. // Pixel Shader
  831. DECLARE_DYNAMIC_PIXEL_SHADER( character_ps30 );
  832. SET_DYNAMIC_PIXEL_SHADER_COMBO( NUM_LIGHTS, nNumLights );
  833. SET_DYNAMIC_PIXEL_SHADER_COMBO( DYN_CSM_ENABLED, (bCSMEnabled) );
  834. SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, bWriteDepthToAlpha );
  835. SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITEWATERFOGTODESTALPHA, bWriteWaterFogToAlpha );
  836. SET_DYNAMIC_PIXEL_SHADER( character_ps30 );
  837. float vEyePos[4] = { 0, 0, 0, 0 };
  838. ShaderApiFast( pShaderAPI )->GetWorldSpaceCameraPosition( vEyePos );
  839. pShaderAPI->SetPixelShaderConstant( 3, vEyePos, 1 );
  840. pShaderAPI->SetPixelShaderFogParams( 19 );
  841. float vParams[4] = { 0, 0, 0, 0 };
  842. params[AMBIENTREFLECTIONBOUNCECOLOR]->GetVecValue( vParams, 3 );
  843. vParams[3] = params[AMBIENTREFLECTIONBOOST]->GetFloatValue();
  844. pShaderAPI->SetPixelShaderConstant( 0, vParams, 1 );
  845. vParams[0] = params[ENVMAPLIGHTSCALE]->GetFloatValue();
  846. vParams[1] = params[SHADOWSATURATION]->GetFloatValue();
  847. vParams[2] = params[METALNESS]->GetFloatValue();
  848. vParams[3] = params[RIMLIGHTALBEDO]->GetFloatValue();
  849. pShaderAPI->SetPixelShaderConstant( 101, vParams, 1 );
  850. SetPixelShaderConstant( 2, SHADOWSATURATIONBOUNDS );
  851. vParams[0] = params[PHONGBOOST]->GetFloatValue();
  852. vParams[1] = params[PHONGALBEDOBOOST]->GetFloatValue();
  853. vParams[2] = params[PHONGEXPONENT]->GetFloatValue();
  854. vParams[3] = params[ANISOTROPYAMOUNT]->GetFloatValue();
  855. pShaderAPI->SetPixelShaderConstant( 10, vParams, 1 );
  856. params[PHONGTINT]->GetVecValue(vParams, 3);
  857. vParams[3] = params[SHADOWRIMBOOST]->GetFloatValue();
  858. pShaderAPI->SetPixelShaderConstant( 11, vParams, 1 );
  859. SetPixelShaderConstant( 12, FRESNELRANGES );
  860. SetPixelShaderConstant( 102, SHADOWTINT );
  861. params[ENVMAPLIGHTSCALEMINMAX]->GetVecValue( vParams, 2 );
  862. vParams[2] = params[ENVMAPCONTRAST]->GetFloatValue();
  863. vParams[3] = params[ENVMAPSATURATION]->GetFloatValue();
  864. pShaderAPI->SetPixelShaderConstant( 103, vParams, 1 );
  865. SetPixelShaderConstant( 104, ENVMAPTINT );
  866. float fRimLightBoost = params[RIMLIGHTBOOST]->GetFloatValue();
  867. vParams[0] = params[RIMLIGHTEXPONENT]->GetFloatValue();
  868. vParams[1] = fRimLightBoost;
  869. vParams[2] = params[SELFILLUMBOOST]->GetFloatValue();
  870. vParams[3] = params[WARPINDEX]->GetFloatValue();
  871. pShaderAPI->SetPixelShaderConstant( 105, vParams, 1 );
  872. float fRimHaloBoost = params[RIMHALOBOOST]->GetFloatValue();
  873. params[RIMLIGHTTINT]->GetVecValue( vParams, 3 );
  874. vParams[3] = fRimHaloBoost * fRimLightBoost;
  875. pShaderAPI->SetPixelShaderConstant( 106, vParams, 1 );
  876. params[FAKERIMTINT]->GetVecValue( vParams, 3 );
  877. float fFakeRimBoost = params[FAKERIMBOOST]->GetFloatValue();
  878. vParams[0] *= fFakeRimBoost;
  879. vParams[1] *= fFakeRimBoost;
  880. vParams[2] *= fFakeRimBoost;
  881. vParams[3] = clamp( 1.0f - params[SHADOWCONTRAST]->GetFloatValue(), 0.0f, 1.0f );
  882. pShaderAPI->SetPixelShaderConstant( 107, vParams, 1 );
  883. //20-25 used
  884. //26-27 used
  885. SetPixelShaderConstant( 33, RIMHALOBOUNDS );
  886. if ( bPreview )
  887. {
  888. params[DETAILSCALE]->GetVecValue( vParams, 4 );
  889. pShaderAPI->SetPixelShaderConstant( 108, vParams, 1 );
  890. params[DETAILPHONGBOOST]->GetVecValue( vParams, 4 );
  891. pShaderAPI->SetPixelShaderConstant( 32, vParams, 1 );
  892. params[DAMAGEDETAILPHONGBOOST]->GetVecValue( vParams, 4 );
  893. pShaderAPI->SetPixelShaderConstant( 100, vParams, 1 );
  894. params[DETAILENVBOOST]->GetVecValue( vParams, 4 );
  895. pShaderAPI->SetPixelShaderConstant( 34, vParams, 1 );
  896. params[DAMAGEDETAILENVBOOST]->GetVecValue( vParams, 4 );
  897. pShaderAPI->SetPixelShaderConstant( 35, vParams, 1 );
  898. params[DETAILPHONGALBEDOTINT]->GetVecValue( vParams, 4 );
  899. pShaderAPI->SetPixelShaderConstant( 36, vParams, 1 );
  900. params[DETAILWARPINDEX]->GetVecValue( vParams, 4 );
  901. pShaderAPI->SetPixelShaderConstant( 37, vParams, 1 );
  902. params[DETAILMETALNESS]->GetVecValue( vParams, 4 );
  903. pShaderAPI->SetPixelShaderConstant( 38, vParams, 1 );
  904. params[DETAILNORMALDEPTH]->GetVecValue( vParams, 4 );
  905. pShaderAPI->SetPixelShaderConstant( 39, vParams, 1 );
  906. params[DAMAGENORMALEDGEDEPTH]->GetVecValue( vParams, 4 );
  907. pShaderAPI->SetPixelShaderConstant( 40, vParams, 1 );
  908. float vParams2[2] = { 0, 0 };
  909. params[DAMAGELEVELS1]->GetVecValue( vParams, 2 );
  910. params[DAMAGELEVELS2]->GetVecValue( vParams2, 2 );
  911. vParams[2] = vParams2[0];
  912. vParams[3] = vParams2[1];
  913. pShaderAPI->SetPixelShaderConstant( 41, vParams, 1 );
  914. params[DAMAGELEVELS3]->GetVecValue( vParams, 2 );
  915. params[DAMAGELEVELS4]->GetVecValue( vParams2, 2 );
  916. vParams[2] = vParams2[0];
  917. vParams[3] = vParams2[1];
  918. pShaderAPI->SetPixelShaderConstant( 42, vParams, 1 );
  919. SetPixelShaderTextureTransform( 43, PATTERNTEXTURETRANSFORM ); // 43-44
  920. params[PATTERNCOLORINDICES]->GetVecValue( vParams, 4 );
  921. vParams[0] = clamp( vParams[0] - 1, 0, 7 );
  922. vParams[1] = clamp( vParams[1] - 1, 0, 7 );
  923. vParams[2] = clamp( vParams[2] - 1, 0, 7 );
  924. vParams[3] = clamp( vParams[3] - 1, 0, 7 );
  925. pShaderAPI->SetPixelShaderConstant( 45, vParams, 1 );
  926. vParams[0] = pow( params[WEARPROGRESS]->GetFloatValue(), params[WEAREXPONENT]->GetFloatValue() );
  927. vParams[1] = params[PATTERNDETAILINFLUENCE]->GetFloatValue();
  928. if ( bPattern )
  929. {
  930. vParams[2] = clamp( params[PATTERNREPLACEINDEX]->GetIntValue() - 1, 0, 7 );
  931. }
  932. else
  933. {
  934. vParams[2] = -1;
  935. }
  936. vParams[3] = 1.0f / 1024.0f; // assuming texture size of 1024. Should be dynamic?
  937. pShaderAPI->SetPixelShaderConstant( 46, vParams, 1 );
  938. float vParams3[3] = { 0, 0, 0 };
  939. params[PALETTECOLOR4]->GetVecValue( vParams3, 3 );
  940. vParams3[0] = SrgbGammaToLinear( vParams3[0] / 255.0f );
  941. vParams3[1] = SrgbGammaToLinear( vParams3[1] / 255.0f );
  942. vParams3[2] = SrgbGammaToLinear( vParams3[2] / 255.0f );
  943. params[PALETTECOLOR1]->GetVecValue( vParams, 3 );
  944. vParams[0] = SrgbGammaToLinear( vParams[0] / 255.0f );
  945. vParams[1] = SrgbGammaToLinear( vParams[1] / 255.0f );
  946. vParams[2] = SrgbGammaToLinear( vParams[2] / 255.0f );
  947. vParams[3] = vParams3[0];
  948. pShaderAPI->SetPixelShaderConstant( 47, vParams, 1 );
  949. params[PALETTECOLOR2]->GetVecValue( vParams, 3 );
  950. vParams[0] = SrgbGammaToLinear( vParams[0] / 255.0f );
  951. vParams[1] = SrgbGammaToLinear( vParams[1] / 255.0f );
  952. vParams[2] = SrgbGammaToLinear( vParams[2] / 255.0f );
  953. vParams[3] = vParams3[1];
  954. pShaderAPI->SetPixelShaderConstant( 48, vParams, 1 );
  955. params[PALETTECOLOR3]->GetVecValue( vParams, 3 );
  956. vParams[0] = SrgbGammaToLinear( vParams[0] / 255.0f );
  957. vParams[1] = SrgbGammaToLinear( vParams[1] / 255.0f );
  958. vParams[2] = SrgbGammaToLinear( vParams[2] / 255.0f );
  959. vParams[3] = vParams3[2];
  960. pShaderAPI->SetPixelShaderConstant( 49, vParams, 1 );
  961. params[PALETTECOLOR8]->GetVecValue( vParams3, 3 );
  962. vParams3[0] = SrgbGammaToLinear( vParams3[0] / 255.0f );
  963. vParams3[1] = SrgbGammaToLinear( vParams3[1] / 255.0f );
  964. vParams3[2] = SrgbGammaToLinear( vParams3[2] / 255.0f );
  965. params[PALETTECOLOR5]->GetVecValue( vParams, 3 );
  966. vParams[0] = SrgbGammaToLinear( vParams[0] / 255.0f );
  967. vParams[1] = SrgbGammaToLinear( vParams[1] / 255.0f );
  968. vParams[2] = SrgbGammaToLinear( vParams[2] / 255.0f );
  969. vParams[3] = vParams3[0];
  970. pShaderAPI->SetPixelShaderConstant( 50, vParams, 1 );
  971. params[PALETTECOLOR6]->GetVecValue( vParams, 3 );
  972. vParams[0] = SrgbGammaToLinear( vParams[0] / 255.0f );
  973. vParams[1] = SrgbGammaToLinear( vParams[1] / 255.0f );
  974. vParams[2] = SrgbGammaToLinear( vParams[2] / 255.0f );
  975. vParams[3] = vParams3[1];
  976. pShaderAPI->SetPixelShaderConstant( 51, vParams, 1 );
  977. params[PALETTECOLOR7]->GetVecValue( vParams, 3 );
  978. vParams[0] = SrgbGammaToLinear( vParams[0] / 255.0f );
  979. vParams[1] = SrgbGammaToLinear( vParams[1] / 255.0f );
  980. vParams[2] = SrgbGammaToLinear( vParams[2] / 255.0f );
  981. vParams[3] = vParams3[2];
  982. pShaderAPI->SetPixelShaderConstant( 52, vParams, 1 );
  983. SetPixelShaderTextureTransform( 53, GRUNGETEXTURETRANSFORM ); // 53-54
  984. params[GRIME]->GetVecValue( vParams, 4);
  985. pShaderAPI->SetPixelShaderConstant( 55, vParams, 1 );
  986. params[WEARDETAILPHONGBOOST]->GetVecValue( vParams, 4 );
  987. pShaderAPI->SetPixelShaderConstant( 56, vParams, 1 );
  988. params[WEARDETAILENVBOOST]->GetVecValue( vParams, 4 );
  989. pShaderAPI->SetPixelShaderConstant( 57, vParams, 1 );
  990. params[DAMAGEEDGEPHONGBOOST]->GetVecValue( vParams, 4 );
  991. pShaderAPI->SetPixelShaderConstant( 58, vParams, 1 );
  992. params[DAMAGEEDGEENVBOOST]->GetVecValue( vParams, 4 );
  993. pShaderAPI->SetPixelShaderConstant( 59, vParams, 1 );
  994. params[CURVATUREWEARBOOST]->GetVecValue( vParams, 4 );
  995. pShaderAPI->SetPixelShaderConstant( 60, vParams, 1 );
  996. params[CURVATUREWEARPOWER]->GetVecValue( vParams, 4 );
  997. pShaderAPI->SetPixelShaderConstant( 61, vParams, 1 );
  998. params[DAMAGEDETAILSATURATION]->GetVecValue( vParams, 4 );
  999. pShaderAPI->SetPixelShaderConstant( 62, vParams, 1 );
  1000. params[DAMAGEGRUNGE]->GetVecValue( vParams, 4);
  1001. pShaderAPI->SetPixelShaderConstant( 63, vParams, 1 );
  1002. params[DETAILGRUNGE]->GetVecValue(vParams, 4);
  1003. pShaderAPI->SetPixelShaderConstant(90, vParams, 1);
  1004. vParams[0] = params[PATTERNPHONGFACTOR]->GetFloatValue();
  1005. vParams[1] = params[PATTERNPAINTTHICKNESS]->GetFloatValue();
  1006. vParams[2] = 1;
  1007. vParams[3] = 0;
  1008. pShaderAPI->SetPixelShaderConstant(91, vParams, 1);
  1009. params[DAMAGEDETAILBRIGHTNESSADJUSTMENT]->GetVecValue(vParams, 4);
  1010. pShaderAPI->SetPixelShaderConstant(92, vParams, 1);
  1011. params[GRUNGEMAX]->GetVecValue(vParams, 4);
  1012. pShaderAPI->SetPixelShaderConstant(93, vParams, 1);
  1013. // c68-89 used by csms
  1014. params[GRIMESATURATION]->GetVecValue(vParams, 4);
  1015. pShaderAPI->SetPixelShaderConstant(94, vParams, 1);
  1016. params[GRIMEBRIGHTNESSADJUSTMENT]->GetVecValue(vParams, 4);
  1017. pShaderAPI->SetPixelShaderConstant(95, vParams, 1);
  1018. SetPixelShaderTextureTransform(96, GRUNGETEXTUREROTATION);
  1019. SetPixelShaderTextureTransform( 98, PATTERNTEXTUREROTATION );
  1020. }
  1021. }
  1022. Draw();
  1023. }
  1024. END_SHADER