TexturedShaders.fx 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640
  1. #define MAX_LIGHTS 16
  2. #define LIGHT_COLOR float4(0, 0, 1, 0)
  3. float3 xLightPositions[MAX_LIGHTS];
  4. //------- Constants --------
  5. float4x4 xView;
  6. float4x4 xLightView;
  7. float4x4 xLightProj;
  8. float4x4 xReflectionView;
  9. float xCaveView;
  10. float xWaterOpacity;
  11. float xWaterMinOpacity;
  12. float4x4 xProjection;
  13. float4x4 xWorld;
  14. int xEnableLighting;
  15. int xEnableShadows;
  16. int xEnableWind;
  17. Texture2D xWaterBumpMap;
  18. float xWaveLength;
  19. float xWaveHeight;
  20. float3 xCamPos;
  21. float xTime;
  22. float xWindForce;
  23. float3 xWindDirection;
  24. float xTimeOfDay;
  25. int xEnableFog;
  26. float xFogStart;
  27. float xFogEnd;
  28. float3 xFogColor;
  29. float4 xRippleColor;
  30. float4 xFlatColor;
  31. float2 pixelSize;
  32. float4 xID;
  33. //------- Technique: Clipping Plane Fix --------
  34. int Clipping;
  35. int GhostMode;
  36. int SelfIllumination;
  37. float4 ClipPlane0;
  38. /*
  39. float4 GetNoise(float4 pos)
  40. {
  41. pos.w = 0;
  42. float mag = dot(pos, pos) * 0.00001;
  43. float sm = sin(mag + 0.1);
  44. float cm = cos(mag);
  45. return float4(cm * 0.2 + sm * 0.1, sm * 0.5 + cm * 0.1, sm * 0.2 + cm * 0.1, 0);
  46. }
  47. */
  48. float4 GetWind(float4 pos, float2 uv, float4 bounds)
  49. {
  50. pos.w = 0;
  51. float windPower = 0.5 + sin(pos.x / 10.0f + pos.y / 10.0f + xTime * (1.2f + xWindForce / 10.0f));
  52. windPower = windPower*0.08f;
  53. float windTemp = (1.0 - (uv.y - bounds.y) / bounds.w);
  54. return float4(xWindDirection * windPower * windTemp, 0);
  55. }
  56. float4 GetFlagWind(float4 pos, float2 uv, float4 bounds)
  57. {
  58. pos.w = 0;
  59. float3 waver = cross(xWindDirection, float3(0, 1, 0)) + xWindDirection * 0.25;
  60. float windPower = 0.5 + sin(uv.x * 10 + uv.y * 10 + xTime * (12.0 + xWindForce * 1000));
  61. windPower *= 0.05;
  62. float windTemp = ((uv.x - bounds.x) / bounds.z);
  63. return float4(waver * windPower * windTemp - float3(0, 0.5, 0) * windTemp * (saturate(1.0 - xWindForce * 1000))
  64. + xWindDirection * windTemp * saturate(xWindForce * 1000), 0);
  65. }
  66. //------- Technique: Clipping Plane Fix --------
  67. //------- Texture Samplers --------
  68. Texture2D xTexture;
  69. Texture2D xIllumination;
  70. sampler IllumSampler = sampler_state { texture = <xIllumination> ; magfilter = LINEAR; minfilter = LINEAR; mipfilter=LINEAR; AddressU = clamp; AddressV = clamp;};
  71. sampler TextureSampler = sampler_state { texture = <xTexture>; magfilter = POINT; minfilter = LINEAR; mipfilter = Linear; AddressU = clamp; AddressV = clamp; };
  72. sampler ColorscaleSampler = sampler_state { texture = <xTexture>; magfilter = POINT; minfilter = LINEAR; mipfilter = Linear; AddressU = clamp; AddressV = clamp; };
  73. sampler WrappedTextureSampler = sampler_state { texture = <xTexture>; magfilter = POINT; minfilter = LINEAR; mipfilter = Linear; AddressU = wrap; AddressV = wrap; };
  74. Texture2D xReflectionMap;
  75. float xWaterReflective;
  76. Texture2D xSunGradient;
  77. Texture2D xAmbientGradient;
  78. Texture2D xTorchGradient;
  79. Texture2D xShoreGradient;
  80. Texture2D xLightmap;
  81. // Light ramp tint
  82. float4 xLightRamp;
  83. // Multiplicative output color.
  84. float4 xVertexColorMultiplier;
  85. sampler LightmapSampler = sampler_state { texture = <xLightmap>; magfilter = POINT; minfilter = LINEAR; mipfilter = POINT; AddressU = clamp; AddressV = clamp; };
  86. sampler SunSampler = sampler_state { texture = <xSunGradient>; magfilter = LINEAR; minfilter = LINEAR; mipfilter = LINEAR; AddressU = clamp; AddressV = clamp; };
  87. sampler AmbientSampler = sampler_state { texture = <xAmbientGradient>; magfilter = LINEAR; minfilter = LINEAR; mipfilter = LINEAR; AddressU = clamp; AddressV = clamp; };
  88. sampler TorchSampler = sampler_state { texture = <xTorchGradient>; magfilter = POINT; minfilter = POINT; mipfilter = POINT; AddressU = clamp; AddressV = clamp; };
  89. sampler ShoreSampler = sampler_state { texture = <xShoreGradient>; magfilter = POINT; minfilter = POINT; mipfilter = POINT; AddressU = wrap; AddressV = clamp; };
  90. sampler ReflectionSampler = sampler_state { texture = <xReflectionMap> ; magfilter = LINEAR; minfilter = LINEAR; mipfilter=LINEAR; AddressU = clamp; AddressV = clamp;};
  91. sampler WaterBumpMapSampler = sampler_state { texture = <xWaterBumpMap> ; magfilter = LINEAR; minfilter = LINEAR; mipfilter=LINEAR; AddressU = wrap; AddressV = wrap;};
  92. Texture2D xShadowMap;
  93. sampler ShadowMapSampler = sampler_state { texture = <xShadowMap>; magfilter = LINEAR; minfilter = LINEAR; mipfilter = LINEAR; AddressU = clamp; AddressV = clamp; };
  94. ///////////// Technique untextured
  95. struct UTVertexToPixel
  96. {
  97. float4 Position : POSITION0;
  98. float4 Color : COLOR0;
  99. float4 ClipDistance : TEXCOORD5;
  100. };
  101. struct UTPixelToFrame
  102. {
  103. float4 Color : COLOR0;
  104. };
  105. UTVertexToPixel UTexturedVS( float4 inPos_ : POSITION, float4 inColor : COLOR0)
  106. {
  107. UTVertexToPixel Output = (UTVertexToPixel)0;
  108. float4 inPos = inPos_; // +GetNoise(inPos_);
  109. float4x4 preViewProjection = mul (xView, xProjection);
  110. float4x4 preWorldViewProjection = mul (xWorld, preViewProjection);
  111. Output.Position = mul(inPos, preWorldViewProjection);
  112. Output.Color = inColor * xVertexColorMultiplier;
  113. Output.ClipDistance = Clipping * dot(mul(xWorld,inPos), ClipPlane0); //MSS - Water Refactor added
  114. return Output;
  115. }
  116. UTVertexToPixel UTexturedVS_Pulse( float4 inPos_ : POSITION, float3 dir : NORMAL, float4 inColor : COLOR0)
  117. {
  118. UTVertexToPixel Output = (UTVertexToPixel)0;
  119. float3 backward = -float3(xView[0][2], xView[1][2], xView[2][2]);
  120. float3 offset = normalize(cross(dir, backward)) * inPos_.w;
  121. float4 inPos = float4(inPos_.xyz + offset * 0.5, 1);
  122. float4x4 preViewProjection = mul (xView, xProjection);
  123. float4x4 preWorldViewProjection = mul (xWorld, preViewProjection);
  124. Output.Position = mul(inPos, preWorldViewProjection);
  125. Output.Color = inColor * xVertexColorMultiplier + float4(.2, .2, .2, 0) * pow(sin(xTime * 2 + 0.1 * inPos.x + 0.2 * inPos.z), 2);
  126. Output.ClipDistance = Clipping * dot(mul(xWorld,inPos), ClipPlane0); //MSS - Water Refactor added
  127. return Output;
  128. }
  129. UTPixelToFrame UTexturedPS(UTVertexToPixel PSIn)
  130. {
  131. UTPixelToFrame Output = (UTPixelToFrame)0;
  132. Output.Color = PSIn.Color;
  133. if (PSIn.ClipDistance.w < 0.0f)
  134. {
  135. Output.Color *= clamp(-1.0f / (PSIn.ClipDistance.w * 0.75f) * 0.25f, 0, 1.0f);
  136. clip(GhostMode * (Output.Color.a) - 0.1f);
  137. }
  138. return Output;
  139. }
  140. technique Untextured
  141. {
  142. pass Pass0
  143. {
  144. VertexShader = compile vs_2_0 UTexturedVS();
  145. PixelShader = compile ps_2_0 UTexturedPS();
  146. }
  147. }
  148. technique Untextured_Pulse
  149. {
  150. pass Pass0
  151. {
  152. VertexShader = compile vs_2_0 UTexturedVS_Pulse();
  153. PixelShader = compile ps_2_0 UTexturedPS();
  154. }
  155. }
  156. float2 ClampTexture(float2 uv, float4 bounds)
  157. {
  158. return float2(clamp(uv.x, bounds.x, bounds.z), clamp(uv.y, bounds.y, bounds.w));
  159. }
  160. ///////////////
  161. // Shadowmaps
  162. struct SMapVertexToPixel
  163. {
  164. float4 Position : POSITION;
  165. float4 WorldPosition : TEXCOORD0;
  166. float2 TextureCoords : TEXCOORD1;
  167. };
  168. struct SMapPixelToFrame
  169. {
  170. float4 Color : COLOR0;
  171. };
  172. float4 GetPositionFromLight(float4 position)
  173. {
  174. float4x4 WorldViewProjection = mul(xLightView, xLightProj);
  175. return mul(position, WorldViewProjection);
  176. }
  177. SMapVertexToPixel ShadowMapVS(float4 inPos : POSITION, float2 inTexCoords : TEXCOORD0, float4x4 world : BLENDWEIGHT)
  178. {
  179. float4 worldPosition = mul(inPos, world);
  180. float4 viewPosition = mul(worldPosition, xView);
  181. SMapVertexToPixel Output = (SMapVertexToPixel)0;
  182. Output.Position = mul(viewPosition, xProjection);
  183. Output.WorldPosition = Output.Position;
  184. Output.TextureCoords = inTexCoords;
  185. return Output;
  186. }
  187. SMapPixelToFrame ShadowMapPixelShader(SMapVertexToPixel PSIn)
  188. {
  189. SMapPixelToFrame Output = (SMapPixelToFrame)0;
  190. float4 texColor = tex2D(TextureSampler, PSIn.TextureCoords);
  191. clip((texColor.a - 0.5));
  192. Output.Color = 1.0f - (PSIn.WorldPosition.z / PSIn.WorldPosition.w);
  193. Output.Color.a = 1.0f;
  194. return Output;
  195. }
  196. SMapVertexToPixel ShadowMapVSNonInstance(float4 inPos : POSITION, float2 inTexCoords : TEXCOORD0)
  197. {
  198. return ShadowMapVS(inPos, inTexCoords, xWorld);
  199. }
  200. SMapVertexToPixel ShadowMapVSInstance(float4 inPos : POSITION, float2 inTexCoords : TEXCOORD0, float4x4 transform : BLENDWEIGHT)
  201. {
  202. return ShadowMapVS(inPos, inTexCoords, transpose(transform));
  203. }
  204. technique Shadow
  205. {
  206. pass Pass0
  207. {
  208. VertexShader = compile vs_3_0 ShadowMapVSNonInstance();
  209. PixelShader = compile ps_3_0 ShadowMapPixelShader();
  210. }
  211. };
  212. technique ShadowInstanced
  213. {
  214. pass Pass0
  215. {
  216. VertexShader = compile vs_3_0 ShadowMapVSInstance();
  217. PixelShader = compile ps_3_0 ShadowMapPixelShader();
  218. }
  219. };
  220. //------- Technique: Textured --------
  221. struct TVertexToPixel
  222. {
  223. float4 Position : SV_POSITION;
  224. float4 LightRamp : COLOR0;
  225. float4 WorldPosition : TEXCOORD0;
  226. float2 TextureCoords : TEXCOORD1;
  227. float4 ClipDistance : TEXCOORD2;
  228. float Fog : TEXCOORD3;
  229. float4 TextureBounds : TEXCOORD4;
  230. float4 VertexColor : COLOR1;
  231. };
  232. struct SelectionBufferToPixel
  233. {
  234. float4 Position : POSITION;
  235. float2 TextureCoords: TEXCOORD1;
  236. float4 ClipDistance : TEXCOORD2;
  237. float4 SelectionColor : COLOR0;
  238. };
  239. struct LightmapToPixel
  240. {
  241. float4 Position : POSITION;
  242. float4 ClipDistance : TEXCOORD0;
  243. float Fog : TEXCOORD1;
  244. float2 LightmapCoords : TEXCOORD2;
  245. float4 LightmapBounds : TEXCOORD3;
  246. float3 WorldPosition : TEXCOORD4;
  247. };
  248. struct TPixelToFrame
  249. {
  250. float4 Color : COLOR0;
  251. };
  252. SelectionBufferToPixel SelectionVS(float4 inPos: POSITION, float2 inTexCoords : TEXCOORD0, float4x4 world : BLENDWEIGHT, float4 selection : COLOR2)
  253. {
  254. SelectionBufferToPixel Output = (SelectionBufferToPixel)0;
  255. float4 worldPosition = mul(inPos, world);
  256. float4 viewPosition = mul(worldPosition, xView);
  257. Output.Position = mul(viewPosition, xProjection);
  258. Output.TextureCoords = inTexCoords;
  259. Output.ClipDistance = dot(worldPosition, ClipPlane0);
  260. Output.SelectionColor = selection;
  261. return Output;
  262. }
  263. float4 Lighting(uniform int max_lights, float4 worldPosition, float4 color)
  264. {
  265. for (int i = 0; i < max_lights; i++)
  266. {
  267. float3 dpos = worldPosition - xLightPositions[i];
  268. float dist = dot(dpos, dpos) + 0.001f;
  269. color = saturate(color + xEnableLighting * LIGHT_COLOR / dist);
  270. }
  271. color = saturate(color + (1.0 - xEnableLighting) * LIGHT_COLOR / 999.0f);
  272. return color;
  273. }
  274. float4 Lighting1Light(float4 worldPosition, float4 color)
  275. {
  276. float3 dpos = worldPosition - xLightPositions[0];
  277. float dist = dot(dpos, dpos) + 0.001f;
  278. color = saturate(color + xEnableLighting * LIGHT_COLOR / dist + (1.0 - xEnableLighting) * LIGHT_COLOR / 999.0f);
  279. return color;
  280. }
  281. TVertexToPixel TexturedVS_Flag(float4 inPos : POSITION,
  282. float2 inTexCoords : TEXCOORD0,
  283. float4 inLightRamp : COLOR0,
  284. float4 inTexSource : TEXCOORD1,
  285. float3 vertColor : COLOR1,
  286. uniform int max_lights)
  287. {
  288. TVertexToPixel Output = (TVertexToPixel)0;
  289. float4 worldPosition = mul(inPos, xWorld);
  290. worldPosition += GetFlagWind(worldPosition, inTexCoords, inTexSource);
  291. Output.WorldPosition = worldPosition;
  292. float4 viewPosition = mul(worldPosition, xView);
  293. Output.Position = mul(viewPosition, xProjection);
  294. Output.TextureCoords = inTexCoords;
  295. Output.ClipDistance = dot(worldPosition, ClipPlane0);
  296. Output.LightRamp = inLightRamp * xLightRamp;
  297. Output.LightRamp.a = xLightRamp.a;
  298. Output.VertexColor.rgb = vertColor * xVertexColorMultiplier.rgb;
  299. Output.LightRamp.a *= xVertexColorMultiplier.a;
  300. Output.LightRamp = Lighting(max_lights, worldPosition, Output.LightRamp);
  301. Output.Fog = saturate((Output.Position.z - xFogStart) / (xFogEnd - xFogStart));
  302. Output.TextureBounds = inTexSource;
  303. return Output;
  304. }
  305. TVertexToPixel TexturedVS(float4 inPos : POSITION,
  306. float2 inTexCoords: TEXCOORD0,
  307. float4 inLightRamp : COLOR0,
  308. float4 inTexSource : TEXCOORD1,
  309. float4x4 world : BLENDWEIGHT,
  310. float4 lightRampMultiplier : COLOR1,
  311. float4 tint,
  312. uniform int max_lights)
  313. {
  314. TVertexToPixel Output = (TVertexToPixel)0;
  315. float4 worldPosition = mul(inPos, world);
  316. worldPosition += xEnableWind * GetWind(worldPosition, inTexCoords, inTexSource);
  317. Output.WorldPosition = worldPosition;
  318. float4 viewPosition = mul(worldPosition, xView);
  319. Output.Position = mul(viewPosition, xProjection);
  320. Output.TextureCoords = inTexCoords;
  321. Output.ClipDistance = dot(worldPosition, ClipPlane0);
  322. Output.LightRamp = inLightRamp * lightRampMultiplier;
  323. Output.LightRamp.a = lightRampMultiplier.a;
  324. Output.VertexColor = tint * xVertexColorMultiplier;
  325. Output.LightRamp.a *= xVertexColorMultiplier.a;
  326. Output.LightRamp = Lighting(max_lights, worldPosition, Output.LightRamp);
  327. Output.Fog = saturate((Output.Position.z - xFogStart) / (xFogEnd - xFogStart));
  328. Output.TextureBounds = inTexSource;
  329. return Output;
  330. }
  331. TVertexToPixel TexturedVS_1Light(float4 inPos : POSITION,
  332. float2 inTexCoords : TEXCOORD0,
  333. float4 inLightRamp : COLOR0,
  334. float4 inTexSource : TEXCOORD1,
  335. float4x4 world : BLENDWEIGHT,
  336. float4 lightTint : COLOR1,
  337. float4 tint)
  338. {
  339. TVertexToPixel Output = (TVertexToPixel)0;
  340. float4 worldPosition = mul(inPos, world);
  341. worldPosition += xEnableWind * GetWind(worldPosition, inTexCoords, inTexSource);
  342. Output.WorldPosition = worldPosition;
  343. float4 viewPosition = mul(worldPosition, xView);
  344. Output.Position = mul(viewPosition, xProjection);
  345. Output.TextureCoords = inTexCoords;
  346. Output.ClipDistance = dot(worldPosition, ClipPlane0);
  347. Output.LightRamp = inLightRamp * lightTint;
  348. Output.LightRamp.a = lightTint.a;
  349. Output.VertexColor = tint * xVertexColorMultiplier;
  350. Output.LightRamp.a *= xVertexColorMultiplier.a;
  351. Output.LightRamp = Lighting1Light(worldPosition, Output.LightRamp);
  352. Output.Fog = saturate((Output.Position.z - xFogStart) / (xFogEnd - xFogStart));
  353. Output.TextureBounds = inTexSource;
  354. return Output;
  355. }
  356. TVertexToPixel TexturedVS_To_Lightmap(float4 inPos : POSITION,
  357. float2 inTexCoords : TEXCOORD0,
  358. float2 inLightmapCoords : TEXCOORD2,
  359. float4 inColor : COLOR0,
  360. float4 inTexSource : TEXCOORD1,
  361. float4 lightTint : COLOR1,
  362. uniform int max_lights)
  363. {
  364. TVertexToPixel Output = (TVertexToPixel)0;
  365. float4 worldPosition = mul(inPos, xWorld);
  366. Output.WorldPosition = worldPosition;
  367. Output.Position = float4(2 * inLightmapCoords.x - 1.0 - pixelSize.x * 0.5, -(2 * inLightmapCoords.y - 1.0 - pixelSize.y * 0.5), 0.0, 1);
  368. Output.TextureCoords = inTexCoords;
  369. Output.LightRamp = inColor * lightTint;
  370. Output.LightRamp.a = lightTint.a;
  371. Output.VertexColor = xLightRamp;
  372. for (int i = 0; i < max_lights; i++)
  373. {
  374. float dx = worldPosition.x - xLightPositions[i].x;
  375. float dy = worldPosition.y - xLightPositions[i].y;
  376. float dz = worldPosition.z - xLightPositions[i].z;
  377. float dist = pow(dx, 2) + pow(dy, 2) + pow(dz, 2) + 0.001f;
  378. Output.LightRamp = saturate(Output.LightRamp + xEnableLighting * LIGHT_COLOR / dist);
  379. }
  380. Output.LightRamp = saturate(Output.LightRamp + (1.0 - xEnableLighting) * LIGHT_COLOR / 999.0f);
  381. Output.TextureBounds = inTexSource;
  382. return Output;
  383. }
  384. LightmapToPixel TexturedVS_From_Lightmap(
  385. float4 inPos : POSITION,
  386. float2 inLightmapCoords : TEXCOORD2,
  387. float4 inLightmapBounds : TEXCOORD3
  388. )
  389. {
  390. LightmapToPixel Output = (LightmapToPixel)0;
  391. float4 worldPosition = mul(inPos, xWorld);
  392. float4 viewPosition = mul(worldPosition, xView);
  393. Output.Position = mul(viewPosition, xProjection);
  394. Output.ClipDistance = dot(worldPosition, ClipPlane0);
  395. Output.Fog = saturate((Output.Position.z - xFogStart) / (xFogEnd - xFogStart));
  396. Output.LightmapBounds = inLightmapBounds;
  397. Output.LightmapCoords = inLightmapCoords;
  398. return Output;
  399. }
  400. TPixelToFrame TexturedPS_From_Lightmap(LightmapToPixel PSIn)
  401. {
  402. TPixelToFrame Output = (TPixelToFrame)0;
  403. float2 textureCoords = ClampTexture(PSIn.LightmapCoords, PSIn.LightmapBounds);
  404. Output.Color = tex2D(LightmapSampler, textureCoords);
  405. clip((Output.Color.a - 0.5));
  406. Output.Color.rgba = float4(lerp(Output.Color.rgb, xFogColor, PSIn.Fog) * Output.Color.a, Output.Color.a);
  407. if (PSIn.ClipDistance.w < 0.0f)
  408. {
  409. Output.Color *= -1.0f / (PSIn.ClipDistance.w * 0.75f) * 0.25f;
  410. clip(GhostMode * (Output.Color.a) - 0.1f);
  411. }
  412. //Output = (TPixelToFrame)0;
  413. //Output.Color = float4(1, 0, 0, 1);
  414. return Output;
  415. }
  416. TPixelToFrame TexturedPS_To_Lightmap(TVertexToPixel PSIn)
  417. {
  418. TPixelToFrame Output = (TPixelToFrame)0;
  419. float4 shadowPos = GetPositionFromLight(PSIn.WorldPosition);
  420. float2 shadowUV = 0.5 * shadowPos.xy / shadowPos.w + float2(0.5, 0.5);
  421. shadowUV.y = 1.0f - shadowUV.y;
  422. /*xEnableShadows
  423. if (shadowUV.x < 1.0 && shadowUV.y < 1.0 && shadowUV.x > 0 && shadowUV.y > 0)
  424. {
  425. float shadowdepth = tex2D(ShadowMapSampler, shadowUV).r;
  426. // Check our value against the depth value
  427. float ourdepth = 1 - (shadowPos.z / shadowPos.w) + 0.01;
  428. // Check the shadowdepth against the depth of this pixel
  429. // a fudge factor is added to account for floating-point error
  430. PSIn.Color.r *= saturate(exp(200 * (ourdepth - shadowdepth)) + 0.25f);
  431. }
  432. */
  433. Output.Color = tex2D(SunSampler, float2(PSIn.LightRamp.r, (xTimeOfDay)));
  434. Output.Color.a *= PSIn.LightRamp.a;
  435. Output.Color.rgb += tex2D(TorchSampler, float2(PSIn.LightRamp.b, 0.5f)).rgb;
  436. Output.Color.rgb *= tex2D(AmbientSampler, float2(PSIn.LightRamp.g, 0.5f)).rgb;
  437. saturate(Output.Color.rgb);
  438. float2 textureCoords = ClampTexture(PSIn.TextureCoords, PSIn.TextureBounds);
  439. float4 texColor = tex2D(TextureSampler, textureCoords);
  440. float4 illumColor = tex2D(IllumSampler, textureCoords);
  441. Output.Color.rgba *= texColor;
  442. Output.Color.rgb *= PSIn.VertexColor;
  443. Output.Color.rgba = lerp(Output.Color.rgba, texColor, SelfIllumination * illumColor.r);
  444. return Output;
  445. }
  446. TVertexToPixel TexturedVSNonInstanced( float4 inPos : POSITION,
  447. float2 inTexCoords: TEXCOORD0,
  448. float4 lightRamp : COLOR0,
  449. float4 inTexSource : TEXCOORD1,
  450. float4 vertColor : COLOR1,
  451. uniform int max_lights)
  452. {
  453. return TexturedVS(inPos, inTexCoords, lightRamp, inTexSource, xWorld, xLightRamp, vertColor, max_lights);
  454. }
  455. TVertexToPixel TexturedVSNonInstanced_1Light(float4 inPos : POSITION,
  456. float2 inTexCoords : TEXCOORD0,
  457. float4 inColor : COLOR0,
  458. float4 inTexSource : TEXCOORD1,
  459. float4 vertColor : COLOR1)
  460. {
  461. return TexturedVS_1Light(inPos, inTexCoords, inColor, inTexSource, xWorld, xLightRamp, vertColor);
  462. }
  463. TVertexToPixel TexturedVSInstanced( float4 inPos : POSITION,
  464. float2 inTexCoords: TEXCOORD0,
  465. float4 inLightRamp : COLOR3,
  466. float4 inTexSource : TEXCOORD1,
  467. float4 id : COLOR4,
  468. float4x4 transform : BLENDWEIGHT,
  469. float4 tint : COLOR5,
  470. uniform int max_lights)
  471. {
  472. return TexturedVS(inPos, inTexCoords, inLightRamp, inTexSource, transpose(transform),
  473. float4(1, 1, 1, tint.a), tint, max_lights);
  474. }
  475. TVertexToPixel TexturedVSTiledInstanced(float4 inPos : POSITION,
  476. float2 inTexCoords : TEXCOORD0,
  477. float4 inLightRamp : COLOR3,
  478. float4 inTexSource : TEXCOORD1,
  479. float4 id : COLOR4,
  480. float4x4 transform : BLENDWEIGHT,
  481. float4 vertexColor : COLOR5,
  482. float4 tileTexSource : TEXCOORD5,
  483. uniform int max_lights)
  484. {
  485. float2 newTexCoord = inTexCoords * float2(tileTexSource.z - tileTexSource.x, tileTexSource.w - tileTexSource.y);
  486. newTexCoord += float2(tileTexSource.x, tileTexSource.y);
  487. return TexturedVS(inPos, newTexCoord, inLightRamp, tileTexSource, transpose(transform),
  488. float4(1, 1, 1, vertexColor.a), vertexColor, max_lights);
  489. }
  490. TVertexToPixel TexturedVSInstanced_1Light(float4 inPos : POSITION,
  491. float2 inTexCoords : TEXCOORD0,
  492. float4 lightRamp : COLOR3,
  493. float4 inTexSource : TEXCOORD1,
  494. float4 id : COLOR4,
  495. float4x4 transform : BLENDWEIGHT,
  496. float4 vertexColor : COLOR5)
  497. {
  498. return TexturedVS_1Light(inPos, inTexCoords, lightRamp, inTexSource, transpose(transform),
  499. float4(1, 1, 1, vertexColor.a), vertexColor);
  500. }
  501. TVertexToPixel TexturedVSTiledInstanced_1Light(float4 inPos : POSITION,
  502. float2 inTexCoords : TEXCOORD0,
  503. float4 lightRamp : COLOR3,
  504. float4 inTexSource : TEXCOORD1,
  505. float4 id : COLOR4,
  506. float4x4 transform : BLENDWEIGHT,
  507. float4 vertexColor : COLOR5,
  508. float4 tileTexSource : TEXCOORD5)
  509. {
  510. float2 newTexCoord = inTexCoords * float2(tileTexSource.z - tileTexSource.x, tileTexSource.w - tileTexSource.y);
  511. newTexCoord += float2(tileTexSource.x, tileTexSource.y);
  512. return TexturedVS_1Light(inPos, newTexCoord, lightRamp, inTexSource, transpose(transform),
  513. float4(1, 1, 1, vertexColor.a), vertexColor);
  514. }
  515. SelectionBufferToPixel SelectionVSNonInstanced(float4 inPos : POSITION, float2 inTexCoords : TEXCOORD0)
  516. {
  517. return SelectionVS(inPos, inTexCoords, xWorld, xID);
  518. }
  519. SelectionBufferToPixel SelectionVSInstanced(float4 inPos : POSITION,
  520. float2 inTexCoords : TEXCOORD0,
  521. float4x4 transform : BLENDWEIGHT,
  522. float4 id : COLOR4)
  523. {
  524. return SelectionVS(inPos, inTexCoords, transpose(transform) , id);
  525. }
  526. SelectionBufferToPixel SelectionVSTiledInstanced(float4 inPos : POSITION,
  527. float2 inTexCoords : TEXCOORD0,
  528. float4x4 transform : BLENDWEIGHT,
  529. float4 id : COLOR4,
  530. float4 tileTexSource : TEXCOORD5)
  531. {
  532. float2 newTexCoord = inTexCoords * float2(tileTexSource.z - tileTexSource.x, tileTexSource.w - tileTexSource.y);
  533. newTexCoord += float2(tileTexSource.x, tileTexSource.y);
  534. return SelectionVS(inPos, newTexCoord, transpose(transform), id);
  535. }
  536. TPixelToFrame TexturedPS_Colorscale(TVertexToPixel PSIn)
  537. {
  538. TPixelToFrame Output = (TPixelToFrame)0;
  539. Output.Color = tex2D(ColorscaleSampler, ClampTexture(PSIn.TextureCoords, PSIn.TextureBounds));
  540. Output.Color.rgb *= tex2D(AmbientSampler, float2(PSIn.LightRamp.g, 0.5f)).rgb;
  541. Output.Color.rgb *= PSIn.VertexColor.rgb;
  542. clip(Output.Color.a - 0.5);
  543. clip(PSIn.ClipDistance.w);
  544. return Output;
  545. }
  546. TPixelToFrame SelectionPS_Alphatest(SelectionBufferToPixel PSIn)
  547. {
  548. TPixelToFrame Output = (TPixelToFrame)0;
  549. float2 textureCoords = PSIn.TextureCoords;
  550. float4 texColor = tex2D(TextureSampler, textureCoords);
  551. clip((texColor.a - 0.5));
  552. clip(PSIn.ClipDistance.w + 1);
  553. Output.Color = PSIn.SelectionColor;
  554. return Output;
  555. }
  556. TPixelToFrame SilhouettePS(TVertexToPixel PSIn)
  557. {
  558. TPixelToFrame Output = (TPixelToFrame)0;
  559. float2 textureCoords = ClampTexture(PSIn.TextureCoords, PSIn.TextureBounds);
  560. float4 texColor = tex2D(TextureSampler, textureCoords);
  561. clip((texColor.a - 0.5));
  562. Output.Color.rgb = PSIn.VertexColor;
  563. Output.Color.a = 0.2;
  564. return Output;
  565. }
  566. // For drawing voxel icons
  567. TPixelToFrame TexturedPS_Icon(TVertexToPixel PSIn)
  568. {
  569. TPixelToFrame Output = (TPixelToFrame)0;
  570. float2 textureCoords = ClampTexture(PSIn.TextureCoords, PSIn.TextureBounds);
  571. float4 texColor = tex2D(TextureSampler, textureCoords);
  572. clip((texColor.a - 0.5));
  573. Output.Color.rgba = texColor;
  574. float3 light1_dir = -normalize(float3(1.5, -1, 1));
  575. float3 light2_dir = -normalize(float3(-2, -1, -0.5));
  576. float3 normal = normalize(PSIn.WorldPosition.xyz);
  577. float3 diffuse1 = normalize(float3(0.5, 0.5, 0.4));
  578. float3 diffuse2 = normalize(float3(0.1, 0.1, 0.3)) * 0.5;
  579. diffuse1 *= clamp(dot(normal, light1_dir), 0, 1);
  580. diffuse2 *= clamp(dot(normal, light2_dir), 0, 1);
  581. float4 illumColor = tex2D(IllumSampler, textureCoords);
  582. Output.Color.rgb *= (diffuse1 + diffuse2 + float3(0.4, 0.42, 0.45));
  583. Output.Color.rgba = lerp(Output.Color.rgba, texColor, SelfIllumination * illumColor.r);
  584. Output.Color.rgb *= xVertexColorMultiplier;
  585. return Output;
  586. }
  587. float4x4 stippleMatrix =
  588. {
  589. 1.0 / 17.0, 9.0 / 17.0, 3.0 / 17.0, 11.0 / 17.0,
  590. 13.0 / 17.0, 5.0 / 17.0, 15.0 / 17.0, 7.0 / 17.0,
  591. 4.0 / 17.0, 12.0 / 17.0, 2.0 / 17.0, 10.0 / 17.0,
  592. 16.0 / 17.0, 8.0 / 17.0, 14.0 / 17.0, 6.0 / 17.0
  593. };
  594. int xTextureWidth;
  595. int xTextureHeight;
  596. int xScreenWidth;
  597. int xScreenHeight;
  598. // ps_2_0 version of the main pixel shader... don't ask why this is needed.
  599. TPixelToFrame TexturedPS2(TVertexToPixel PSIn)
  600. {
  601. TPixelToFrame Output = (TPixelToFrame) 0;
  602. float2 textureCoords = ClampTexture(PSIn.TextureCoords, PSIn.TextureBounds);
  603. float4 texColor = tex2D(TextureSampler, textureCoords);
  604. clip((texColor.a - 0.5));
  605. Output.Color = tex2D(SunSampler, float2(PSIn.LightRamp.r, (xTimeOfDay)));
  606. Output.Color.a *= PSIn.LightRamp.a;
  607. float alpha = smoothstep(0.0f, 1.0f, (1.0 - PSIn.LightRamp.r) * 1.25);
  608. Output.Color.a = lerp(Output.Color.a, alpha, xCaveView);
  609. Output.Color.rgb += tex2D(TorchSampler, float2(PSIn.LightRamp.b, 0.5f)).rgb;
  610. Output.Color.rgb *= tex2D(AmbientSampler, float2(PSIn.LightRamp.g, 0.5f)).rgb;
  611. float4 illumColor = tex2D(IllumSampler, textureCoords);
  612. Output.Color.rgba *= texColor;
  613. Output.Color.rgb *= PSIn.VertexColor;
  614. Output.Color.rgba = lerp(Output.Color.rgba, texColor, SelfIllumination * illumColor.r);
  615. Output.Color.rgba = float4(lerp(Output.Color.rgb, xFogColor, PSIn.Fog) * Output.Color.a, Output.Color.a);
  616. if (PSIn.ClipDistance.w - 0.5f * xCaveView < 0.0f)
  617. {
  618. Output.Color *= clamp(-1.0f / (PSIn.ClipDistance.w * 0.75f) * 0.25f, 0, 1);
  619. clip(GhostMode * (Output.Color.a) - 0.1f);
  620. }
  621. if (xCaveView * PSIn.LightRamp.r > 0.5)
  622. {
  623. Output.Color.rgb = float3(Output.Color.r, Output.Color.r, Output.Color.r);
  624. }
  625. return Output;
  626. }
  627. TPixelToFrame TexturedPS(TVertexToPixel PSIn)
  628. {
  629. TPixelToFrame Output = (TPixelToFrame) 0;
  630. float2 textureCoords = ClampTexture(PSIn.TextureCoords, PSIn.TextureBounds);
  631. float4 texColor = tex2D(TextureSampler, textureCoords);
  632. clip((texColor.a - 0.5));
  633. Output.Color = tex2D(SunSampler, float2(PSIn.LightRamp.r, (xTimeOfDay)));
  634. Output.Color.a *= PSIn.LightRamp.a;
  635. float alpha = smoothstep(0.0f, 1.0f, (1.0 - PSIn.LightRamp.r) * 1.25);
  636. float screenWidth = lerp(0, 1.0 - saturate(length(PSIn.Position.xy - float2(xScreenWidth * 0.5, xScreenHeight * 0.5)) / 700), xCaveView);
  637. Output.Color.a = lerp(Output.Color.a, alpha, screenWidth);
  638. Output.Color.rgb += tex2D(TorchSampler, float2(PSIn.LightRamp.b, 0.5f)).rgb;
  639. Output.Color.rgb *= tex2D(AmbientSampler, float2(PSIn.LightRamp.g, 0.5f)).rgb;
  640. float4 illumColor = tex2D(IllumSampler, textureCoords);
  641. Output.Color.rgba *= texColor;
  642. Output.Color.rgba *= PSIn.VertexColor.rgba;
  643. Output.Color.rgba = lerp(Output.Color.rgba, texColor, SelfIllumination * illumColor.r);
  644. Output.Color.rgba = float4(lerp(Output.Color.rgb, xFogColor, PSIn.Fog) * Output.Color.a, Output.Color.a);
  645. if (PSIn.ClipDistance.w - 0.5f * xCaveView < 0.0f)
  646. {
  647. Output.Color *= clamp(-1.0f / (PSIn.ClipDistance.w * 0.75f) * 0.25f, 0, 1);
  648. clip(GhostMode * (Output.Color.a) - 0.1f);
  649. }
  650. if (xCaveView * PSIn.LightRamp.r > 0.5)
  651. {
  652. Output.Color.rgb = float3(Output.Color.r, Output.Color.r, Output.Color.r);
  653. }
  654. return Output;
  655. }
  656. TPixelToFrame TexturedPS_Alphatest(TVertexToPixel PSIn)
  657. {
  658. TPixelToFrame Output = TexturedPS(PSIn);
  659. clip(Output.Color.a - stippleMatrix[PSIn.Position.x % 4][PSIn.Position.y % 4]);
  660. Output.Color.a = 1.0;
  661. return Output;
  662. }
  663. int transparencytable[4] =
  664. {
  665. 0, 255,
  666. 255, 0
  667. };
  668. TPixelToFrame TexturedPS_Alphatest_Stipple(TVertexToPixel PSIn)
  669. {
  670. TPixelToFrame Output = TexturedPS_Alphatest(PSIn);
  671. int x = (int) (fmod(PSIn.Position.x, 2));
  672. int y = (int) (fmod(PSIn.Position.y, 2));
  673. clip(100 - transparencytable[x + y * 2]);
  674. return Output;
  675. }
  676. TPixelToFrame TexturedPS_Color(TVertexToPixel PSIn)
  677. {
  678. TPixelToFrame Output = (TPixelToFrame) 0;
  679. /*
  680. if (xEnableShadows)
  681. {
  682. float4 shadowPos = GetPositionFromLight(PSIn.WorldPosition);
  683. float2 shadowUV = 0.5 * shadowPos.xy / shadowPos.w + float2(0.5, 0.5);
  684. shadowUV.y = 1.0f - shadowUV.y;
  685. if (shadowUV.x < 1.0 && shadowUV.y < 1.0 && shadowUV.x > 0 && shadowUV.y > 0)
  686. {
  687. float shadowdepth = tex2D(ShadowMapSampler, shadowUV).r;
  688. // Check our value against the depth value
  689. float ourdepth = 1 - (shadowPos.z / shadowPos.w) + 0.05;
  690. // Check the shadowdepth against the depth of this pixel
  691. // a fudge factor is added to account for floating-point error
  692. PSIn.Color.r *= saturate(exp(100 * (ourdepth - shadowdepth)) + 0.25f);
  693. }
  694. }
  695. */
  696. Output.Color = tex2D(SunSampler, float2(PSIn.LightRamp.r, (xTimeOfDay)));
  697. Output.Color.rgb += tex2D(TorchSampler, float2(PSIn.LightRamp.b, 0.5f)).rgb;
  698. saturate(Output.Color.rgb);
  699. Output.Color.rgb *= tex2D(AmbientSampler, float2(PSIn.LightRamp.g, 0.5f)).rgb;
  700. Output.Color.rgb *= PSIn.VertexColor;
  701. float4 texColor = tex2D(TextureSampler, ClampTexture(PSIn.TextureCoords, PSIn.TextureBounds));
  702. float4 illumColor = tex2D(IllumSampler, ClampTexture(PSIn.TextureCoords, PSIn.TextureBounds));
  703. Output.Color.rgba *= texColor;
  704. Output.Color.rgba = lerp(Output.Color.rgba, texColor, SelfIllumination * illumColor.r);
  705. Output.Color.rgba = float4(lerp(Output.Color.rgb, xFogColor, PSIn.Fog), Output.Color.a * PSIn.LightRamp.a);
  706. if (PSIn.ClipDistance.w < 0.0f)
  707. {
  708. Output.Color *= clamp(-1.0f / (PSIn.ClipDistance.w * 0.75f) * 0.25f, 0, 1);
  709. clip(GhostMode * (Output.Color.a) - 0.1f);
  710. }
  711. return Output;
  712. }
  713. technique Selection
  714. {
  715. pass Pass0
  716. {
  717. VertexShader = compile vs_3_0 SelectionVSNonInstanced();
  718. PixelShader = compile ps_3_0 SelectionPS_Alphatest();
  719. }
  720. };
  721. technique Textured
  722. {
  723. pass Pass0
  724. {
  725. VertexShader = compile vs_3_0 TexturedVSNonInstanced(MAX_LIGHTS);
  726. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  727. }
  728. }
  729. technique Textured_Stipple
  730. {
  731. pass Pass0
  732. {
  733. VertexShader = compile vs_3_0 TexturedVSNonInstanced(1);
  734. PixelShader = compile ps_3_0 TexturedPS_Alphatest_Stipple();
  735. }
  736. }
  737. technique Icon
  738. {
  739. pass Pass0
  740. {
  741. VertexShader = compile vs_3_0 TexturedVSNonInstanced(MAX_LIGHTS);
  742. PixelShader = compile ps_3_0 TexturedPS_Icon();
  743. }
  744. }
  745. /*
  746. technique Textured_0_Lights
  747. {
  748. pass Pass0
  749. {
  750. VertexShader = compile vs_3_0 TexturedVSNonInstanced(0);
  751. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  752. }
  753. }
  754. */
  755. technique Textured_1_Light
  756. {
  757. pass Pass0
  758. {
  759. VertexShader = compile vs_3_0 TexturedVSNonInstanced_1Light();
  760. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  761. }
  762. }
  763. technique Textured_2_Lights
  764. {
  765. pass Pass0
  766. {
  767. VertexShader = compile vs_3_0 TexturedVSNonInstanced(2);
  768. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  769. }
  770. }
  771. technique Textured_3_Lights
  772. {
  773. pass Pass0
  774. {
  775. VertexShader = compile vs_3_0 TexturedVSNonInstanced(3);
  776. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  777. }
  778. }
  779. technique Textured_4_Lights
  780. {
  781. pass Pass0
  782. {
  783. VertexShader = compile vs_3_0 TexturedVSNonInstanced(4);
  784. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  785. }
  786. }
  787. technique Textured_5_Lights
  788. {
  789. pass Pass0
  790. {
  791. VertexShader = compile vs_3_0 TexturedVSNonInstanced(5);
  792. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  793. }
  794. }
  795. technique Textured_6_Lights
  796. {
  797. pass Pass0
  798. {
  799. VertexShader = compile vs_3_0 TexturedVSNonInstanced(6);
  800. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  801. }
  802. }
  803. technique Textured_7_Lights
  804. {
  805. pass Pass0
  806. {
  807. VertexShader = compile vs_3_0 TexturedVSNonInstanced(7);
  808. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  809. }
  810. }
  811. technique Textured_8_Lights
  812. {
  813. pass Pass0
  814. {
  815. VertexShader = compile vs_3_0 TexturedVSNonInstanced(8);
  816. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  817. }
  818. }
  819. technique Textured_9_Lights
  820. {
  821. pass Pass0
  822. {
  823. VertexShader = compile vs_3_0 TexturedVSNonInstanced(9);
  824. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  825. }
  826. }
  827. technique Textured_10_Lights
  828. {
  829. pass Pass0
  830. {
  831. VertexShader = compile vs_3_0 TexturedVSNonInstanced(10);
  832. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  833. }
  834. }
  835. technique Textured_11_Lights
  836. {
  837. pass Pass0
  838. {
  839. VertexShader = compile vs_3_0 TexturedVSNonInstanced(11);
  840. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  841. }
  842. }
  843. technique Textured_12_Lights
  844. {
  845. pass Pass0
  846. {
  847. VertexShader = compile vs_3_0 TexturedVSNonInstanced(12);
  848. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  849. }
  850. }
  851. technique Textured_13_Lights
  852. {
  853. pass Pass0
  854. {
  855. VertexShader = compile vs_3_0 TexturedVSNonInstanced(13);
  856. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  857. }
  858. }
  859. technique Textured_14_Lights
  860. {
  861. pass Pass0
  862. {
  863. VertexShader = compile vs_3_0 TexturedVSNonInstanced(14);
  864. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  865. }
  866. }
  867. technique Textured_15_Lights
  868. {
  869. pass Pass0
  870. {
  871. VertexShader = compile vs_3_0 TexturedVSNonInstanced(15);
  872. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  873. }
  874. }
  875. technique Textured_16_Lights
  876. {
  877. pass Pass0
  878. {
  879. VertexShader = compile vs_3_0 TexturedVSNonInstanced(16);
  880. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  881. }
  882. }
  883. technique Textured_Flag
  884. {
  885. pass Pass0
  886. {
  887. VertexShader = compile vs_2_0 TexturedVS_Flag(MAX_LIGHTS);
  888. PixelShader = compile ps_2_0 TexturedPS2();
  889. }
  890. }
  891. technique Silhouette
  892. {
  893. pass Pass0
  894. {
  895. VertexShader = compile vs_3_0 TexturedVSNonInstanced(MAX_LIGHTS);
  896. PixelShader = compile ps_3_0 SilhouettePS();
  897. }
  898. }
  899. technique Textured_From_Lightmap
  900. {
  901. pass Pass0
  902. {
  903. VertexShader = compile vs_3_0 TexturedVS_From_Lightmap();
  904. PixelShader = compile ps_3_0 TexturedPS_From_Lightmap();
  905. }
  906. }
  907. technique Lightmap
  908. {
  909. pass Pass0
  910. {
  911. VertexShader = compile vs_3_0 TexturedVS_To_Lightmap(MAX_LIGHTS);
  912. PixelShader = compile ps_3_0 TexturedPS_To_Lightmap();
  913. }
  914. }
  915. technique Textured_colorscale
  916. {
  917. pass Pass0
  918. {
  919. VertexShader = compile vs_3_0 TexturedVSNonInstanced(MAX_LIGHTS);
  920. PixelShader = compile ps_3_0 TexturedPS_Colorscale();
  921. }
  922. }
  923. technique Instanced
  924. {
  925. pass Pass0
  926. {
  927. VertexShader = compile vs_3_0 TexturedVSInstanced(MAX_LIGHTS);
  928. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  929. }
  930. }
  931. technique Instanced_1_Light
  932. {
  933. pass Pass0
  934. {
  935. VertexShader = compile vs_3_0 TexturedVSInstanced_1Light();
  936. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  937. }
  938. }
  939. technique Instanced_2_Lights
  940. {
  941. pass Pass0
  942. {
  943. VertexShader = compile vs_3_0 TexturedVSInstanced(2);
  944. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  945. }
  946. }
  947. technique Instanced_3_Lights
  948. {
  949. pass Pass0
  950. {
  951. VertexShader = compile vs_3_0 TexturedVSInstanced(3);
  952. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  953. }
  954. }
  955. technique Instanced_4_Lights
  956. {
  957. pass Pass0
  958. {
  959. VertexShader = compile vs_3_0 TexturedVSInstanced(4);
  960. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  961. }
  962. }
  963. technique Instanced_5_Lights
  964. {
  965. pass Pass0
  966. {
  967. VertexShader = compile vs_3_0 TexturedVSInstanced(5);
  968. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  969. }
  970. }
  971. technique Instanced_6_Lights
  972. {
  973. pass Pass0
  974. {
  975. VertexShader = compile vs_3_0 TexturedVSInstanced(6);
  976. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  977. }
  978. }
  979. technique Instanced_7_Lights
  980. {
  981. pass Pass0
  982. {
  983. VertexShader = compile vs_3_0 TexturedVSInstanced(7);
  984. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  985. }
  986. }
  987. technique Instanced_8_Lights
  988. {
  989. pass Pass0
  990. {
  991. VertexShader = compile vs_3_0 TexturedVSInstanced(8);
  992. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  993. }
  994. }
  995. technique Instanced_9_Lights
  996. {
  997. pass Pass0
  998. {
  999. VertexShader = compile vs_3_0 TexturedVSInstanced(9);
  1000. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  1001. }
  1002. }
  1003. technique Instanced_10_Lights
  1004. {
  1005. pass Pass0
  1006. {
  1007. VertexShader = compile vs_3_0 TexturedVSInstanced(10);
  1008. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  1009. }
  1010. }
  1011. technique Instanced_11_Lights
  1012. {
  1013. pass Pass0
  1014. {
  1015. VertexShader = compile vs_3_0 TexturedVSInstanced(11);
  1016. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  1017. }
  1018. }
  1019. technique Instanced_12_Lights
  1020. {
  1021. pass Pass0
  1022. {
  1023. VertexShader = compile vs_3_0 TexturedVSInstanced(12);
  1024. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  1025. }
  1026. }
  1027. technique Instanced_13_Lights
  1028. {
  1029. pass Pass0
  1030. {
  1031. VertexShader = compile vs_3_0 TexturedVSInstanced(13);
  1032. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  1033. }
  1034. }
  1035. technique Instanced_14_Lights
  1036. {
  1037. pass Pass0
  1038. {
  1039. VertexShader = compile vs_3_0 TexturedVSInstanced(14);
  1040. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  1041. }
  1042. }
  1043. technique Instanced_15_Lights
  1044. {
  1045. pass Pass0
  1046. {
  1047. VertexShader = compile vs_3_0 TexturedVSInstanced(15);
  1048. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  1049. }
  1050. }
  1051. technique Instanced_16_Lights
  1052. {
  1053. pass Pass0
  1054. {
  1055. VertexShader = compile vs_3_0 TexturedVSInstanced(16);
  1056. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  1057. }
  1058. }
  1059. technique TiledInstanced
  1060. {
  1061. pass Pass0
  1062. {
  1063. VertexShader = compile vs_3_0 TexturedVSTiledInstanced(MAX_LIGHTS);
  1064. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  1065. }
  1066. }
  1067. technique TiledInstanced_1_Light
  1068. {
  1069. pass Pass0
  1070. {
  1071. VertexShader = compile vs_3_0 TexturedVSTiledInstanced_1Light();
  1072. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  1073. }
  1074. }
  1075. technique TiledInstanced_2_Lights
  1076. {
  1077. pass Pass0
  1078. {
  1079. VertexShader = compile vs_3_0 TexturedVSTiledInstanced(2);
  1080. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  1081. }
  1082. }
  1083. technique TiledInstanced_3_Lights
  1084. {
  1085. pass Pass0
  1086. {
  1087. VertexShader = compile vs_3_0 TexturedVSTiledInstanced(3);
  1088. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  1089. }
  1090. }
  1091. technique TiledInstanced_4_Lights
  1092. {
  1093. pass Pass0
  1094. {
  1095. VertexShader = compile vs_3_0 TexturedVSTiledInstanced(4);
  1096. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  1097. }
  1098. }
  1099. technique TiledInstanced_5_Lights
  1100. {
  1101. pass Pass0
  1102. {
  1103. VertexShader = compile vs_3_0 TexturedVSTiledInstanced(5);
  1104. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  1105. }
  1106. }
  1107. technique TiledInstanced_6_Lights
  1108. {
  1109. pass Pass0
  1110. {
  1111. VertexShader = compile vs_3_0 TexturedVSTiledInstanced(6);
  1112. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  1113. }
  1114. }
  1115. technique TiledInstanced_7_Lights
  1116. {
  1117. pass Pass0
  1118. {
  1119. VertexShader = compile vs_3_0 TexturedVSTiledInstanced(7);
  1120. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  1121. }
  1122. }
  1123. technique TiledInstanced_8_Lights
  1124. {
  1125. pass Pass0
  1126. {
  1127. VertexShader = compile vs_3_0 TexturedVSTiledInstanced(8);
  1128. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  1129. }
  1130. }
  1131. technique TiledInstanced_9_Lights
  1132. {
  1133. pass Pass0
  1134. {
  1135. VertexShader = compile vs_3_0 TexturedVSTiledInstanced(9);
  1136. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  1137. }
  1138. }
  1139. technique TiledInstanced_10_Lights
  1140. {
  1141. pass Pass0
  1142. {
  1143. VertexShader = compile vs_3_0 TexturedVSTiledInstanced(10);
  1144. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  1145. }
  1146. }
  1147. technique TiledInstanced_11_Lights
  1148. {
  1149. pass Pass0
  1150. {
  1151. VertexShader = compile vs_3_0 TexturedVSTiledInstanced(11);
  1152. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  1153. }
  1154. }
  1155. technique TiledInstanced_12_Lights
  1156. {
  1157. pass Pass0
  1158. {
  1159. VertexShader = compile vs_3_0 TexturedVSTiledInstanced(12);
  1160. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  1161. }
  1162. }
  1163. technique TiledInstanced_13_Lights
  1164. {
  1165. pass Pass0
  1166. {
  1167. VertexShader = compile vs_3_0 TexturedVSTiledInstanced(13);
  1168. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  1169. }
  1170. }
  1171. technique TiledInstanced_14_Lights
  1172. {
  1173. pass Pass0
  1174. {
  1175. VertexShader = compile vs_3_0 TexturedVSTiledInstanced(14);
  1176. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  1177. }
  1178. }
  1179. technique TiledInstanced_15_Lights
  1180. {
  1181. pass Pass0
  1182. {
  1183. VertexShader = compile vs_3_0 TexturedVSTiledInstanced(15);
  1184. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  1185. }
  1186. }
  1187. technique TiledInstanced_16_Lights
  1188. {
  1189. pass Pass0
  1190. {
  1191. VertexShader = compile vs_3_0 TexturedVSTiledInstanced(16);
  1192. PixelShader = compile ps_3_0 TexturedPS_Alphatest();
  1193. }
  1194. }
  1195. technique Instanced_SelectionBuffer
  1196. {
  1197. pass Pass0
  1198. {
  1199. VertexShader = compile vs_3_0 SelectionVSInstanced();
  1200. PixelShader = compile ps_3_0 SelectionPS_Alphatest();
  1201. }
  1202. }
  1203. technique TiledInstanced_SelectionBuffer
  1204. {
  1205. pass Pass0
  1206. {
  1207. VertexShader = compile vs_3_0 SelectionVSTiledInstanced();
  1208. PixelShader = compile ps_3_0 SelectionPS_Alphatest();
  1209. }
  1210. }
  1211. //------- Technique: Water --------
  1212. struct WVertexToPixel
  1213. {
  1214. float4 Position : POSITION;
  1215. float2 TextureSamplingPos : TEXCOORD5;
  1216. float4 ReflectionMapSamplingPos : TEXCOORD1;
  1217. float2 BumpMapSamplingPos : TEXCOORD2;
  1218. float4 RefractionMapSamplingPos : TEXCOORD3;
  1219. float4 Position3D : TEXCOORD4;
  1220. float2 UnMovedTextureSamplingPos : TEXCOORD6;
  1221. float4 Color : COLOR0;
  1222. float Fog : TEXCOORD7;
  1223. float ClipDistance : COLOR1;
  1224. };
  1225. struct WPixelToFrame
  1226. {
  1227. float4 Color : COLOR0;
  1228. };
  1229. WVertexToPixel WaterVS(float4 inPos_ : POSITION, float2 inTex: TEXCOORD0, float4 inColor : COLOR0)
  1230. {
  1231. float4 inPos = inPos_;// +GetNoise(inPos_);
  1232. WVertexToPixel Output = (WVertexToPixel)0;
  1233. float4x4 preViewProjection = mul (xView, xProjection);
  1234. float4x4 preWorldViewProjection = mul (xWorld, preViewProjection);
  1235. float4x4 preReflectionViewProjection = mul (xReflectionView, xProjection);
  1236. float4x4 preWorldReflectionViewProjection = mul (xWorld, preReflectionViewProjection);
  1237. Output.Position = mul(inPos, preWorldViewProjection);
  1238. Output.ReflectionMapSamplingPos = mul(inPos, preWorldReflectionViewProjection);
  1239. Output.RefractionMapSamplingPos = mul(inPos, preWorldViewProjection);
  1240. Output.Position3D = mul(inPos, xWorld);
  1241. Output.BumpMapSamplingPos = inTex/xWaveLength;
  1242. float st = sin(xTime * 0.2 + inTex.y * 0.1);
  1243. float2 moveVector = xWindDirection.xz * xWindForce * xTime * 100;
  1244. moveVector.x += st;
  1245. moveVector.y += 1.0 - st;
  1246. Output.BumpMapSamplingPos = moveVector + inTex;
  1247. Output.TextureSamplingPos = moveVector + inTex;
  1248. Output.UnMovedTextureSamplingPos = inTex;
  1249. Output.Color = inColor;
  1250. Output.Fog = saturate((Output.Position.z - xFogStart) / (xFogEnd - xFogStart));
  1251. Output.ClipDistance = Clipping * dot(Output.Position3D, ClipPlane0);
  1252. return Output;
  1253. }
  1254. WPixelToFrame WaterPS(WVertexToPixel PSIn)
  1255. {
  1256. WPixelToFrame Output = (WPixelToFrame)0;
  1257. clip(PSIn.ClipDistance);
  1258. Output.Color = PSIn.Color;
  1259. float4 bumpColor = tex2D(WaterBumpMapSampler, PSIn.BumpMapSamplingPos);
  1260. float2 perturbation = xWaveHeight * (bumpColor.rg - 0.5f) * 2.0f;
  1261. float2 ProjectedTexCoords;
  1262. ProjectedTexCoords.x = PSIn.ReflectionMapSamplingPos.x / PSIn.ReflectionMapSamplingPos.w / 2.0f + 0.5f;
  1263. ProjectedTexCoords.y = -PSIn.ReflectionMapSamplingPos.y / PSIn.ReflectionMapSamplingPos.w / 2.0f + 0.5f;
  1264. float2 perturbatedTexCoords = ProjectedTexCoords + perturbation;
  1265. float4 reflectiveColor = tex2D(ReflectionSampler, perturbatedTexCoords);
  1266. float3 eyeVector = normalize(xCamPos.xyz - PSIn.Position3D.xyz);
  1267. float3 normalVector = float3(0, 1, 0);
  1268. float fresnelTerm = abs(dot(eyeVector, normalVector));
  1269. float4 dullColor = tex2D(WrappedTextureSampler, PSIn.TextureSamplingPos);
  1270. Output.Color = dullColor;
  1271. Output.Color = lerp(reflectiveColor, dullColor, fresnelTerm);
  1272. Output.Color = lerp(dullColor, Output.Color, xWaterReflective);
  1273. Output.Color.rgba = float4(lerp(Output.Color.rgb, xFogColor, PSIn.Fog) * Output.Color.a, Output.Color.a);
  1274. float st = -xTime * 0.1 + lerp(perturbation.r / xWaveHeight, PSIn.Color.r, 0.8);
  1275. Output.Color.rgb += (xRippleColor * (PSIn.Color.r * 1.5) * tex2D(ShoreSampler, st)).rgb;
  1276. Output.Color.a = lerp(xWaterMinOpacity, xWaterOpacity, 1.0 - fresnelTerm);
  1277. return Output;
  1278. }
  1279. WVertexToPixel WaterVS_Flat(float4 inPos : POSITION, float2 inTex : TEXCOORD0, float4 inColor : COLOR0)
  1280. {
  1281. WVertexToPixel Output = (WVertexToPixel)0;
  1282. float4x4 preViewProjection = mul(xView, xProjection);
  1283. float4 pos3d = mul(inPos, xWorld);
  1284. Output.Position = mul(pos3d, preViewProjection);
  1285. Output.Color = xFlatColor;
  1286. Output.ClipDistance = Clipping * dot(mul(xWorld, inPos), ClipPlane0);
  1287. return Output;
  1288. }
  1289. WPixelToFrame WaterPS_Textured(WVertexToPixel PSIn)
  1290. {
  1291. WPixelToFrame Output = (WPixelToFrame)0;
  1292. clip(PSIn.ClipDistance);
  1293. Output.Color = tex2D(WrappedTextureSampler, PSIn.TextureSamplingPos);
  1294. float r = PSIn.Color.r;
  1295. Output.Color.rgba = float4(lerp(Output.Color.rgb, xFogColor, PSIn.Fog) * Output.Color.a, Output.Color.a);
  1296. float3 eyeVector = normalize(xCamPos.xyz - PSIn.Position3D.xyz);
  1297. float3 normalVector = float3(0, 1, 0);
  1298. float fresnelTerm = abs(dot(eyeVector, normalVector));
  1299. float st = xTime * 0.1 + r;
  1300. Output.Color.rgb += (xRippleColor * (r * 1.5) * tex2D(ShoreSampler, st)).rgb;
  1301. //Output.Color.rgb = float3(fresnelTerm, 0, 0);
  1302. Output.Color.a = lerp(xWaterMinOpacity, xWaterOpacity, 1.0 - fresnelTerm);
  1303. return Output;
  1304. }
  1305. WVertexToPixel WaterVS_Textured(float4 inPos_ : POSITION, float2 inTex : TEXCOORD0, float4 inColor : COLOR0)
  1306. {
  1307. float4 inPos = inPos_; //+GetNoise(inPos_);
  1308. WVertexToPixel Output = (WVertexToPixel)0;
  1309. float4x4 preViewProjection = mul(xView, xProjection);
  1310. float4x4 preWorldViewProjection = mul(xWorld, preViewProjection);
  1311. Output.Position = mul(inPos, preWorldViewProjection);
  1312. Output.Position3D = mul(inPos, xWorld);
  1313. float st = sin(xTime * 0.2 + inTex.y * 0.1);
  1314. float2 moveVector = xWindDirection.xz * xWindForce * xTime * 1000;
  1315. moveVector.x += st;
  1316. moveVector.y += 1.0 - st;
  1317. Output.TextureSamplingPos = moveVector + inTex;
  1318. Output.Color = inColor;
  1319. Output.Fog = saturate((Output.Position.z - xFogStart) / (xFogEnd - xFogStart));
  1320. Output.ClipDistance = Clipping * dot(Output.Position3D, ClipPlane0);
  1321. return Output;
  1322. }
  1323. WPixelToFrame WaterPS_Flat(WVertexToPixel PSIn)
  1324. {
  1325. WPixelToFrame Output = (WPixelToFrame)0;
  1326. Output.Color = PSIn.Color;
  1327. return Output;
  1328. }
  1329. technique Water
  1330. {
  1331. pass Pass0
  1332. {
  1333. VertexShader = compile vs_3_0 WaterVS();
  1334. PixelShader = compile ps_3_0 WaterPS();
  1335. }
  1336. }
  1337. technique WaterFlat
  1338. {
  1339. pass Pass0
  1340. {
  1341. VertexShader = compile vs_3_0 WaterVS_Flat();
  1342. PixelShader = compile ps_3_0 WaterPS_Flat();
  1343. }
  1344. }
  1345. technique WaterTextured
  1346. {
  1347. pass Pass0
  1348. {
  1349. VertexShader = compile vs_3_0 WaterVS_Textured();
  1350. PixelShader = compile ps_3_0 WaterPS_Textured();
  1351. }
  1352. }