effect.txt 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918
  1. /**
  2. * SHADER ADDON
  3. * Featuring BlurShift, Sharpen, Noise, LumaSharpen, Vibrance, Contrast, Black Level
  4. * Exterior/Interior separation ready (some also has Day/Night factors), GUI-enabled
  5. * By ZeroKing
  6. */
  7. /**
  8. * ENBSeries
  9. * visit http://enbdev.com for updates
  10. * Copyright (c) 2007-2014 Boris Vorontsov
  11. */
  12. //--------------------------//
  13. // Internal parameters //
  14. // Can be modified //
  15. //--------------------------//
  16. //////////////////
  17. // DEFINES //
  18. //////////////////
  19. #define ESHARPENING
  20. #define ESHARPENINGCOLOR
  21. #define ECOLORSHIFT
  22. #define SharpMethod 4
  23. #define NoiseMethod 0
  24. // Set your resolution here
  25. float XCoord <
  26. string UIName="Horizontal Pixel Resolution";
  27. string UIWidget="Spinner";
  28. float UIMin=0.0;
  29. float UIMax=7680.0;
  30. > = {1920};
  31. float YCoord <
  32. string UIName="Vertical Pixel Resolution";
  33. string UIWidget="Spinner";
  34. float UIMin=0.0;
  35. float UIMax=4320.0;
  36. > = {1080};
  37. ///////////////
  38. // CHOICES //
  39. ///////////////
  40. bool C_BLACKLEVEL <
  41. string UIName = "Enable Black Level";
  42. > = {false};
  43. bool C_CONTRASTCURVES <
  44. string UIName = "Enable Contrast";
  45. > = {false};
  46. bool C_VIBRANCE <
  47. string UIName = "Enable Vibrance";
  48. > = {false};
  49. //////////////////////////////
  50. // BLUR-SHIFT AND SHARPEN //
  51. //////////////////////////////
  52. #define BlurSamplingRange BlurRange
  53. #define SharpSamplingRange SharpRange
  54. #define SharpeningAmount SharpAmount
  55. #define ShiftSamplingRange ShiftRange
  56. float BlurRange <
  57. string UIName="Blur Sampling Range";
  58. string UIWidget="Spinner";
  59. float UIMin=0.0;
  60. float UIMax=1.0;
  61. > = {0.25};
  62. float SharpRange <
  63. string UIName="Sharp Sampling Range";
  64. string UIWidget="Spinner";
  65. float UIMin=0.0;
  66. float UIMax=1.0;
  67. > = {0.75};
  68. float SharpAmount <
  69. string UIName="Sharpening Amount";
  70. string UIWidget="Spinner";
  71. float UIMin=0.0;
  72. float UIMax=5.0;
  73. > = {1.5};
  74. float ShiftRange <
  75. string UIName="Shift Sampling Range";
  76. string UIWidget="Spinner";
  77. float UIMin=0.0;
  78. float UIMax=1.0;
  79. > = {0.25};
  80. //////////////
  81. // NOISE //
  82. //////////////
  83. float NoiseAmountExt <
  84. string UIName="Noise Amount - Exterior";
  85. string UIWidget="Spinner";
  86. float UIMin=0.0;
  87. float UIMax=1.0;
  88. > = {0.0};
  89. float NoiseAmountInt <
  90. string UIName="Noise Amount - Interior";
  91. string UIWidget="Spinner";
  92. float UIMin=0.0;
  93. float UIMax=1.0;
  94. > = {0.0};
  95. float NoiseFinenessExt <
  96. string UIName="Noise Fineness - Exterior";
  97. string UIWidget="Spinner";
  98. float UIMin=0.0;
  99. float UIMax=100.0;
  100. > = {50};
  101. float NoiseFinenessInt <
  102. string UIName="Noise Fineness - Interior";
  103. string UIWidget="Spinner";
  104. float UIMin=0.0;
  105. float UIMax=100.0;
  106. > = {50};
  107. //////////////////
  108. // CONTRAST //
  109. //////////////////
  110. float ContrastCurveDayExt <
  111. string UIName="Contrast - Exterior Day";
  112. string UIWidget="Spinner";
  113. float UIMin=-1.0;
  114. float UIMax=1.0;
  115. > = {0};
  116. float ContrastCurveDayInt <
  117. string UIName="Contrast - Interior Day";
  118. string UIWidget="Spinner";
  119. float UIMin=-1.0;
  120. float UIMax=1.0;
  121. > = {0};
  122. float ContrastCurveNightExt <
  123. string UIName="Contrast - Exterior Night";
  124. string UIWidget="Spinner";
  125. float UIMin=-1.0;
  126. float UIMax=1.0;
  127. > = {0};
  128. float ContrastCurveNightInt <
  129. string UIName="Contrast - Interior Night";
  130. string UIWidget="Spinner";
  131. float UIMin=-1.0;
  132. float UIMax=1.0;
  133. > = {0};
  134. //////////////////
  135. // VIBRANCE //
  136. //////////////////
  137. float VibranceDayExt <
  138. string UIName="Vibrance - Exterior Day";
  139. string UIWidget="Spinner";
  140. float UIMin=-1.0;
  141. float UIMax=1.0;
  142. > = {0};
  143. float VibranceDayInt <
  144. string UIName="Vibrance - Interior Day";
  145. string UIWidget="Spinner";
  146. float UIMin=-1.0;
  147. float UIMax=1.0;
  148. > = {0};
  149. float VibranceNightExt <
  150. string UIName="Vibrance - Exterior Night";
  151. string UIWidget="Spinner";
  152. float UIMin=-1.0;
  153. float UIMax=1.0;
  154. > = {0};
  155. float VibranceNightInt <
  156. string UIName="Vibrance - Interior Night";
  157. string UIWidget="Spinner";
  158. float UIMin=-1.0;
  159. float UIMax=1.0;
  160. > = {0};
  161. ////////////////////
  162. // LUMASHARPEN //
  163. ////////////////////
  164. float sharp_strengthExt <
  165. string UIName="LumaSharpen Strength - Exterior";
  166. string UIWidget="Spinner";
  167. float UIMin=0.0;
  168. float UIMax=5.0;
  169. > = {0.75};
  170. float sharp_strengthInt <
  171. string UIName="LumaSharpen Strength - Interior";
  172. string UIWidget="Spinner";
  173. float UIMin=0.0;
  174. float UIMax=5.0;
  175. > = {0.75};
  176. float sharp_clampExt <
  177. string UIName="LumaSharpen Clamp - Exterior";
  178. string UIWidget="Spinner";
  179. float UIMin=0.0;
  180. float UIMax=1.0;
  181. > = {0.025};
  182. float sharp_clampInt <
  183. string UIName="LumaSharpen Clamp - Interior";
  184. string UIWidget="Spinner";
  185. float UIMin=0.0;
  186. float UIMax=1.0;
  187. > = {0.025};
  188. ////////////////////
  189. // BLACK LEVELS //
  190. ////////////////////
  191. float BlackPointDayExt <
  192. string UIName="Black Level - Exterior Day";
  193. string UIWidget="Spinner";
  194. float UIMin=0.0;
  195. float UIMax=255.0;
  196. > = {5};
  197. float BlackPointDayInt <
  198. string UIName="Black Level - Interior Day";
  199. string UIWidget="Spinner";
  200. float UIMin=0.0;
  201. float UIMax=255.0;
  202. > = {5};
  203. float WhitePointDayExt <
  204. string UIName="White Level - Exterior Day";
  205. string UIWidget="Spinner";
  206. float UIMin=0.0;
  207. float UIMax=255.0;
  208. > = {235};
  209. float WhitePointDayInt <
  210. string UIName="White Level - Interior Day";
  211. string UIWidget="Spinner";
  212. float UIMin=0.0;
  213. float UIMax=255.0;
  214. > = {235};
  215. float BlackPointNightExt <
  216. string UIName="Black Level - Exterior Night";
  217. string UIWidget="Spinner";
  218. float UIMin=0.0;
  219. float UIMax=255.0;
  220. > = {5};
  221. float BlackPointNightInt <
  222. string UIName="Black Level - Interior Night";
  223. string UIWidget="Spinner";
  224. float UIMin=0.0;
  225. float UIMax=255.0;
  226. > = {5};
  227. float WhitePointNightExt <
  228. string UIName="White Level - Exterior Night";
  229. string UIWidget="Spinner";
  230. float UIMin=0.0;
  231. float UIMax=255.0;
  232. > = {235};
  233. float WhitePointNightInt <
  234. string UIName="White Level - Interior Night";
  235. string UIWidget="Spinner";
  236. float UIMin=0.0;
  237. float UIMax=255.0;
  238. > = {235};
  239. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  240. //--------------------------//
  241. // External parameters //
  242. // Do not modify //
  243. //--------------------------//
  244. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  245. // Keyboard controlled temporary variables.
  246. // Press and hold key 1,2,3...8 together with PageUp or PageDown to modify.
  247. // By default all set to 1.0
  248. float4 tempF1; //0,1,2,3
  249. float4 tempF2; //5,6,7,8
  250. float4 tempF3; //9,0
  251. float4 Timer; //x=generic timer in range 0..1, period of 16777216 ms (4.6 hours), w=frame time elapsed (in seconds)
  252. float4 ScreenSize; //x=Width, y=1/Width, z=ScreenScaleY, w=1/ScreenScaleY
  253. float ENightDayFactor; //changes in range 0..1, 0 means that night time, 1 - day time
  254. float EInteriorFactor; //changes 0 or 1. 0 means that exterior, 1 - interior
  255. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  256. //////////////////
  257. // TEXTURES //
  258. //////////////////
  259. texture2D texColor;
  260. texture2D texNoise;
  261. ///////////////////
  262. // SAMPLERS //
  263. ///////////////////
  264. sampler2D SamplerColor = sampler_state
  265. {
  266. Texture = <texColor>;
  267. MinFilter = LINEAR;
  268. MagFilter = LINEAR;
  269. MipFilter = NONE;
  270. AddressU = Clamp;
  271. AddressV = Clamp;
  272. SRGBTexture=FALSE;
  273. MaxMipLevel=0;
  274. MipMapLodBias=0;
  275. };
  276. sampler2D SamplerNoise = sampler_state
  277. {
  278. Texture = <texNoise>;
  279. MinFilter = LINEAR;
  280. MagFilter = LINEAR;
  281. MipFilter = NONE;
  282. AddressU = Wrap;
  283. AddressV = Wrap;
  284. SRGBTexture=FALSE;
  285. MaxMipLevel=0;
  286. MipMapLodBias=0;
  287. };
  288. //////////////////
  289. // STRUCTS //
  290. //////////////////
  291. struct VS_OUTPUT_POST
  292. {
  293. float4 vpos : POSITION;
  294. float2 txcoord : TEXCOORD0;
  295. };
  296. struct VS_INPUT_POST
  297. {
  298. float3 pos : POSITION;
  299. float2 txcoord : TEXCOORD0;
  300. };
  301. VS_OUTPUT_POST VS_PostProcess(VS_INPUT_POST IN)
  302. {
  303. VS_OUTPUT_POST OUT;
  304. float4 pos=float4(IN.pos.x,IN.pos.y,IN.pos.z,1.0);
  305. OUT.vpos=pos;
  306. OUT.txcoord.xy=IN.txcoord.xy;
  307. return OUT;
  308. }
  309. //////////////////
  310. // SHADERS //
  311. //////////////////
  312. float4 PS_ProcessLumaSharpen(VS_OUTPUT_POST IN, float2 vPos : VPOS, float2 tex : TEXCOORD0) : COLOR
  313. {
  314. float2 coord = IN.txcoord.xy;
  315. #define px (1/XCoord)
  316. #define py (1/YCoord)
  317. // Bias value
  318. float offset_bias = 1.0;
  319. float sharp_strength = sharp_strengthExt;
  320. float sharp_clamp = sharp_clampExt;
  321. if (EInteriorFactor)
  322. {
  323. sharp_strength = sharp_strengthInt;
  324. sharp_clamp = sharp_clampInt;
  325. };
  326. #define sharp_strength_luma (CoefLuma * sharp_strength)
  327. #define CoefLuma float4(0.2126, 0.7152, 0.0722, 0)
  328. half4 ori = tex2D(SamplerColor, coord.xy);
  329. [branch] if (any(frac(ori.rgb)))
  330. {
  331. #if SharpMethod == 1
  332. // -- Gaussian filter --
  333. // [ 2/9, 4/9, ] [ 1 , 2 , ]
  334. // [ 4/9, 8/9, 4/9] = [ 2 , 4 , 2 ]
  335. // [ , 2/9, 2/9] [ , 2 , 1 ]
  336. half4 blur_ori = tex2Dlod(SamplerColor, float4(tex,tex) + float4(-px,py,-px,py) / 3 * offset_bias); // North West
  337. blur_ori += tex2Dlod(SamplerColor, float4(tex,tex) + float4(px,-py,px,-py) / 3 * offset_bias); // South East
  338. //Divide by the number of texture fetches
  339. blur_ori /= 2;
  340. #endif
  341. // -- Pattern 2 -- A 9 tap gaussian using 4+1 texture fetches.
  342. #if SharpMethod == 2
  343. // -- Gaussian filter --
  344. // [ .25, .50, .25] [ 1 , 2 , 1 ]
  345. // [ .50, 1, .50] = [ 2 , 4 , 2 ]
  346. // [ .25, .50, .25] [ 1 , 2 , 1 ]
  347. half4 blur_ori = tex2Dlod(SamplerColor, float4(tex,tex) + float4(-px,py,-px,py) * 0.5 * offset_bias); // North West
  348. blur_ori += tex2Dlod(SamplerColor, float4(tex,tex) + float4(px,-py,px,-py) * 0.5 * offset_bias); // South East
  349. if (any((blur_ori.rgb / 2) - ori.rgb))
  350. {
  351. blur_ori += tex2Dlod(SamplerColor, float4(tex,tex) + float4(-px,-py,-px,-py) * 0.5 * offset_bias); // South West
  352. blur_ori += tex2Dlod(SamplerColor, float4(tex,tex) + float4(px,py,px,py) * 0.5 * offset_bias); // North East
  353. //Divide by the number of texture fetches
  354. blur_ori *= 0.25;;
  355. }
  356. //Divide by the number of texture fetches
  357. blur_ori *= 0.25;;
  358. #endif
  359. // -- Pattern 3 -- An experimental 17 tap gaussian using 4+1 texture fetches.
  360. #if SharpMethod == 3
  361. // -- Gaussian filter --
  362. // [ , 4 , 6 , , ]
  363. // [ ,16 ,24 ,16 , 4 ]
  364. // [ 6 ,24 ,50 ,24 , 6 ]
  365. // [ 4 ,16 ,24 ,16 , ]
  366. // [ , , 6 , 4 , ]
  367. half4 blur_ori = tex2Dlod(SamplerColor, float4(tex,tex) + float4(-0.4*px,1.2*py,-0.4*px,1.2*py) * offset_bias); // North North West
  368. blur_ori += tex2Dlod(SamplerColor, float4(tex,tex) + float4(0.4*px,-1.2*py,0.4*px,-1.2*py) * offset_bias); // South South East
  369. blur_ori += tex2Dlod(SamplerColor, float4(tex,tex) + float4(1.2*px,0.4*py,0,0) * offset_bias); // East North East
  370. blur_ori += tex2Dlod(SamplerColor, float4(tex,tex) + float4(-1.2*px,-0.4*py,0,0) * offset_bias); // West South West
  371. blur_ori += ori; // Probably not needed. Only serves to lessen the effect.
  372. blur_ori /= 5; //Divide by the number of texture fetches
  373. #endif
  374. // -- Pattern 4 -- A 9 tap high pass using 4+1 texture fetches.
  375. #if SharpMethod == 4
  376. // -- Gaussian filter --
  377. // [ .50, .50, .50] [ 1 , 1 , 1 ]
  378. // [ .50, , .50] = [ 1 , , 1 ]
  379. // [ .50, .50, .50] [ 1 , 1 , 1 ]
  380. half4 blur_ori = tex2Dlod(SamplerColor, float4(tex,tex) + float4(0.5 * -px,py,0.5 * -px,py) * offset_bias); // North North West
  381. blur_ori += tex2Dlod(SamplerColor, float4(tex,tex) + float4(0.5 * px,-py,0.5 * px,-py)); // South South East
  382. blur_ori += tex2Dlod(SamplerColor, float4(tex,tex) + float4(-px,0.5 * -py,-px,0.5 * -py)); // West South West
  383. blur_ori += tex2Dlod(SamplerColor, float4(tex,tex) + float4(px,0.5 * py,px,0.5 * py) * offset_bias); // East North East
  384. blur_ori += (2 * ori); // Probably not needed. Only serves to lessen the effect.
  385. blur_ori /= 6; //Divide by the number of texture fetches
  386. #endif
  387. // -- Calculate the sharpening --
  388. half sharp = ori - blur_ori;
  389. // -- Adjust strength of the sharpening --
  390. sharp = dot(sharp, sharp_strength_luma);
  391. // -- Clamping the maximum amount of sharpening to prevent halo artifacts --
  392. sharp = clamp(sharp, -sharp_clamp, sharp_clamp);
  393. // -- Combining the values to get the final sharpened pixel --
  394. half4 done = ori + sharp;
  395. return done;
  396. }
  397. else
  398. {
  399. return ori;
  400. }
  401. }
  402. float4 PS_ProcessBlur(VS_OUTPUT_POST IN, float2 vPos : VPOS) : COLOR
  403. {
  404. float4 res;
  405. float4 coord=0.0;
  406. coord.xy=IN.txcoord.xy;
  407. float4 origcolor;
  408. coord.w=0.0;
  409. origcolor=tex2Dlod(SamplerColor, coord);
  410. float2 offset[16]=
  411. {
  412. float2(1.0, 1.0),
  413. float2(-1.0, -1.0),
  414. float2(-1.0, 1.0),
  415. float2(1.0, -1.0),
  416. float2(1.0, 0.0),
  417. float2(-1.0, 0.0),
  418. float2(0.0, 1.0),
  419. float2(0.0, -1.0),
  420. float2(1.41, 0.0),
  421. float2(-1.41, 0.0),
  422. float2(0.0, 1.41),
  423. float2(0.0, -1.41),
  424. float2(1.41, 1.41),
  425. float2(-1.41, -1.41),
  426. float2(-1.41, 1.41),
  427. float2(1.41, -1.41)
  428. };
  429. int i=0;
  430. float4 tcol=origcolor;
  431. float invscreensize=1.0/ScreenSize;
  432. for (i=0; i<16; i++)
  433. {
  434. float2 tdir=offset[i].xy;
  435. coord.xy=IN.txcoord.xy+tdir.xy*invscreensize*BlurSamplingRange;
  436. float4 ct=tex2Dlod(SamplerColor, coord);
  437. tcol+=ct;
  438. }
  439. tcol*=0.05882353;
  440. res.xyz=tcol.xyz;
  441. res.w=1.0;
  442. return res;
  443. }
  444. float4 PS_ProcessSharpen(VS_OUTPUT_POST IN, float2 vPos : VPOS) : COLOR
  445. {
  446. float4 res;
  447. float4 coord=0.0;
  448. coord.xy=IN.txcoord.xy;
  449. float4 origcolor;
  450. coord.w=0.0;
  451. origcolor=tex2Dlod(SamplerColor, coord);
  452. float2 offset[8]=
  453. {
  454. float2(1.0, 1.0),
  455. float2(-1.0, -1.0),
  456. float2(-1.0, 1.0),
  457. float2(1.0, -1.0),
  458. float2(1.41, 0.0),
  459. float2(-1.41, 0.0),
  460. float2(0.0, 1.41),
  461. float2(0.0, -1.41)
  462. };
  463. int i=0;
  464. float4 tcol=origcolor;
  465. float invscreensize=1.0/ScreenSize;
  466. for (i=0; i<8; i++)
  467. {
  468. float2 tdir=offset[i].xy;
  469. coord.xy=IN.txcoord.xy+tdir.xy*invscreensize*SharpSamplingRange;
  470. float4 ct=tex2Dlod(SamplerColor, coord);
  471. tcol+=ct;
  472. }
  473. tcol*=0.1111;
  474. //sharp
  475. #ifdef ESHARPENING
  476. #ifdef ESHARPENINGCOLOR
  477. //color
  478. res=origcolor*(1.0+((origcolor-tcol)*SharpeningAmount));
  479. #else
  480. //non color
  481. float difffact=dot((origcolor.xyz-tcol.xyz), 0.333);
  482. res=origcolor*(1.0+difffact*SharpeningAmount);
  483. #endif
  484. //less sharpening for bright pixels
  485. float rgray=origcolor.z;
  486. rgray=pow(rgray, 3.0);
  487. res=lerp(res, origcolor, saturate(rgray));
  488. #endif
  489. res.w=1.0;
  490. return res;
  491. }
  492. float4 PS_ProcessShift(VS_OUTPUT_POST IN, float2 vPos : VPOS) : COLOR
  493. {
  494. float4 res;
  495. float4 coord=0.0;
  496. coord.xy=IN.txcoord.xy;
  497. float4 origcolor;
  498. coord.w=0.0;
  499. origcolor=tex2Dlod(SamplerColor, coord);
  500. int i=0;
  501. #ifdef ECOLORSHIFT
  502. float4 tcol=origcolor;
  503. float2 invscreensize=1.0/ScreenSize.x;
  504. invscreensize.y=invscreensize.y/ScreenSize.z;
  505. coord.xy=IN.txcoord.xy;
  506. origcolor=tex2Dlod(SamplerColor, coord);
  507. res.y=origcolor.y;
  508. coord.xy=IN.txcoord.xy;
  509. coord.y-=invscreensize*ShiftSamplingRange;
  510. origcolor=tex2Dlod(SamplerColor, coord);
  511. res.x=origcolor.x;
  512. coord.xy=IN.txcoord.xy;
  513. coord.y+=invscreensize*ShiftSamplingRange;
  514. origcolor=tex2Dlod(SamplerColor, coord);
  515. res.z=origcolor.z;
  516. #endif
  517. res.w=1.0;
  518. return res;
  519. }
  520. float4 PS_ProcessContrast(VS_OUTPUT_POST IN, float2 vPos : VPOS) : COLOR
  521. {
  522. float ContrastCurve = lerp(ContrastCurveNightExt, ContrastCurveDayExt, ENightDayFactor);
  523. if (EInteriorFactor)
  524. {
  525. ContrastCurve = lerp(ContrastCurveNightInt, ContrastCurveDayInt, ENightDayFactor);
  526. };
  527. float4 res;
  528. float3 origcolor=tex2D(SamplerColor, IN.txcoord.xy);
  529. float3 lumCoeff = float3(0.212656, 0.715158, 0.072186); //Calculate luma with these values
  530. float luma = dot(lumCoeff, origcolor.rgb);
  531. float3 chroma = origcolor.rgb - luma;
  532. float Curves_contrast_blend = ContrastCurve;
  533. float PI = 3.1415926535897932384626433832795;
  534. float x = luma; //If the curve should be applied to Luma
  535. x = x - 0.5;
  536. x = x / ((abs(x)*1.25) + 0.375 ) + 0.5;
  537. x = lerp(luma, x, Curves_contrast_blend); //if the curve should be applied to both Luma and Chroma
  538. if (C_CONTRASTCURVES==true)
  539. {
  540. res.rgb = x + chroma; //Blend by Curves_contrast
  541. }
  542. if (C_CONTRASTCURVES==false)
  543. {
  544. res.rgb = origcolor.rgb;
  545. }
  546. res.w=1.0;
  547. return res;
  548. }
  549. float4 PS_ProcessVibrance(VS_OUTPUT_POST IN, float2 vPos : VPOS) : COLOR
  550. {
  551. float Vibrance = lerp(VibranceNightExt, VibranceDayExt, ENightDayFactor);
  552. if (EInteriorFactor)
  553. {
  554. Vibrance = lerp(VibranceNightInt, VibranceDayInt, ENightDayFactor);
  555. };
  556. float4 res;
  557. float3 origcolor = tex2D(SamplerColor, IN.txcoord.xy);
  558. float3 lumCoeff = float3(0.212656, 0.715158, 0.072186); //Calculate luma with these values
  559. float max_color = max(origcolor.r, max(origcolor.g,origcolor.b)); //Find the strongest color
  560. float min_color = min(origcolor.r, min(origcolor.g,origcolor.b)); //Find the weakest color
  561. float color_saturation = max_color - min_color; //Saturation is the difference between min and max
  562. float luma = dot(lumCoeff, origcolor.rgb); //Calculate luma (grey)
  563. if (C_VIBRANCE==true)
  564. {
  565. res.rgb = lerp(luma, origcolor.rgb, (1.0 + (Vibrance * (1.0 - (sign(Vibrance) * color_saturation))))); //Extrapolate between luma and original by 1 + (1-saturation) - current
  566. }
  567. if (C_VIBRANCE==false)
  568. {
  569. res.rgb = origcolor.rgb;
  570. }
  571. res.w=1.0;
  572. return res;
  573. }
  574. float4 PS_ProcessNoise(VS_OUTPUT_POST IN, float2 vPos : VPOS) : COLOR
  575. {
  576. float NoiseAmount = NoiseAmountExt;
  577. float NoiseFineness = NoiseFinenessExt;
  578. if (EInteriorFactor)
  579. {
  580. NoiseAmount = NoiseAmountInt;
  581. NoiseFineness = NoiseFinenessInt;
  582. };
  583. float4 coord=0.0;
  584. coord.xy=IN.txcoord.xy;
  585. coord.w=0.0;
  586. #define noise_strength_luma (CoefLuma * NoiseAmount)
  587. #define CoefLuma float4(0.2126, 0.7152, 0.0722, 0)
  588. float4 tcol=tex2Dlod(SamplerColor, coord);
  589. float origgray=max(tcol.x, tcol.y);
  590. origgray=max(origgray, tcol.z);
  591. coord.xy=IN.txcoord.xy*NoiseFineness + frac(Timer.x * 100000.0 + Timer.x);
  592. float4 cnoi=tex2Dlod(SamplerNoise, coord);
  593. #if NoiseMethod == 1
  594. tcol=lerp(tcol, (cnoi.x+0.5)*tcol, noise_strength_luma*saturate(1.0-origgray*0.5));
  595. #endif
  596. #if NoiseMethod == 0
  597. tcol=lerp(tcol, (cnoi.x+0.5)*tcol, NoiseAmount*saturate(1.0-origgray*0.5));
  598. #endif
  599. tcol.w=1.0;
  600. return tcol;
  601. }
  602. float4 PS_LevelsPass(VS_OUTPUT_POST IN, float2 vPos : VPOS) : COLOR
  603. {
  604. float Levels_black_point = lerp(BlackPointNightExt, BlackPointDayExt, ENightDayFactor);
  605. float Levels_white_point = lerp(WhitePointNightExt, WhitePointDayExt, ENightDayFactor);
  606. if (EInteriorFactor)
  607. {
  608. Levels_black_point = lerp(BlackPointNightInt, BlackPointDayInt, ENightDayFactor);
  609. Levels_white_point = lerp(WhitePointNightInt, WhitePointDayInt, ENightDayFactor);
  610. };
  611. #define black_point_float ( Levels_black_point / 255.0 )
  612. #define white_point_float ( 255.0 / (Levels_white_point - Levels_black_point))
  613. float4 res;
  614. float3 origcolor = tex2D(SamplerColor, IN.txcoord.xy);
  615. if (C_BLACKLEVEL==true)
  616. {
  617. res.rgb = origcolor.rgb * white_point_float - (black_point_float * white_point_float);
  618. }
  619. if (C_BLACKLEVEL==false)
  620. {
  621. res.rgb = origcolor.rgb;
  622. }
  623. res.w=1.0;
  624. return res;
  625. }
  626. ///////////////////////
  627. // TECHNIQUES //
  628. ///////////////////////
  629. technique PostProcess
  630. {
  631. pass P0
  632. {
  633. VertexShader = compile vs_3_0 VS_PostProcess();
  634. PixelShader = compile ps_3_0 PS_ProcessNoise();
  635. DitherEnable=FALSE;
  636. ZEnable=FALSE;
  637. CullMode=NONE;
  638. ALPHATESTENABLE=FALSE;
  639. SEPARATEALPHABLENDENABLE=FALSE;
  640. AlphaBlendEnable=FALSE;
  641. StencilEnable=FALSE;
  642. FogEnable=FALSE;
  643. SRGBWRITEENABLE=FALSE;
  644. }
  645. }
  646. technique PostProcess2
  647. {
  648. pass P0
  649. {
  650. VertexShader = compile vs_3_0 VS_PostProcess();
  651. PixelShader = compile ps_3_0 PS_ProcessBlur();
  652. DitherEnable=FALSE;
  653. ZEnable=FALSE;
  654. CullMode=NONE;
  655. ALPHATESTENABLE=FALSE;
  656. SEPARATEALPHABLENDENABLE=FALSE;
  657. AlphaBlendEnable=FALSE;
  658. StencilEnable=FALSE;
  659. FogEnable=FALSE;
  660. SRGBWRITEENABLE=FALSE;
  661. }
  662. }
  663. technique PostProcess3
  664. {
  665. pass P0
  666. {
  667. VertexShader = compile vs_3_0 VS_PostProcess();
  668. PixelShader = compile ps_3_0 PS_ProcessSharpen();
  669. DitherEnable=FALSE;
  670. ZEnable=FALSE;
  671. CullMode=NONE;
  672. ALPHATESTENABLE=FALSE;
  673. SEPARATEALPHABLENDENABLE=FALSE;
  674. AlphaBlendEnable=FALSE;
  675. StencilEnable=FALSE;
  676. FogEnable=FALSE;
  677. SRGBWRITEENABLE=FALSE;
  678. }
  679. }
  680. technique PostProcess4
  681. {
  682. pass P0
  683. {
  684. VertexShader = compile vs_3_0 VS_PostProcess();
  685. PixelShader = compile ps_3_0 PS_ProcessShift();
  686. DitherEnable=FALSE;
  687. ZEnable=FALSE;
  688. CullMode=NONE;
  689. ALPHATESTENABLE=FALSE;
  690. SEPARATEALPHABLENDENABLE=FALSE;
  691. AlphaBlendEnable=FALSE;
  692. StencilEnable=FALSE;
  693. FogEnable=FALSE;
  694. SRGBWRITEENABLE=FALSE;
  695. }
  696. }
  697. technique PostProcess5
  698. {
  699. pass P0
  700. {
  701. VertexShader = compile vs_3_0 VS_PostProcess();
  702. PixelShader = compile ps_3_0 PS_ProcessContrast();
  703. DitherEnable=FALSE;
  704. ZEnable=FALSE;
  705. CullMode=NONE;
  706. ALPHATESTENABLE=FALSE;
  707. SEPARATEALPHABLENDENABLE=FALSE;
  708. AlphaBlendEnable=FALSE;
  709. StencilEnable=FALSE;
  710. FogEnable=FALSE;
  711. SRGBWRITEENABLE=FALSE;
  712. }
  713. }
  714. technique PostProcess6
  715. {
  716. pass P0
  717. {
  718. VertexShader = compile vs_3_0 VS_PostProcess();
  719. PixelShader = compile ps_3_0 PS_ProcessVibrance();
  720. DitherEnable=FALSE;
  721. ZEnable=FALSE;
  722. CullMode=NONE;
  723. ALPHATESTENABLE=FALSE;
  724. SEPARATEALPHABLENDENABLE=FALSE;
  725. AlphaBlendEnable=FALSE;
  726. StencilEnable=FALSE;
  727. FogEnable=FALSE;
  728. SRGBWRITEENABLE=FALSE;
  729. }
  730. }
  731. technique PostProcess7
  732. {
  733. pass P0
  734. {
  735. VertexShader = compile vs_3_0 VS_PostProcess();
  736. PixelShader = compile ps_3_0 PS_ProcessLumaSharpen();
  737. DitherEnable=FALSE;
  738. ZEnable=FALSE;
  739. CullMode=NONE;
  740. ALPHATESTENABLE=FALSE;
  741. SEPARATEALPHABLENDENABLE=FALSE;
  742. AlphaBlendEnable=FALSE;
  743. StencilEnable=FALSE;
  744. FogEnable=FALSE;
  745. SRGBWRITEENABLE=FALSE;
  746. }
  747. }
  748. technique PostProcess8
  749. {
  750. pass P0
  751. {
  752. VertexShader = compile vs_3_0 VS_PostProcess();
  753. PixelShader = compile ps_3_0 PS_LevelsPass();
  754. DitherEnable=FALSE;
  755. ZEnable=FALSE;
  756. CullMode=NONE;
  757. ALPHATESTENABLE=FALSE;
  758. SEPARATEALPHABLENDENABLE=FALSE;
  759. AlphaBlendEnable=FALSE;
  760. StencilEnable=FALSE;
  761. FogEnable=FALSE;
  762. SRGBWRITEENABLE=FALSE;
  763. }
  764. }