Advertisement
Guest User

3D LUT

a guest
Apr 27th, 2021
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.83 KB | None | 0 0
  1. //++++++++++++++++++++++++++++++++++++++++++++
  2. // ENBSeries effect file
  3. // visit http://enbdev.com for updates
  4. // Copyright (c) 2007-2013 Boris Vorontsov
  5. //++++++++++++++++++++++++++++++++++++++++++++
  6.  
  7.  
  8. // 3D ENABLER TRUE OR FALSE
  9. bool 3dlut <
  10. string UIName="Enable LUT";
  11. string UIWidget="Toggle";
  12. > = true;
  13.  
  14. //post processing mode. Change value (could be 1, 2, 3, 4). Every mode have own internal parameters, look below
  15. #ifndef POSTPROCESS
  16. #define POSTPROCESS 2
  17. #endif
  18.  
  19. //use original game processing first, then mine
  20. //#define APPLYGAMECOLORCORRECTION
  21.  
  22.  
  23.  
  24. //+++++++++++++++++++++++++++++
  25. //internal parameters, can be modified
  26. //+++++++++++++++++++++++++++++
  27. //modify these values to tweak various color processing
  28.  
  29.  
  30. //POSTPROCESS 2
  31. //float EBrightnessV2=2.5;
  32. float EBrightnessV2Day
  33. <
  34. string UIName="Brightness Day";
  35. string UIWidget="Spinner";
  36. float UIMin=0.0;
  37. float UIMax=1.0;
  38. > = {1.0};
  39.  
  40. float EBrightnessV2Night
  41. <
  42. string UIName="Brightness Night";
  43. string UIWidget="Spinner";
  44. float UIMin=0.0;
  45. float UIMax=1.0;
  46. > = {1.0};
  47.  
  48. float EBrightnessV2Interior
  49. <
  50. string UIName="Brightness Interior";
  51. string UIWidget="Spinner";
  52. float UIMin=0.0;
  53. float UIMax=1.0;
  54. > = {1.0};
  55.  
  56. float EAdaptationMinV2Day
  57. <
  58. string UIName="Adaptation Day Min";
  59. string UIWidget="Spinner";
  60. float UIMin=0.0;
  61. float UIMax=1.0;
  62. > = {0.08};
  63.  
  64. float EAdaptationMinV2Night
  65. <
  66. string UIName="Adaptation Night Min";
  67. string UIWidget="Spinner";
  68. float UIMin=0.0;
  69. float UIMax=1.0;
  70. > = {0.08};
  71.  
  72. float EAdaptationMinV2Interior
  73. <
  74. string UIName="Adaptation Interior Min";
  75. string UIWidget="Spinner";
  76. float UIMin=0.0;
  77. float UIMax=1.0;
  78. > = {0.08};
  79.  
  80.  
  81. float EAdaptationMaxV2Day
  82. <
  83. string UIName="Adaptation Day Max";
  84. string UIWidget="Spinner";
  85. float UIMin=0.0;
  86. float UIMax=1.0;
  87. > = {0.13};
  88.  
  89. float EAdaptationMaxV2Night
  90. <
  91. string UIName="Adaptation Night Max";
  92. string UIWidget="Spinner";
  93. float UIMin=0.0;
  94. float UIMax=1.0;
  95. > = {0.13};
  96.  
  97. float EAdaptationMaxV2Interior
  98. <
  99. string UIName="Adaptation Interior Max";
  100. string UIWidget="Spinner";
  101. float UIMin=0.0;
  102. float UIMax=1.0;
  103. > = {0.13};
  104.  
  105. float EToneMappingCurveV2Day
  106. <
  107. string UIName="ToneMapping Curve Day";
  108. string UIWidget="Spinner";
  109. float UIMin=0.0;
  110. float UIMax=100.0;
  111. > = {7.5};
  112.  
  113. float EToneMappingCurveV2Night
  114. <
  115. string UIName="ToneMapping Curve Night";
  116. string UIWidget="Spinner";
  117. float UIMin=0.0;
  118. float UIMax=100.0;
  119. > = {10.0};
  120.  
  121. float EToneMappingCurveV2Interior
  122. <
  123. string UIName="ToneMapping Curve Interior";
  124. string UIWidget="Spinner";
  125. float UIMin=0.0;
  126. float UIMax=100.0;
  127. > = {8.5};
  128.  
  129.  
  130. float EIntensityContrastV2Day
  131. <
  132. string UIName="Contrast Day";
  133. string UIWidget="Spinner";
  134. float UIMin=0.0;
  135. float UIMax=10.0;
  136. > = {1.35};
  137.  
  138. float EIntensityContrastV2Night
  139. <
  140. string UIName="Contrast Night";
  141. string UIWidget="Spinner";
  142. float UIMin=0.0;
  143. float UIMax=10.0;
  144. > = {1.25};
  145.  
  146. float EIntensityContrastV2Interior
  147. <
  148. string UIName="Contrast Interior";
  149. string UIWidget="Spinner";
  150. float UIMin=0.0;
  151. float UIMax=10.0;
  152. > = {1.3};
  153.  
  154. float EColorSaturationV2Day
  155. <
  156. string UIName="Saturation Day";
  157. string UIWidget="Spinner";
  158. float UIMin=0.0;
  159. float UIMax=10.0;
  160. > = {1.25};
  161.  
  162. float EColorSaturationV2Night
  163. <
  164. string UIName="Saturation Night";
  165. string UIWidget="Spinner";
  166. float UIMin=0.0;
  167. float UIMax=10.0;
  168. > = {0.9};
  169.  
  170. float EColorSaturationV2Interior
  171. <
  172. string UIName="Saturation Interior";
  173. string UIWidget="Spinner";
  174. float UIMin=0.0;
  175. float UIMax=10.0;
  176. > = {1.0};
  177.  
  178. float EToneMappingOversaturationV2Day
  179. <
  180. string UIName="Overbright Dampening Day";
  181. string UIWidget="Spinner";
  182. float UIMin=0.0;
  183. float UIMax=100.0;
  184. > = {75.0};
  185.  
  186. float EToneMappingOversaturationV2Night
  187. <
  188. string UIName="Overbright Dampening Night";
  189. string UIWidget="Spinner";
  190. float UIMin=0.0;
  191. float UIMax=100.0;
  192. > = {50.0};
  193.  
  194. float EToneMappingOversaturationV2Interior
  195. <
  196. string UIName="Overbright Dampening Interior";
  197. string UIWidget="Spinner";
  198. float UIMin=0.0;
  199. float UIMax=100.0;
  200. > = {30.0};
  201.  
  202. //parameters for ldr color correction, if enabled
  203. float ECCGamma
  204. <
  205. string UIName="CC: Gamma";
  206. string UIWidget="Spinner";
  207. float UIMin=0.2;//not zero!!!
  208. float UIMax=5.0;
  209. > = {1.0};
  210.  
  211. float ECCInBlack
  212. <
  213. string UIName="CC: In black";
  214. string UIWidget="Spinner";
  215. float UIMin=0.0;
  216. float UIMax=1.0;
  217. > = {0.0};
  218.  
  219. float ECCInWhite
  220. <
  221. string UIName="CC: In white";
  222. string UIWidget="Spinner";
  223. float UIMin=0.0;
  224. float UIMax=1.0;
  225. > = {1.0};
  226.  
  227. float ECCOutBlack
  228. <
  229. string UIName="CC: Out black";
  230. string UIWidget="Spinner";
  231. float UIMin=0.0;
  232. float UIMax=1.0;
  233. > = {0.0};
  234.  
  235. float ECCOutWhite
  236. <
  237. string UIName="CC: Out white";
  238. string UIWidget="Spinner";
  239. float UIMin=0.0;
  240. float UIMax=1.0;
  241. > = {1.0};
  242.  
  243. float ECCBrightness
  244. <
  245. string UIName="CC: Brightness";
  246. string UIWidget="Spinner";
  247. float UIMin=0.0;
  248. float UIMax=10.0;
  249. > = {1.0};
  250.  
  251. float ECCContrastGrayLevel
  252. <
  253. string UIName="CC: Contrast gray level";
  254. string UIWidget="Spinner";
  255. float UIMin=0.01;
  256. float UIMax=0.99;
  257. > = {0.5};
  258.  
  259. float ECCContrast
  260. <
  261. string UIName="CC: Contrast";
  262. string UIWidget="Spinner";
  263. float UIMin=0.0;
  264. float UIMax=10.0;
  265. > = {1.0};
  266.  
  267. float ECCSaturation
  268. <
  269. string UIName="CC: Saturation";
  270. string UIWidget="Spinner";
  271. float UIMin=0.0;
  272. float UIMax=10.0;
  273. > = {1.0};
  274.  
  275. float ECCDesaturateShadows
  276. <
  277. string UIName="CC: Desaturate shadows";
  278. string UIWidget="Spinner";
  279. float UIMin=0.0;
  280. float UIMax=1.0;
  281. > = {0.0};
  282.  
  283. float3 ECCColorBalanceShadows <
  284. string UIName="CC: Color balance shadows";
  285. string UIWidget="Color";
  286. > = {0.5, 0.5, 0.5};
  287.  
  288. float3 ECCColorBalanceHighlights <
  289. string UIName="CC: Color balance highlights";
  290. string UIWidget="Color";
  291. > = {0.5, 0.5, 0.5};
  292.  
  293. float3 ECCChannelMixerR <
  294. string UIName="CC: Channel mixer R";
  295. string UIWidget="Color";
  296. > = {1.0, 0.0, 0.0};
  297.  
  298. float3 ECCChannelMixerG <
  299. string UIName="CC: Channel mixer G";
  300. string UIWidget="Color";
  301. > = {0.0, 1.0, 0.0};
  302.  
  303. float3 ECCChannelMixerB <
  304. string UIName="CC: Channel mixer B";
  305. string UIWidget="Color";
  306. > = {0.0, 0.0, 1.0};
  307.  
  308.  
  309.  
  310. //+++++++++++++++++++++++++++++
  311. //external parameters, do not modify
  312. //+++++++++++++++++++++++++++++
  313. //keyboard controlled temporary variables (in some versions exists in the config file). Press and hold key 1,2,3...8 together with PageUp or PageDown to modify. By default all set to 1.0
  314. float4 tempF1; //0,1,2,3
  315. float4 tempF2; //5,6,7,8
  316. float4 tempF3; //9,0
  317. //x=generic timer in range 0..1, period of 16777216 ms (4.6 hours), w=frame time elapsed (in seconds)
  318. float4 Timer;
  319. //x=Width, y=1/Width, z=ScreenScaleY, w=1/ScreenScaleY
  320. float4 ScreenSize;
  321. //changes in range 0..1, 0 means that night time, 1 - day time
  322. float ENightDayFactor;
  323. //changes 0 or 1. 0 means that exterior, 1 - interior
  324. float EInteriorFactor;
  325. //enb version of bloom applied, ignored if original post processing used
  326. float EBloomAmount;
  327.  
  328.  
  329. //+++++++++++++++++++++++++++++
  330. // LUT texture helper
  331. //+++++++++++++++++++++++++++++
  332.  
  333.  
  334. #define LOAD_TEXTURE( Name, Path, sampler, UV )
  335. texture2D tex##Name <string ResourceName= #Path ; >;
  336. sampler2D Sampler##Name = sampler_state
  337. {
  338. Texture = < tex##Name >;
  339. MinFilter = sampler;
  340. MagFilter = sampler;
  341. MipFilter = NONE;
  342. AddressU = UV;
  343. AddressV = UV;
  344. SRGBTexture=FALSE;
  345. }
  346.  
  347. LOAD_TEXTURE( LUT_Day, LUT_Day.png, LINEAR, CLAMP ); // day
  348. LOAD_TEXTURE( LUT_Night, LUT_Night.png, LINEAR, CLAMP ); // night
  349. LOAD_TEXTURE( LUT_Int, LUT_Int.png, LINEAR, CLAMP ); // interior
  350.  
  351.  
  352. //+++++++++++++++++++++++++++++
  353. //
  354. //+++++++++++++++++++++++++++++
  355.  
  356.  
  357. texture2D texs0;//color falloutnv
  358. texture2D texs1;//bloom falloutnv
  359. texture2D texs3;//bloom enb
  360. texture2D texs4;//adaptation enb
  361. texture2D texs7;//palette enb
  362.  
  363. sampler2D _s0 = sampler_state
  364. {
  365. Texture = <texs0>;
  366. MinFilter = POINT;//
  367. MagFilter = POINT;//
  368. MipFilter = NONE;//LINEAR;
  369. AddressU = Clamp;
  370. AddressV = Clamp;
  371. SRGBTexture=FALSE;
  372. MaxMipLevel=0;
  373. MipMapLodBias=0;
  374. };
  375.  
  376. sampler2D _s1 = sampler_state
  377. {
  378. Texture = <texs1>;
  379. MinFilter = LINEAR;//
  380. MagFilter = LINEAR;//
  381. MipFilter = NONE;//LINEAR;
  382. AddressU = Clamp;
  383. AddressV = Clamp;
  384. SRGBTexture=FALSE;
  385. MaxMipLevel=0;
  386. MipMapLodBias=0;
  387. };
  388.  
  389. sampler2D _s3 = sampler_state
  390. {
  391. Texture = <texs3>;
  392. MinFilter = LINEAR;//
  393. MagFilter = LINEAR;//
  394. MipFilter = NONE;//LINEAR;
  395. AddressU = Clamp;
  396. AddressV = Clamp;
  397. SRGBTexture=FALSE;
  398. MaxMipLevel=0;
  399. MipMapLodBias=0;
  400. };
  401.  
  402. sampler2D _s4 = sampler_state
  403. {
  404. Texture = <texs4>;
  405. MinFilter = LINEAR;//
  406. MagFilter = LINEAR;//
  407. MipFilter = NONE;//LINEAR;
  408. AddressU = Clamp;
  409. AddressV = Clamp;
  410. SRGBTexture=FALSE;
  411. MaxMipLevel=0;
  412. MipMapLodBias=0;
  413. };
  414.  
  415. sampler2D _s7 = sampler_state
  416. {
  417. Texture = <texs7>;
  418. MinFilter = LINEAR;
  419. MagFilter = LINEAR;
  420. MipFilter = NONE;
  421. AddressU = Clamp;
  422. AddressV = Clamp;
  423. SRGBTexture=FALSE;
  424. MaxMipLevel=0;
  425. MipMapLodBias=0;
  426. };
  427.  
  428. struct VS_OUTPUT_POST
  429. {
  430. float4 vpos : POSITION;
  431. float2 txcoord0 : TEXCOORD0;
  432. };
  433. struct VS_INPUT_POST
  434. {
  435. float3 pos : POSITION;
  436. float2 txcoord0 : TEXCOORD0;
  437. };
  438.  
  439.  
  440.  
  441. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  442. //
  443. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  444. VS_OUTPUT_POST VS_Quad(VS_INPUT_POST IN)
  445. {
  446. VS_OUTPUT_POST OUT;
  447.  
  448. OUT.vpos=float4(IN.pos.x,IN.pos.y,IN.pos.z,1.0);
  449.  
  450. OUT.txcoord0.xy=IN.txcoord0.xy;
  451.  
  452. return OUT;
  453. }
  454.  
  455.  
  456. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  457. // LUT Function
  458. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  459.  
  460.  
  461. static const float2 CLut_Size = float2(1024.0, 32.0);
  462.  
  463. float3 CLutFunc( float3 colorIN, sampler2D LutSampler ) {
  464. float2 CLut_pSize = 1.0 / CLut_Size;
  465. float4 CLut_UV;
  466. colorIN = saturate(colorIN) * ( CLut_Size.y - 1.0);
  467. CLut_UV.w = floor(colorIN.b);
  468. CLut_UV.xy = (colorIN.rg + 0.5) * CLut_pSize;
  469. CLut_UV.x += CLut_UV.w * CLut_pSize.y;
  470. CLut_UV.z = CLut_UV.x + CLut_pSize.y;
  471. return lerp( tex2Dlod(LutSampler, CLut_UV.xyzz).rgb,
  472. tex2Dlod(LutSampler, CLut_UV.zyzz).rgb, colorIN.b - CLut_UV.w);
  473. }
  474.  
  475. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  476. //
  477. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  478.  
  479.  
  480. //falloutnv shader specific externals, do not modify
  481. float4 _c1 : register(c1);
  482. float4 _c2 : register(c2);
  483. float4 _c19 : register(c19);
  484. float4 _c20 : register(c20);
  485. float4 _c22 : register(c22);
  486.  
  487. float4 PS_C1DAE3F7(VS_OUTPUT_POST IN, float2 vPos : VPOS) : COLOR
  488. {
  489. float4 _oC0=0.0; //output
  490.  
  491. float4 r0;
  492. float4 r1;
  493. float4 r2;
  494. float4 r3;
  495. float4 r4;
  496. float4 r5;
  497. float4 r6;
  498. float4 r7;
  499. float4 r8;
  500. float4 r9;
  501. float4 r10;
  502. float4 r11;
  503.  
  504.  
  505. float4 _v0=0.0;
  506.  
  507. _v0.xy=IN.txcoord0.xy;
  508. r1=tex2D(_s0, _v0.xy); //color
  509.  
  510. //apply bloom
  511. float4 xcolorbloom=tex2D(_s3, _v0.xy);
  512.  
  513. xcolorbloom.xyz=xcolorbloom-r1;
  514. xcolorbloom.xyz=max(xcolorbloom, 0.0);
  515. r1.xyz+=xcolorbloom*EBloomAmount;
  516.  
  517. r11=r1; //my bypass
  518. _oC0.xyz=r1.xyz; //for future use without game color corrections
  519.  
  520.  
  521. #ifdef APPLYGAMECOLORCORRECTION
  522. //apply original
  523.  
  524. // float3 BlurScale;
  525. // float4 Cinematic;
  526. // sampler2D DestBlend;
  527. // float4 Fade;
  528. // float4 HDRParam;
  529. // sampler2D Src0;
  530. // float4 Tint;
  531. // Registers:
  532. // Name Reg Size
  533. // ------------ ----- ----
  534. // HDRParam c1 1
  535. // BlurScale c2 1
  536. // Cinematic c19 1
  537. // Tint c20 1
  538. // Fade c22 1
  539. // Src0 s0 1
  540. // DestBlend s1 1
  541. //todo apply uv offsets to coordinates
  542. r0=tex2D(_s0, IN.txcoord0.xy);//r0=tex2D(_s0, IN.txcoord1.xy);
  543. r1=tex2D(_s1, IN.txcoord0.xy);
  544. r0.w=max(r1.w, _c1.x);
  545. r0.w=1.0/r0.w;
  546. r1.w=r0.w * 0.5;
  547. r0.w=r0.w * _c1.x;
  548. r1.xyz=r1 * r1.w;
  549. r2.xyz=max(r1, 0.0);
  550. r0.xyz=r0.w * r0 + r2.xyz;
  551. r0.w=dot(r0.xyz, float3(0.298999995, 0.587000012, 0.114));
  552. r1.xyz=lerp(r0.w, r0, _c19.x);
  553. r0.xyz=_c20 * r0.w - r1;
  554. r0.xyz=_c20.w * r0 + r1;
  555. r0.xyz=_c19.w * r0 - _c19.y;
  556. r0.xyz=_c19.z * r0 + _c19.y;
  557. r1.xyz=lerp(r0, _c22, _c22.w);
  558. r1.w=_c2.z;
  559. _oC0=r1;
  560.  
  561. #endif //APPLYGAMECOLORCORRECTION
  562.  
  563.  
  564.  
  565. float4 color=_oC0;
  566. color.xyz = _c19.w * color.xyz;
  567.  
  568. //adaptation in time
  569. float4 Adaptation=tex2D(_s4, 0.5);
  570. float grayadaptation=max(max(Adaptation.x, Adaptation.y), Adaptation.z);
  571.  
  572. #if (POSTPROCESS==1)
  573.  
  574. grayadaptation=max(grayadaptation, 0.0);
  575. grayadaptation=min(grayadaptation, 50.0);
  576. color.xyz=color.xyz/(grayadaptation*EAdaptationMaxV1+EAdaptationMinV1);//*tempF1.x
  577.  
  578. float cgray=dot(color.xyz, float3(0.27, 0.67, 0.06));
  579. cgray=pow(cgray, EContrastV1);
  580. float3 poweredcolor=pow(color.xyz, EColorSaturationV1);
  581. float newgray=dot(poweredcolor.xyz, float3(0.27, 0.67, 0.06));
  582. color.xyz=poweredcolor.xyz*cgray/(newgray+0.0001);
  583.  
  584. float3 luma=color.xyz;
  585. float lumamax=300.0;
  586. color.xyz=(color.xyz * (1.0 + color.xyz/lumamax))/(color.xyz + EToneMappingCurveV1);
  587.  
  588. #endif
  589.  
  590.  
  591.  
  592. #if (POSTPROCESS==2)
  593.  
  594. float newEAdaptationMax=lerp( lerp(EAdaptationMaxV2Night, EAdaptationMaxV2Day, ENightDayFactor), EAdaptationMaxV2Interior, EInteriorFactor );
  595. float newEAdaptationMin=lerp( lerp(EAdaptationMinV2Night, EAdaptationMinV2Day, ENightDayFactor), EAdaptationMinV2Interior, EInteriorFactor );
  596. float newEBrightnessV2=lerp( lerp(EBrightnessV2Night, EBrightnessV2Day, ENightDayFactor), EBrightnessV2Interior, EInteriorFactor );
  597. float newEToneMappingCurve=lerp( lerp(EToneMappingCurveV2Night, EToneMappingCurveV2Day, ENightDayFactor), EToneMappingCurveV2Interior, EInteriorFactor );
  598. float newEIntensityContrastV2=lerp( lerp(EIntensityContrastV2Night, EIntensityContrastV2Day, ENightDayFactor), EIntensityContrastV2Interior, EInteriorFactor );
  599. float newEColorSaturationV2=lerp( lerp(EColorSaturationV2Night, EColorSaturationV2Day, ENightDayFactor), EColorSaturationV2Interior, EInteriorFactor );
  600. float newEToneMappingOversaturationV2=lerp( lerp(EToneMappingOversaturationV2Night, EToneMappingOversaturationV2Day, ENightDayFactor), EToneMappingOversaturationV2Interior, EInteriorFactor );
  601.  
  602.  
  603. grayadaptation=max(grayadaptation, 0.0);
  604. grayadaptation=min(grayadaptation, 50.0);
  605. color.xyz=color.xyz/(grayadaptation*newEAdaptationMax+newEAdaptationMin);//*tempF1.x
  606.  
  607. color.xyz*=(newEBrightnessV2);
  608. color.xyz+=0.000001;
  609. float3 xncol=normalize(color.xyz);
  610. float3 scl=color.xyz/xncol.xyz;
  611. scl=pow(scl, newEIntensityContrastV2);
  612. xncol.xyz=pow(xncol.xyz, newEColorSaturationV2);
  613. color.xyz=scl*xncol.xyz;
  614.  
  615. float lumamax=newEToneMappingOversaturationV2;
  616. color.xyz=(color.xyz * (1.0 + color.xyz/lumamax))/(color.xyz + newEToneMappingCurve);
  617.  
  618. #endif
  619.  
  620.  
  621. #if (POSTPROCESS==3)
  622.  
  623. grayadaptation=max(grayadaptation, 0.0);
  624. grayadaptation=min(grayadaptation, 50.0);
  625. color.xyz=color.xyz/(grayadaptation*EAdaptationMaxV3+EAdaptationMinV3);//*tempF1.x
  626.  
  627. float lumamax=EToneMappingOversaturationV3;
  628. color.xyz=(color.xyz * (1.0 + color.xyz/lumamax))/(color.xyz + EToneMappingCurveV3);
  629.  
  630. #endif
  631.  
  632. //color.xyz=tex2D(_s0, _v0.xy) + xcolorbloom.xyz*float3(0.7, 0.6, 1.0)*0.5;
  633. //color.xyz=tex2D(_s0, _v0.xy) + xcolorbloom.xyz*float3(0.7, 0.6, 1.0)*0.5;
  634. //color.xyz*=0.7;
  635.  
  636.  
  637. #if (POSTPROCESS==4)
  638.  
  639. grayadaptation=max(grayadaptation, 0.0);
  640. grayadaptation=min(grayadaptation, 50.0);
  641. color.xyz=color.xyz/(grayadaptation*EAdaptationMaxV4+EAdaptationMinV4);
  642.  
  643. float Y = dot(color.xyz, float3(0.299, 0.587, 0.114)); //0.299 * R + 0.587 * G + 0.114 * B;
  644. float U = dot(color.xyz, float3(-0.14713, -0.28886, 0.436)); //-0.14713 * R - 0.28886 * G + 0.436 * B;
  645. float V = dot(color.xyz, float3(0.615, -0.51499, -0.10001)); //0.615 * R - 0.51499 * G - 0.10001 * B;
  646. Y=pow(Y, EBrightnessCurveV4);
  647. Y=Y*EBrightnessMultiplierV4;
  648. // Y=Y/(Y+EBrightnessToneMappingCurveV4);
  649. // float desaturatefact=saturate(Y*Y*Y*1.7);
  650. // U=lerp(U, 0.0, desaturatefact);
  651. // V=lerp(V, 0.0, desaturatefact);
  652. color.xyz=V * float3(1.13983, -0.58060, 0.0) + U * float3(0.0, -0.39465, 2.03211) + Y;
  653.  
  654. color.xyz=max(color.xyz, 0.0);
  655. color.xyz=color.xyz/(color.xyz+EBrightnessToneMappingCurveV4);
  656.  
  657. #endif
  658.  
  659.  
  660.  
  661. //pallete texture (0.082+ version feature)
  662. #ifdef E_CC_PALETTE
  663. color.rgb=saturate(color.rgb);
  664. float3 brightness=Adaptation.xyz;//tex2D(_s4, 0.5);//adaptation luminance
  665. // brightness=saturate(brightness);//old version from ldr games
  666. brightness=(brightness/(brightness+1.0));//new version
  667. brightness=max(brightness.x, max(brightness.y, brightness.z));//new version
  668. float3 palette;
  669. float4 uvsrc=0.0;
  670. uvsrc.y=brightness.r;
  671. uvsrc.x=color.r;
  672. palette.r=tex2Dlod(_s7, uvsrc).r;
  673. uvsrc.x=color.g;
  674. uvsrc.y=brightness.g;
  675. palette.g=tex2Dlod(_s7, uvsrc).g;
  676. uvsrc.x=color.b;
  677. uvsrc.y=brightness.b;
  678. palette.b=tex2Dlod(_s7, uvsrc).b;
  679. color.rgb=palette.rgb;
  680. #endif //E_CC_PALETTE
  681.  
  682.  
  683.  
  684. #ifdef E_CC_PROCEDURAL
  685. float tempgray;
  686. float4 tempvar;
  687. float3 tempcolor;
  688. /*
  689. //these replaced by "levels"
  690. //+++ gamma
  691. if (ECCGamma!=1.0)
  692. color=pow(color, 1.0/ECCGamma);
  693.  
  694. //+++ brightness like in photoshop
  695. color=color+ECCAditiveBrightness;
  696.  
  697. //+++ lightness
  698. tempvar.x=saturate(ELightness);
  699. tempvar.y=saturate(1.0+ECCLightness);
  700. color=tempvar.x*(1.0-color) + (tempvar.y*color);
  701. */
  702. //+++ levels like in photoshop, including gamma, lightness, additive brightness
  703. color=max(color-ECCInBlack, 0.0) / max(ECCInWhite-ECCInBlack, 0.0001);
  704. if (ECCGamma!=1.0) color=pow(color, ECCGamma);
  705. color=color*(ECCOutWhite-ECCOutBlack) + ECCOutBlack;
  706.  
  707. //+++ brightness
  708. color=color*ECCBrightness;
  709.  
  710. //+++ contrast
  711. color=(color-ECCContrastGrayLevel) * ECCContrast + ECCContrastGrayLevel;
  712.  
  713. //+++ saturation
  714. tempgray=dot(color, 0.3333);
  715. color=lerp(tempgray, color, ECCSaturation);
  716.  
  717. //+++ desaturate shadows
  718. tempgray=dot(color, 0.3333);
  719. tempvar.x=saturate(1.0-tempgray);
  720. tempvar.x*=tempvar.x;
  721. tempvar.x*=tempvar.x;
  722. color=lerp(color, tempgray, ECCDesaturateShadows*tempvar.x);
  723.  
  724. //+++ color balance
  725. color=saturate(color);
  726. tempgray=dot(color, 0.3333);
  727. float2 shadow_highlight=float2(1.0-tempgray, tempgray);
  728. shadow_highlight*=shadow_highlight;
  729. color.rgb+=(ECCColorBalanceHighlights*2.0-1.0)*color * shadow_highlight.x;
  730. color.rgb+=(ECCColorBalanceShadows*2.0-1.0)*(1.0-color) * shadow_highlight.y;
  731.  
  732. //+++ channel mixer
  733. tempcolor=color;
  734. color.r=dot(tempcolor, ECCChannelMixerR);
  735. color.g=dot(tempcolor, ECCChannelMixerG);
  736. color.b=dot(tempcolor, ECCChannelMixerB);
  737. #endif //E_CC_PROCEDURAL
  738.  
  739. color.xyz = 3dlut ? lerp( lerp( CLutFunc(color.rgb, SamplerLUT_Night),
  740. CLutFunc(color.rgb, SamplerLUT_Day), ENightDayFactor),
  741. CLutFunc(color.rgb, SamplerLUT_Int), EInteriorFactor) : color.xyz;
  742.  
  743. _oC0.w=1.0;
  744. _oC0.xyz=color.xyz;
  745. return _oC0;
  746. }
  747.  
  748.  
  749.  
  750. //switch between vanilla and mine post processing
  751. technique Shader_C1DAE3F7 <string UIName="ENBSeries";>
  752. {
  753. pass p0
  754. {
  755. VertexShader = compile vs_3_0 VS_Quad();
  756. PixelShader = compile ps_3_0 PS_C1DAE3F7();
  757.  
  758. ColorWriteEnable=ALPHA|RED|GREEN|BLUE;
  759. ZEnable=FALSE;
  760. ZWriteEnable=FALSE;
  761. CullMode=NONE;
  762. AlphaTestEnable=FALSE;
  763. AlphaBlendEnable=FALSE;
  764. SRGBWRITEENABLE=FALSE;
  765. }
  766. }
  767.  
  768.  
  769.  
  770. //original shader of post processing
  771. technique Shader_ORIGINALPOSTPROCESS <string UIName="Vanilla";>
  772. {
  773. pass p0
  774. {
  775. //VertexShader = compile vs_3_0 VS_Quad();
  776. VertexShader=
  777. asm
  778. {
  779. // Parameters:
  780. // float4 geometryOffset;
  781. // float4 texOffset0;
  782. // float4 texOffset1;
  783. // Registers:
  784. // Name Reg Size
  785. // -------------- ----- ----
  786. // geometryOffset c0 1
  787. // texOffset0 c1 1
  788. // texOffset1 c2 1
  789. //
  790. vs_1_1
  791. def c3, 2, -2, 0, 0
  792. dcl_position v0
  793. dcl_texcoord v1
  794. mov r0.xy, c0
  795. mad oPos.xy, r0, -c3, v0
  796. add oT0.xy, v1, c1
  797. add oT1.xy, v1, c2
  798. mov oPos.zw, v0
  799. };
  800. PixelShader=
  801. asm
  802. {
  803. // Parameters:
  804. // float3 BlurScale;
  805. // float4 Cinematic;
  806. // sampler2D DestBlend;
  807. // float4 Fade;
  808. // float4 HDRParam;
  809. // sampler2D Src0;
  810. // float4 Tint;
  811. // Registers:
  812. // Name Reg Size
  813. // ------------ ----- ----
  814. // HDRParam c1 1
  815. // BlurScale c2 1
  816. // Cinematic c19 1
  817. // Tint c20 1
  818. // Fade c22 1
  819. // Src0 s0 1
  820. // DestBlend s1 1
  821. //
  822. ps_2_x
  823. def c0, 0.5, 0, 0, 0
  824. def c3, 0.298999995, 0.587000012, 0.114, 0
  825. dcl t0.xy
  826. dcl t1.xy
  827. dcl_2d s0
  828. dcl_2d s1
  829. texld r0, t1, s1
  830. texld r1, t0, s0
  831. max r0.w, r1.w, c1.x
  832. rcp r0.w, r0.w
  833. mul r1.w, r0.w, c0.x
  834. mul r0.w, r0.w, c1.x
  835. mul r1.xyz, r1, r1.w
  836. max r2.xyz, r1, c0.y
  837. mad r0.xyz, r0.w, r0, r2
  838. dp3 r0.w, r0, c3
  839. lrp r1.xyz, c19.x, r0, r0.w
  840. mad r0.xyz, r0.w, c20, -r1
  841. mad r0.xyz, c20.w, r0, r1
  842. mad r0.xyz, c19.w, r0, -c19.y
  843. mad r0.xyz, c19.z, r0, c19.y
  844. lrp r1.xyz, c22.w, c22, r0
  845. mov r1.w, c2.z
  846. mov oC0, r1
  847. };
  848. ColorWriteEnable=ALPHA|RED|GREEN|BLUE;
  849. ZEnable=FALSE;
  850. ZWriteEnable=FALSE;
  851. CullMode=NONE;
  852. AlphaTestEnable=FALSE;
  853. AlphaBlendEnable=FALSE;
  854. SRGBWRITEENABLE=FALSE;
  855. }
  856. }
  857.  
  858.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement