BasicW3D.fxh 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337
  1. //////////////////////////////////////////////////////////////////////////////
  2. // ©2005 Electronic Arts Inc
  3. //
  4. // FX Shader for simple material with one texture
  5. //////////////////////////////////////////////////////////////////////////////
  6. //#define SUPPORT_RECOLORING 1 // Defined only in Infantry.fx!
  7. //#define SUPPORT_HOLOGRAPHIC //Enable Holographic shader support branch
  8. //#define SUPPORT_HDR // Define for HDR Multiplier Support
  9. //#define DISABLE_EXPRESSION_EVALUATORS
  10. //#define SUPPORT_SSAO 0 // disable SSAO
  11. //#define SUPPORT_FROZEN 1 // Defined to change appearance of infantry to ice
  12. //#define SUPPORT_RADIATION 1 // Used only for defining radiation infantry deaths
  13. //#define SUPPORT_CHRONORIFT 1 // Defined to change appearance of infantry to Chrono Rifted
  14. //#define SUPPORT_CRUSHED // enable crushed vertex shader for infantry that die from Yuriko's special ability
  15. #define USE_INTERACTIVE_LIGHTS 1
  16. #define SUPPORT_CLOUDS 1
  17. #define SUPPORT_FOG 1
  18. #define SUPPORT_GLOBAL_LIGHTS 1
  19. #define SUPPORT_LOCAL_LIGHTS 1
  20. #define MaxNumPointLights 3
  21. #include "Common.fxh"
  22. #include "Gamma.fxh"
  23. #include "SSAO.fxh"
  24. #include "Random.fxh"
  25. #include "ShadowMap.fxh"
  26. int _SasGlobal : SasGlobal
  27. <
  28. string UIWidget = "None";
  29. int3 SasVersion = int3(1, 0, 0);
  30. int MaxLocalLights = MaxNumPointLights;
  31. int MaxSupportedInstancingMode = INSTANCING_MODE_ONE_PER_DRAW_CALL;
  32. > = 0;
  33. #if defined(EA_PLATFORM_WINDOWS) && defined(_3DSMAX_)
  34. // ----------------------------------------------------------------------------
  35. // SAMPLER : nhendricks : had to pull these in here for MAX to compile
  36. // ----------------------------------------------------------------------------
  37. #define SAMPLER_2D_BEGIN(samplerName, annotations) \
  38. texture samplerName \
  39. < \
  40. annotations \
  41. >; \
  42. sampler2D samplerName##Sampler = sampler_state \
  43. { \
  44. Texture = < samplerName >;
  45. #define SAMPLER_2D_END };
  46. #define SAMPLER( samplerName ) samplerName##Sampler
  47. #define SAMPLER_CUBE_BEGIN(samplerName, annotations) \
  48. texture samplerName \
  49. < \
  50. annotations \
  51. >; \
  52. samplerCUBE samplerName##Sampler = sampler_state \
  53. { \
  54. Texture = < samplerName >;
  55. #define SAMPLER_CUBE_END };
  56. #endif
  57. // ----------------------------------------------------------------------------
  58. // Skinning
  59. // ----------------------------------------------------------------------------
  60. #define MaxSkinningBonesPerVertex 2
  61. #include "Skinning.fxh"
  62. // ----------------------------------------------------------------------------
  63. // Transformations
  64. // ----------------------------------------------------------------------------
  65. #if defined(_WW3D_)
  66. #if !defined(USE_INDIRECT_CONSTANT)
  67. float4x4 ViewProjection
  68. <
  69. string UIWidget = "None";
  70. string SasBindAddress = "Sas.Camera.WorldToProjection";
  71. >;
  72. float3 EyePosition
  73. <
  74. string UIWidget = "None";
  75. string SasBindAddress = "Sas.Camera.Position";
  76. >;
  77. #endif // #if !defined(USE_INDIRECT_CONSTANT)
  78. float4x4 GetViewProjection()
  79. {
  80. return ViewProjection;
  81. }
  82. float3 GetEyePosition()
  83. {
  84. return EyePosition;
  85. }
  86. #else // #if defined(_WW3D_)
  87. float4x4 View : View;
  88. float4x3 ViewI : ViewInverse;
  89. float4x4 Projection : Projection;
  90. float4x4 GetViewProjection()
  91. {
  92. return mul(View, Projection);
  93. }
  94. float3 GetEyePosition()
  95. {
  96. return ViewI[3];
  97. }
  98. #endif // #if defined(_WW3D_)
  99. float Time : Time;
  100. // ----------------------------------------------------------------------------
  101. // Material parameters
  102. // ----------------------------------------------------------------------------
  103. float3 ColorAmbient
  104. <
  105. string UIName = "Ambient Material Color";
  106. string UIWidget = "Color";
  107. > = float3(1.0, 1.0, 1.0);
  108. float3 ColorDiffuse
  109. <
  110. string UIName = "Diffuse Material Color";
  111. string UIWidget = "Color";
  112. > = float3(1.0, 1.0, 1.0);
  113. float3 ColorSpecular
  114. <
  115. string UIName = "Specular Material Color";
  116. string UIWidget = "Color";
  117. > = float3(0.0, 0.0, 0.0);
  118. float Shininess
  119. <
  120. string UIName = "Specular Shininess";
  121. string UIWidget = "Slider";
  122. float UIMax = 100;
  123. > = 1.0;
  124. float3 ColorEmissive
  125. <
  126. string UIName = "Emissive Material Color";
  127. string UIWidget = "Color";
  128. > = float3(0.0, 0.0, 0.0);
  129. #if defined(SUPPORT_HDR)
  130. float HDRMultiplier
  131. <
  132. string UIName = "HDR Multiplier";
  133. string UIWidget = "Slider";
  134. float UIMax = 100;
  135. > = 1.0;
  136. #endif
  137. SAMPLER_2D_BEGIN( Texture_0,
  138. string UIName = "Base Texture";
  139. )
  140. MinFilter = MinFilterBest;
  141. MagFilter = MagFilterBest;
  142. MipFilter = MipFilterBest;
  143. AddressU = Wrap;
  144. AddressV = Wrap;
  145. SAMPLER_2D_END
  146. // ----------------------------------------------------------------------------
  147. // House coloring
  148. // ----------------------------------------------------------------------------
  149. bool DepthWriteEnable
  150. <
  151. string UIName = "Depth Write Enable";
  152. > = true;
  153. bool AlphaTestEnable
  154. <
  155. string UIName = "Alpha Test Enable";
  156. > = false;
  157. bool CullingEnable
  158. <
  159. string UIName = "Culling Enable";
  160. > = true;
  161. static const int BlendMode_Opaque = 0;
  162. static const int BlendMode_Alpha = 1;
  163. static const int BlendMode_Additive = 2;
  164. int BlendMode
  165. <
  166. string UIName = "Blend mode (0: opaque, 1: alpha, 2: additive)";
  167. int UIMin = 0;
  168. int UIMax = 2;
  169. > = BlendMode_Opaque;
  170. // ----------------------------------------------------------------------------
  171. // Tree Sway
  172. // ----------------------------------------------------------------------------
  173. #if defined(TREE_SWAY)
  174. float SwayStartHeight
  175. <
  176. string UIName = "Sway Start Height";
  177. string UIWidget = "Slider";
  178. > = 15.0;
  179. float SwayStartRadius
  180. <
  181. string UIName = "Sway Start Radius";
  182. string UIWidget = "Slider";
  183. float UIMin = 0.01;
  184. float UIMax = 1000;
  185. > = 5.0;
  186. float SwayStrength
  187. <
  188. string UIName = "Sway Strength";
  189. string UIWidget = "Slider";
  190. float UIMin = 0;
  191. float UIMax = 100;
  192. > = 1.0;
  193. void ApplyTreeSway(VSInputSkinningMultipleBones InSkin, int NumJointsPerVertex, inout float3 WorldPosition)
  194. {
  195. // Only vertices above SwayStartHeight, which is relative to the origin of the object, will be affected
  196. // Above SwayStartHeight, the amount of sway will ramp up to full strength based on the SwayStartRadius
  197. float3 worldPivotPosition = GetFirstBonePosition(InSkin.BlendIndices, NumJointsPerVertex);
  198. float pivotOffset = WorldPosition.z - worldPivotPosition.z;
  199. float swayHeight = pivotOffset - SwayStartHeight;
  200. float swayAmount = clamp( swayHeight / SwayStartRadius, 0, 1 ) * SwayStrength;
  201. // Make the sway unique based on the position of the object in the world
  202. float2 phaseOffset = GetRandomFloatValues( float2(0, 0), float2(20, 20), 3, ( worldPivotPosition.x + worldPivotPosition.y ) * 2 );
  203. float2 phase = Time.xx + phaseOffset;
  204. float2 sway = sin( phase );
  205. WorldPosition.xy += swayAmount * sway;
  206. }
  207. #endif // defined(TREE_SWAY)
  208. // ----------------------------------------------------------------------------
  209. // Shroud
  210. // ----------------------------------------------------------------------------
  211. ShroudSetup Shroud
  212. <
  213. string UIWidget = "None";
  214. #if !defined(_W3DVIEW_)
  215. string SasBindAddress = "Terrain.Shroud";
  216. #endif
  217. > = DEFAULT_SHROUD;
  218. SAMPLER_2D_BEGIN( ShroudTexture,
  219. string UIWidget = "None";
  220. string SasBindAddress = "Terrain.Shroud.Texture";
  221. )
  222. MinFilter = Linear;
  223. MagFilter = Linear;
  224. MipFilter = Linear;
  225. AddressU = Clamp;
  226. AddressV = Clamp;
  227. SAMPLER_2D_END
  228. // ----------------------------------------------------------------------------
  229. // Frozen shader ice normal map
  230. // ----------------------------------------------------------------------------
  231. #if defined(SUPPORT_FROZEN)
  232. SAMPLER_2D_BEGIN( FrozenNormalMap,
  233. string UIWidget = "None";
  234. string SasBindAddress = "WW3D.FXDistortionFractal";
  235. )
  236. MinFilter = MinFilterBest;
  237. MagFilter = MagFilterBest;
  238. MipFilter = MipFilterBest;
  239. MaxAnisotropy = 8;
  240. AddressU = Wrap;
  241. AddressV = Wrap;
  242. SAMPLER_2D_END
  243. SAMPLER_CUBE_BEGIN( EnvironmentTexture,
  244. string UIWidget = "None";
  245. string SasBindAddress = "Objects.LightSpaceEnvironmentMap";
  246. string ResourceType = "Cube";
  247. )
  248. MinFilter = Linear;
  249. MagFilter = Linear;
  250. MipFilter = Linear;
  251. AddressU = Clamp;
  252. AddressV = Clamp;
  253. AddressW = Clamp;
  254. SAMPLER_CUBE_END
  255. #endif
  256. // ----------------------------------------------------------------------------
  257. // Chrono Rift texture map
  258. // ----------------------------------------------------------------------------
  259. #if defined(SUPPORT_CHRONORIFT)
  260. SAMPLER_2D_BEGIN( ChronoRiftTexture,
  261. string UIWidget = "None";
  262. string SasBindAddress = "WW3D.FXChronoRift";
  263. )
  264. MipFilter = Linear;
  265. MinFilter = Linear;
  266. MagFilter = Linear;
  267. AddressU = WRAP;
  268. AddressV = WRAP;
  269. SAMPLER_2D_END
  270. #endif
  271. // ----------------------------------------------------------------------------
  272. // Clouds
  273. // ----------------------------------------------------------------------------
  274. SAMPLER_2D_BEGIN( CloudTexture,
  275. string UIWidget = "None";
  276. string SasBindAddress = "Terrain.Cloud.Texture";
  277. string ResourceName = "ShaderPreviewCloud.dds";
  278. )
  279. MinFilter = Linear;
  280. MagFilter = Linear;
  281. MipFilter = Linear;
  282. AddressU = Wrap;
  283. AddressV = Wrap;
  284. SAMPLER_2D_END
  285. // ----------------------------------------------------------------------------
  286. // FOG
  287. // ----------------------------------------------------------------------------
  288. // Variations for handling fog in the pixel shader
  289. static const int FogMode_Disabled = 0;
  290. static const int FogMode_Opaque = 1;
  291. static const int FogMode_Additive = 2;
  292. #if !defined(USE_INDIRECT_CONSTANT)
  293. float OpacityOverride
  294. <
  295. string UIWidget = "None";
  296. string SasBindAddress = "WW3D.OpacityOverride";
  297. > = 1.0;
  298. float3 TintColor
  299. <
  300. string UIWidget = "None";
  301. string SasBindAddress = "WW3D.TintColor";
  302. > = float3(1, 1, 1);
  303. #endif // #if !defined(USE_INDIRECT_CONSTANT)
  304. // ----------------------------------------------------------------------------
  305. // SHADER : DEFAULT
  306. // ----------------------------------------------------------------------------
  307. struct VSOutput
  308. {
  309. float4 Position : POSITION;
  310. float4 DiffuseColor_Opacity : TEXCOORD1;
  311. float4 SpecularColor_Fog : COLOR1;
  312. float2 BaseTexCoord : TEXCOORD0;
  313. float4 CloudTexCoord_ShroudTexCoord : TEXCOORD2;
  314. #if defined (SUPPORT_HOLOGRAPHIC)
  315. float EdgeFade : TEXCOORD3;
  316. #else
  317. float4 ShadowMapTexCoord : TEXCOORD3;
  318. float3 MainLightDiffuseColor : TEXCOORD4;
  319. float3 MainLightSpecularColor : TEXCOORD5;
  320. #endif
  321. #if defined (SUPPORT_FROZEN)
  322. float3 WorldNormal : TEXCOORD6;
  323. float3 WorldEyeDir : TEXCOORD7;
  324. #endif
  325. #if defined(SUPPORT_RADIATION) || defined(SUPPORT_CHRONORIFT)
  326. float3 EdgeFallOff : TEXCOORD6;
  327. #endif
  328. };
  329. // ----------------------------------------------------------------------------
  330. #if defined(EA_PLATFORM_PS3)
  331. VSOutput VS(VSInputSkinningMultipleBones InSkin,
  332. float2 TexCoord0 : TEXCOORD0,
  333. float4 VertexColor: COLOR0,
  334. uniform int numJointsPerVertex,
  335. uniform bool usePointLights,
  336. uniform bool isFrozenPass)
  337. {
  338. USE_DIRECTIONAL_LIGHT_INTERACTIVE(DirectionalLight, 0);
  339. VSOutput Out;
  340. float3 worldPosition = 0;
  341. float3 worldNormal = 0;
  342. CalculatePositionAndNormal(InSkin, numJointsPerVertex, worldPosition, worldNormal);
  343. #if defined(SUPPORT_CRUSHED)
  344. worldPosition += worldNormal * OpacityOverride * 3;
  345. #endif // SUPPORT_CRUSHED
  346. VertexColor.w *= GetOpacity(InSkin, numJointsPerVertex);
  347. VertexColor.xyz *= TintColor;
  348. // $Note (WSK) - diffuse light is not working yet, we simply want the opacity term for now
  349. float3 diffuseLight = 0;
  350. float3 diffuseColor = (ColorEmissive + AmbientLightColor * ColorAmbient
  351. + diffuseLight * ColorDiffuse) * VertexColor.xyz;
  352. #if defined(SUPPORT_CRUSHED)
  353. Out.DiffuseColor_Opacity = float4(diffuseColor / 2, VertexColor.w);
  354. #else
  355. Out.DiffuseColor_Opacity = float4(diffuseColor / 2, OpacityOverride * VertexColor.w);
  356. #endif
  357. Out.Position = mul(float4(worldPosition, 1), GetViewProjection());
  358. Out.BaseTexCoord = TexCoord0;
  359. Out.CloudTexCoord_ShroudTexCoord.zw = CalculateShroudTexCoord(Shroud, worldPosition).yx;
  360. return Out;
  361. }
  362. #else // EA_PLATFORM_WINDOWS || EA_PLATFORM_XENON
  363. VSOutput VS(VSInputSkinningMultipleBones InSkin,
  364. float2 TexCoord0 : TEXCOORD0,
  365. float4 VertexColor: COLOR0,
  366. uniform int numJointsPerVertex,
  367. uniform bool usePointLights,
  368. uniform bool isFrozenPass)
  369. {
  370. USE_DIRECTIONAL_LIGHT_INTERACTIVE(DirectionalLight, 0);
  371. VSOutput Out;
  372. float3 worldPosition = 0;
  373. float3 worldNormal = 0;
  374. CalculatePositionAndNormal(InSkin, numJointsPerVertex, worldPosition, worldNormal);
  375. #if defined(SUPPORT_CRUSHED)
  376. worldPosition += worldNormal * OpacityOverride * 3;
  377. #endif // SUPPORT_CRUSHED
  378. VertexColor.w *= GetOpacity(InSkin, numJointsPerVertex);
  379. #if defined(TREE_SWAY)
  380. ApplyTreeSway(InSkin, numJointsPerVertex, worldPosition);
  381. #endif
  382. #if defined(_3DSMAX_)
  383. // Default vertex color is 0 in Max, that's bad.
  384. VertexColor = 1.0;
  385. #endif
  386. VertexColor.xyz *= TintColor;
  387. if (isFrozenPass)
  388. {
  389. // Extrude geo to create a shell for the ice
  390. worldPosition += worldNormal * 1.5;
  391. }
  392. //Out.Position = mul(mul(float4(worldPosition, 1), View), Projection);
  393. ISOLATE Out.Position = mul(float4(worldPosition, 1), GetViewProjection());
  394. // Compute view direction in world space
  395. float3 worldEyeDir = normalize(GetEyePosition() - worldPosition);
  396. #if defined (SUPPORT_HOLOGRAPHIC)
  397. float edgeFade = 1-pow(saturate(dot(worldNormal,worldEyeDir)),0.5f);
  398. Out.EdgeFade = edgeFade;
  399. Out.DiffuseColor_Opacity = float4(.1,1,.1, OpacityOverride * VertexColor.w);
  400. Out.SpecularColor_Fog.xyz = float3(1,1,1);
  401. #else
  402. // Compute light
  403. // Compute directional lights
  404. if (NumDirectionalLights > 0)
  405. {
  406. float3 halfEyeLightVector = normalize(DirectionalLight[0].Direction + worldEyeDir);
  407. float4 lighting = lit(dot(worldNormal, DirectionalLight[0].Direction),
  408. dot(worldNormal, halfEyeLightVector), Shininess);
  409. float3 diffuseLight = DirectionalLight[0].Color * lighting.y;
  410. float3 specularLight = DirectionalLight[0].Color * lighting.z;
  411. Out.MainLightDiffuseColor = diffuseLight * ColorDiffuse * VertexColor.xyz / 2;
  412. Out.MainLightSpecularColor = specularLight * ColorSpecular / 2;
  413. }
  414. float3 diffuseLight = 0;
  415. float3 specularLight = 0;
  416. for (int i = 1; i < NumDirectionalLights; i++)
  417. {
  418. float3 halfEyeLightVector = normalize(DirectionalLight[i].Direction + worldEyeDir);
  419. float4 lighting = lit(dot(worldNormal, DirectionalLight[i].Direction),
  420. dot(worldNormal, halfEyeLightVector), Shininess);
  421. diffuseLight += DirectionalLight[i].Color * lighting.y;
  422. specularLight += DirectionalLight[i].Color * lighting.z;
  423. }
  424. // Compute point lights
  425. if (usePointLights)
  426. {
  427. for (int i = 0; i < NumPointLights; i++)
  428. {
  429. diffuseLight += CalculatePointLightDiffuse(PointLight[i], worldPosition, worldNormal);
  430. }
  431. }
  432. float3 diffuseColor = (ColorEmissive + AmbientLightColor * ColorAmbient
  433. + diffuseLight * ColorDiffuse) * VertexColor.xyz;
  434. #if defined(SUPPORT_HDR)
  435. diffuseColor.xyz *= HDRMultiplier;
  436. #endif //SUPPORT_HDR
  437. #if defined(SUPPORT_CRUSHED)
  438. Out.DiffuseColor_Opacity = float4(diffuseColor / 2, VertexColor.w);
  439. #else
  440. Out.DiffuseColor_Opacity = float4(diffuseColor / 2, OpacityOverride * VertexColor.w);
  441. #endif
  442. Out.SpecularColor_Fog.xyz = specularLight * ColorSpecular / 2;
  443. // Calculate shadow map texture coordinates
  444. Out.ShadowMapTexCoord = CalculateShadowMapTexCoord(worldPosition);
  445. #endif //SUPPORT_HOLOGRAPHIC
  446. // Set base texture coordinate
  447. if (isFrozenPass)
  448. {
  449. // Use world coords when mapping
  450. Out.BaseTexCoord = worldPosition.xy * .025;
  451. }
  452. else
  453. {
  454. #if defined(SUPPORT_HOLOGRAPHIC)
  455. // Use world coords when mapping rotated 45 degrees
  456. // Build Texture Rotation Matrix And Convert Degrees to Radians --
  457. float cosAngle = 0;
  458. float sinAngle = 0;
  459. float2x2 uvCoordRotate = { 1.0f, 0.0f, 1.0f, 0.0f };
  460. sincos (45 * .017453, sinAngle, cosAngle);
  461. // Build Rotation
  462. uvCoordRotate[0][0] = cosAngle;
  463. uvCoordRotate[0][1] = -sinAngle;
  464. uvCoordRotate[1][1] = uvCoordRotate[0][0];
  465. uvCoordRotate[1][0] = -uvCoordRotate[0][1];
  466. Out.BaseTexCoord = mul(worldPosition.xy, uvCoordRotate) * .1;
  467. #else
  468. // pass texture coordinates
  469. Out.BaseTexCoord = TexCoord0;
  470. #endif
  471. }
  472. // Calculate cloud layer coordinates
  473. Out.CloudTexCoord_ShroudTexCoord.xy = CalculateCloudTexCoord(Cloud, worldPosition, Time);
  474. // Calculate shroud texture coordinates
  475. Out.CloudTexCoord_ShroudTexCoord.zw = CalculateShroudTexCoord(Shroud, worldPosition).yx;
  476. // Calculate fog
  477. Out.SpecularColor_Fog.w = CalculateFog(Fog, worldPosition, GetEyePosition());
  478. #if defined(SUPPORT_FROZEN)
  479. Out.WorldEyeDir = worldEyeDir;
  480. // Build 3x3 tranform from object to tangent space
  481. Out.WorldNormal = worldNormal;
  482. #endif
  483. #if defined(SUPPORT_FORMATIONPREVIEW)
  484. float fallOff = 1 - dot(worldEyeDir, worldNormal);
  485. Out.DiffuseColor_Opacity.xyz = min(float3(0.0,0.055,0.045) + pow(fallOff, 2.5) * float3(0.0,1.0,0.0), 2);
  486. #endif
  487. #if defined(SUPPORT_RADIATION)
  488. float fallOff = 1 - dot(worldEyeDir, worldNormal);
  489. Out.EdgeFallOff = pow(fallOff, 1.1) * 4;
  490. Out.BaseTexCoord = TexCoord0 + (worldPosition.xy * .05) + (Time *.15);
  491. #endif
  492. #if defined(SUPPORT_CHRONORIFT)
  493. float fallOff = 1 - dot(worldEyeDir, worldNormal);
  494. Out.EdgeFallOff = pow(fallOff, 2);
  495. Out.BaseTexCoord = TexCoord0 + (worldPosition.xy * .05) + (Time *.3);
  496. #endif
  497. return Out;
  498. }
  499. #endif
  500. // Xenon vertex shader: Remove uniform from NumJointsPerVertex parameter and have it do real branching.
  501. VSOutput VS_Xenon(VSInputSkinningMultipleBones InSkin,
  502. float2 TexCoord0 : TEXCOORD0,
  503. float4 VertexColor: COLOR0,
  504. uniform bool isFrozenPass)
  505. {
  506. return VS(InSkin, TexCoord0, VertexColor, NumJointsPerVertex, true, isFrozenPass);
  507. }
  508. // ----------------------------------------------------------------------------
  509. #if defined(EA_PLATFORM_PS3)
  510. float4 PS(VSOutput In, uniform int fogMode, uniform bool hasShadow,
  511. uniform bool recolorEnable, uniform bool isFrozenPass, float2 vPos : PIXELLOC) COLORTARGET
  512. {
  513. float4 color = In.DiffuseColor_Opacity;
  514. float2 shroudTexCoord = In.CloudTexCoord_ShroudTexCoord.wz;
  515. float4 baseTexture = tex2D( SAMPLER(Texture_0), In.BaseTexCoord);
  516. #if defined(SUPPORT_RECOLORING)
  517. if (recolorEnable && !isFrozenPass)
  518. {
  519. baseTexture.xyz = lerp(baseTexture.xyz, baseTexture.xyz * RecolorColor * 2, baseTexture.w);
  520. baseTexture.w = 1;
  521. }
  522. #endif //defined(SUPPORT_RECOLORING)
  523. baseTexture *= tex2D( SAMPLER(ShroudTexture), shroudTexCoord).x;
  524. color.xyz = baseTexture.xyz;
  525. return(color);
  526. }
  527. #else // EA_PLATFORM_WINDOWS || EA_PLATFORM_XENON
  528. float4 PS(VSOutput In, uniform int fogMode, uniform bool hasShadow,
  529. uniform bool recolorEnable, uniform bool isFrozenPass, float2 vPos : PIXELLOC) COLORTARGET
  530. {
  531. float2 shroudTexCoord = In.CloudTexCoord_ShroudTexCoord.wz;
  532. float2 cloudTexCoord = In.CloudTexCoord_ShroudTexCoord.xy;
  533. float4 color = In.DiffuseColor_Opacity;
  534. #if defined(SUPPORT_HOLOGRAPHIC)
  535. float4 textureSampler = tex2D( SAMPLER(Texture_0), In.BaseTexCoord);
  536. textureSampler.xyz = GammaToLinear(textureSampler.xyz);
  537. color.xyz = textureSampler.xyz + color.xyz * (In.EdgeFade + 0.25);
  538. color.w *= saturate(textureSampler.x * 2 + .5);
  539. #else
  540. #if defined(SUPPORT_FROZEN)
  541. if (isFrozenPass)
  542. {
  543. // Get bump map normal
  544. float3 bumpNormal;
  545. bumpNormal = (float3)tex2D(SAMPLER(FrozenNormalMap), In.BaseTexCoord) * 2.0 - 1.0;
  546. // Compute view direction in world space
  547. float3 reflVect = -reflect(In.WorldEyeDir,bumpNormal);
  548. // Although not technically correct, since we use the Cubemap to fake specular, multiply against the shadow map and add to color
  549. float3 envcolor = texCUBE( SAMPLER(EnvironmentTexture), reflVect).xyz;
  550. color.xyz = min((In.DiffuseColor_Opacity + envcolor * DirectionalLight[0].Color) * float3(.25, .4, .5),.3);
  551. }
  552. #endif
  553. float3 specularColor = In.SpecularColor_Fog.xyz;
  554. float fogStrength = In.SpecularColor_Fog.w;
  555. float3 cloud = float3(1, 1, 1);
  556. #if defined(_WW3D_) && !defined(_W3DVIEW_)
  557. cloud = GammaToLinear(tex2D( SAMPLER(CloudTexture), cloudTexCoord));
  558. #endif
  559. if (hasShadow)
  560. {
  561. cloud *= shadow( SAMPLER(ShadowMap), In.ShadowMapTexCoord);
  562. }
  563. float4 baseTexture = tex2D( SAMPLER(Texture_0), In.BaseTexCoord);
  564. #if defined(SUPPORT_RECOLORING)
  565. if (recolorEnable && !isFrozenPass)
  566. {
  567. baseTexture.xyz = lerp(baseTexture.xyz, baseTexture.xyz * RecolorColor * 2, baseTexture.w);
  568. baseTexture.w = 1;
  569. }
  570. #endif //defined(SUPPORT_RECOLORING)
  571. baseTexture.xyz = GammaToLinear(baseTexture.xyz);
  572. #if defined(SUPPORT_RADIATION)
  573. color.xyz += In.EdgeFallOff;
  574. #endif
  575. if (!isFrozenPass)
  576. {
  577. color.xyz += In.MainLightDiffuseColor * cloud;
  578. specularColor += In.MainLightSpecularColor * cloud;
  579. color.xyz += specularColor.xyz;
  580. color *= baseTexture;
  581. }
  582. // Overbrighten
  583. color.xyz += color.xyz;
  584. #if defined(SUPPORT_FORMATIONPREVIEW)
  585. color = In.DiffuseColor_Opacity;
  586. #endif // SUPPORT_FORMATIONPREVIEW
  587. #if SUPPORT_SSAO
  588. color.xyz *= ComputeSSAO(vPos);
  589. #endif
  590. // Apply fog
  591. if (fogMode == FogMode_Opaque)
  592. {
  593. color.xyz = lerp(Fog.Color, color.xyz, fogStrength);
  594. }
  595. else if (fogMode == FogMode_Additive)
  596. {
  597. // Fog used with additive blending just needs to reduce the additive influence, not blend towards the fog color
  598. color.xyz *= fogStrength;
  599. }
  600. #endif //SUPPORT_HOLOGRAPHIC
  601. #if defined(SUPPORT_CHRONORIFT)
  602. float3 Texture0 = GammaToLinear(tex2D( SAMPLER(ChronoRiftTexture), In.BaseTexCoord.xy *2));
  603. float3 Texture1 = GammaToLinear(tex2D( SAMPLER(ChronoRiftTexture), In.BaseTexCoord.yx *2));
  604. color.xyz = Texture0 * Texture1 * 50;
  605. // Compute view direction in world space
  606. color.xyz += In.EdgeFallOff * float3(0.3,0.6,3.0);
  607. color.xyz = min(color.xyz,2);
  608. color.w = In.DiffuseColor_Opacity.w;
  609. #endif // SUPPORT_CHRONORIFT
  610. #if defined(_WW3D_) && !defined(_W3DVIEW_)
  611. // Apply shroud
  612. color.xyz *= tex2D( SAMPLER(ShroudTexture), shroudTexCoord);
  613. #endif
  614. return CorrectForFrameBufferGamma(color);
  615. }
  616. #endif
  617. float4 PS_Xenon(VSOutput In, uniform bool isFrozenPass, float2 vPos : PIXELLOC) : COLOR
  618. {
  619. return PS( In, (Fog.IsEnabled ? (BlendMode == BlendMode_Additive ? FogMode_Additive : FogMode_Opaque) : FogMode_Disabled), 1, HasRecolorColors, isFrozenPass, vPos);
  620. }
  621. DEFINE_ARRAY_MULTIPLIER(VS_Multiplier_NumJointsPerVertex = 1);
  622. #define VS_NumJointsPerVertex(isFrozenPass) \
  623. compile VS_3_0 VS(0, true, isFrozenPass), \
  624. compile VS_3_0 VS(1, true, isFrozenPass), \
  625. compile VS_3_0 VS(2, true, isFrozenPass)
  626. DEFINE_ARRAY_MULTIPLIER(VS_Multiplier_Final = VS_Multiplier_NumJointsPerVertex * 3);
  627. #if SUPPORTS_SHADER_ARRAYS
  628. vertexshader VS_Array[VS_Multiplier_Final] =
  629. {
  630. VS_NumJointsPerVertex(false)
  631. };
  632. #if defined(SUPPORT_FROZEN)
  633. vertexshader VS_Frozen_Array[VS_Multiplier_Final] =
  634. {
  635. VS_NumJointsPerVertex(true)
  636. };
  637. #endif
  638. #endif
  639. DEFINE_ARRAY_MULTIPLIER(PS_Multiplier_FogMode = 1);
  640. #define PS_FogMode(hasShadow, houseColorEnable, isFrozenPass) \
  641. compile PS_3_0 PS(FogMode_Disabled, hasShadow, houseColorEnable, isFrozenPass), \
  642. compile PS_3_0 PS(FogMode_Opaque, hasShadow, houseColorEnable, isFrozenPass), \
  643. compile PS_3_0 PS(FogMode_Additive, hasShadow, houseColorEnable, isFrozenPass)
  644. DEFINE_ARRAY_MULTIPLIER(PS_Multiplier_NumShadows = PS_Multiplier_FogMode * 3);
  645. #define PS_NumShadows(houseColorEnable, isFrozenPass) \
  646. PS_FogMode(0, houseColorEnable, isFrozenPass), \
  647. PS_FogMode(1, houseColorEnable, isFrozenPass)
  648. #if defined(SUPPORT_RECOLORING)
  649. DEFINE_ARRAY_MULTIPLIER(PS_Multiplier_RecolorEnable = PS_Multiplier_NumShadows * 2);
  650. #define PS_RecolorEnable(isFrozenPass) \
  651. PS_NumShadows(false, isFrozenPass), \
  652. PS_NumShadows(true, isFrozenPass)
  653. DEFINE_ARRAY_MULTIPLIER(PS_Multiplier_Final = PS_Multiplier_RecolorEnable * 2);
  654. #else // defined(SUPPORT_RECOLORING)
  655. DEFINE_ARRAY_MULTIPLIER(PS_Multiplier_Final = PS_Multiplier_NumShadows * 2);
  656. DEFINE_ARRAY_MULTIPLIER(PS_Multiplier_RecolorEnable = 0);
  657. #define PS_RecolorEnable(isFrozenPass) \
  658. PS_NumShadows(false, isFrozenPass)
  659. #endif // defined(SUPPORT_RECOLORING)
  660. #if SUPPORTS_SHADER_ARRAYS
  661. pixelshader PS_Array[PS_Multiplier_Final] =
  662. {
  663. PS_RecolorEnable(false)
  664. };
  665. #if defined(SUPPORT_FROZEN)
  666. pixelshader PS_Frozen_Array[PS_Multiplier_Final] =
  667. {
  668. PS_RecolorEnable(true)
  669. };
  670. #endif
  671. #endif
  672. // ----------------------------------------------------------------------------
  673. // TECHNIQUE : DEFAULT
  674. // ----------------------------------------------------------------------------
  675. technique Default
  676. {
  677. pass P0
  678. #if !defined(SUPPORT_FROZEN) && !defined(SUPPORT_CHRONORIFT)
  679. <
  680. USE_EXPRESSION_EVALUATOR("BasicW3D")
  681. >
  682. #endif
  683. {
  684. VertexShader = ARRAY_EXPRESSION_VS(VS_Array,
  685. min(NumJointsPerVertex, 2) * VS_Multiplier_NumJointsPerVertex,
  686. // Non-array alternative:
  687. compile VS_VERSION VS_Xenon(false)
  688. );
  689. PixelShader = ARRAY_EXPRESSION_PS(PS_Array,
  690. (Fog.IsEnabled ? (BlendMode == BlendMode_Additive ? FogMode_Additive : FogMode_Opaque) : FogMode_Disabled) * PS_Multiplier_FogMode
  691. + HasShadow * PS_Multiplier_NumShadows
  692. + HasRecolorColors * PS_Multiplier_RecolorEnable,
  693. // Non-array alternative:
  694. compile PS_VERSION PS_Xenon(false)
  695. );
  696. ZEnable = true;
  697. ZFunc = ZFUNC_INFRONT;
  698. #if defined(SUPPORT_FROZEN)
  699. ZWriteEnable = true;
  700. CullMode = CW;
  701. AlphaBlendEnable = false;
  702. AlphaTestEnable = false;
  703. #elif defined(SUPPORT_CHRONORIFT)
  704. ZWriteEnable = true;
  705. CullMode = CW;
  706. AlphaBlendEnable = true;
  707. SrcBlend = One;
  708. DestBlend = One;
  709. AlphaTestEnable = true;
  710. #elif !EXPRESSION_EVALUATOR_ENABLED
  711. ZWriteEnable = ( DepthWriteEnable );
  712. CullMode = ( CullingEnable ? D3DCULL_CW : D3DCULL_NONE );
  713. AlphaBlendEnable = ( BlendMode != BlendMode_Opaque || OpacityOverride < 0.99 );
  714. SrcBlend = ( BlendMode == BlendMode_Additive && OpacityOverride >= 0.99 ? D3DBLEND_ONE : D3DBLEND_SRCALPHA );
  715. DestBlend = ( BlendMode == BlendMode_Additive ? D3DBLEND_ONE : D3DBLEND_INVSRCALPHA );
  716. AlphaTestEnable = ( AlphaTestEnable );
  717. #endif
  718. AlphaFunc = GreaterEqual;
  719. AlphaRef = DEFAULT_ALPHATEST_THRESHOLD;
  720. }
  721. #if defined(SUPPORT_FROZEN)
  722. pass p1
  723. {
  724. VertexShader = ARRAY_EXPRESSION_VS(VS_Frozen_Array,
  725. min(NumJointsPerVertex, 2) * VS_Multiplier_NumJointsPerVertex,
  726. // Non-array alternative:
  727. compile VS_VERSION VS_Xenon(true)
  728. );
  729. PixelShader = ARRAY_EXPRESSION_PS(PS_Frozen_Array,
  730. (Fog.IsEnabled ? (BlendMode == BlendMode_Additive ? FogMode_Additive : FogMode_Opaque) : FogMode_Disabled) * PS_Multiplier_FogMode
  731. + HasShadow * PS_Multiplier_NumShadows
  732. + HasRecolorColors * PS_Multiplier_RecolorEnable,
  733. // Non-array alternative:
  734. compile PS_VERSION PS_Xenon(true)
  735. );
  736. ZEnable = true;
  737. ZFunc = ZFUNC_INFRONT;
  738. ZWriteEnable = false;
  739. CullMode = CW;
  740. AlphaBlendEnable = true;
  741. SrcBlend = One;
  742. DestBlend = One;
  743. AlphaTestEnable = false;
  744. StencilEnable = false;
  745. }
  746. #endif // SUPPORT_FROZEN
  747. }
  748. #if ENABLE_LOD
  749. // ----------------------------------------------------------------------------
  750. // TECHNIQUE : Default Medium LOD
  751. // ----------------------------------------------------------------------------
  752. // ----------------------------------------------------------------------------
  753. float4 PS_M(VSOutput In, uniform int fogMode, uniform bool hasShadow,
  754. uniform bool recolorEnable) : COLOR
  755. {
  756. float2 shroudTexCoord = In.CloudTexCoord_ShroudTexCoord.wz;
  757. float2 cloudTexCoord = In.CloudTexCoord_ShroudTexCoord.xy;
  758. float4 color = In.DiffuseColor_Opacity;
  759. #if !defined (SUPPORT_HOLOGRAPHIC)
  760. float3 specularColor = In.SpecularColor_Fog.xyz;
  761. float fogStrength = In.SpecularColor_Fog.w;
  762. float3 cloud = float3(1, 1, 1);
  763. #if defined(_WW3D_) && !defined(_W3DVIEW_)
  764. cloud = tex2D( SAMPLER(CloudTexture), cloudTexCoord);
  765. #endif
  766. #if !defined(SUPPORT_FROZEN)
  767. if (hasShadow)
  768. {
  769. cloud *= shadow( SAMPLER(ShadowMap), In.ShadowMapTexCoord);
  770. }
  771. color.xyz += In.MainLightDiffuseColor * cloud;
  772. specularColor += In.MainLightSpecularColor * cloud;
  773. #endif
  774. // if (numTextures < 2 || secondaryTextureBlendMode != SecTexBlend_SpecularAlpha)
  775. color.xyz += specularColor.xyz;
  776. float4 baseTexture = tex2D( SAMPLER(Texture_0), In.BaseTexCoord);
  777. #if defined(SUPPORT_RECOLORING)
  778. if (recolorEnable)
  779. {
  780. baseTexture.xyz = lerp(baseTexture.xyz, baseTexture.xyz * RecolorColor * 2, baseTexture.w);
  781. baseTexture.w = 1;
  782. }
  783. #endif //defined(SUPPORT_RECOLORING)
  784. #if defined(SUPPORT_FROZEN)
  785. color.xyz *= baseTexture.xyz; // Remove diffuse alpha from opacity calculation, uses only vertex alpha
  786. #else
  787. color *= baseTexture;
  788. #endif
  789. // Overbrighten
  790. color.xyz += color.xyz;
  791. #if defined(SUPPORT_FORMATIONPREVIEW)
  792. color = In.DiffuseColor_Opacity;
  793. #endif
  794. #if defined(SUPPORT_CHRONORIFT)
  795. float3 Texture0 = tex2D( SAMPLER(ChronoRiftTexture), In.BaseTexCoord.xy * 2);
  796. float3 Texture1 = tex2D( SAMPLER(ChronoRiftTexture), In.BaseTexCoord.yx * 2);
  797. color.xyz = Texture0 * Texture1 * 3;
  798. // Compute view direction in world space
  799. color.xyz += In.EdgeFallOff * float3(0.3,0.6,3.0);
  800. color.xyz = min(color.xyz,2);
  801. color.w = In.DiffuseColor_Opacity.w;
  802. #endif // SUPPORT_CHRONORIFT
  803. // Apply fog
  804. if (fogMode == FogMode_Opaque)
  805. {
  806. color.xyz = lerp(Fog.Color, color.xyz, fogStrength);
  807. }
  808. else if (fogMode == FogMode_Additive)
  809. {
  810. // Fog used with additive blending just needs to reduce the additive influence, not blend towards the fog color
  811. color.xyz *= fogStrength;
  812. }
  813. #endif // SUPPORT_HOLOGRAPHIC
  814. #if defined(_WW3D_) && !defined(_W3DVIEW_)
  815. // Apply shroud
  816. color.xyz *= tex2D( SAMPLER(ShroudTexture), shroudTexCoord);
  817. #endif
  818. return color;
  819. }
  820. DEFINE_ARRAY_MULTIPLIER(VS_M_Multiplier_NumJointsPerVertex = 1);
  821. #define VS_M_NumJointsPerVertex \
  822. compile VS_2_0 VS(0, false, false), \
  823. compile VS_2_0 VS(1, false, false), \
  824. compile VS_2_0 VS(2, false, false)
  825. DEFINE_ARRAY_MULTIPLIER(VS_M_Multiplier_Final = VS_M_Multiplier_NumJointsPerVertex * 3);
  826. #if SUPPORTS_SHADER_ARRAYS
  827. vertexshader VS_M_Array[VS_M_Multiplier_Final] = { VS_M_NumJointsPerVertex };
  828. #endif
  829. DEFINE_ARRAY_MULTIPLIER(PS_M_Multiplier_FogMode = 1);
  830. #define PS_M_FogMode(hasShadow, houseColorEnable) \
  831. compile PS_2_0 PS_M(FogMode_Disabled, hasShadow, houseColorEnable), \
  832. compile PS_2_0 PS_M(FogMode_Opaque, hasShadow, houseColorEnable), \
  833. compile PS_2_0 PS_M(FogMode_Additive, hasShadow, houseColorEnable)
  834. DEFINE_ARRAY_MULTIPLIER(PS_M_Multiplier_NumShadows = PS_M_Multiplier_FogMode * 3);
  835. #define PS_M_NumShadows(houseColorEnable) \
  836. PS_M_FogMode(0, houseColorEnable), \
  837. PS_M_FogMode(1, houseColorEnable)
  838. #if defined(SUPPORT_RECOLORING)
  839. DEFINE_ARRAY_MULTIPLIER(PS_M_Multiplier_RecolorEnable = PS_M_Multiplier_NumShadows * 2);
  840. #define PS_M_RecolorEnable \
  841. PS_M_NumShadows(false), \
  842. PS_M_NumShadows(true)
  843. DEFINE_ARRAY_MULTIPLIER(PS_M_Multiplier_Final = PS_M_Multiplier_RecolorEnable * 2);
  844. #else // defined(SUPPORT_RECOLORING)
  845. DEFINE_ARRAY_MULTIPLIER(PS_M_Multiplier_Final = PS_M_Multiplier_NumShadows * 2);
  846. DEFINE_ARRAY_MULTIPLIER(PS_M_Multiplier_RecolorEnable = 0);
  847. #define PS_M_RecolorEnable \
  848. PS_M_NumShadows(false)
  849. #endif // defined(SUPPORT_RECOLORING)
  850. #if SUPPORTS_SHADER_ARRAYS
  851. pixelshader PS_M_Array[PS_M_Multiplier_Final] = { PS_M_RecolorEnable };
  852. #endif
  853. technique _Default_M
  854. {
  855. pass P0
  856. #if !defined(SUPPORT_CHRONORIFT)
  857. <
  858. USE_EXPRESSION_EVALUATOR("BasicW3D")
  859. >
  860. #endif
  861. {
  862. VertexShader = ARRAY_EXPRESSION_VS(VS_M_Array,
  863. min(NumJointsPerVertex, 2) * VS_M_Multiplier_NumJointsPerVertex,
  864. // Non-array alternative:
  865. compile VS_VERSION VS_Xenon()
  866. );
  867. PixelShader = ARRAY_EXPRESSION_PS(PS_M_Array,
  868. (Fog.IsEnabled ? (BlendMode == BlendMode_Additive ? FogMode_Additive : FogMode_Opaque) : FogMode_Disabled) * PS_M_Multiplier_FogMode
  869. + HasShadow * PS_M_Multiplier_NumShadows
  870. + HasRecolorColors * PS_M_Multiplier_RecolorEnable,
  871. // Non-array alternative:
  872. compile PS_VERSION PS_Xenon()
  873. );
  874. ZEnable = true;
  875. ZFunc = ZFUNC_INFRONT;
  876. #if defined(SUPPORT_CHRONORIFT)
  877. ZWriteEnable = true;
  878. CullMode = CW;
  879. AlphaBlendEnable = true;
  880. SrcBlend = One;
  881. DestBlend = One;
  882. AlphaTestEnable = true;
  883. #elif !EXPRESSION_EVALUATOR_ENABLED
  884. ZWriteEnable = ( DepthWriteEnable );
  885. CullMode = ( CullingEnable ? D3DCULL_CW : D3DCULL_NONE );
  886. AlphaBlendEnable = ( BlendMode != BlendMode_Opaque || OpacityOverride < 0.99 );
  887. SrcBlend = ( BlendMode == BlendMode_Additive && OpacityOverride >= 0.99 ? D3DBLEND_ONE : D3DBLEND_SRCALPHA );
  888. DestBlend = ( BlendMode == BlendMode_Additive ? D3DBLEND_ONE : D3DBLEND_INVSRCALPHA );
  889. AlphaTestEnable = ( AlphaTestEnable );
  890. #endif
  891. AlphaFunc = GreaterEqual;
  892. AlphaRef = DEFAULT_ALPHATEST_THRESHOLD;
  893. }
  894. }
  895. // ----------------------------------------------------------------------------
  896. // TECHNIQUE : Default Low LOD
  897. // ----------------------------------------------------------------------------
  898. technique _Default_L
  899. {
  900. pass P0
  901. #if !defined(SUPPORT_CHRONORIFT)
  902. <
  903. USE_EXPRESSION_EVALUATOR("BasicW3D")
  904. >
  905. #endif
  906. {
  907. VertexShader = ARRAY_EXPRESSION_VS(VS_M_Array,
  908. min(NumJointsPerVertex, 2) * VS_M_Multiplier_NumJointsPerVertex,
  909. // Non-array alternative:
  910. compile VS_VERSION VS_Xenon()
  911. );
  912. PixelShader = ARRAY_EXPRESSION_PS(PS_M_Array,
  913. FogMode_Disabled * PS_M_Multiplier_FogMode // Low LOD has no fog
  914. + HasShadow * PS_M_Multiplier_NumShadows
  915. + HasRecolorColors * PS_M_Multiplier_RecolorEnable,
  916. // Non-array alternative:
  917. compile PS_VERSION PS_Xenon()
  918. );
  919. ZEnable = true;
  920. ZFunc = ZFUNC_INFRONT;
  921. #if defined(SUPPORT_CHRONORIFT)
  922. ZWriteEnable = true;
  923. CullMode = CW;
  924. AlphaBlendEnable = true;
  925. SrcBlend = One;
  926. DestBlend = One;
  927. AlphaTestEnable = true;
  928. #elif !EXPRESSION_EVALUATOR_ENABLED
  929. ZWriteEnable = ( DepthWriteEnable );
  930. CullMode = ( CullingEnable ? D3DCULL_CW : D3DCULL_NONE );
  931. AlphaBlendEnable = ( BlendMode != BlendMode_Opaque || OpacityOverride < 0.99 );
  932. SrcBlend = ( BlendMode == BlendMode_Additive && OpacityOverride >= 0.99 ? D3DBLEND_ONE : D3DBLEND_SRCALPHA );
  933. DestBlend = ( BlendMode == BlendMode_Additive ? D3DBLEND_ONE : D3DBLEND_INVSRCALPHA );
  934. AlphaTestEnable = ( AlphaTestEnable );
  935. #endif
  936. AlphaFunc = GreaterEqual;
  937. AlphaRef = DEFAULT_ALPHATEST_THRESHOLD;
  938. }
  939. }
  940. #endif // if ENABLE_LOD
  941. // ----------------------------------------------------------------------------
  942. // SHADER: CreateShadowMap
  943. // ----------------------------------------------------------------------------
  944. struct VSOutput_CreateShadowMap
  945. {
  946. float4 Position : POSITION;
  947. float Opacity : COLOR0;
  948. float2 BaseTexCoord : TEXCOORD0;
  949. float Depth : TEXCOORD1;
  950. };
  951. // ----------------------------------------------------------------------------
  952. VSOutput_CreateShadowMap CreateShadowMapVS(VSInputSkinningMultipleBones InSkin,
  953. float2 TexCoord0 : TEXCOORD0, float4 VertexColor: COLOR0,
  954. uniform int numJointsPerVertex)
  955. {
  956. VSOutput_CreateShadowMap Out;
  957. float3 worldPosition = 0;
  958. float3 ignoredWorldNormal;
  959. CalculatePositionAndNormal(InSkin, numJointsPerVertex, worldPosition, ignoredWorldNormal);
  960. #if defined(SUPPORT_CRUSHED)
  961. worldPosition += ignoredWorldNormal * OpacityOverride * 3;
  962. #endif // SUPPORT_CRUSHED
  963. VertexColor.w *= GetOpacity(InSkin, numJointsPerVertex);
  964. #if defined(TREE_SWAY)
  965. ApplyTreeSway(InSkin, numJointsPerVertex, worldPosition);
  966. #endif
  967. //Out.Position = mul(mul(float4(worldPosition, 1), View), Projection);
  968. ISOLATE Out.Position = mul(float4(worldPosition, 1), GetViewProjection());
  969. Out.Opacity = OpacityOverride * VertexColor.w;
  970. // Scale with animated offset on texture coordinates 0
  971. Out.BaseTexCoord = TexCoord0;
  972. Out.Depth = Out.Position.z / Out.Position.w;
  973. // Don't render additive objects
  974. if (BlendMode == BlendMode_Additive)
  975. {
  976. Out.Position = float4(1, 1, 1, 0);
  977. }
  978. return Out;
  979. }
  980. // Xenon vertex shader: Remove uniform from NumJointsPerVertex parameter and have it do real branching.
  981. VSOutput_CreateShadowMap CreateShadowMapVS_Xenon(VSInputSkinningMultipleBones InSkin,
  982. float2 TexCoord0 : TEXCOORD0,
  983. float4 VertexColor: COLOR0)
  984. {
  985. return CreateShadowMapVS(InSkin, TexCoord0, VertexColor, NumJointsPerVertex);
  986. }
  987. // ----------------------------------------------------------------------------
  988. float4 CreateShadowMapPS(VSOutput_CreateShadowMap In, uniform bool alphaTestEnable) : COLOR
  989. {
  990. float opacity = In.Opacity;
  991. #if !defined(SUPPORT_RECOLORING) && !defined(SUPPORT_FROZEN)// House colored shaders use texture alpha for house color strength instead of opacity
  992. opacity *= tex2D( SAMPLER(Texture_0), In.BaseTexCoord).w;
  993. #endif
  994. if (alphaTestEnable)
  995. {
  996. // Simulate alpha testing for floating point render target
  997. clip(opacity - ((float)DEFAULT_ALPHATEST_THRESHOLD / 255));
  998. }
  999. return In.Depth;
  1000. }
  1001. #define VSCreateShadowMap_NumJointsPerVertex \
  1002. compile VS_2_0 CreateShadowMapVS(0), \
  1003. compile VS_2_0 CreateShadowMapVS(1), \
  1004. compile VS_2_0 CreateShadowMapVS(2)
  1005. DEFINE_ARRAY_MULTIPLIER(VSCreateShadowMap_Multiplier_Final = 3);
  1006. #if SUPPORTS_SHADER_ARRAYS
  1007. vertexshader VSCreateShadowMap_Array[VSCreateShadowMap_Multiplier_Final] =
  1008. {
  1009. VSCreateShadowMap_NumJointsPerVertex
  1010. };
  1011. #endif
  1012. #define PSCreateShadowMap_AlphaTestEnable \
  1013. compile PS_2_0 CreateShadowMapPS(false), \
  1014. compile PS_2_0 CreateShadowMapPS(true)
  1015. DEFINE_ARRAY_MULTIPLIER(PSCreateShadowMap_Multiplier_Final = 2);
  1016. #if SUPPORTS_SHADER_ARRAYS
  1017. pixelshader PSCreateShadowMap_Array[PSCreateShadowMap_Multiplier_Final] =
  1018. {
  1019. PSCreateShadowMap_AlphaTestEnable
  1020. };
  1021. #endif
  1022. // ----------------------------------------------------------------------------
  1023. // TECHNIQUE : CreateShadowMap
  1024. // ----------------------------------------------------------------------------
  1025. #if !defined(SUPPORT_HOLOGRAPHIC)
  1026. #if defined(SUPPORT_FORMATIONPREVIEW) || defined(SUPPORT_CHRONORIFT)
  1027. technique _CreateDepthMap // Don't cast a shadow, but still render to the depth map
  1028. #else
  1029. technique _CreateShadowMap
  1030. #endif
  1031. {
  1032. pass P0
  1033. <
  1034. USE_EXPRESSION_EVALUATOR("BasicW3D_CreateShadowMap")
  1035. >
  1036. {
  1037. VertexShader = ARRAY_EXPRESSION_VS(VSCreateShadowMap_Array,
  1038. min(NumJointsPerVertex, 2),
  1039. // Non-array alternative:
  1040. compile VS_VERSION CreateShadowMapVS_Xenon()
  1041. );
  1042. PixelShader = ARRAY_EXPRESSION_PS(PSCreateShadowMap_Array,
  1043. (AlphaTestEnable || BlendMode == BlendMode_Alpha),
  1044. // Non-array alternative:
  1045. compile PS_VERSION CreateShadowMapPS(true)
  1046. );
  1047. ZEnable = true;
  1048. ZFunc = ZFUNC_INFRONT;
  1049. #if !EXPRESSION_EVALUATOR_ENABLED
  1050. ZWriteEnable = ( DepthWriteEnable );
  1051. CullMode = ( CullingEnable ? D3DCULL_CW : D3DCULL_NONE );
  1052. #endif
  1053. AlphaBlendEnable = false;
  1054. AlphaTestEnable = false; // Handled in pixel shader ( AlphaTestEnable /*|| BlendMode == BlendMode_Alpha */);
  1055. // AlphaFunc = GreaterEqual;
  1056. // AlphaRef = DEFAULT_ALPHATEST_THRESHOLD;
  1057. }
  1058. }
  1059. #endif //Dont return shadows for Holographic