Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.71 KB | None | 0 0
  1. //++++++++++++++++++++++++++++++++++++++++++++++++
  2. // Clouds from SA_DirectX 2.0
  3. // Copyright Boris Vorontsov / Maxim Dubinov (Makarus)
  4. // Editing and combining as well as cloud settings by AP84
  5. //++++++++++++++++++++++++++++++++++++++++++++++++
  6. //internal parameters, can be modified
  7. //+++++++++++++++++++++++++++++
  8. float EShadowAmount
  9. <
  10. string UIName="Lighting: ShadowAmount";
  11. string UIWidget="Spinner";
  12. float UIMin=0.0;
  13. float UIMax=1.0;
  14. > = {0.5};
  15.  
  16. float4 tempF1; float4 tempF2; float4 tempF3;
  17. float4 ScreenSize; float4 Timer;float ENightDayFactor;
  18. float4 SunDirection; float EInteriorFactor; float FadeFactor; float FieldOfView;
  19. float4 MatrixVP[4]; float4 MatrixInverseVP[4]; float4 MatrixVPRotation[4]; float4 MatrixInverseVPRotation[4];
  20. float4 MatrixView[4];float4 MatrixInverseView[4];float4 CameraPosition;float GameTime;float4 CustomShaderConstants1[8];
  21. float4 WeatherAndTime;float4x4 MatrixWVP;float4x4 MatrixWVPInverse;float4x4 MatrixWorld; float4x4 MatrixProj;float4 FogParam;float4 FogFarColor;
  22.  
  23. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
  24. //Textures
  25. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
  26.  
  27. texture2D texEnv;
  28. texture2D texOriginal;
  29. texture2D texColor;
  30. texture2D texDepth;
  31. texture2D texNoise;
  32. texture2D texShadow;
  33. texture2D texNormal;
  34. texture2D texNs < string ResourceName="Noise.png"; >;
  35. texture2D texNs2 < string ResourceName="NoiseCd.png";>;
  36.  
  37. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
  38. //Sampler Inputs
  39. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
  40.  
  41. sampler2D SamplerEnv = sampler_state
  42. {
  43. Texture = <texEnv>;
  44. MinFilter = LINEAR;
  45. MagFilter = LINEAR;
  46. MipFilter = LINEAR;
  47. AddressU = Mirror;
  48. AddressV = Mirror;
  49. SRGBTexture=FALSE;
  50. MaxMipLevel=0;
  51. MipMapLodBias=0;
  52. };
  53.  
  54. sampler2D SamplerOriginal = sampler_state
  55. {
  56. Texture = <texOriginal>;
  57. MinFilter = LINEAR;
  58. MagFilter = LINEAR;
  59. MipFilter = LINEAR;//NONE;
  60. AddressU = Clamp;
  61. AddressV = Clamp;
  62. SRGBTexture=FALSE;
  63. MaxMipLevel=0;
  64. MipMapLodBias=0;
  65. };
  66.  
  67. sampler2D SamplerNormal = sampler_state
  68. {
  69. Texture = <texNormal>;
  70. MinFilter = Anisotropic;
  71. MagFilter = Anisotropic;
  72. MipFilter = LINEAR;
  73. AddressU = Wrap;
  74. AddressV = Wrap;
  75. SRGBTexture=FALSE;
  76. MaxMipLevel=0;
  77. MipMapLodBias=0;
  78. };
  79.  
  80. sampler2D SamplerColor = sampler_state
  81. {
  82. Texture = <texColor>;
  83. MinFilter = LINEAR;
  84. MagFilter = LINEAR;
  85. MipFilter = NONE;
  86. AddressU = Clamp;
  87. AddressV = Clamp;
  88. SRGBTexture=TRUE;
  89. MaxMipLevel=2;
  90. MipMapLodBias=0;
  91. };
  92.  
  93. sampler2D SamplerDepth = sampler_state
  94. {
  95. Texture = <texDepth>;
  96. MinFilter = LINEAR;
  97. MagFilter = LINEAR;
  98. MipFilter = LINEAR;
  99. AddressU = Wrap;
  100. AddressV = Wrap;
  101. AddressW = Wrap;
  102. SRGBTexture=TRUE;
  103. MaxMipLevel=1;
  104. MipMapLodBias=0;
  105. };
  106.  
  107. sampler2D SamplerNoise = sampler_state
  108. {
  109. Texture = <texNoise>;
  110. MinFilter = POINT;
  111. MagFilter = POINT;
  112. MipFilter = NONE;
  113. AddressU = Wrap;
  114. AddressV = Wrap;
  115. SRGBTexture=FALSE;
  116. MaxMipLevel=2;
  117. MipMapLodBias=0;
  118. };
  119.  
  120. sampler2D SamplerShadow = sampler_state
  121. {
  122. Texture = <texShadow>;
  123. MinFilter = LINEAR;
  124. MagFilter = LINEAR;
  125. MipFilter = NONE;//NONE;
  126. AddressU = Clamp;
  127. AddressV = Clamp;
  128. SRGBTexture=FALSE;
  129. MaxMipLevel=0;
  130. MipMapLodBias=0;
  131. };
  132.  
  133.  
  134. sampler2D SamplerNs = sampler_state
  135. {
  136. Texture = <texNs>;
  137. MinFilter = LINEAR;
  138. MagFilter = LINEAR;
  139. MipFilter = LINEAR;
  140. AddressU = Wrap;
  141. AddressV = Wrap;
  142. AddressW = Wrap;
  143. SRGBTexture=FALSE;
  144. MaxMipLevel=0;
  145. MipMapLodBias=0;
  146. };
  147.  
  148. sampler2D SamplerNs2 = sampler_state
  149. {
  150. Texture = <texNs2>;
  151. MinFilter = LINEAR;
  152. MagFilter = LINEAR;
  153. MipFilter = LINEAR;
  154. AddressU = Wrap;
  155. AddressV = Wrap;
  156. AddressW = Wrap;
  157. SRGBTexture=FALSE;
  158. MaxMipLevel=0;
  159. MipMapLodBias=0;
  160. };
  161.  
  162.  
  163. struct VS_OUTPUT_POST
  164. {
  165. float4 vpos : POSITION;
  166. float2 txcoord : TEXCOORD0;
  167. };
  168.  
  169. struct VS_INPUT_POST
  170. {
  171. float3 pos : POSITION;
  172. float2 txcoord : TEXCOORD0;
  173. };
  174.  
  175. ////////////////////////////////////////////////////////////////
  176. VS_OUTPUT_POST VS_PostProcess(VS_INPUT_POST IN)
  177. {
  178. VS_OUTPUT_POST OUT;
  179. float4 pos=float4(IN.pos.x,IN.pos.y,IN.pos.z,1.0);
  180. OUT.vpos=pos;
  181. OUT.txcoord.xy=IN.txcoord.xy;
  182. return OUT;
  183. }
  184.  
  185. ////////////////////////////////////////////////////////////////////////////////////
  186. /////////////////////////////////////SA_DirectX/////////////////////////////////////
  187. ////////////////////////////////////////////////////////////////////////////////////
  188.  
  189. float4 WorldPos(in float2 coord)
  190. {
  191. float d0 = tex2D(SamplerDepth, coord.xy).x;
  192. float4 tvec;
  193. tvec.xy = coord.xy*2.0-1.0;
  194. tvec.y = -tvec.y;
  195. tvec.z = d0;
  196. tvec.w = 1.0;
  197. float4 wpos;
  198. wpos.x = dot(tvec, MatrixInverseVPRotation[0]);
  199. wpos.y = dot(tvec, MatrixInverseVPRotation[1]);
  200. wpos.z = dot(tvec, MatrixInverseVPRotation[2]);
  201. wpos.w = dot(tvec, MatrixInverseVPRotation[3]);
  202. wpos.xyz/= wpos.w;
  203. return wpos;
  204. }
  205.  
  206. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  207.  
  208. float CalculateGameTime0(in float t)
  209. {
  210. float x1 = smoothstep(0.0, 4.0, t);
  211. float x2 = smoothstep(4.0, 5.0, t);
  212. float x3 = smoothstep(5.0, 6.0, t);
  213. float x4 = smoothstep(6.0, 7.0, t);
  214. float xE = smoothstep(8.0, 11.0, t);
  215. float x5 = smoothstep(16.0, 17.0, t);
  216. float x6 = smoothstep(18.0, 19.0, t);
  217. float x7 = smoothstep(19.0, 20.0, t);
  218. float xG = smoothstep(20.0, 21.0, t);
  219. float xZ = smoothstep(21.0, 22.0, t);
  220. float x8 = smoothstep(22.0, 23.0, t);
  221. float x9 = smoothstep(23.0, 24.0, t);
  222.  
  223. float3 t0 = lerp(0.0, 0.1, x1);
  224. t0 = lerp(t0, 0.2, x2);
  225. t0 = lerp(t0, 0.8, x3);
  226. t0 = lerp(t0, 0.9, x4);
  227. t0 = lerp(t0, 1.0, xE);
  228. t0 = lerp(t0, 1.0, x5);
  229. t0 = lerp(t0, 0.9, x6);
  230. t0 = lerp(t0, 0.5, x7);
  231. t0 = lerp(t0, 0.4, xG);
  232. t0 = lerp(t0, 0.3, xZ);
  233. t0 = lerp(t0, 0.2, x8);
  234. t0 = lerp(t0, 0.0, x9);
  235. return t0;
  236. }
  237.  
  238. float CalculateGameTime(in float t)
  239. {
  240. float x1 = smoothstep(0.0, 4.0, t);
  241. float x2 = smoothstep(4.0, 5.0, t);
  242. float x3 = smoothstep(5.0, 6.0, t);
  243. float x4 = smoothstep(6.0, 7.0, t);
  244. float xE = smoothstep(8.0, 11.0, t);
  245. float x5 = smoothstep(16.0, 17.0, t);
  246. float x6 = smoothstep(18.0, 19.0, t);
  247. float x7 = smoothstep(19.0, 20.0, t);
  248. float xG = smoothstep(20.0, 21.0, t);
  249. float xZ = smoothstep(21.0, 22.0, t);
  250. float x8 = smoothstep(22.0, 23.0, t);
  251. float x9 = smoothstep(23.0, 24.0, t);
  252.  
  253. float3 t0 = lerp(0.0, 0.1, x1);
  254. t0 = lerp(t0, 0.7, x2);
  255. t0 = lerp(t0, 1.0, x3);
  256. t0 = lerp(t0, 1.0, x4);
  257. t0 = lerp(t0, 1.0, xE);
  258. t0 = lerp(t0, 1.0, x5);
  259. t0 = lerp(t0, 0.9, x6);
  260. t0 = lerp(t0, 0.8, x7);
  261. t0 = lerp(t0, 0.6, xG);
  262. t0 = lerp(t0, 0.4, xZ);
  263. t0 = lerp(t0, 0.2, x8);
  264. t0 = lerp(t0, 0.0, x9);
  265. return t0;
  266. }
  267.  
  268. float Noise1(in float3 p)
  269. {
  270. float t = (Timer.x * 5.0) * 20.0;
  271. p.z += 0.5 * t;
  272. p.xyz += 1.0 * t;
  273. float2 uv = (p * float2(17.2, 17.2));
  274. float2 c = (uv + 0.5) / 20.0;
  275. float r0 = tex2Dlod(SamplerNs, float4(c*0.04, 0.0, 0.0)).x;
  276. return r0;
  277. }
  278.  
  279. float Noise2(in float3 p)
  280. {
  281. float t = (Timer.x * 20.0) * 20.0;
  282. p.z += 0.5 * t;
  283. p.xyz += 1.0 * t;
  284. float2 uv = (p * float2(17.2, 17.2));
  285. float2 c = (uv + 0.5) / 20.0;
  286. float r0 = tex2Dlod(SamplerNs2, float4(c*0.04, 0.0, 0.0)).x;
  287. return r0;
  288. }
  289.  
  290. float4 GWP(in float2 c, in float d)
  291. {
  292. float4 t;
  293. float4 w;
  294. t.xy=c.xy*2.0-1.0;
  295. t.y=-t.y;
  296. t.z=d;
  297. t.w=1.0;
  298. w.x=dot(t, MatrixInverseVPRotation[0]);
  299. w.y=dot(t, MatrixInverseVPRotation[1]);
  300. w.z=dot(t, MatrixInverseVPRotation[2]);
  301. w.w=dot(t, MatrixInverseVPRotation[3]);
  302. w.xyz/=w.w;
  303. //w.xyz+=CameraPosition;
  304. return w;
  305. }
  306.  
  307. float SunLight(in float2 c, in float d)
  308. {
  309. float3 v0=SunDirection.xyz;
  310. float3 v2=normalize(float3(-0.09, -0.94, 0.31));
  311. float t0 = GameTime;
  312. float x1 = smoothstep(0.0, 4.0, t0);
  313. float x2 = smoothstep(4.0, 23.0, t0);
  314. float x3 = smoothstep(23.0, 24.0, t0);
  315. float3 sv = lerp(v2, v0, x1);
  316. sv = lerp(sv, v0, x2);
  317. sv = lerp(sv, v2, x3);
  318. float4 WorldP = GWP(c, d);
  319. float c0 = 6.07;
  320. float3 np = normalize(WorldP.xyz);
  321. float f0 = 0.95 - dot(-sv, np);
  322. f0 = pow(f0, c0);
  323. float r0 = (f0*f0);
  324. return r0/40000.0;
  325. }
  326.  
  327. float Coverage(in float v, in float d, in float c)
  328. {
  329. c = clamp(c - (1.0 - v), 0.0, 1.0 - d)/(1.0 - d);
  330. c = max(0.0, c * 1.1 - 0.1);
  331. c = c = c * c * (3.0 - 2.0 * c);
  332. return c;
  333. }
  334.  
  335. float fcc
  336. <
  337. string UIName="Clouds - Coverage";
  338. string UIWidget="Spinner";
  339. float UIMin=0.0;
  340. float UIMax=0.55;
  341. > = {0.40};
  342.  
  343. float4 GenerateClouds(float4 worldpos, in float3 sunlight)
  344. {
  345. float t = (Timer.x * 1000.0)*20.0;
  346. float3 vecm = normalize(float3(-0.09, -0.94, 0.31));
  347. float3 sv0=-SunDirection.xyz;
  348. float3 sv2=-vecm;
  349.  
  350. float t0 = GameTime;
  351. float x1 = smoothstep(0.0, 4.0, t0);
  352. float x2 = smoothstep(4.0, 5.0, t0);
  353. float x3 = smoothstep(5.0, 6.0, t0);
  354. float x4 = smoothstep(6.0, 7.0, t0);
  355. float xE = smoothstep(8.0, 11.0, t0);
  356. float x5 = smoothstep(16.0, 17.0, t0);
  357. float x6 = smoothstep(18.0, 19.0, t0);
  358. float x7 = smoothstep(19.0, 20.0, t0);
  359. float xG = smoothstep(20.0, 21.0, t0);
  360. float xZ = smoothstep(21.0, 22.0, t0);
  361. float x8 = smoothstep(22.0, 23.0, t0);
  362. float x9 = smoothstep(23.0, 24.0, t0);
  363. float x10 = smoothstep(4.0, 23.0, t0);
  364. float x11 = smoothstep(23.0, 24.0, t0);
  365.  
  366. float3 sv = lerp(sv2, sv0, x1);
  367. sv = lerp(sv, sv0, x10);
  368. sv = lerp(sv, sv2, x11);
  369.  
  370. float3 wp = worldpos/1.5;
  371. wp.x *= 0.04;
  372. wp.y *= 0.10;
  373. wp.y -= t * 0.01;
  374. float3 wp1 = wp * float3(1.0, 0.5, 1.0) + float3(0.0, t * 0.01, 0.0);
  375.  
  376. float noise = Noise2(wp * float3(1.0, 0.5, 1.0) + float3(0.0, t * 0.01, 0.0));
  377. wp *= 3.0;
  378. wp.xy -= t * 0.04;
  379. wp.x += 2.0;
  380. float3 wp2 = wp;
  381.  
  382. noise += (2.0 - abs(Noise2(wp) * 0.8)) * 0.25;
  383. wp *= 10.0;
  384. wp.xy -= t * 0.035;
  385. float3 wp3 = wp;
  386.  
  387. noise += (2.0 - abs(Noise1(wp) * 1.0)) * 0.03;
  388. noise /= 0.80;
  389.  
  390. float4 wx = WeatherAndTime;
  391. float CovCurrent;
  392. float CovNext;
  393. if (wx.x==0,1) CovCurrent = fcc;
  394. if (wx.y==0,1) CovNext = fcc;
  395.  
  396. if (wx.x==0) CovCurrent = 0.00;
  397. if (wx.x==2) CovCurrent = 0.00;
  398. if (wx.x==6) CovCurrent = 0.00;
  399. if (wx.x==11) CovCurrent = 0.00;
  400. if (wx.x==13) CovCurrent = 0.00;
  401. if (wx.x==17) CovCurrent = 0.00;
  402.  
  403. if (wx.x==4) CovCurrent = 1.70;
  404. if (wx.x==7) CovCurrent = 1.70;
  405. if (wx.x==8) CovCurrent = 1.70;
  406. if (wx.x==9) CovCurrent = 1.70;
  407. if (wx.x==12) CovCurrent = 1.70;
  408. if (wx.x==15) CovCurrent = 1.70;
  409. if (wx.x==16) CovCurrent = 1.70;
  410.  
  411. if (wx.y==0) CovNext = 0.00;
  412. if (wx.y==2) CovNext = 0.00;
  413. if (wx.y==6) CovNext = 0.00;
  414. if (wx.y==11) CovNext = 0.00;
  415. if (wx.y==13) CovNext = 0.00;
  416. if (wx.y==17) CovNext = 0.00;
  417.  
  418. if (wx.y==4) CovNext = 1.70;
  419. if (wx.y==7) CovNext = 1.70;
  420. if (wx.y==8) CovNext = 1.70;
  421. if (wx.y==9) CovNext = 1.70;
  422. if (wx.y==12) CovNext = 1.70;
  423. if (wx.y==15) CovNext = 1.70;
  424. if (wx.y==16) CovNext = 1.70;
  425.  
  426. float3 wmix0 = lerp(CovCurrent, CovNext, pow(wx.z, 0.9));
  427.  
  428. float coverage = wmix0;
  429. float dn = 0.1 - 0.3 * 0.3;
  430. noise = Coverage(coverage, dn, noise);
  431.  
  432. float d0 = Noise2(wp1 + sv.xyz * 0.70 / 2.3);
  433. d0 += (2.0 - abs(Noise2(wp2 + sv.xyz * 0.70 / 2.3) * 0.8)) * 0.25;
  434. d0 += (2.0 - abs(Noise1(wp3 + sv.xyz * 0.70 / 2.3) * 1.0)) * 0.03;
  435. d0 = Coverage(0.84, dn, d0);
  436.  
  437. float bf = lerp(clamp(pow(noise, 0.5) * 0.5, 0.0, 1.0), 0.5, pow(sunlight, 1.0));
  438. d0 *= bf;
  439.  
  440. float3 lt = lerp(float3(0.0275, 0.0353, 0.0471), 0.01, x1);
  441. lt = lerp(lt, float3(1.0, 0.627, 0.235)*0.6, x2);
  442. lt = lerp(lt, float3(1.0, 0.627, 0.235), x3);
  443. lt = lerp(lt, float3(1.0, 0.627, 0.235), x4);
  444. lt = lerp(lt, float3(1.0, 1.0, 1.0), xE);
  445. lt = lerp(lt, float3(1.0, 1.0, 1.0), x5);
  446. lt = lerp(lt, float3(1.0, 0.627, 0.235), x6);
  447. lt = lerp(lt, float3(1.0, 0.627, 0.235), x7);
  448. lt = lerp(lt, 0.5, xG);
  449. lt = lerp(lt, 0.3, xZ);
  450. lt = lerp(lt, 0.1, x8);
  451. lt = lerp(lt, float3(0.0275, 0.0353, 0.0471), x9);
  452.  
  453. float3 sh = lerp(float3(0.051, 0.0784, 0.118)*0.05, float3(0.03, 0.04, 0.05)*0.2, x1);
  454. sh = lerp(sh, float3(0.157, 0.165, 0.216)*0.6, x2);
  455. sh = lerp(sh, float3(0.157, 0.165, 0.216), x3);
  456. sh = lerp(sh, float3(0.157, 0.165, 0.216), x4);
  457. sh = lerp(sh, float3(0.392, 0.392, 0.392), xE);
  458. sh = lerp(sh, float3(0.392, 0.392, 0.392), x5);
  459. sh = lerp(sh, float3(0.157, 0.165, 0.216), x6);
  460. sh = lerp(sh, float3(0.157, 0.165, 0.216), x7);
  461. sh = lerp(sh, float3(0.157, 0.165, 0.216), xG);
  462. sh = lerp(sh, float3(0.157, 0.165, 0.216)*0.6, xZ);
  463. sh = lerp(sh, float3(0.157, 0.165, 0.216)*0.4, x8);
  464. sh = lerp(sh, float3(0.051, 0.0784, 0.118)*0.05, x9);
  465.  
  466. float3 fmix = lerp(0.02, 0.1, x1);
  467. fmix = lerp(fmix, 0.1, x2);
  468. fmix = lerp(fmix, 0.2, x3);
  469. fmix = lerp(fmix, 0.5, x4);
  470. fmix = lerp(fmix, 0.5, xE);
  471. fmix = lerp(fmix, 0.5, x5);
  472. fmix = lerp(fmix, 0.3, x6);
  473. fmix = lerp(fmix, 0.2, x7);
  474. fmix = lerp(fmix, 0.1, xG);
  475. fmix = lerp(fmix, 0.05, xZ);
  476. fmix = lerp(fmix, 0.03, x8);
  477. fmix = lerp(fmix, 0.02, x9);
  478.  
  479. float3 fmix2 = lerp(0.01, 0.1, x1);
  480. fmix2 = lerp(fmix2, 0.05, x2);
  481. fmix2 = lerp(fmix2, 0.1, x3);
  482. fmix2 = lerp(fmix2, 0.2, x4);
  483. fmix2 = lerp(fmix2, 0.2, xE);
  484. fmix2 = lerp(fmix2, 0.2, x5);
  485. fmix2 = lerp(fmix2, 0.1, x6);
  486. fmix2 = lerp(fmix2, 0.08, x7);
  487. fmix2 = lerp(fmix2, 0.05, xG);
  488. fmix2 = lerp(fmix2, 0.03, xZ);
  489. fmix2 = lerp(fmix2, 0.02, x8);
  490. fmix2 = lerp(fmix2, 0.01, x9);
  491.  
  492. float3 ColorSun = lerp(float3(0.0392, 0.0588, 0.0784)*0.2, float3(0.05, 0.04, 0.02)*0.0, x1);
  493. ColorSun = lerp(ColorSun, float3(0.40, 0.08, 0.0)*0.8, x2);
  494. ColorSun = lerp(ColorSun, float3(0.45, 0.07, 0.0), x3);
  495. ColorSun = lerp(ColorSun, float3(0.392, 0.118, 0.0588), x4);
  496. ColorSun = lerp(ColorSun, float3(0.392, 0.275, 0.118), xE);
  497. ColorSun = lerp(ColorSun, float3(0.392, 0.275, 0.118), x5);
  498. ColorSun = lerp(ColorSun, float3(0.392, 0.08, 0.0), x6);
  499. ColorSun = lerp(ColorSun, float3(0.392, 0.08, 0.0), x7);
  500. ColorSun = lerp(ColorSun, float3(0.392, 0.118, 0.0588), xG);
  501. ColorSun = lerp(ColorSun, float3(0.392, 0.118, 0.0588)*0.4, xZ);
  502. ColorSun = lerp(ColorSun, float3(0.392, 0.118, 0.0588)*0.2, x8);
  503. ColorSun = lerp(ColorSun, float3(0.0392, 0.0588, 0.0784)*0.2, x9);
  504.  
  505. float3 SunCurrent;
  506. float3 SunNext;
  507.  
  508. float3 m0 = float3(min(1.0, d0), min(1.0, d0), min(1.0, d0));
  509. float3 color = lerp((pow(sunlight, 0.5)*ColorSun*50.0)+lt, sh, m0);
  510. float3 colorPasm = lerp(fmix, fmix2, m0);
  511.  
  512. if (wx.x==0,1) SunCurrent = color;
  513. if (wx.y==0,1) SunNext = color;
  514.  
  515. if (wx.x==4) SunCurrent = colorPasm;
  516. if (wx.x==7) SunCurrent = colorPasm;
  517. if (wx.x==8) SunCurrent = colorPasm;
  518. if (wx.x==9) SunCurrent = colorPasm;
  519. if (wx.x==12) SunCurrent = colorPasm;
  520. if (wx.x==15) SunCurrent = colorPasm;
  521. if (wx.x==16) SunCurrent = colorPasm;
  522.  
  523. if (wx.y==4) SunNext = colorPasm;
  524. if (wx.y==7) SunNext = colorPasm;
  525. if (wx.y==8) SunNext = colorPasm;
  526. if (wx.y==9) SunNext = colorPasm;
  527. if (wx.y==12) SunNext = colorPasm;
  528. if (wx.y==15) SunNext = colorPasm;
  529. if (wx.y==16) SunNext = colorPasm;
  530.  
  531. float3 wmix = lerp(SunCurrent, SunNext, wx.z);
  532.  
  533. float4 r0 = float4(wmix.rgb, (noise*noise*noise));
  534. return r0;
  535. }
  536.  
  537. float IntersectPlane(float3 pos, float3 dir)
  538. {
  539. return -pos.z/dir.z;
  540. }
  541.  
  542. ////////////////////////////////////////////////////////////////////////////////////
  543. /////////////////////////////////////SA_DirectX/////////////////////////////////////
  544. ////////////////////////////////////////////////////////////////////////////////////
  545. float4 PS_DX1(VS_OUTPUT_POST IN, float2 vPos : VPOS) : COLOR
  546. {
  547. float t = GameTime;
  548. float tf = CalculateGameTime(t);
  549. float tf2 = CalculateGameTime0(t);
  550.  
  551. float2 coord = IN.txcoord.xy;
  552. float4 r0 = tex2D(SamplerColor, coord.xy);
  553. float d0 = tex2D(SamplerDepth, coord.xy).x;
  554. float4 wpos = WorldPos(coord);
  555. //Sky------------------------------------------------------------------------------
  556. float4 w0 = wpos+CameraPosition;
  557. float4 cam = CameraPosition;
  558. float4 np0 = float4(normalize(wpos.xyz), 1.0);
  559. np0.xyz = normalize(w0.xyz-float3(cam.xy, 0.0));
  560. float3 vec = normalize(float3(0.0, 0.0, 1.0));
  561. float3 hv = normalize(-vec+np0);
  562. float np4 = (np0.z * (2.0)) + 0.40;
  563. np4 *= lerp(0.0, 1.0, tf2);
  564. float3 a2 = np4;
  565. float3 sc = 1.0;
  566. float3 sn = 1.0;
  567.  
  568. float4 wx = WeatherAndTime;
  569. float3 wmix0 = lerp(sc, sn, wx.z);
  570. float4 worldpos = GWP(coord, d0);
  571. float L = worldpos.xyz;
  572. //Clouds---------------------------------------------------------------------------
  573. float d3 = pow(tex2D(SamplerDepth, coord).x, 17000.0);
  574. float3 sc0 = SunLight(coord, d3);
  575. float3 w1 = float3(1.0, 1.0, 3.33);
  576. float4 ns = float4(normalize(worldpos.xyz), 1.0);
  577. float ip = IntersectPlane(w1, ns.xyz);
  578. float4 r1 = r0;
  579. if (ip <= 1.0)
  580. if( 10000.0 < L || d0 == 1)
  581. {
  582. float4 c0 = GenerateClouds(float4((ns.xyz*ip*15.0), 1.0), sc0);
  583. c0.a = min(1.0, c0.a);
  584. r1.xyz = lerp(r0, c0.rgb*1.0, c0.a);
  585. }
  586. r0.xyz = lerp(r0, r1, smoothstep(0.0, 0.10, pow(ns.z, 1.66)));
  587. //---------------------------------------------------------------------------------
  588. return r0;
  589. }
  590.  
  591. ////////////////////////////////////////////////////////////////////////////////////
  592. /////////////////////////////////////SA_DirectX/////////////////////////////////////
  593. ////////////////////////////////////////////////////////////////////////////////////
  594.  
  595.  
  596. float4 PS_Shadow(VS_OUTPUT_POST IN, float2 vPos : VPOS) : COLOR
  597. {
  598. float4 res;
  599.  
  600. float4 color=tex2D(SamplerColor, IN.txcoord.xy);
  601. float4 shadowtex=tex2D(SamplerShadow, IN.txcoord.xy);
  602. float depth=tex2D(SamplerDepth, IN.txcoord.xy).x;
  603.  
  604. float4 origcolor=color;
  605.  
  606. float4 tempvec;
  607. float4 worldpos;
  608. tempvec.xy=IN.txcoord.xy*2.0-1.0;
  609. tempvec.y=-tempvec.y;
  610. tempvec.z=depth;
  611. tempvec.w=1.0;
  612. worldpos.x=dot(tempvec, MatrixInverseVP[0]);
  613. worldpos.y=dot(tempvec, MatrixInverseVP[1]);
  614. worldpos.z=dot(tempvec, MatrixInverseVP[2]);
  615. worldpos.w=dot(tempvec, MatrixInverseVP[3]);
  616. worldpos.xyz/=worldpos.w;
  617. worldpos.w=1.0;
  618. worldpos.z=dot(worldpos, MatrixVP[2]);
  619. float fogdist;
  620. fogdist=worldpos.z;
  621. float fadefact=(FogParam.w - fogdist) / (FogParam.w - FogParam.z);
  622. fadefact=saturate(1.0-fadefact);
  623. //remove fog
  624. color.xyz=(color.xyz - FogFarColor.xyz*fadefact)/(1.00001-fadefact);
  625. color.xyz=max(color.xyz, 0.0);
  626.  
  627.  
  628.  
  629. //remove from sides
  630. float4 normal=tex2D(SamplerNormal, IN.txcoord.xy);
  631. normal.xyz=normal.xyz*2.0-1.0;
  632. float4 normalpos;
  633. tempvec.xyz=normal.xyz;
  634. tempvec.x=-tempvec.x;
  635. tempvec.w=1.0;
  636. normalpos.x=dot(tempvec.xyz, MatrixInverseView[0]);
  637. normalpos.y=dot(tempvec.xyz, MatrixInverseView[1]);
  638. normalpos.z=dot(tempvec.xyz, MatrixInverseView[2]);
  639. normalpos.xyz=normalize(normalpos.xyz);
  640. float3 sunvec=SunDirection.xyz;
  641. float sidefact=dot(normalpos.xyz, sunvec.xyz);
  642. sidefact*=saturate(SunDirection.z * 6.0); //if sun below horizon, disable this
  643. shadowtex*=saturate(1.0-sidefact * 6.0);
  644. shadowtex=lerp(shadowtex, 1.0, fadefact); //reduce based on fog, guess not required becaose of defog code
  645. shadowtex=lerp(1.0, shadowtex, EShadowAmount); //reduce in general
  646.  
  647. //apply shadow
  648. color.xyz*=shadowtex;
  649.  
  650. //apply fog again
  651. color.xyz=lerp(color.xyz, FogFarColor.xyz, fadefact);
  652.  
  653. res=color;
  654.  
  655. //ignore sky
  656. if (depth>=0.999999) res=origcolor;
  657.  
  658. res.w=1.0; //color.w;
  659. return res;
  660. }
  661.  
  662. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  663.  
  664. technique PostProcess
  665. {
  666. pass P0
  667. {
  668. VertexShader = compile vs_3_0 VS_PostProcess();
  669. PixelShader = compile ps_3_0 PS_DX1();
  670. }
  671. }
  672.  
  673.  
  674. technique PostProcess2
  675. {
  676. pass P0
  677. {
  678. VertexShader = compile vs_3_0 VS_PostProcess();
  679. PixelShader = compile ps_3_0 PS_Shadow();
  680.  
  681. ALPHATESTENABLE=FALSE;
  682. SEPARATEALPHABLENDENABLE=FALSE;
  683. AlphaBlendEnable=FALSE;
  684. SRGBWRITEENABLE=FALSE;
  685. }
  686. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement