Objects.fxh 65 KB

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