Objects.fxh 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464
  1. //////////////////////////////////////////////////////////////////////////////
  2. // ©2008 Electronic Arts Inc
  3. //
  4. // FX Shader for vehicles and structures. Infantry should use Infantry.fx
  5. //////////////////////////////////////////////////////////////////////////////
  6. //#define SUPPORT_RECOLORING 1 // Defined only in faction specific versions
  7. //#define SUPPORT_SPECMAP 1 // Define for objects shader with specularity/envmap/self illumination map
  8. //#define SUPPORT_LIGHTMAP 1 // Define for objects that use a lightmap (supports HDR)
  9. //#define SPECIFY_CUSTOM_ENVMAP 1 // Define to allow environment cube map to be specified in art tool instead of taken from code binding
  10. //#define SUPPORT_DAMAGETEXTURE 1 // Define to allow blending between a damage texture and pristine texture based on vertex or bone based alpha values
  11. //#define SUPPORT_FILLDAMAGETEXTURE 1 // Define to allow blending between a damage texture and pristine texture based on vertex or bone based alpha values
  12. //#define SUPPORT_JAPANBUILDUP 1 // Defined for Japanese Building Construction Shader
  13. //#define SUPPORT_FROZEN 1 // Defined to change appearance of object to ice
  14. //#define SUPPORT_TESLA 1 // It is what you think it is
  15. //#define SUPPORT_ALTMAPPING 1 // Defined to change mapping coords if using Iron Curtain or Chrono Rift
  16. //#define SUPPORT_IRONCURTAIN 1 // Defined to change appearance of object to invulnerable
  17. //#define SUPPORT_CHRONORIFT 1 // Defined to change appearance of object to phased
  18. //#define SUPPORT_CRUSHED 1 // Defined to change the vertex shader over time to a crushed object from Yuriko
  19. //#define SUPPORT_XRAY 1 // Used to automagically fade out objects between Yuriko and the camera; specific to her commando levels
  20. //#define SUPPORT_NOSHADOWS 1 // Used in Yuriko's level to remove shadow casting from specific objects
  21. //#define SUPPORT_REFLECTION 1 // Uses the realtime reflection buffer
  22. //#define SUPPORT_FORMATIONPREVIEW 1 // Defined to change appearance of object for formation preview
  23. //#define SUPPORT_PSYONIC 1 // Defined for Yuriko's super power of lifting objects in the air
  24. //#define SUPPORT_TREAD_SCROLLING 1 // Defined for animating the texcoord 0 based on the bone opacity, used for tank tread animation
  25. //#define SUPPORT_SSAO
  26. #define USE_INTERACTIVE_LIGHTS 1
  27. #define PER_PIXEL_POINT_LIGHT
  28. #define SUPPORT_CLOUDS 1
  29. #define SUPPORT_FOG 1
  30. #define SUPPORT_GLOBAL_LIGHTS 1
  31. #define SUPPORT_LOCAL_LIGHTS 1
  32. #define MaxNumPointLights 8
  33. #define FIRSTPASS 0
  34. #define FROZENPASS 1
  35. #define TESLAPASS 2
  36. #include "Common.fxh"
  37. #include "Gamma.fxh"
  38. #include "SSAO.fxh"
  39. #include "ShadowMap.fxh"
  40. #include "MacroTexture.fxh"
  41. int _SasGlobal : SasGlobal
  42. <
  43. string UIWidget = "None";
  44. int3 SasVersion = int3(1, 0, 0);
  45. #if defined(SUPPORT_FORMATIONPREVIEW)
  46. string RenderBin = "StaticSort1";
  47. #elif defined(SUPPORT_XRAY)
  48. string RenderBin = "PartiallyTransparentWall";
  49. #elif defined(SUPPORT_REFLECTION)
  50. string RenderBin = "TerrainLikeGroundObject";
  51. #endif
  52. int MaxLocalLights = MaxNumPointLights;
  53. int MaxSupportedInstancingMode = INSTANCING_MODE_ONE_PER_DRAW_CALL;
  54. > = 0;
  55. #if defined(EA_PLATFORM_WINDOWS) && defined(_3DSMAX_)
  56. // ----------------------------------------------------------------------------
  57. // SAMPLER : nhendricks : had to pull these in here for MAX to compile
  58. // ----------------------------------------------------------------------------
  59. #define SAMPLER_2D_BEGIN(samplerName, annotations) \
  60. texture samplerName \
  61. < \
  62. annotations \
  63. >; \
  64. sampler2D samplerName##Sampler = sampler_state \
  65. { \
  66. Texture = < samplerName >;
  67. #define SAMPLER_2D_END };
  68. #define SAMPLER( samplerName ) samplerName##Sampler
  69. #define SAMPLER_CUBE_BEGIN(samplerName, annotations) \
  70. texture samplerName \
  71. < \
  72. annotations \
  73. >; \
  74. samplerCUBE samplerName##Sampler = sampler_state \
  75. { \
  76. Texture = < samplerName >;
  77. #define SAMPLER_CUBE_END };
  78. #if defined(_3DSMAX_)
  79. #define DECLARE_MAPPING_TEXCOORD(texcoordIndex) \
  80. int _3DSTexcoordMapping##texcoordIndex : Texcoord \
  81. < \
  82. int Texcoord = texcoordIndex; \
  83. int MapChannel = 1 + texcoordIndex; \
  84. string UIWidget = "None"; \
  85. >;
  86. #define DECLARE_VERTEXCOLOR_INPUT(variableName, firstTexcoordIndex, secondTexCoordIndex) \
  87. float3 _3DSVertexColor : TEXCOORD##firstTexcoordIndex, \
  88. float _3DSVertexAlpha : TEXCOORD##secondTexCoordIndex
  89. #define DECLARE_VERTEXCOLOR_INPUT_STRUCT(variableName, firstTexcoordIndex, secondTexCoordIndex) \
  90. float3 _3DSVertexColor : TEXCOORD##firstTexcoordIndex; \
  91. float _3DSVertexAlpha : TEXCOORD##secondTexCoordIndex
  92. #endif
  93. #endif
  94. DECLARE_MAPPING_TEXCOORD(0)
  95. #if defined(SUPPORT_DAMAGETEXTURE) || defined(SUPPORT_LIGHTMAP)
  96. DECLARE_MAPPING_TEXCOORD(1)
  97. DECLARE_MAPPING_VERTEXCOLOR(2, 3)
  98. #else
  99. DECLARE_MAPPING_VERTEXCOLOR(1, 2)
  100. #endif
  101. #if defined(SUPPORT_DAMAGETEXTURE)
  102. #define EXPRESSION_EVALUATOR_NAME "Buildings"
  103. #else
  104. #define EXPRESSION_EVALUATOR_NAME "Objects"
  105. #endif
  106. // ----------------------------------------------------------------------------
  107. // Skinning
  108. // ----------------------------------------------------------------------------
  109. #define MaxSkinningBonesPerVertex 1
  110. #include "Skinning.fxh"
  111. // ----------------------------------------------------------------------------
  112. // Light sources
  113. // ----------------------------------------------------------------------------
  114. #define NumDirectionalLightsPerPixel 2
  115. #define NumDirectionalLightsPerPixel_M 1
  116. // ----------------------------------------------------------------------------
  117. // Cloud layer
  118. // ----------------------------------------------------------------------------
  119. SAMPLER_2D_BEGIN( CloudTexture,
  120. string UIWidget = "None";
  121. string SasBindAddress = "Terrain.Cloud.Texture";
  122. string ResourceName = "ShaderPreviewCloud.dds";
  123. )
  124. MinFilter = Linear;
  125. MagFilter = Linear;
  126. MipFilter = Linear;
  127. AddressU = Wrap;
  128. AddressV = Wrap;
  129. SAMPLER_2D_END
  130. // ----------------------------------------------------------------------------
  131. // Environment map
  132. // ----------------------------------------------------------------------------
  133. SAMPLER_CUBE_BEGIN( EnvironmentTexture,
  134. string UIWidget = "None";
  135. string SasBindAddress = "Objects.LightSpaceEnvironmentMap";
  136. string ResourceType = "Cube";
  137. )
  138. MinFilter = Linear;
  139. MagFilter = Linear;
  140. MipFilter = Linear;
  141. AddressU = Clamp;
  142. AddressV = Clamp;
  143. AddressW = Clamp;
  144. SAMPLER_CUBE_END
  145. // ----------------------------------------------------------------------------
  146. // Japanese Building Construction Mask
  147. // ----------------------------------------------------------------------------
  148. #if defined(SUPPORT_JAPANBUILDUP)
  149. SAMPLER_2D_BEGIN( JapanBuildMaskTexture,
  150. string UIWidget = "None";
  151. string SasBindAddress = "WW3D.FXJapanBuildMask";
  152. )
  153. MipFilter = Linear;
  154. MinFilter = Linear;
  155. MagFilter = Linear;
  156. AddressU = WRAP;
  157. AddressV = WRAP;
  158. SAMPLER_2D_END
  159. #endif
  160. // ----------------------------------------------------------------------------
  161. // Frozen shader ice normal map
  162. // ----------------------------------------------------------------------------
  163. #if defined(SUPPORT_FROZEN) || defined(SUPPORT_TESLA)
  164. SAMPLER_2D_BEGIN( FractalNormalMap,
  165. string UIWidget = "None";
  166. string SasBindAddress = "WW3D.FXDistortionFractal";
  167. )
  168. MinFilter = MinFilterBest;
  169. MagFilter = MagFilterBest;
  170. MipFilter = MipFilterBest;
  171. MaxAnisotropy = 8;
  172. AddressU = Wrap;
  173. AddressV = Wrap;
  174. SAMPLER_2D_END
  175. #endif
  176. // ----------------------------------------------------------------------------
  177. // Iron Curtain texture map
  178. // ----------------------------------------------------------------------------
  179. #if defined(SUPPORT_IRONCURTAIN)
  180. SAMPLER_2D_BEGIN( IronCurtainTexture,
  181. string UIWidget = "None";
  182. string SasBindAddress = "WW3D.FXIronCurtain";
  183. )
  184. MipFilter = Linear;
  185. MinFilter = Linear;
  186. MagFilter = Linear;
  187. AddressU = WRAP;
  188. AddressV = WRAP;
  189. SAMPLER_2D_END
  190. #endif
  191. // ----------------------------------------------------------------------------
  192. // Chrono Rift texture map
  193. // ----------------------------------------------------------------------------
  194. #if defined(SUPPORT_CHRONORIFT)
  195. SAMPLER_2D_BEGIN( ChronoRiftTexture,
  196. string UIWidget = "None";
  197. string SasBindAddress = "WW3D.FXChronoRift";
  198. )
  199. MipFilter = Linear;
  200. MinFilter = Linear;
  201. MagFilter = Linear;
  202. AddressU = WRAP;
  203. AddressV = WRAP;
  204. SAMPLER_2D_END
  205. #endif
  206. // ----------------------------------------------------------------------------
  207. // Tesla Hit Effect texture map
  208. // ----------------------------------------------------------------------------
  209. #if defined(SUPPORT_TESLA)
  210. SAMPLER_2D_BEGIN( TeslaTexture,
  211. string UIWidget = "None";
  212. string SasBindAddress = "WW3D.FXLightningTeslaHit";
  213. )
  214. MipFilter = Linear;
  215. MinFilter = Linear;
  216. MagFilter = Linear;
  217. AddressU = WRAP;
  218. AddressV = WRAP;
  219. SAMPLER_2D_END
  220. #endif
  221. // ----------------------------------------------------------------------------
  222. // Xray texture map
  223. // ----------------------------------------------------------------------------
  224. #if defined(SUPPORT_XRAY)
  225. SAMPLER_2D_BEGIN( XrayTexture,
  226. string UIWidget = "None";
  227. string SasBindAddress = "WW3D.FXXrayMask";
  228. )
  229. MipFilter = Linear;
  230. MinFilter = Linear;
  231. MagFilter = Linear;
  232. AddressU = CLAMP;
  233. AddressV = CLAMP;
  234. SAMPLER_2D_END
  235. #define XRAY_TRANSPARENCY_THRESHOLD 0.05
  236. #endif
  237. #if defined(SUPPORT_REFLECTION) // Uses the realtime reflection buffer
  238. // ----------------------------------------------------------------------------
  239. // Reflection - uses water reflection buffer
  240. // ----------------------------------------------------------------------------
  241. SAMPLER_2D_BEGIN( ReflectionTexture,
  242. string UIWidget = "None";
  243. string SasBindAddress = "Water.ReflectionTexture";
  244. )
  245. MipFilter = Point;
  246. MinFilter = Linear;
  247. MagFilter = Linear;
  248. AddressU = CLAMP;
  249. AddressV = CLAMP;
  250. SAMPLER_2D_END
  251. #endif
  252. // ----------------------------------------------------------------------------
  253. // Editable parameters
  254. // ----------------------------------------------------------------------------
  255. SAMPLER_2D_BEGIN( DiffuseTexture,
  256. string UIName = "Diffuse Texture";
  257. )
  258. MinFilter = MinFilterBest;
  259. MagFilter = MagFilterBest;
  260. MipFilter = MipFilterBest;
  261. MaxAnisotropy = 8;
  262. AddressU = Wrap;
  263. AddressV = Wrap;
  264. SAMPLER_2D_END
  265. SAMPLER_2D_BEGIN( NormalMap,
  266. string UIName = "Normal Texture";
  267. )
  268. MinFilter = MinFilterBest;
  269. MagFilter = MagFilterBest;
  270. MipFilter = MipFilterBest;
  271. MaxAnisotropy = 8;
  272. AddressU = Wrap;
  273. AddressV = Wrap;
  274. SAMPLER_2D_END
  275. #if defined(SUPPORT_SPECMAP)
  276. SAMPLER_2D_BEGIN( SpecMap,
  277. string UIName = "Specular Map";
  278. )
  279. MinFilter = MinFilterBest;
  280. MagFilter = MagFilterBest;
  281. MipFilter = MipFilterBest;
  282. MaxAnisotropy = 8;
  283. AddressU = Wrap;
  284. AddressV = Wrap;
  285. SAMPLER_2D_END
  286. #endif
  287. // ----------------------------------------------------------------------------
  288. // Light map
  289. // ----------------------------------------------------------------------------
  290. #if defined(SUPPORT_LIGHTMAP)
  291. SAMPLER_2D_BEGIN( LightMap,
  292. string UIName = "Light Map";
  293. )
  294. MinFilter = MinFilterBest;
  295. MagFilter = MagFilterBest;
  296. MipFilter = MipFilterBest;
  297. MaxAnisotropy = 8;
  298. AddressU = Clamp;
  299. AddressV = Clamp;
  300. SAMPLER_2D_END
  301. #endif
  302. #if defined(SUPPORT_DAMAGETEXTURE)
  303. SAMPLER_2D_BEGIN( DamagedTexture,
  304. string UIName = "Damaged Texture";
  305. )
  306. MinFilter = MinFilterBest;
  307. MagFilter = MagFilterBest;
  308. MipFilter = MipFilterBest;
  309. MaxAnisotropy = 8;
  310. AddressU = Wrap;
  311. AddressV = Wrap;
  312. SAMPLER_2D_END
  313. #if defined(_3DSMAX_)
  314. bool PreviewFullyDamaged
  315. <
  316. string UIName = "Preview Fully Damaged";
  317. bool ExportValue = false;
  318. > = false;
  319. #endif // defined(_3DSMAX_)
  320. #endif // defined(SUPPORT_DAMAGETEXTURE)
  321. #if defined(MATERIAL_PARAMS_ALLIED)
  322. // Fixed material parameters for ALLIED
  323. static const float BumpScale = 1.5;
  324. static const float3 AmbientColor = float3(0.1, 0.1, 0.1);
  325. static const float4 DiffuseColor = float4(1.0, 1.0, 1.0, 1.0);
  326. static const float3 SpecularColor = float3(0.8, 0.8, 0.8);
  327. static const float SpecularExponent = 50.0;
  328. #elif defined(MATERIAL_PARAMS_SOVIET)
  329. // Fixed material parameters for SOVIET
  330. static const float BumpScale = 1.5;
  331. static const float3 AmbientColor = float3(0.1, 0.1, 0.1);
  332. static const float4 DiffuseColor = float4(1.0, 1.0, 1.0, 1.0);
  333. static const float3 SpecularColor = float3(0.8, 0.8, 0.8);
  334. static const float SpecularExponent = 45.0;
  335. #elif defined(MATERIAL_PARAMS_JAPAN)
  336. // Fixed material parameters for JAPAN
  337. static const float BumpScale = 1.5;
  338. static const float3 AmbientColor = float3(0.1, 0.1, 0.1);
  339. static const float4 DiffuseColor = float4(1.0, 1.0, 1.0, 1.0);
  340. static const float3 SpecularColor = float3(0.8, 0.8, 0.8);
  341. static const float SpecularExponent = 50.0;
  342. #elif defined(SUPPORT_FROZEN)
  343. // Fixed material parameters for frozen objects
  344. static const float BumpScale = 3;
  345. static const float3 AmbientColor = float3(1, 1, 1);
  346. static const float4 DiffuseColor = float4(1.0, 1.0, 1.0, 1.0);
  347. static const float3 SpecularColor = float3(0.8, 0.8, 0.8);
  348. static const float SpecularExponent = 50.0;
  349. #else
  350. // Material parameters defined by UI
  351. float BumpScale
  352. <
  353. string UIName = "Bump Height";
  354. string UIWidget = "Slider";
  355. float UIMin = 0.0;
  356. float UIMax = 10.0;
  357. float UIStep = 0.1;
  358. > = 1.0;
  359. float3 AmbientColor
  360. <
  361. string UIName = "Ambient Color";
  362. string UIWidget = "Color";
  363. > = float3(0.4, 0.4, 0.4);
  364. float4 DiffuseColor
  365. <
  366. string UIName = "Diffuse Color";
  367. string UIWidget = "Color";
  368. > = float4(1.0, 1.0, 1.0, 1.0);
  369. float3 SpecularColor
  370. <
  371. string UIName = "Specular Color";
  372. string UIWidget = "Color";
  373. > = float3(0.8, 0.8, 0.8);
  374. float SpecularExponent
  375. <
  376. string UIName = "Specular Exponent";
  377. string UIWidget = "Slider";
  378. float UIMax = 200.0f;
  379. float UIMin = 0;
  380. float UIStep = 1.0f;
  381. > = 50.0;
  382. #endif // Material parameters defined by UI
  383. #if defined(SUPPORT_SPECMAP)
  384. float EnvMult
  385. <
  386. string UIName = "Reflection Multiplier";
  387. string UIWidget = "Slider";
  388. float UIMax = 1.0f;
  389. float UIMin = 0;
  390. float UIStep = 0.01f;
  391. > = 1.0;
  392. #endif
  393. #if defined(SUPPORT_DAMAGETEXTURE)
  394. // For damage texture rendering we always need alpha testing to be enabled. So don't offer it as configuration option.
  395. const bool AlphaTestEnable = true;
  396. #else
  397. bool AlphaTestEnable
  398. <
  399. string UIName = "Alpha Test Enable";
  400. > = false;
  401. #endif
  402. // ----------------------------------------------------------------------------
  403. // Shroud
  404. // ----------------------------------------------------------------------------
  405. ShroudSetup Shroud
  406. <
  407. string UIWidget = "None";
  408. string SasBindAddress = "Terrain.Shroud";
  409. > = DEFAULT_SHROUD;
  410. SAMPLER_2D_BEGIN( ShroudTexture,
  411. string UIWidget = "None";
  412. string SasBindAddress = "Terrain.Shroud.Texture";
  413. )
  414. MinFilter = Linear;
  415. MagFilter = Linear;
  416. MipFilter = Linear;
  417. AddressU = Clamp;
  418. AddressV = Clamp;
  419. SAMPLER_2D_END
  420. #if !defined(USE_INDIRECT_CONSTANT)
  421. float OpacityOverride
  422. <
  423. string UIWidget = "None";
  424. string SasBindAddress = "WW3D.OpacityOverride";
  425. > = 1.0;
  426. float3 TintColor
  427. <
  428. string UIWidget = "None";
  429. string SasBindAddress = "WW3D.TintColor";
  430. > = float3(1, 1, 1);
  431. #endif // #if !defined(USE_INDIRECT_CONSTANT)
  432. // ----------------------------------------------------------------------------
  433. // Transformations (world transformations are in skinning header)
  434. // ----------------------------------------------------------------------------
  435. #if defined(_WW3D_)
  436. #if !defined(USE_INDIRECT_CONSTANT)
  437. float4x4 ViewProjection
  438. <
  439. string UIWidget = "None";
  440. string SasBindAddress = "Sas.Camera.WorldToProjection";
  441. >;
  442. float3 EyePosition
  443. <
  444. string UIWidget = "None";
  445. string SasBindAddress = "Sas.Camera.Position";
  446. >;
  447. #endif // #if !defined(USE_INDIRECT_CONSTANT)
  448. float4x4 GetViewProjection()
  449. {
  450. return ViewProjection;
  451. }
  452. float3 GetEyePosition()
  453. {
  454. return EyePosition;
  455. }
  456. #else // #if defined(_WW3D_)
  457. float4x4 View : View;
  458. float4x3 ViewI : ViewInverse;
  459. float4x4 Projection : Projection;
  460. float4x4 GetViewProjection()
  461. {
  462. return mul(View, Projection);
  463. }
  464. float3 GetEyePosition()
  465. {
  466. return ViewI[3];
  467. }
  468. #endif // #if defined(_WW3D_)
  469. // Time (ie. material is animated)
  470. float Time : Time;
  471. // ----------------------------------------------------------------------------
  472. // SHADER: Default High LOD
  473. // ----------------------------------------------------------------------------
  474. struct VSOutput_H
  475. {
  476. float4 Position : POSITION;
  477. float4 TexCoord0_TexCoord1 : TEXCOORD0;
  478. float3x3 TangentToWorldSpace : TEXCOORD1_CENTROID;
  479. float3 WorldPosition : TEXCOORD4;
  480. float4 ShadowMapTexCoord : TEXCOORD5;
  481. float4 ShroudTexCoord_CloudTexCoord : TEXCOORD6;
  482. #if defined(SUPPORT_XRAY)
  483. float3 ScreenSpaceCoord : TEXCOORD7;
  484. #endif
  485. float4 Color : COLOR0;
  486. #if defined(SUPPORT_REFLECTION)
  487. float3 VertexColor : COLOR1;
  488. #endif
  489. };
  490. // ----------------------------------------------------------------------------
  491. // SHADER: VS
  492. // ----------------------------------------------------------------------------
  493. #if defined(EA_PLATFORM_PS3)
  494. VSOutput_H VS_H(VSInputSkinningOneBoneTangentFrame InSkin,
  495. float2 TexCoord0 : TEXCOORD0,
  496. #if defined(SUPPORT_DAMAGETEXTURE) || defined(SUPPORT_LIGHTMAP)
  497. float2 TexCoord1 : TEXCOORD1,
  498. DECLARE_VERTEXCOLOR_INPUT(VertexColor, 2, 3),
  499. #else
  500. DECLARE_VERTEXCOLOR_INPUT(VertexColor, 1, 2),
  501. #endif
  502. uniform int numJointsPerVertex,
  503. uniform int isMultiPass)
  504. {
  505. VSOutput_H Out;
  506. float3 worldPosition = 0;
  507. float3 worldNormal = 0;
  508. float3 worldTangent = 0;
  509. float3 worldBinormal = 0;
  510. CalculatePositionAndTangentFrame(InSkin, numJointsPerVertex, worldPosition, worldNormal, worldTangent, worldBinormal);
  511. // Get the skins opacity value
  512. VertexColor.w *= GetOpacity(InSkin, numJointsPerVertex);
  513. #if defined(_3DSMAX_) && defined(SUPPORT_DAMAGETEXTURE)
  514. if (PreviewFullyDamaged)
  515. {
  516. VertexColor.w = 0.0;
  517. }
  518. #endif
  519. #if !defined(SUPPORT_ALTMAPPING)
  520. #if defined(SUPPORT_CRUSHED)
  521. Out.Color = float4(AmbientLightColor * AmbientColor, 1);
  522. #else
  523. Out.Color = float4(AmbientLightColor * AmbientColor, OpacityOverride);
  524. #endif
  525. #if !defined(SUPPORT_REFLECTION)
  526. Out.Color *= VertexColor;
  527. #endif
  528. #endif // SUPPORT_ALTMAPPING
  529. Out.TexCoord0_TexCoord1.xy = TexCoord0.xy;
  530. Out.Position = mul(float4(worldPosition, 1), GetViewProjection());
  531. Out.ShroudTexCoord_CloudTexCoord.xy = CalculateShroudTexCoord(Shroud, worldPosition);
  532. return Out;
  533. }
  534. #else // EA_PLATFORM_WINDOWS || EA_PLATFORM_XENON
  535. VSOutput_H VS_H(VSInputSkinningOneBoneTangentFrame InSkin,
  536. float2 TexCoord0 : TEXCOORD0,
  537. #if defined(SUPPORT_DAMAGETEXTURE) || defined(SUPPORT_LIGHTMAP)
  538. float2 TexCoord1 : TEXCOORD1,
  539. DECLARE_VERTEXCOLOR_INPUT(VertexColor, 2, 3),
  540. #else
  541. DECLARE_VERTEXCOLOR_INPUT(VertexColor, 1, 2),
  542. #endif
  543. uniform int numJointsPerVertex,
  544. uniform int isMultiPass)
  545. {
  546. USE_VERTEXCOLOR(VertexColor);
  547. USE_TEXCOORD(TexCoord0);
  548. #if defined(SUPPORT_DAMAGETEXTURE) || defined(SUPPORT_LIGHTMAP)
  549. USE_TEXCOORD(TexCoord1);
  550. #endif
  551. USE_DIRECTIONAL_LIGHT_INTERACTIVE(DirectionalLight, 0);
  552. VSOutput_H Out;
  553. float3 worldPosition = 0;
  554. float3 worldNormal = 0;
  555. float3 worldTangent = 0;
  556. float3 worldBinormal = 0;
  557. CalculatePositionAndTangentFrame(InSkin, numJointsPerVertex,
  558. worldPosition, worldNormal, worldTangent, worldBinormal);
  559. // Get the skins opacity value
  560. VertexColor.w *= GetOpacity(InSkin, numJointsPerVertex);
  561. #if defined(_3DSMAX_) && defined(SUPPORT_DAMAGETEXTURE)
  562. if (PreviewFullyDamaged)
  563. {
  564. VertexColor.w = 0.0;
  565. }
  566. #endif
  567. #if defined(SUPPORT_TREAD_SCROLLING)
  568. // Tread scrolling uses the vertex color opacity for animating the U coordinate
  569. TexCoord0.x += VertexColor.w;
  570. // Don't use it for opacity then.
  571. VertexColor.w = 1.0f;
  572. #endif
  573. if (isMultiPass == FROZENPASS)
  574. {
  575. // Extrude geo to create a shell for the ice
  576. worldPosition += worldNormal * 1.5;
  577. }
  578. // Build 3x3 tranform from object to tangent space
  579. Out.TangentToWorldSpace = float3x3(-worldBinormal, -worldTangent, worldNormal);
  580. #if !defined(SUPPORT_ALTMAPPING)
  581. #if defined(SUPPORT_CRUSHED) || defined(SUPPORT_PSYONIC)
  582. Out.Color = float4(AmbientLightColor * AmbientColor, 1);
  583. #else
  584. Out.Color = float4(AmbientLightColor * AmbientColor, OpacityOverride);
  585. #endif
  586. // Compute remaining directional lights per vertex, others will be done in pixel shader
  587. float3 diffuseLight = 0;
  588. for (int i = NumDirectionalLightsPerPixel; i < NumDirectionalLights; i++)
  589. {
  590. diffuseLight += DirectionalLight[i].Color * max(0, dot(worldNormal, DirectionalLight[i].Direction));
  591. }
  592. Out.Color.xyz += diffuseLight * DiffuseColor;
  593. Out.Color.xyz /= 2; // Prevent clamping in interpolator
  594. #if !defined(SUPPORT_REFLECTION)
  595. Out.Color *= VertexColor;
  596. #endif
  597. #endif // SUPPORT_ALTMAPPING
  598. Out.WorldPosition = worldPosition;
  599. Out.ShadowMapTexCoord = CalculateShadowMapTexCoord(worldPosition);
  600. if (isMultiPass == TESLAPASS)
  601. {
  602. // Hi-jack shadow coords as we dont use them in this pass
  603. Out.ShadowMapTexCoord.xy = (TexCoord0 * .003) + (worldPosition.xy * .003);
  604. Out.ShadowMapTexCoord.wz = (TexCoord0 * .5);
  605. Out.ShadowMapTexCoord.wz += Time * .15;
  606. }
  607. // pass texture coordinates for fetching the diffuse and normal maps
  608. Out.TexCoord0_TexCoord1.xy = TexCoord0.xy;
  609. if (isMultiPass == FROZENPASS)
  610. {
  611. // Use world coords when mapping
  612. Out.TexCoord0_TexCoord1.xy = worldPosition.xy * .015;
  613. }
  614. // transform position to projection space
  615. ISOLATE Out.Position = mul(float4(worldPosition, 1), GetViewProjection());
  616. #if defined(SUPPORT_DAMAGETEXTURE) || defined(SUPPORT_LIGHTMAP)
  617. float2 texCoord1 = TexCoord1;
  618. #else
  619. float2 texCoord1 = TexCoord0;
  620. #endif
  621. Out.TexCoord0_TexCoord1.zw = texCoord1.yx;
  622. #if defined (SUPPORT_ALTMAPPING)
  623. // -------------------------------------------------------------------------------
  624. // -- Texture Coords and Mapping -------------------------------------------------
  625. // -------------------------------------------------------------------------------
  626. // Build Tex coords, animate and scale ---------------------------------------
  627. float texScalar = .75; // Scale
  628. float texSpeed = Time * .3; // animate coords as a multiplier of Time
  629. float texDivergenceAngle = 55; // this is the angle difference between the 2 coords
  630. // Use the tex coords on the model but offset them slightly based on world
  631. // coords to keep multiple units from animating in sync
  632. float2 TexCoords = (TexCoord0 + (worldPosition.xy * .003)) * texScalar;
  633. // Build Texture Rotation Matrix And Convert Degrees to Radians --
  634. float cosAngle = 0;
  635. float sinAngle = 0;
  636. float2x2 uvCoordRotate = { 1.0f, 0.0f, 1.0f, 0.0f };
  637. sincos (texDivergenceAngle * .017453, sinAngle, cosAngle);
  638. // Build Rotation
  639. uvCoordRotate[0][0] = cosAngle;
  640. uvCoordRotate[0][1] = -sinAngle;
  641. uvCoordRotate[1][1] = uvCoordRotate[0][0];
  642. uvCoordRotate[1][0] = -uvCoordRotate[0][1];
  643. // Rotate and Animate Divergence Texture Coords --------------------
  644. float2 TexCoordsDiverge = mul(TexCoords, uvCoordRotate);
  645. TexCoordsDiverge.x += texSpeed;
  646. float2 TexCoordsDivergeInv = mul(TexCoords, transpose(uvCoordRotate));
  647. TexCoordsDivergeInv.x += texSpeed;
  648. Out.TexCoord0_TexCoord1.xy = TexCoordsDiverge;
  649. Out.TexCoord0_TexCoord1.zw = TexCoordsDivergeInv;
  650. //Hi-jack shadow coords for this shader since we dont use them
  651. Out.ShadowMapTexCoord.xy = TexCoord0;
  652. Out.Color = 0;
  653. #endif //SUPPORT_ALTMAPPING
  654. Out.ShroudTexCoord_CloudTexCoord.xy = CalculateShroudTexCoord(Shroud, worldPosition);
  655. Out.ShroudTexCoord_CloudTexCoord.zw = CalculateCloudTexCoord(Cloud, worldPosition, Time);
  656. #if defined(SUPPORT_XRAY)
  657. Out.ScreenSpaceCoord.xy = normalize(mul(float4(worldPosition, 1), GetViewProjection()));
  658. Out.ScreenSpaceCoord.xy += .5;
  659. // Generate a scalar based on viewspace to cull the XRay texture from removing objects behind Yuriko
  660. Out.ScreenSpaceCoord.z = (saturate(length(worldPosition - GetEyePosition()) * .02 - 6));
  661. #endif
  662. #if defined(SUPPORT_REFLECTION) //Pass Vertex Colors to the Pixel Shader
  663. Out.VertexColor = VertexColor.xyz;
  664. #endif
  665. return Out;
  666. }
  667. #endif
  668. // ----------------------------------------------------------------------------
  669. // SHADER: VS_Xenon
  670. // ----------------------------------------------------------------------------
  671. VSOutput_H VS_Xenon(VSInputSkinningOneBoneTangentFrame InSkin,
  672. float2 TexCoord0 : TEXCOORD0,
  673. #if defined(SUPPORT_DAMAGETEXTURE) || defined(SUPPORT_LIGHTMAP)
  674. float2 TexCoord1 : TEXCOORD1,
  675. DECLARE_VERTEXCOLOR_INPUT(VertexColor, 2, 3),
  676. #else
  677. DECLARE_VERTEXCOLOR_INPUT(VertexColor, 1, 2),
  678. #endif
  679. uniform int isMultiPass)
  680. {
  681. int joints = NumJointsPerVertex;
  682. return VS_H( InSkin, TexCoord0,
  683. #if defined(SUPPORT_DAMAGETEXTURE) || defined(SUPPORT_LIGHTMAP)
  684. TexCoord1,
  685. #endif
  686. PASS_THROUGH_VERTEXCOLOR(VertexColor), min(joints, 1), isMultiPass);
  687. }
  688. // ----------------------------------------------------------------------------
  689. // SHADER: PS
  690. // ----------------------------------------------------------------------------
  691. #if defined(EA_PLATFORM_PS3)
  692. float4 PS_H(VSOutput_H In, uniform bool hasShadow, uniform bool recolorEnabled,
  693. float2 vPos : PIXELLOC, uniform int isMultiPass) COLORTARGET
  694. {
  695. USE_DIRECTIONAL_LIGHT_INTERACTIVE(DirectionalLight, 0);
  696. float2 texCoord0 = In.TexCoord0_TexCoord1.xy;
  697. float2 shroudTexCoord = In.ShroudTexCoord_CloudTexCoord.xy;
  698. // Get diffuse color
  699. float4 baseTexture = tex2D( SAMPLER(DiffuseTexture), texCoord0);
  700. #if defined(SUPPORT_RECOLORING)
  701. if (recolorEnabled)
  702. {
  703. float4 recolorColor = tex2D( SAMPLER(SpecMap), texCoord0);
  704. baseTexture.xyz = lerp(baseTexture.xyz, baseTexture.xyz * RecolorColor * 2, recolorColor.z);
  705. baseTexture.w = 1;
  706. }
  707. #endif //defined(SUPPORT_RECOLORING)
  708. float4 color = baseTexture;
  709. color.w = In.Color.w;
  710. color.xyz *= tex2D(SAMPLER(ShroudTexture), shroudTexCoord).x;
  711. return(color);
  712. }
  713. #else // EA_PLATFORM_WINDOWS || EA_PLATFORM_XENON
  714. float4 PS_H(VSOutput_H In, uniform bool hasShadow, uniform bool recolorEnabled,
  715. float2 vPos : PIXELLOC, uniform int isMultiPass) COLORTARGET
  716. {
  717. USE_DIRECTIONAL_LIGHT_INTERACTIVE(DirectionalLight, 0);
  718. float2 texCoord0 = In.TexCoord0_TexCoord1.xy;
  719. float2 texCoord1 = In.TexCoord0_TexCoord1.wz;
  720. float2 shroudTexCoord = In.ShroudTexCoord_CloudTexCoord.xy;
  721. float2 cloudTexCoord = In.ShroudTexCoord_CloudTexCoord.zw;
  722. float3 worldEyeDir = normalize(GetEyePosition() - In.WorldPosition);
  723. // Get diffuse color
  724. float4 baseTexture = tex2D( SAMPLER(DiffuseTexture), texCoord0);
  725. #if defined(SUPPORT_RECOLORING)
  726. if (recolorEnabled)
  727. {
  728. float4 recolorColor = tex2D( SAMPLER(SpecMap), texCoord0);
  729. baseTexture.xyz = lerp(baseTexture.xyz, baseTexture.xyz * RecolorColor * 2, recolorColor.z);
  730. }
  731. #endif //defined(SUPPORT_RECOLORING)
  732. baseTexture.xyz = GammaToLinear(baseTexture.xyz);
  733. float3 diffuse = baseTexture.xyz * DiffuseColor;
  734. // Get bump map normal
  735. float3 bumpNormal;
  736. bumpNormal = (float3)tex2D(SAMPLER(NormalMap), texCoord0) * 2.0 - 1.0;
  737. #if defined(SUPPORT_FROZEN)
  738. if (isMultiPass == FROZENPASS)
  739. {
  740. bumpNormal = (float3)tex2D(SAMPLER(FractalNormalMap), texCoord0) * 2.0 - 1.0;
  741. }
  742. #endif
  743. #if defined(SUPPORT_ALTMAPPING)
  744. bumpNormal = (float3)tex2D(SAMPLER(NormalMap), In.ShadowMapTexCoord.xy) * 2.0 - 1.0;
  745. #endif
  746. // Scale normal to increase/decrease bump effect
  747. bumpNormal.xy *= BumpScale;
  748. // Bring bump normal into world space
  749. bumpNormal = mul(bumpNormal, In.TangentToWorldSpace);
  750. bumpNormal = normalize(bumpNormal);
  751. float4 color = baseTexture;
  752. color.xyz *= In.Color.xyz;
  753. float3 specularColor = SpecularColor;
  754. float shadowSampler = 1;
  755. if (hasShadow)
  756. {
  757. shadowSampler = shadow( SAMPLER(ShadowMap), In.ShadowMapTexCoord );
  758. }
  759. #if defined(SUPPORT_PSYONIC)
  760. // Calculate Fresnel Effect
  761. float fresnelDiffuse = pow( 1-dot( worldEyeDir, bumpNormal), 4);
  762. float3 fresnelColor = fresnelDiffuse * float3(2,2,10);
  763. color.xyz += float3(fresnelColor * OpacityOverride);
  764. #endif
  765. #if defined(SUPPORT_SPECMAP)
  766. // Read spec map
  767. float4 specTexture = tex2D(SAMPLER(SpecMap), texCoord0);
  768. float specularStrength = specTexture.x; // Specular lighting mask
  769. if (isMultiPass == FROZENPASS)
  770. {
  771. specularStrength = 1;
  772. color.xyz = float3(0, 0, 0);
  773. diffuse.xyz = float3(.13, .33, .5);
  774. }
  775. // Compute view direction in world space
  776. float3 reflVect = -reflect(worldEyeDir,bumpNormal);
  777. #if defined(SUPPORT_REFLECTION)
  778. // Calculate reflection texture
  779. float4 hPosition = mul(float4(In.WorldPosition.xyz, 1), GetViewProjection());
  780. float2 reflectionTexCoord = (0.5 * (hPosition.xy + hPosition.w * float2(1.0, 1.0)) ) / hPosition.w;
  781. reflectionTexCoord += bumpNormal * .025;
  782. // Calculate Fresnel Effect
  783. float fresnelDiffuse = pow( 1-dot( worldEyeDir, bumpNormal), 1.5);
  784. float3 reflectionColor = tex2D( SAMPLER(ReflectionTexture), reflectionTexCoord.xy );
  785. color.xyz += reflectionColor * fresnelDiffuse;
  786. #endif
  787. // Although not technically correct, since we use the Cubemap to fake specular, multiply against the shadow map and add to color
  788. float3 envcolor = texCUBE( SAMPLER(EnvironmentTexture), reflVect).xyz;
  789. color.xyz += envcolor.xyz * DirectionalLight[0].Color * specularStrength * shadowSampler;
  790. #endif // SUPPORT_SPECMAP
  791. #if !defined(SUPPORT_ALTMAPPING)
  792. if (isMultiPass != TESLAPASS)
  793. {
  794. for (int i = 0; i < NumDirectionalLightsPerPixel; i++)
  795. {
  796. // Compute lighting
  797. float3 cloud = float3(1, 1, 1);
  798. if (i == 0)
  799. {
  800. #if defined(_WW3D_) && !defined(_W3DVIEW_)
  801. cloud = GammaToLinear(tex2D( SAMPLER(CloudTexture), cloudTexCoord));
  802. #endif
  803. cloud *= shadowSampler;
  804. }
  805. float4 diffuseTerm = dot(bumpNormal, DirectionalLight[i].Direction);
  806. float diffuseLighting = max(0, diffuseTerm);
  807. color.xyz += DirectionalLight[i].Color * cloud * (diffuse * diffuseLighting);
  808. }
  809. // Compute point lights
  810. float3 diffuseLight = 0;
  811. #if !defined(EA_PLATFORM_PS3) // PS3 TODO - 'sce-cgc.exe' does not like this for some reason :(
  812. for (int i = 0; i < NumPointLights; i++)
  813. {
  814. diffuseLight += CalculatePointLightDiffuse(PointLight[i], In.WorldPosition, bumpNormal);
  815. }
  816. #endif
  817. #if defined(SUPPORT_LIGHTMAP)
  818. float3 lightMapTexture = GammaToLinear(tex2D(SAMPLER(LightMap), texCoord1));
  819. diffuseLight += lightMapTexture.xyz * 10;
  820. #endif
  821. color.xyz += diffuseLight * diffuse;
  822. } // (isMultiPass == FIRSTPASS)
  823. #endif // SUPPORT_ALTMAPPING
  824. #if defined(SUPPORT_FILLDAMAGETEXTURE) && defined(SUPPORT_DAMAGETEXTURE)
  825. // Get Damaged Texture on 2nd UV Coords
  826. float4 damagedTexture = tex2D(SAMPLER(DamagedTexture), texCoord1);
  827. color *= damagedTexture * (1 - In.Color.w);
  828. #elif defined(SUPPORT_DAMAGETEXTURE)
  829. // Get Damaged Texture on 2nd UV Coords
  830. float4 damagedTexture = tex2D(SAMPLER(DamagedTexture), texCoord1);
  831. color *= lerp(damagedTexture, 1.0.xxxx, In.Color.w);
  832. #elif !defined(SUPPORT_JAPANBUILDUP) && !defined(SUPPORT_ALTMAPPING)
  833. color.w *= In.Color.w;
  834. #endif
  835. #if defined(SUPPORT_IRONCURTAIN)
  836. float3 Texture0 = GammaToLinear(tex2D( SAMPLER(IronCurtainTexture), texCoord0 * 1));
  837. float3 Texture1 = GammaToLinear(tex2D( SAMPLER(IronCurtainTexture), texCoord1 * 1));
  838. color.xyz = Texture0 * Texture1 * 30;
  839. // Compute view direction in world space
  840. float fresnelDiffuse = pow( 1-dot( worldEyeDir, bumpNormal), 4.0);
  841. color.xyz += (float3(2.0,0.05,0.025) * fresnelDiffuse);
  842. color.w = 1;
  843. #endif // SUPPORT_IRONCURTAIN
  844. #if defined(SUPPORT_CHRONORIFT)
  845. float3 Texture0 = GammaToLinear(tex2D( SAMPLER(ChronoRiftTexture), texCoord0*2));
  846. float3 Texture1 = GammaToLinear(tex2D( SAMPLER(ChronoRiftTexture), texCoord1*2));
  847. color.xyz = Texture0 * Texture1 * 50;
  848. // Compute view direction in world space
  849. float fresnelDiffuse = pow( 1-dot( worldEyeDir, bumpNormal), 2.0);
  850. color.xyz += fresnelDiffuse * float3(0.3,0.6,3.0);
  851. color.xyz = min(color.xyz,2);
  852. color.w = 1;
  853. #endif // SUPPORT_CHRONORIFT
  854. #if defined(SUPPORT_FORMATIONPREVIEW)
  855. color.xyz = float3(0.0,0.055,0.045);
  856. // Compute view direction in world space
  857. float fresnelDiffuse = pow( 1-dot( worldEyeDir, bumpNormal), 2.5);
  858. color.xyz += (float3(0.0,1.0,0.0) * fresnelDiffuse * 3);
  859. color.xyz = min(color.xyz,2);
  860. color.w = OpacityOverride;
  861. #endif // SUPPORT_FORMATIONPREVIEW
  862. #if defined(SUPPORT_JAPANBUILDUP)
  863. // Get Buildup Mask
  864. float Mask = smoothstep(.3,.51,texCoord0.y + (In.Color.w * 1.2) - .65);
  865. float buildupTexture = tex2D( SAMPLER(JapanBuildMaskTexture), texCoord0 * 50).x + .5;
  866. buildupTexture = pow(buildupTexture,3)*6;
  867. float3 maskColor = buildupTexture * float3(.9,3,.9);
  868. color.xyz = lerp(maskColor,color.xyz, clamp(1,0,Mask));
  869. clip(Mask - ((float)DEFAULT_ALPHATEST_THRESHOLD / 255));
  870. #endif
  871. if (isMultiPass == FIRSTPASS)
  872. {
  873. color.xyz *= TintColor;
  874. }
  875. #if defined(SUPPORT_TESLA)
  876. if (isMultiPass == TESLAPASS)
  877. {
  878. float3 Texture0 = GammaToLinear(tex2D( SAMPLER(FractalNormalMap), In.ShadowMapTexCoord.xy));
  879. Texture0 = Texture0 * 2 - 1;
  880. float3 Texture1 = GammaToLinear(tex2D( SAMPLER(TeslaTexture), In.ShadowMapTexCoord.zw * 1.5 + (Texture0.xy * .04)));
  881. Texture1 *= GammaToLinear(tex2D( SAMPLER(TeslaTexture), In.ShadowMapTexCoord.wz * 3 + (Texture0.xy * .04)));
  882. color.xyz = Texture1 * 50;
  883. // Compute view direction in world space
  884. float fresnelDiffuse = pow( 1-dot( worldEyeDir, bumpNormal), 4.0);
  885. color.xyz += fresnelDiffuse * float3(0.07,0.15,.75);
  886. color.xyz = min(color.xyz,4);
  887. color.w = 1;
  888. }
  889. #endif // SUPPORT_TESLA
  890. #if defined(SUPPORT_XRAY) && !defined(_3DSMAX_)
  891. float xrayTexture = saturate(tex2D( SAMPLER(XrayTexture), In.ScreenSpaceCoord.xy).x);
  892. // Use the scalar that we computed in the vertex shader to get a Z-Depth multiplier
  893. xrayTexture = lerp(In.ScreenSpaceCoord.z,1,xrayTexture);
  894. clip(xrayTexture - XRAY_TRANSPARENCY_THRESHOLD);
  895. color.w *= xrayTexture;
  896. #endif
  897. #if defined(SUPPORT_REFLECTION)
  898. // Do this at the end so that it also affects the reflection and environment passes
  899. color.xyz *= In.VertexColor;
  900. #endif
  901. #if defined(_WW3D_) && !defined(_W3DVIEW_)
  902. color.xyz *= tex2D(SAMPLER(ShroudTexture), shroudTexCoord);
  903. #endif
  904. #if SUPPORT_SSAO
  905. color.xyz *= ComputeSSAO(vPos);
  906. #endif
  907. return CorrectForFrameBufferGamma(color);
  908. }
  909. #endif
  910. // ----------------------------------------------------------------------------
  911. // SHADER: PS_Xenon
  912. // ----------------------------------------------------------------------------
  913. float4 PS_Xenon( VSOutput_H In, float2 vPos : PIXELLOC, uniform int isMultiPass) : COLOR
  914. {
  915. return PS_H( In, HasShadow, HasRecolorColors, vPos, isMultiPass);
  916. }
  917. // ----------------------------------------------------------------------------
  918. // Arrays: Default_H
  919. // ----------------------------------------------------------------------------
  920. DEFINE_ARRAY_MULTIPLIER( VS_H_Multiplier_Final = 2 );
  921. #define VS_H_NumJointsPerVertex(isMultiPass) \
  922. compile VS_3_0 VS_H(0, isMultiPass), \
  923. compile VS_3_0 VS_H(1, isMultiPass)
  924. #if SUPPORTS_SHADER_ARRAYS
  925. vertexshader VS_H_Array[VS_H_Multiplier_Final] =
  926. {
  927. VS_H_NumJointsPerVertex(FIRSTPASS)
  928. };
  929. #if defined(SUPPORT_FROZEN)
  930. vertexshader VS_H_Frozen_Array[VS_H_Multiplier_Final] =
  931. {
  932. VS_H_NumJointsPerVertex(FROZENPASS)
  933. };
  934. #endif // SUPPORT_FROZEN
  935. #if defined(SUPPORT_TESLA)
  936. vertexshader VS_H_Tesla_Array[VS_H_Multiplier_Final] =
  937. {
  938. VS_H_NumJointsPerVertex(TESLAPASS)
  939. };
  940. #endif // SUPPORT_TESLA
  941. #endif // SUPPORTS_SHADER_ARRAYS
  942. DEFINE_ARRAY_MULTIPLIER( PS_H_Multiplier_NumShadows = 1 );
  943. #define PS_H_NumShadows(recolorEnabled, isMultiPass) \
  944. compile PS_3_0 PS_H(0, recolorEnabled, isMultiPass), \
  945. compile PS_3_0 PS_H(1, recolorEnabled, isMultiPass)
  946. DEFINE_ARRAY_MULTIPLIER( PS_H_Multiplier_RecolorEnabled = PS_H_Multiplier_NumShadows * 2 );
  947. #define PS_H_RecolorEnabled(isMultiPass) \
  948. PS_H_NumShadows(false, isMultiPass), \
  949. PS_H_NumShadows(true, isMultiPass)
  950. DEFINE_ARRAY_MULTIPLIER( PS_H_Multiplier_Final = PS_H_Multiplier_RecolorEnabled * 2 );
  951. #if SUPPORTS_SHADER_ARRAYS
  952. pixelshader PS_H_Array[PS_H_Multiplier_Final] =
  953. {
  954. PS_H_RecolorEnabled(FIRSTPASS)
  955. };
  956. #if defined(SUPPORT_FROZEN)
  957. pixelshader PS_H_Frozen_Array[PS_H_Multiplier_Final] =
  958. {
  959. PS_H_RecolorEnabled(FROZENPASS)
  960. };
  961. #endif // SUPPORT_FROZEN
  962. #if defined(SUPPORT_TESLA)
  963. pixelshader PS_H_Tesla_Array[PS_H_Multiplier_Final] =
  964. {
  965. PS_H_RecolorEnabled(TESLAPASS)
  966. };
  967. #endif // SUPPORT_TESLA
  968. #endif // SUPPORTS_SHADER_ARRAYS
  969. // ----------------------------------------------------------------------------
  970. // Technique: Default
  971. // ----------------------------------------------------------------------------
  972. technique Default
  973. {
  974. pass p0
  975. #if !defined(SUPPORT_DAMAGETEXTURE) && !defined(SUPPORT_CHRONORIFT) && !defined(SUPPORT_XRAY)
  976. <
  977. USE_EXPRESSION_EVALUATOR(EXPRESSION_EVALUATOR_NAME)
  978. >
  979. #endif
  980. {
  981. VertexShader = ARRAY_EXPRESSION_VS( VS_H_Array,
  982. min(NumJointsPerVertex, 1),
  983. compile VS_VERSION VS_Xenon(false) );
  984. PixelShader = ARRAY_EXPRESSION_PS( PS_H_Array,
  985. HasShadow * PS_H_Multiplier_NumShadows
  986. + HasRecolorColors * PS_H_Multiplier_RecolorEnabled,
  987. compile PS_VERSION PS_Xenon(false) );
  988. ZEnable = true;
  989. ZFunc = ZFUNC_INFRONT;
  990. ZWriteEnable = true;
  991. CullMode = CW;
  992. #if defined(SUPPORT_DAMAGETEXTURE)
  993. AlphaBlendEnable = false;
  994. #elif defined(SUPPORT_CHRONORIFT)
  995. AlphaBlendEnable = true;
  996. SrcBlend = One;
  997. DestBlend = One;
  998. #elif defined(SUPPORT_XRAY)
  999. AlphaBlendEnable = true;
  1000. #else
  1001. #if !EXPRESSION_EVALUATOR_ENABLED
  1002. AlphaBlendEnable = ( OpacityOverride < 0.99);
  1003. #endif
  1004. SrcBlend = SrcAlpha;
  1005. DestBlend = InvSrcAlpha;
  1006. #endif
  1007. AlphaFunc = GreaterEqual;
  1008. AlphaRef = DEFAULT_ALPHATEST_THRESHOLD;
  1009. #if defined(SUPPORT_DAMAGETEXTURE)
  1010. AlphaTestEnable = true;
  1011. #elif defined(SUPPORT_CHRONORIFT)
  1012. AlphaTestEnable = false;
  1013. #elif defined(SUPPORT_XRAY)
  1014. AlphaTestEnable = false;
  1015. #else
  1016. #if !EXPRESSION_EVALUATOR_ENABLED
  1017. AlphaTestEnable = ( AlphaTestEnable );
  1018. #endif
  1019. #endif
  1020. }
  1021. #if defined(SUPPORT_FROZEN)
  1022. pass p1
  1023. {
  1024. VertexShader = ARRAY_EXPRESSION_VS( VS_H_Frozen_Array,
  1025. min(NumJointsPerVertex, 1),
  1026. compile VS_VERSION VS_Xenon(FROZENPASS) );
  1027. PixelShader = ARRAY_EXPRESSION_PS( PS_H_Frozen_Array,
  1028. HasShadow * PS_H_Multiplier_NumShadows
  1029. + HasRecolorColors * PS_H_Multiplier_RecolorEnabled,
  1030. compile PS_VERSION PS_Xenon(FROZENPASS) );
  1031. ZEnable = true;
  1032. ZFunc = ZFUNC_INFRONT;
  1033. ZWriteEnable = false;
  1034. CullMode = CW;
  1035. AlphaBlendEnable = true;
  1036. SrcBlend = One;
  1037. DestBlend = One;
  1038. AlphaTestEnable = false;
  1039. }
  1040. #endif // SUPPORT_FROZEN
  1041. #if defined(SUPPORT_TESLA)
  1042. pass p1
  1043. {
  1044. VertexShader = ARRAY_EXPRESSION_VS( VS_H_Tesla_Array,
  1045. min(NumJointsPerVertex, 1),
  1046. compile VS_VERSION VS_Xenon(TESLAPASS) );
  1047. PixelShader = ARRAY_EXPRESSION_PS( PS_H_Tesla_Array,
  1048. HasShadow * PS_H_Multiplier_NumShadows
  1049. + HasRecolorColors * PS_H_Multiplier_RecolorEnabled,
  1050. compile PS_VERSION PS_Xenon(TESLAPASS) );
  1051. ZEnable = true;
  1052. ZFunc = ZFUNC_INFRONT;
  1053. ZWriteEnable = false;
  1054. CullMode = CW;
  1055. AlphaBlendEnable = true;
  1056. SrcBlend = One;
  1057. DestBlend = One;
  1058. AlphaTestEnable = false;
  1059. StencilEnable = false;
  1060. }
  1061. #endif // SUPPORT_TESLA
  1062. }
  1063. #if ENABLE_LOD
  1064. // ----------------------------------------------------------------------------
  1065. // SHADER: DEFAULT (Medium)
  1066. // ----------------------------------------------------------------------------
  1067. struct VSOutput_M {
  1068. float4 Position : POSITION;
  1069. float4 TexCoord0_TexCoord1 : TEXCOORD0;
  1070. float4 LightVector[NumDirectionalLightsPerPixel_M] : TEXCOORD1_CENTROID;
  1071. float3 HalfEyeLightVector : TEXCOORD2_CENTROID;
  1072. float4 ShroudTexCoord_CloudTexCoord : TEXCOORD3;
  1073. float4 ShadowMapTexCoord : TEXCOORD4;
  1074. float2 MacroTexCoord : TEXCOORD5;
  1075. #if defined(SUPPORT_ALTMAPPING) || defined(SUPPORT_TESLA) || defined(SUPPORT_PSYONIC)
  1076. float3 WorldTangentEyeDir : TEXCOORD6;
  1077. #endif
  1078. #if defined(SUPPORT_TESLA)
  1079. float4 TeslaTexCoord : TEXCOORD7;
  1080. #endif
  1081. #if defined(SUPPORT_XRAY)
  1082. float3 ScreenSpaceCoord : TEXCOORD7;
  1083. #endif
  1084. float4 Color : COLOR0;
  1085. };
  1086. // ----------------------------------------------------------------------------
  1087. // SHADER: VS
  1088. // ----------------------------------------------------------------------------
  1089. VSOutput_M VS_M(VSInputSkinningOneBoneTangentFrame InSkin,
  1090. float2 TexCoord0 : TEXCOORD0,
  1091. #if defined(SUPPORT_DAMAGETEXTURE) || defined(SUPPORT_LIGHTMAP)
  1092. float2 TexCoord1 : TEXCOORD1,
  1093. DECLARE_VERTEXCOLOR_INPUT(VertexColor, 2, 3),
  1094. #else
  1095. DECLARE_VERTEXCOLOR_INPUT(VertexColor, 1, 2),
  1096. #endif
  1097. uniform int numJointsPerVertex,
  1098. uniform int isMultiPass)
  1099. {
  1100. USE_VERTEXCOLOR(VertexColor);
  1101. USE_TEXCOORD(TexCoord0);
  1102. #if defined(SUPPORT_DAMAGETEXTURE) || defined(SUPPORT_LIGHTMAP)
  1103. USE_TEXCOORD(TexCoord1);
  1104. #endif
  1105. USE_DIRECTIONAL_LIGHT_INTERACTIVE(DirectionalLight, 0);
  1106. VSOutput_M Out;
  1107. float3 worldPosition = 0;
  1108. float3 worldNormal = 0;
  1109. float3 worldTangent = 0;
  1110. float3 worldBinormal = 0;
  1111. CalculatePositionAndTangentFrame(InSkin, numJointsPerVertex,
  1112. worldPosition, worldNormal, worldTangent, worldBinormal);
  1113. // Get the skins opacity value
  1114. VertexColor.w *= GetOpacity(InSkin, numJointsPerVertex);
  1115. #if defined(_3DSMAX_) && defined(SUPPORT_DAMAGETEXTURE)
  1116. if (PreviewFullyDamaged)
  1117. {
  1118. VertexColor.w = 0.0;
  1119. }
  1120. #endif
  1121. #if defined(SUPPORT_TREAD_SCROLLING)
  1122. // Tread scrolling uses the vertex color opacity for animating the U coordinate
  1123. TexCoord0.x += VertexColor.w;
  1124. // Don't use it for opacity then.
  1125. VertexColor.w = 1.0f;
  1126. #endif
  1127. if (isMultiPass == FROZENPASS)
  1128. {
  1129. // Extrude geo to create a shell for the ice
  1130. worldPosition += worldNormal * 1.5;
  1131. }
  1132. // transform position to projection space
  1133. Out.Position = mul(float4(worldPosition, 1), GetViewProjection());
  1134. // Compute view direction in world space
  1135. float3 worldEyeDir = normalize(GetEyePosition() - worldPosition);
  1136. // Build 3x3 tranform from object to tangent space
  1137. float3x3 worldToTangentSpace = transpose(float3x3(-worldBinormal, -worldTangent, worldNormal));
  1138. for (int i = 0; i < NumDirectionalLightsPerPixel_M; i++)
  1139. {
  1140. // Compute lighting direction in tangent space
  1141. Out.LightVector[i] = float4(mul(DirectionalLight[i].Direction, worldToTangentSpace), 0);
  1142. }
  1143. // Compute half direction between view and light direction in tangent space
  1144. Out.HalfEyeLightVector.xyz = normalize(mul(DirectionalLight[0].Direction + worldEyeDir, worldToTangentSpace));
  1145. #if !defined(SUPPORT_ALTMAPPING)
  1146. #if defined(SUPPORT_CRUSHED) || defined(SUPPORT_PSYONIC)
  1147. Out.Color = float4(AmbientLightColor * AmbientColor, 1);
  1148. #else
  1149. Out.Color = float4(AmbientLightColor * AmbientColor, OpacityOverride);
  1150. #endif
  1151. // Compute remaining directional lights per vertex, others will be done in pixel shader
  1152. float3 diffuseLight = 0;
  1153. for (int i = NumDirectionalLightsPerPixel_M; i < NumDirectionalLights; i++)
  1154. {
  1155. diffuseLight += DirectionalLight[i].Color * max(0, dot(worldNormal, DirectionalLight[i].Direction));
  1156. }
  1157. Out.Color.xyz += diffuseLight * DiffuseColor;
  1158. Out.Color *= VertexColor;
  1159. #endif // SUPPORT_ALTMAPPING
  1160. // pass texture coordinates for fetching the diffuse and normal maps
  1161. Out.TexCoord0_TexCoord1.xy = TexCoord0.xy;
  1162. if (isMultiPass == FROZENPASS)
  1163. {
  1164. // Use world coords when mapping
  1165. Out.TexCoord0_TexCoord1.xy = worldPosition.xy * .015;
  1166. }
  1167. #if defined(SUPPORT_DAMAGETEXTURE) || defined(SUPPORT_LIGHTMAP)
  1168. float2 texCoord1 = TexCoord1;
  1169. #else
  1170. float2 texCoord1 = TexCoord0;
  1171. #endif
  1172. Out.TexCoord0_TexCoord1.zw = texCoord1.yx;
  1173. Out.ShadowMapTexCoord = CalculateShadowMapTexCoord(worldPosition);
  1174. #if defined (SUPPORT_ALTMAPPING)
  1175. // -------------------------------------------------------------------------------
  1176. // -- Texture Coords and Mapping -------------------------------------------------
  1177. // -------------------------------------------------------------------------------
  1178. // Build Tex coords, animate and scale ---------------------------------------
  1179. float texScalar = .75; // Scale
  1180. float texSpeed = Time * .3; // animate coords as a multiplier of Time
  1181. float texDivergenceAngle = 55; // this is the angle difference between the 2 coords
  1182. // Use the tex coords on the model but offset them slightly based on world
  1183. // coords to keep multiple units from animating in sync
  1184. float2 TexCoords = (TexCoord0 + (worldPosition.xy * .003)) * texScalar;
  1185. // Build Texture Rotation Matrix And Convert Degrees to Radians --
  1186. float cosAngle = 0;
  1187. float sinAngle = 0;
  1188. float2x2 uvCoordRotate = { 1.0f, 0.0f, 1.0f, 0.0f };
  1189. sincos (texDivergenceAngle * .017453, sinAngle, cosAngle);
  1190. // Build Rotation
  1191. uvCoordRotate[0][0] = cosAngle;
  1192. uvCoordRotate[0][1] = -sinAngle;
  1193. uvCoordRotate[1][1] = uvCoordRotate[0][0];
  1194. uvCoordRotate[1][0] = -uvCoordRotate[0][1];
  1195. // Rotate and Animate Divergence Texture Coords --------------------
  1196. float2 TexCoordsDiverge = mul(TexCoords, uvCoordRotate);
  1197. TexCoordsDiverge.x += texSpeed;
  1198. float2 TexCoordsDivergeInv = mul(TexCoords, transpose(uvCoordRotate));
  1199. TexCoordsDivergeInv.x += texSpeed;
  1200. Out.TexCoord0_TexCoord1.xy = TexCoordsDiverge;
  1201. Out.TexCoord0_TexCoord1.zw = TexCoordsDivergeInv;
  1202. //Hi-jack shadow coords for this shader since we dont use them
  1203. Out.ShadowMapTexCoord.xy = TexCoord0;
  1204. Out.WorldTangentEyeDir = mul(worldEyeDir, worldToTangentSpace);
  1205. Out.Color = 0;
  1206. #endif //SUPPORT_ALTMAPPING
  1207. #if defined(SUPPORT_PSYONIC)
  1208. Out.WorldTangentEyeDir = mul(worldEyeDir, worldToTangentSpace);
  1209. #endif
  1210. #if defined(SUPPORT_TESLA)
  1211. Out.WorldTangentEyeDir = mul(worldEyeDir, worldToTangentSpace);
  1212. Out.TeslaTexCoord.xy = (TexCoord0 * .003) + (worldPosition.xy * .003);
  1213. Out.TeslaTexCoord.wz = (TexCoord0 * .5);
  1214. Out.TeslaTexCoord.wz += Time * .15;
  1215. #endif
  1216. Out.ShroudTexCoord_CloudTexCoord.xy = CalculateShroudTexCoord(Shroud, worldPosition);
  1217. Out.ShroudTexCoord_CloudTexCoord.zw = CalculateCloudTexCoord(Cloud, worldPosition, Time);
  1218. Out.MacroTexCoord = CalculateMacroTexCoord(worldPosition);
  1219. #if defined(SUPPORT_XRAY)
  1220. Out.ScreenSpaceCoord.xy = normalize(mul(float4(worldPosition, 1), GetViewProjection()));
  1221. Out.ScreenSpaceCoord.xy += .5;
  1222. // Generate a scalar based on viewspace to cull the XRay texture from removing objects behind Yuriko
  1223. Out.ScreenSpaceCoord.z = (saturate(length(worldPosition - GetEyePosition()) * .02 - 6));
  1224. #endif
  1225. return Out;
  1226. }
  1227. // ----------------------------------------------------------------------------
  1228. // SHADER: PS
  1229. // ----------------------------------------------------------------------------
  1230. // This will save us .5ms on the GPU on a 6800 card. Worth it and there is no visual difference.
  1231. #define float4 half4
  1232. #define float3 half3
  1233. #define float2 half2
  1234. #define float half
  1235. float4 PS_M(VSOutput_M In, uniform bool hasShadow, uniform bool recolorEnabled, uniform int isMultiPass) COLORTARGET
  1236. {
  1237. float2 texCoord0 = In.TexCoord0_TexCoord1.xy;
  1238. #if defined(SUPPORT_JAPANBUILDUP)
  1239. // Get Buildup Mask. The pixel can be clipped early to save processing instead of at the end.
  1240. float Mask = smoothstep(.3,.51,texCoord0.y + (In.Color.w * 1.2) - .65);
  1241. clip(Mask - ((float)DEFAULT_ALPHATEST_THRESHOLD / 255));
  1242. #endif
  1243. float2 texCoord1 = In.TexCoord0_TexCoord1.wz;
  1244. float2 cloudTexCoord = In.ShroudTexCoord_CloudTexCoord.zw;
  1245. // Get diffuse color
  1246. float4 baseTexture = tex2D( SAMPLER(DiffuseTexture), texCoord0);
  1247. float3 specularColor = SpecularColor;
  1248. // ngavalas
  1249. // Yes there is duplicate code here, but duplicating it makes it slightly more understandable
  1250. // as to what is going on. Basically, if we are support recoloring and specular mapping,
  1251. // we can save a texture read since they use the same texture.
  1252. // If we are using one or the other then we just do the texture read and calculate
  1253. // the values normally.
  1254. #if defined(SUPPORT_RECOLORING) && defined(SUPPORT_SPECMAP)
  1255. float4 specTexture = tex2D( SAMPLER(SpecMap), texCoord0);
  1256. float specularStrength = specTexture.x; // Specular lighting mask
  1257. specularColor = SpecularColor * specularStrength;
  1258. if (recolorEnabled)
  1259. {
  1260. baseTexture.xyz = lerp(baseTexture.xyz, baseTexture.xyz * RecolorColor * 2, specTexture.z);
  1261. }
  1262. #elif defined(SUPPORT_SPECMAP)
  1263. float4 specTexture = tex2D( SAMPLER(SpecMap), texCoord0);
  1264. float specularStrength = specTexture.x; // Specular lighting mask
  1265. specularColor = SpecularColor * specularStrength;
  1266. #elif defined(SUPPORT_RECOLORING)
  1267. float4 specTexture = tex2D( SAMPLER(SpecMap), texCoord0);
  1268. if (recolorEnabled)
  1269. {
  1270. baseTexture.xyz = lerp(baseTexture.xyz, baseTexture.xyz * RecolorColor * 2, specTexture.z);
  1271. }
  1272. #endif
  1273. float3 diffuse = baseTexture.xyz * DiffuseColor;
  1274. // Get bump map normal
  1275. float3 bumpNormal = (float3)tex2D( SAMPLER(NormalMap), texCoord0) * 2.0 - 1.0;
  1276. #if defined(SUPPORT_FROZEN)
  1277. if (isMultiPass == FROZENPASS)
  1278. {
  1279. bumpNormal = (float3)tex2D(SAMPLER(FractalNormalMap), texCoord0) * 2.0 - 1.0;
  1280. }
  1281. #endif
  1282. #if defined(SUPPORT_ALTMAPPING)
  1283. bumpNormal = (float3)tex2D(SAMPLER(NormalMap), In.ShadowMapTexCoord.xy) * 2.0 - 1.0;
  1284. #endif
  1285. // Scale normal to increase/decrease bump effect
  1286. bumpNormal.xy *= BumpScale;
  1287. bumpNormal = normalize(bumpNormal);
  1288. float4 color = baseTexture;
  1289. color.xyz *= In.Color.xyz;
  1290. #if defined(SUPPORT_FROZEN)
  1291. if (isMultiPass == FROZENPASS)
  1292. {
  1293. specularStrength = 1;
  1294. color.xyz = float3(0, 0, 0);
  1295. diffuse.xyz = float3(.13, .33, .5);
  1296. }
  1297. #endif
  1298. #if !defined(SUPPORT_ALTMAPPING)
  1299. for (int i = 0; i < NumDirectionalLightsPerPixel_M; i++)
  1300. {
  1301. // Compute lighting
  1302. float3 lightVec = In.LightVector[i].xyz;
  1303. float3 halfVec = In.HalfEyeLightVector.xyz;
  1304. float4 diffuseTerm = dot( bumpNormal, lightVec );
  1305. float4 specularTerm = dot( bumpNormal, halfVec );
  1306. float4 lighting = lit( diffuseTerm, specularTerm, SpecularExponent );
  1307. if (i == 0)
  1308. {
  1309. if (hasShadow)
  1310. {
  1311. lighting.yz *= shadow( SAMPLER(ShadowMap), In.ShadowMapTexCoord );
  1312. }
  1313. float3 cloud = float3(1, 1, 1);
  1314. #if defined(_WW3D_) && !defined(_W3DVIEW_)
  1315. cloud = tex2D( SAMPLER(CloudTexture), cloudTexCoord);
  1316. #endif
  1317. color.xyz += DirectionalLight[0].Color * cloud * (diffuse * lighting.y + specularColor * lighting.z);
  1318. }
  1319. else
  1320. {
  1321. color.xyz += DirectionalLight[i].Color * (diffuse * lighting.y);
  1322. }
  1323. }
  1324. #endif
  1325. #if defined(SUPPORT_PSYONIC)
  1326. // Calculate Fresnel Effect
  1327. float fresnelDiffuse = pow( 1-dot( In.WorldTangentEyeDir, bumpNormal), 4);
  1328. float3 fresnelColor = fresnelDiffuse * float3(2,2,10);
  1329. color.xyz += float3(fresnelColor * OpacityOverride);
  1330. #endif
  1331. #if defined(SUPPORT_LIGHTMAP)
  1332. float3 lightMapTexture = tex2D(SAMPLER(LightMap), texCoord1);
  1333. float3 diffuseLight = lightMapTexture.xyz * 10;
  1334. color.xyz += diffuseLight * diffuse;
  1335. #endif
  1336. // this is ugly but I couldn't think of a better way to do it. -Sean
  1337. #if defined(SUPPORT_FILLDAMAGETEXTURE) && defined(SUPPORT_DAMAGETEXTURE)
  1338. // Get Damaged Texture on 2nd UV Coords
  1339. float4 damagedTexture = tex2D(SAMPLER(DamagedTexture), texCoord1);
  1340. // color *= lerp(damagedTexture, float4(1.0, 1.0, 1.0, 0.0) , ( In.Color.w));
  1341. color *= damagedTexture * (1 - In.Color.w);
  1342. #elif defined(SUPPORT_DAMAGETEXTURE)
  1343. // Get Damaged Texture on 2nd UV Coords
  1344. float4 damagedTexture = tex2D(SAMPLER(DamagedTexture), texCoord1);
  1345. color *= lerp(damagedTexture, 1.0.xxxx, In.Color.w);
  1346. #elif !defined(SUPPORT_JAPANBUILDUP)
  1347. color.w *= In.Color.w;
  1348. #endif
  1349. #if defined(SUPPORT_IRONCURTAIN)
  1350. float3 Texture0 = tex2D( SAMPLER(IronCurtainTexture), texCoord0);
  1351. float3 Texture1 = tex2D( SAMPLER(IronCurtainTexture), texCoord1);
  1352. color.xyz = Texture0 * Texture1 * 5;
  1353. // Compute view direction in world space
  1354. float fresnelDiffuse = pow( 1-dot( In.WorldTangentEyeDir, bumpNormal), 4.0);
  1355. color.xyz += (float3(2.0,0.05,0.025) * fresnelDiffuse);
  1356. color.w = 1;
  1357. #endif // SUPPORT_IRONCURTAIN
  1358. #if defined(SUPPORT_CHRONORIFT)
  1359. float3 Texture0 = tex2D( SAMPLER(ChronoRiftTexture), texCoord0*2);
  1360. float3 Texture1 = tex2D( SAMPLER(ChronoRiftTexture), texCoord1*2);
  1361. color.xyz = Texture0 * Texture1 * 2;
  1362. // Compute view direction in world space
  1363. float fresnelDiffuse = pow( 1-dot( In.WorldTangentEyeDir, bumpNormal), 2.0);
  1364. color.xyz += fresnelDiffuse * float3(0.3,0.6,3.0);
  1365. color.xyz = min(color.xyz,2);
  1366. color.w = 1;
  1367. #endif // SUPPORT_CHRONORIFT
  1368. #if defined(SUPPORT_FORMATIONPREVIEW)
  1369. color.xyz = float3(0.0,0.055,0.045);
  1370. // Compute view direction in world space
  1371. float fresnelDiffuse = pow( 1-dot( In.WorldTangentEyeDir, bumpNormal), 2.5);
  1372. color.xyz += (float3(0.0,1.0,0.0) * fresnelDiffuse * 3);
  1373. color.xyz = min(color.xyz,2);
  1374. color.w = OpacityOverride;
  1375. #endif // SUPPORT_FORMATIONPREVIEW
  1376. #if defined(SUPPORT_JAPANBUILDUP)
  1377. float buildupTexture = tex2D( SAMPLER(JapanBuildMaskTexture), texCoord0 * 50).x + .5;
  1378. buildupTexture = pow(buildupTexture,3)*6;
  1379. float3 maskColor = buildupTexture * float3(.9,3,.9);
  1380. color.xyz = lerp(maskColor,color.xyz, clamp(1,0,Mask));
  1381. #endif
  1382. #if defined(SUPPORT_TESLA)
  1383. float3 Texture0 = tex2D( SAMPLER(FractalNormalMap), In.TeslaTexCoord.xy);
  1384. Texture0 = Texture0 * 2 - 1;
  1385. float3 Texture1 = tex2D( SAMPLER(TeslaTexture), In.TeslaTexCoord.zw * 1.5 + (Texture0.xy * .04));
  1386. Texture1 *= tex2D( SAMPLER(TeslaTexture), In.TeslaTexCoord.wz * 3 + (Texture0.xy * .04));
  1387. color.xyz += Texture1 * 20;
  1388. // Compute view direction in world space
  1389. float fresnelDiffuse = pow( 1-dot(In.WorldTangentEyeDir, bumpNormal), 4.0);
  1390. color.xyz += fresnelDiffuse * float3(0.07,0.15,.75);
  1391. color.xyz = min(color.xyz,4);
  1392. color.w = 1;
  1393. #endif // SUPPORT_TESLA
  1394. if (isMultiPass == FIRSTPASS)
  1395. {
  1396. color.xyz *= TintColor;
  1397. }
  1398. #if defined(SUPPORT_XRAY)
  1399. float xrayTexture = saturate(tex2D( SAMPLER(XrayTexture), In.ScreenSpaceCoord.xy).x);
  1400. // Use the scalar that we computed in the vertex shader to get a Z-Depth multiplier
  1401. xrayTexture = lerp(In.ScreenSpaceCoord.z,1,xrayTexture);
  1402. clip(xrayTexture - XRAY_TRANSPARENCY_THRESHOLD);
  1403. color.w *= xrayTexture;
  1404. #endif
  1405. #if defined(_WW3D_) && !defined(_W3DVIEW_)
  1406. color.xyz *= tex2D( SAMPLER(ShroudTexture), In.ShroudTexCoord_CloudTexCoord.xy );
  1407. #endif
  1408. return color;
  1409. }
  1410. // We only want to do this for the really expensive part. The rest of the shader can be normal.
  1411. #undef float4
  1412. #undef float3
  1413. #undef float2
  1414. #undef float
  1415. // ----------------------------------------------------------------------------
  1416. // Arrays: Default_M
  1417. // ----------------------------------------------------------------------------
  1418. DEFINE_ARRAY_MULTIPLIER( VS_M_Multiplier_Final = 2 );
  1419. #define VS_M_NumJointsPerVertex(isMultiPass) \
  1420. compile VS_3_0 VS_M(0, isMultiPass), \
  1421. compile VS_3_0 VS_M(1, isMultiPass)
  1422. #if SUPPORTS_SHADER_ARRAYS
  1423. vertexshader VS_M_Array[VS_M_Multiplier_Final] =
  1424. {
  1425. VS_M_NumJointsPerVertex(FIRSTPASS)
  1426. };
  1427. #if defined(SUPPORT_FROZEN)
  1428. vertexshader VS_M_Frozen_Array[VS_M_Multiplier_Final] =
  1429. {
  1430. VS_M_NumJointsPerVertex(FROZENPASS)
  1431. };
  1432. #endif // SUPPORT_FROZEN
  1433. #endif
  1434. DEFINE_ARRAY_MULTIPLIER( PS_M_Multiplier_HasShadow = 1 );
  1435. #define PS_M_HasShadow(recolorEnabled, isMultiPass) \
  1436. compile PS_3_0 PS_M(false, recolorEnabled, isMultiPass), \
  1437. compile PS_3_0 PS_M(true, recolorEnabled, isMultiPass)
  1438. DEFINE_ARRAY_MULTIPLIER( PS_M_Multiplier_RecolorEnabled = PS_M_Multiplier_HasShadow * 2 );
  1439. #define PS_M_RecolorEnabled(isMultiPass) \
  1440. PS_M_HasShadow(false, isMultiPass), \
  1441. PS_M_HasShadow(true, isMultiPass)
  1442. DEFINE_ARRAY_MULTIPLIER( PS_M_Multiplier_Final = PS_M_Multiplier_RecolorEnabled * 2 );
  1443. #if SUPPORTS_SHADER_ARRAYS
  1444. pixelshader PS_M_Array[PS_M_Multiplier_Final] =
  1445. {
  1446. PS_M_RecolorEnabled(FIRSTPASS)
  1447. };
  1448. #if defined(SUPPORT_FROZEN)
  1449. pixelshader PS_M_Frozen_Array[PS_M_Multiplier_Final] =
  1450. {
  1451. PS_M_RecolorEnabled(FROZENPASS)
  1452. };
  1453. #endif // SUPPORT_FROZEN
  1454. #endif
  1455. // ----------------------------------------------------------------------------
  1456. // Technique: Default_M
  1457. // ----------------------------------------------------------------------------
  1458. technique Default_M
  1459. {
  1460. pass p0
  1461. #if !defined(SUPPORT_DAMAGETEXTURE) && !defined(SUPPORT_CHRONORIFT) && !defined(SUPPORT_XRAY)
  1462. <
  1463. USE_EXPRESSION_EVALUATOR(EXPRESSION_EVALUATOR_NAME)
  1464. >
  1465. #endif
  1466. {
  1467. VertexShader = ARRAY_EXPRESSION_VS( VS_M_Array,
  1468. min(NumJointsPerVertex, 1),
  1469. NO_ARRAY_ALTERNATIVE);
  1470. PixelShader = ARRAY_EXPRESSION_PS( PS_M_Array,
  1471. HasShadow * PS_M_Multiplier_HasShadow
  1472. + HasRecolorColors * PS_M_Multiplier_RecolorEnabled,
  1473. NO_ARRAY_ALTERNATIVE);
  1474. ZEnable = true;
  1475. ZFunc = ZFUNC_INFRONT;
  1476. ZWriteEnable = true;
  1477. CullMode = CW;
  1478. #if defined(SUPPORT_DAMAGETEXTURE)
  1479. AlphaBlendEnable = false;
  1480. #elif defined(SUPPORT_CHRONORIFT)
  1481. AlphaBlendEnable = true;
  1482. SrcBlend = One;
  1483. DestBlend = One;
  1484. #elif defined(SUPPORT_XRAY)
  1485. AlphaBlendEnable = true;
  1486. #else
  1487. #if !EXPRESSION_EVALUATOR_ENABLED
  1488. AlphaBlendEnable = ( OpacityOverride < 0.99);
  1489. #endif
  1490. SrcBlend = SrcAlpha;
  1491. DestBlend = InvSrcAlpha;
  1492. #endif
  1493. AlphaFunc = GreaterEqual;
  1494. AlphaRef = DEFAULT_ALPHATEST_THRESHOLD;
  1495. #if defined(SUPPORT_DAMAGETEXTURE)
  1496. AlphaTestEnable = true;
  1497. #elif defined(SUPPORT_CHRONORIFT)
  1498. AlphaTestEnable = false;
  1499. #elif defined(SUPPORT_XRAY)
  1500. AlphaTestEnable = false;
  1501. #else
  1502. #if !EXPRESSION_EVALUATOR_ENABLED
  1503. AlphaTestEnable = ( AlphaTestEnable );
  1504. #endif
  1505. #endif
  1506. }
  1507. #if defined(SUPPORT_FROZEN)
  1508. pass p1
  1509. {
  1510. VertexShader = ARRAY_EXPRESSION_VS( VS_M_Frozen_Array,
  1511. min(NumJointsPerVertex, 1),
  1512. NO_ARRAY_ALTERNATIVE);
  1513. PixelShader = ARRAY_EXPRESSION_PS( PS_M_Frozen_Array,
  1514. HasShadow * PS_M_Multiplier_HasShadow
  1515. + HasRecolorColors * PS_M_Multiplier_RecolorEnabled,
  1516. NO_ARRAY_ALTERNATIVE);
  1517. ZEnable = true;
  1518. ZFunc = ZFUNC_INFRONT;
  1519. ZWriteEnable = false;
  1520. CullMode = CW;
  1521. AlphaBlendEnable = true;
  1522. SrcBlend = One;
  1523. DestBlend = One;
  1524. AlphaTestEnable = false;
  1525. StencilEnable = false;
  1526. }
  1527. #endif // SUPPORT_FROZEN
  1528. }
  1529. // ----------------------------------------------------------------------------
  1530. // SHADER: Low
  1531. // ----------------------------------------------------------------------------
  1532. struct VSOutput_L
  1533. {
  1534. float4 Position : POSITION;
  1535. float4 Color : COLOR0;
  1536. float4 TexCoord0_TexCoord1 : TEXCOORD0;
  1537. float2 ShroudTexCoord : TEXCOORD1;
  1538. #if defined(SUPPORT_ALTMAPPING) || defined(SUPPORT_PSYONIC)
  1539. float3 FallOffColor : TEXCOORD2;
  1540. #endif
  1541. #if defined(SUPPORT_XRAY)
  1542. float3 ScreenSpaceCoord : TEXCOORD3;
  1543. #endif
  1544. };
  1545. // ----------------------------------------------------------------------------
  1546. // SHADER: VS
  1547. // ----------------------------------------------------------------------------
  1548. VSOutput_L VS_L(VSInputSkinningOneBoneTangentFrame InSkin,
  1549. float2 TexCoord0 : TEXCOORD0,
  1550. #if defined(SUPPORT_DAMAGETEXTURE)
  1551. float2 TexCoord1 : TEXCOORD1,
  1552. DECLARE_VERTEXCOLOR_INPUT(VertexColor, 2, 3),
  1553. #else
  1554. DECLARE_VERTEXCOLOR_INPUT(VertexColor, 1, 2),
  1555. #endif
  1556. uniform int numJointsPerVertex)
  1557. {
  1558. USE_VERTEXCOLOR(VertexColor);
  1559. USE_TEXCOORD(TexCoord0);
  1560. #if defined(SUPPORT_DAMAGETEXTURE)
  1561. USE_TEXCOORD(TexCoord1);
  1562. #endif
  1563. USE_DIRECTIONAL_LIGHT_INTERACTIVE(DirectionalLight, 0);
  1564. VSOutput_L Out;
  1565. float3 worldPosition = 0;
  1566. float3 worldNormal = 0;
  1567. float3 worldTangent = 0;
  1568. float3 worldBinormal = 0;
  1569. CalculatePositionAndTangentFrame(InSkin, numJointsPerVertex,
  1570. worldPosition, worldNormal, worldTangent, worldBinormal);
  1571. /*
  1572. #if defined(SUPPORT_CRUSHED)
  1573. float3 objectCenter = GetFirstBonePosition(0, numJointsPerVertex);
  1574. float crushMask = frac(dot(worldPosition, 1..xxx)*.1);
  1575. crushMask += (TexCoord0.x + TexCoord0.y) * 15;
  1576. crushMask -= OpacityOverride;
  1577. crushMask = clamp(int(crushMask),0,3);
  1578. crushMask *= .33;
  1579. float3 objectSpacePosition = worldPosition - objectCenter;
  1580. float3 objectSpherePosition = normalize(objectSpacePosition) * 10;
  1581. objectSpacePosition = lerp(objectSpherePosition, objectSpacePosition, crushMask);
  1582. worldPosition = objectSpacePosition + objectCenter;
  1583. #endif // SUPPORT_CRUSHED
  1584. */
  1585. // Get the skins opacity value
  1586. VertexColor.w *= GetOpacity(InSkin, numJointsPerVertex);
  1587. #if defined(_3DSMAX_) && defined(SUPPORT_DAMAGETEXTURE)
  1588. if (PreviewFullyDamaged)
  1589. {
  1590. VertexColor.w = 0.0;
  1591. }
  1592. #endif
  1593. #if defined(SUPPORT_TREAD_SCROLLING)
  1594. // Tread scrolling uses the vertex color opacity for animating the U coordinate
  1595. TexCoord0.x += VertexColor.w;
  1596. // Don't use it for opacity then.
  1597. VertexColor.w = 1.0f;
  1598. #endif
  1599. // transform position to projection space
  1600. Out.Position = mul(float4(worldPosition, 1), GetViewProjection());
  1601. #if !defined (SUPPORT_ALTMAPPING)
  1602. #if defined(SUPPORT_CRUSHED) || defined(SUPPORT_PSYONIC)
  1603. Out.Color = float4(AmbientLightColor * AmbientColor, 1);
  1604. #else
  1605. Out.Color = float4(AmbientLightColor * AmbientColor, OpacityOverride);
  1606. #endif
  1607. // Compute remaining directional lights per vertex, others will be done in pixel shader
  1608. float3 diffuseLight = 0;
  1609. for (int i = 0; i < NumDirectionalLights; i++)
  1610. {
  1611. diffuseLight += DirectionalLight[i].Color * max(0, dot(worldNormal, DirectionalLight[i].Direction));
  1612. }
  1613. Out.Color.xyz += diffuseLight * DiffuseColor;
  1614. Out.Color *= VertexColor;
  1615. #endif // SUPPORT_ALTMAPPING
  1616. // pass texture coordinates for fetching the diffuse and normal maps
  1617. Out.TexCoord0_TexCoord1.xy = TexCoord0.xy;
  1618. #if defined(SUPPORT_DAMAGETEXTURE)
  1619. float2 texCoord1 = TexCoord1;
  1620. #else
  1621. float2 texCoord1 = TexCoord0;
  1622. #endif
  1623. #if defined (SUPPORT_ALTMAPPING)
  1624. // -------------------------------------------------------------------------------
  1625. // -- Texture Coords and Mapping -------------------------------------------------
  1626. // -------------------------------------------------------------------------------
  1627. // Build Tex coords, animate and scale ---------------------------------------
  1628. float texScalar = .75; // Scale
  1629. float texSpeed = Time * .3; // animate coords as a multiplier of Time
  1630. float texDivergenceAngle = 55; // this is the angle difference between the 2 coords
  1631. // Use the tex coords on the model but offset them slightly based on world
  1632. // coords to keep multiple units from animating in sync
  1633. float2 TexCoords = (TexCoord0 + (worldPosition.xy * .003)) * texScalar;
  1634. // Build Texture Rotation Matrix And Convert Degrees to Radians --
  1635. float cosAngle = 0;
  1636. float sinAngle = 0;
  1637. float2x2 uvCoordRotate = { 1.0f, 0.0f, 1.0f, 0.0f };
  1638. sincos (texDivergenceAngle * .017453, sinAngle, cosAngle);
  1639. // Build Rotation
  1640. uvCoordRotate[0][0] = cosAngle;
  1641. uvCoordRotate[0][1] = -sinAngle;
  1642. uvCoordRotate[1][1] = uvCoordRotate[0][0];
  1643. uvCoordRotate[1][0] = -uvCoordRotate[0][1];
  1644. // Rotate and Animate Divergence Texture Coords --------------------
  1645. float2 TexCoordsDiverge = mul(TexCoords, uvCoordRotate);
  1646. TexCoordsDiverge.x += texSpeed;
  1647. float2 TexCoordsDivergeInv = mul(TexCoords, transpose(uvCoordRotate));
  1648. TexCoordsDivergeInv.x += texSpeed;
  1649. Out.TexCoord0_TexCoord1.xy = TexCoordsDiverge;
  1650. Out.TexCoord0_TexCoord1.zw = TexCoordsDivergeInv;
  1651. Out.Color = 0;
  1652. // Compute view direction in world space
  1653. float3 worldEyeDir = normalize(GetEyePosition() - worldPosition);
  1654. #endif //SUPPORT_ALTMAPPING
  1655. #if defined(SUPPORT_IRONCURTAIN)
  1656. float worldTangentEyeDir = 1 - dot(worldEyeDir, worldNormal);
  1657. // Compute view direction in world space
  1658. Out.FallOffColor = pow(worldTangentEyeDir, 4.0) * float3(2.0,0.05,0.025);
  1659. #endif // SUPPORT_IRONCURTAIN
  1660. #if defined(SUPPORT_CHRONORIFT)
  1661. float worldTangentEyeDir = 1 - dot(worldEyeDir, worldNormal);
  1662. // Compute view direction in world space
  1663. Out.FallOffColor = pow(worldTangentEyeDir, 2.0) * float3(0.3,0.6,3.0);
  1664. #endif // SUPPORT_CHRONORIFT
  1665. #if defined(SUPPORT_FORMATIONPREVIEW)
  1666. float worldTangentEyeDir = 1 - dot(worldEyeDir, worldNormal);
  1667. // Compute view direction in world space
  1668. Out.FallOffColor = pow(worldTangentEyeDir, 2.5) * float3(0.0,1.05,0.0);
  1669. #endif // SUPPORT_FORMATIONPREVIEW
  1670. #if defined(SUPPORT_PSYONIC)
  1671. // Compute view direction in world space
  1672. float3 worldEyeDir = normalize(GetEyePosition() - worldPosition);
  1673. // Calculate Fresnel Effect
  1674. float fresnelDiffuse = pow( 1-dot( worldEyeDir, worldNormal), 4);
  1675. float3 fresnelColor = fresnelDiffuse * float3(2,2,10);
  1676. Out.FallOffColor = float3(fresnelColor * OpacityOverride);
  1677. #endif // SUPPORT_PSYONIC
  1678. Out.TexCoord0_TexCoord1.zw = texCoord1.yx;
  1679. Out.ShroudTexCoord = CalculateShroudTexCoord(Shroud, worldPosition);
  1680. #if defined(SUPPORT_XRAY)
  1681. Out.ScreenSpaceCoord.xy = normalize(mul(float4(worldPosition, 1), GetViewProjection()));
  1682. Out.ScreenSpaceCoord.xy += .5;
  1683. // Generate a scalar based on viewspace to cull the XRay texture from removing objects behind Yuriko
  1684. Out.ScreenSpaceCoord.z = (saturate(length(worldPosition - GetEyePosition()) * .02 - 6));
  1685. #endif
  1686. return Out;
  1687. }
  1688. // ----------------------------------------------------------------------------
  1689. // SHADER: PS
  1690. // ----------------------------------------------------------------------------
  1691. float4 PS_L(VSOutput_L In, uniform bool recolorEnabled) COLORTARGET
  1692. {
  1693. float2 texCoord0 = In.TexCoord0_TexCoord1.xy;
  1694. float2 texCoord1 = In.TexCoord0_TexCoord1.wz;
  1695. // Get diffuse color
  1696. float4 baseTexture = tex2D( SAMPLER(DiffuseTexture), texCoord0);
  1697. #if defined(SUPPORT_RECOLORING)
  1698. if (recolorEnabled)
  1699. {
  1700. float4 recolorColor = tex2D( SAMPLER(SpecMap), texCoord0);
  1701. baseTexture.xyz = lerp(baseTexture.xyz, baseTexture.xyz * RecolorColor * 2, recolorColor.z);
  1702. }
  1703. #endif //defined(SUPPORT_RECOLORING)
  1704. float4 color = baseTexture;
  1705. color.xyz *= In.Color.xyz;
  1706. // this is ugly but I couldn't think of a better way to do it. -Sean
  1707. #if defined(SUPPORT_FILLDAMAGETEXTURE) && defined(SUPPORT_DAMAGETEXTURE)
  1708. // Get Damaged Texture on 2nd UV Coords
  1709. float4 damagedTexture = tex2D(SAMPLER(DamagedTexture), texCoord1);
  1710. color *= damagedTexture * (1 - In.Color.w);
  1711. #elif defined(SUPPORT_DAMAGETEXTURE)
  1712. // Get Damaged Texture on 2nd UV Coords
  1713. float4 damagedTexture = tex2D(SAMPLER(DamagedTexture), texCoord1);
  1714. color *= lerp(damagedTexture, 1.0.xxxx, In.Color.w);
  1715. #elif !defined(SUPPORT_JAPANBUILDUP)
  1716. color.w *= In.Color.w;
  1717. #endif
  1718. #if defined(SUPPORT_IRONCURTAIN)
  1719. float3 Texture0 = tex2D( SAMPLER(IronCurtainTexture), texCoord0);
  1720. float3 Texture1 = tex2D( SAMPLER(IronCurtainTexture), texCoord1);
  1721. color.xyz = Texture0 * Texture1 * 5;
  1722. // Compute view direction in world space
  1723. color.xyz += In.FallOffColor;
  1724. color.w = 1;
  1725. #endif // SUPPORT_IRONCURTAIN
  1726. #if defined(SUPPORT_CHRONORIFT)
  1727. float3 Texture0 = tex2D( SAMPLER(ChronoRiftTexture), texCoord0);
  1728. float3 Texture1 = tex2D( SAMPLER(ChronoRiftTexture), texCoord1);
  1729. color.xyz = Texture0 * Texture1 * 2;
  1730. color.xyz += In.FallOffColor;
  1731. color.w = 1;
  1732. #endif // SUPPORT_CHRONORIFT
  1733. #if defined(SUPPORT_FORMATIONPREVIEW)
  1734. color.xyz = float3(0.0,0.22,0.18);
  1735. color.xyz += In.FallOffColor;
  1736. color.xyz = min(color.xyz,2);
  1737. color.w = OpacityOverride;
  1738. #endif // SUPPORT_CHRONORIFT
  1739. #if defined(SUPPORT_PSYONIC)
  1740. color.xyz += In.FallOffColor;
  1741. #endif
  1742. color.xyz *= TintColor;
  1743. #if defined(SUPPORT_XRAY)
  1744. float xrayTexture = saturate(tex2D( SAMPLER(XrayTexture), In.ScreenSpaceCoord.xy).x);
  1745. // Use the scalar that we computed in the vertex shader to get a Z-Depth multiplier
  1746. xrayTexture = lerp(In.ScreenSpaceCoord.z,1,xrayTexture);
  1747. clip(xrayTexture - XRAY_TRANSPARENCY_THRESHOLD);
  1748. color.w *= xrayTexture;
  1749. #endif
  1750. #if defined(_WW3D_) && !defined(_W3DVIEW_)
  1751. color.xyz *= tex2D( SAMPLER(ShroudTexture), In.ShroudTexCoord );
  1752. #endif
  1753. #if defined(SUPPORT_JAPANBUILDUP)
  1754. // Get Buildup Mask
  1755. float Mask = smoothstep(.3,.51,texCoord0.y + (In.Color.w * 1.2) - .65);
  1756. float buildupTexture = tex2D( SAMPLER(JapanBuildMaskTexture), texCoord0 * 50).x + .5;
  1757. buildupTexture = pow(buildupTexture,3)*6;
  1758. float3 maskColor = buildupTexture * float3(.9,3,.9);
  1759. color.xyz = lerp(maskColor,color.xyz, clamp(1,0,Mask));
  1760. clip(Mask - ((float)DEFAULT_ALPHATEST_THRESHOLD / 255));
  1761. #endif
  1762. return color;
  1763. }
  1764. // ----------------------------------------------------------------------------
  1765. // Arrays: Default_L
  1766. // ----------------------------------------------------------------------------
  1767. DEFINE_ARRAY_MULTIPLIER( VS_L_Multiplier_Final = 2 );
  1768. #define VS_L_NumJointsPerVertex \
  1769. compile VS_2_0 VS_L(0), \
  1770. compile VS_2_0 VS_L(1)
  1771. #if SUPPORTS_SHADER_ARRAYS
  1772. vertexshader VS_L_Array[VS_L_Multiplier_Final] =
  1773. {
  1774. VS_L_NumJointsPerVertex
  1775. };
  1776. #endif
  1777. DEFINE_ARRAY_MULTIPLIER( PS_L_Multiplier_RecolorEnabled = 1 );
  1778. #define PS_L_RecolorEnabled \
  1779. compile PS_2_0 PS_L(false), \
  1780. compile PS_2_0 PS_L(true)
  1781. DEFINE_ARRAY_MULTIPLIER( PS_L_Multiplier_Final = PS_L_Multiplier_RecolorEnabled * 2 );
  1782. #if SUPPORTS_SHADER_ARRAYS
  1783. pixelshader PS_L_Array[PS_L_Multiplier_Final] =
  1784. {
  1785. PS_L_RecolorEnabled
  1786. };
  1787. #endif
  1788. // ----------------------------------------------------------------------------
  1789. // Technique: Default_L
  1790. // ----------------------------------------------------------------------------
  1791. technique Default_L
  1792. {
  1793. pass p0
  1794. #if !defined(SUPPORT_DAMAGETEXTURE) && !defined(SUPPORT_CHRONORIFT) && !defined(SUPPORT_XRAY)
  1795. <
  1796. USE_EXPRESSION_EVALUATOR(EXPRESSION_EVALUATOR_NAME)
  1797. >
  1798. #endif
  1799. {
  1800. VertexShader = ARRAY_EXPRESSION_VS( VS_L_Array,
  1801. min(NumJointsPerVertex, 1),
  1802. NO_ARRAY_ALTERNATIVE);
  1803. PixelShader = ARRAY_EXPRESSION_PS( PS_L_Array,
  1804. HasRecolorColors * PS_L_Multiplier_RecolorEnabled,
  1805. NO_ARRAY_ALTERNATIVE);
  1806. ZEnable = true;
  1807. ZFunc = ZFUNC_INFRONT;
  1808. ZWriteEnable = true;
  1809. CullMode = CW;
  1810. #if defined(SUPPORT_DAMAGETEXTURE)
  1811. AlphaBlendEnable = false;
  1812. #elif defined(SUPPORT_CHRONORIFT)
  1813. AlphaBlendEnable = true;
  1814. SrcBlend = One;
  1815. DestBlend = One;
  1816. #elif defined(SUPPORT_XRAY)
  1817. AlphaBlendEnable = true;
  1818. #else
  1819. #if !EXPRESSION_EVALUATOR_ENABLED
  1820. AlphaBlendEnable = ( OpacityOverride < 0.99);
  1821. #endif
  1822. SrcBlend = SrcAlpha;
  1823. DestBlend = InvSrcAlpha;
  1824. #endif
  1825. AlphaFunc = GreaterEqual;
  1826. AlphaRef = DEFAULT_ALPHATEST_THRESHOLD;
  1827. #if defined(SUPPORT_DAMAGETEXTURE)
  1828. AlphaTestEnable = true;
  1829. #elif defined(SUPPORT_CHRONORIFT)
  1830. AlphaTestEnable = false;
  1831. #elif defined(SUPPORT_XRAY)
  1832. AlphaTestEnable = false;
  1833. #else
  1834. #if !EXPRESSION_EVALUATOR_ENABLED
  1835. AlphaTestEnable = ( AlphaTestEnable );
  1836. #endif
  1837. #endif
  1838. }
  1839. }
  1840. #endif // ENABLE_LOD
  1841. // ----------------------------------------------------------------------------
  1842. // SHADER: CreateShadowMapVS
  1843. // ----------------------------------------------------------------------------
  1844. struct VSOutput_CreateShadowMap
  1845. {
  1846. float4 Position : POSITION;
  1847. float2 TexCoord0 : TEXCOORD0;
  1848. #if defined(SUPPORT_DAMAGETEXTURE)
  1849. float2 TexCoord1 : TEXCOORD2;
  1850. #endif
  1851. float Depth : TEXCOORD1;
  1852. float Opacity : COLOR0;
  1853. };
  1854. // ----------------------------------------------------------------------------
  1855. VSOutput_CreateShadowMap CreateShadowMapVS(VSInputSkinningOneBoneTangentFrame InSkin,
  1856. float2 TexCoord0 : TEXCOORD0,
  1857. #if defined(SUPPORT_DAMAGETEXTURE)
  1858. float2 TexCoord1 : TEXCOORD1,
  1859. #endif
  1860. float4 VertexColor: COLOR0,
  1861. uniform int numJointsPerVertex)
  1862. {
  1863. VSOutput_CreateShadowMap Out;
  1864. float3 worldPosition = 0;
  1865. float3 worldNormal = 0;
  1866. float3 worldTangent = 0;
  1867. float3 worldBinormal = 0;
  1868. CalculatePositionAndTangentFrame(InSkin, numJointsPerVertex,
  1869. worldPosition, worldNormal, worldTangent, worldBinormal);
  1870. /*
  1871. #if defined(SUPPORT_CRUSHED)
  1872. float3 objectCenter = GetFirstBonePosition(0, numJointsPerVertex);
  1873. float crushMask = frac(dot(worldPosition, 1..xxx)*.1);
  1874. crushMask += (TexCoord0.x + TexCoord0.y) * 15;
  1875. crushMask -= OpacityOverride;
  1876. crushMask = clamp(int(crushMask),0,3);
  1877. crushMask *= .33;
  1878. float3 objectSpacePosition = worldPosition - objectCenter;
  1879. float3 objectSpherePosition = normalize(objectSpacePosition) * 10;
  1880. objectSpacePosition = lerp(objectSpherePosition, objectSpacePosition, crushMask);
  1881. worldPosition = objectSpacePosition + objectCenter;
  1882. #endif // SUPPORT_CRUSHED
  1883. */
  1884. // Get the skins opacity value, used later as blend factor for the damage texture
  1885. VertexColor.w *= GetOpacity(InSkin, numJointsPerVertex);
  1886. #if defined(_3DSMAX_)
  1887. // Default vertex color is 0 in Max, that's bad.
  1888. VertexColor = 1.0;
  1889. #endif
  1890. #if defined(SUPPORT_TREAD_SCROLLING)
  1891. // Tread scrolling uses the vertex color opacity for animating the U coordinate
  1892. TexCoord0.x += VertexColor.w;
  1893. // Don't use it for opacity then.
  1894. VertexColor.w = 1.0f;
  1895. #endif
  1896. // Transform position to projection space
  1897. ISOLATE Out.Position = mul(float4(worldPosition, 1), GetViewProjection());
  1898. Out.Depth = Out.Position.z / Out.Position.w;
  1899. Out.Opacity = OpacityOverride * VertexColor.w;
  1900. Out.TexCoord0 = TexCoord0;
  1901. #if defined(SUPPORT_DAMAGETEXTURE)
  1902. Out.TexCoord1 = TexCoord1;
  1903. #endif
  1904. return Out;
  1905. }
  1906. // ----------------------------------------------------------------------------
  1907. float4 CreateShadowMapPS(VSOutput_CreateShadowMap In, uniform bool alphaTestEnable) COLORTARGET
  1908. {
  1909. #if defined(SUPPORT_JAPANBUILDUP)
  1910. // Get Buildup Mask
  1911. float Mask = smoothstep(.4,.51,In.TexCoord0.y + (In.Opacity * 1.2) - .65);
  1912. clip(Mask - ((float)DEFAULT_ALPHATEST_THRESHOLD / 255));
  1913. #else
  1914. float opacity = tex2D(SAMPLER(DiffuseTexture), In.TexCoord0).w;
  1915. #if defined(SUPPORT_FILLDAMAGETEXTURE) && defined(SUPPORT_DAMAGETEXTURE)
  1916. // Get Damaged Texture on 2nd UV Coords
  1917. float damagedTexture = tex2D(SAMPLER(DamagedTexture), In.TexCoord1).w;
  1918. opacity *= damagedTexture * (1 - In.Opacity);
  1919. #elif defined(SUPPORT_DAMAGETEXTURE)
  1920. // Get Damaged Texture on 2nd UV Coords
  1921. float damagedTexture = tex2D(SAMPLER(DamagedTexture), In.TexCoord1).w;
  1922. opacity *= lerp(damagedTexture, 1.0, In.Opacity);
  1923. #elif !defined(SUPPORT_JAPANBUILDUP)
  1924. opacity *= In.Opacity;
  1925. #endif
  1926. if (alphaTestEnable)
  1927. {
  1928. // Simulate alpha testing for floating point render target
  1929. clip(opacity - ((float)DEFAULT_ALPHATEST_THRESHOLD / 255));
  1930. }
  1931. #endif //SUPPORT_JAPANBUILDUP
  1932. return In.Depth;
  1933. }
  1934. // ----------------------------------------------------------------------------
  1935. // SHADER: CreateShadowMapVS_Xenon
  1936. // ----------------------------------------------------------------------------
  1937. VSOutput_CreateShadowMap CreateShadowMapVS_Xenon(VSInputSkinningOneBoneTangentFrame InSkin,
  1938. float2 TexCoord : TEXCOORD0,
  1939. #if defined(SUPPORT_DAMAGETEXTURE)
  1940. float2 TexCoord1 : TEXCOORD1,
  1941. #endif
  1942. float4 VertexColor: COLOR0)
  1943. {
  1944. return CreateShadowMapVS( InSkin,
  1945. TexCoord,
  1946. #if defined(SUPPORT_DAMAGETEXTURE)
  1947. TexCoord1,
  1948. #endif
  1949. VertexColor, min(NumJointsPerVertex, 1) );
  1950. }
  1951. // ----------------------------------------------------------------------------
  1952. float4 CreateShadowMapPS_Xenon(VSOutput_CreateShadowMap In) : COLOR
  1953. {
  1954. return CreateShadowMapPS(In, AlphaTestEnable);
  1955. }
  1956. // ----------------------------------------------------------------------------
  1957. // Technique _CreateShadowMap
  1958. // ----------------------------------------------------------------------------
  1959. DEFINE_ARRAY_MULTIPLIER( VSCreateShadowMap_Multiplier_Final = 2 );
  1960. #define VSCreateShadowMap_NumJointsPerVertex \
  1961. compile VS_2_0 CreateShadowMapVS(0), \
  1962. compile VS_2_0 CreateShadowMapVS(1)
  1963. #if SUPPORTS_SHADER_ARRAYS
  1964. vertexshader VSCreateShadowMap_Array[VSCreateShadowMap_Multiplier_Final] =
  1965. {
  1966. VSCreateShadowMap_NumJointsPerVertex
  1967. };
  1968. #endif
  1969. #define PSCreateShadowMap_AlphaTestEnable \
  1970. compile PS_2_0 CreateShadowMapPS(false), \
  1971. compile PS_2_0 CreateShadowMapPS(true)
  1972. DEFINE_ARRAY_MULTIPLIER( PSCreateShadowMap_Multiplier_Final = 2 );
  1973. #if SUPPORTS_SHADER_ARRAYS
  1974. pixelshader PSCreateShadowMap_Array[PSCreateShadowMap_Multiplier_Final] =
  1975. {
  1976. PSCreateShadowMap_AlphaTestEnable
  1977. };
  1978. #endif
  1979. // ----------------------------------------------------------------------------
  1980. #if defined(SUPPORT_FORMATIONPREVIEW) || defined(SUPPORT_CHRONORIFT) || defined(SUPPORT_NOSHADOWS)
  1981. technique _CreateDepthMap // Don't cast a shadow, but still render to the depth map
  1982. #else
  1983. technique _CreateShadowMap
  1984. #endif
  1985. {
  1986. pass p0
  1987. {
  1988. VertexShader = ARRAY_EXPRESSION_VS( VSCreateShadowMap_Array,
  1989. min(NumJointsPerVertex, 1),
  1990. compile VS_VERSION CreateShadowMapVS_Xenon() );
  1991. PixelShader = ARRAY_EXPRESSION_PS( PSCreateShadowMap_Array,
  1992. AlphaTestEnable,
  1993. compile PS_VERSION CreateShadowMapPS_Xenon() );
  1994. ZEnable = true;
  1995. ZFunc = ZFUNC_INFRONT;
  1996. ZWriteEnable = true;
  1997. CullMode = CW;
  1998. AlphaBlendEnable = false;
  1999. AlphaTestEnable = false;
  2000. }
  2001. }