enbeffectprepass.fx 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848
  1. //++++++++++++++++++++++++++++++++++++++++++++
  2. // ENBSeries effect file
  3. // visit http://enbdev.com for updates
  4. // Copyright (c) 2007-2011 Boris Vorontsov
  5. //
  6. // Using decompiled shader of TES Skyrim
  7. //++++++++++++++++++++++++++++++++++++++++++++
  8. //+++++++++++++++++++++++++++++++++++++++++++++++
  9. // Unreal Cinema ENB - The Directors Cut - 0.219
  10. //+++++++++++++++++++++++++++++++++++++++++++++++
  11. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  12. // Additions and Tweaking by Kyokushinoyama, & Unreal Warfare
  13. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  14. #define ENABLE_FLIP_DAY_NIGHT_FACTOR
  15. //++++++++++++++++++++++++++++++++++++++++++++
  16. //#define NOT_BLURRING_SKY_MODE
  17. #define DEPTH_OF_FIELD_QUALITY 2
  18. //1-7
  19. //++++++++++++++++++++++++++++++++++++++++++++
  20. //#define USE_TIGHT_OFFSETS 1
  21. //#define USE_CENTERED_OFFSETS 1
  22. //#define USE_REGULAR_OFFSETS 1
  23. //#define USE_ORIGINAL_OFFSETS 1
  24. //#define USE_WIDE_OFFSETS 1
  25. #define USE_NATURAL_OFFSETS 1
  26. //++++++++++++++++++++++++++++++++++++++++++++
  27. #define AUTO_FOCUS
  28. //++++++++++++++++++++++++++++++++++++++++++++
  29. //#define TILT_SHIFT
  30. // Day, Night, Interior angles
  31. float TiltShiftAngleDay=30.0;
  32. float TiltShiftAngleNight=30.0;
  33. float TiltShiftAngleInterior=30.0;
  34. //++++++++++++++++++++++++++++++++++++++++++++
  35. #define POLYGONAL_BOKEH
  36. #define POLYGON_NUM 5
  37. //#define POLYGON_NUM 6
  38. //#define POLYGON_NUM 7
  39. //#define POLYGON_NUM 8
  40. //++++++++++++++++++++++++++++++++++++++++++++
  41. // FOCUS POINT DAY
  42. float2 FocusPointDay=float2(0.5, 0.5);
  43. // FOCUS POINT NIGHT
  44. float2 FocusPointNight=float2(0.5, 0.5);
  45. // FOCUS POINT INTERIOR
  46. float2 FocusPointInterior=float2(0.5, 0.5);
  47. // DYNAMIC DOF DAY SETTINGS
  48. float FocusSampleRangeDay=1.0;
  49. float NearBlurCurveDay=14.70;
  50. float FarBlurCurveDay=2.75;
  51. float DepthClipDay=999999999.0;
  52. // DYNAMIC DOF NIGHT SETTINGS
  53. float FocusSampleRangeNight=1.0;
  54. float NearBlurCurveNight=14.70;
  55. float FarBlurCurveNight=2.75;
  56. float DepthClipNight=999999999.0;
  57. // DYNAMIC DOF INTERIOR SETTINGS
  58. float FocusSampleRangeInterior=1.0;
  59. float NearBlurCurveInterior=14.70;
  60. float FarBlurCurveInterior=2.75;
  61. float DepthClipInterior=999999999.0;
  62. //++++++++++++++++++++++++++++++++++++++++++++
  63. // DAY SETTINGS
  64. float FocalPlaneDepthDay=1.00;
  65. float FarBlurDepthDay=100.00;
  66. // NIGHT SETTINGS
  67. float FocalPlaneDepthNight=1.00;
  68. float FarBlurDepthNight=100.00;
  69. // INTERIOR SETTINGS
  70. float FocalPlaneDepthInterior=1.00;
  71. float FarBlurDepthInterior=100.00;
  72. //++++++++++++++++++++++++++++++++++++++++++++
  73. // BOKEH DAY SETTINGS
  74. float BokehBiasDay=0.00; //Impacts overall brightness-exposure - Leave @0.00 for normalize
  75. float BokehBiasCurveDay=0.75;
  76. float BokehBrightnessThresholdDay=1.00;
  77. float BokehBrightnessMultiplierDay=1.00;
  78. float RadiusScaleMultiplierDay=0.13;
  79. // BOKEH NIGHT SETTINGS
  80. float BokehBiasNight=0.00; //Impacts overall brightness-exposure - Leave @0.00 for normalize
  81. float BokehBiasCurveNight=0.75;
  82. float BokehBrightnessThresholdNight=1.00;
  83. float BokehBrightnessMultiplierNight=1.00;
  84. float RadiusScaleMultiplierNight=0.13;
  85. // BOKEH INTERIOR SETTINGS
  86. float BokehBiasInterior=0.00; //Impacts overall brightness-exposure - Leave @0.00 for normalize
  87. float BokehBiasCurveInterior=0.75;
  88. float BokehBrightnessThresholdInterior=1.00;
  89. float BokehBrightnessMultiplierInterior=1.00;
  90. float RadiusScaleMultiplierInterior=0.13;
  91. //++++++++++++++++++++++++++++++++++++++++++++
  92. // GRAIN GLOBAL SETTINGS
  93. float NoiseAmount=0.055;
  94. float NoiseCurve=0.0;
  95. // GRAIN DIFFUSION DAY
  96. float NoiseDiffusionDay=3.0; //High values dampen grain, depending on Noise Amounts and Curves - 3.0 will 'disable' grain
  97. // GRAIN DIFFUSION NIGHT
  98. float NoiseDiffusionNight=3.0; //High values dampen grain, depending on Noise Amounts and Curves - 3.0 will 'disable' grain
  99. // GRAIN DIFFUSION INTERIOR
  100. float NoiseDiffusionInterior=3.0; //High values dampen grain, depending on Noise Amounts and Curves - 3.0 will 'disable' grain
  101. //++++++++++++++++++++++++++++++++++++++++++++
  102. // CHROMATIC ABERRATION DAY
  103. float ChromaticAberrationAmountDay=0.25;
  104. // CHROMATIC ABERRATION NIGHT
  105. float ChromaticAberrationAmountNight=0.25;
  106. // CHROMATIC ABERRATION INTERIOR
  107. float ChromaticAberrationAmountInterior=0.25;
  108. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  109. // EXTERNAL PARAMETERS BEGINS HERE, SHOULD NOT BE MODIFIED UNLESS YOU KNOW WHAT YOU ARE DOING!!!
  110. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  111. #ifndef ENABLE_FLIP_DAY_NIGHT_FACTOR
  112. 1 - ENightDayFactor = ENightDayFactor;
  113. #endif
  114. //++++++++++++++++++++++++++++++++++++++++++++
  115. float4 tempF1; //0,1,2,3
  116. float4 tempF2; //5,6,7,8
  117. float4 tempF3; //9,0
  118. float4 ScreenSize;
  119. float4 Timer;
  120. float ENightDayFactor;
  121. float EInteriorFactor;
  122. float FadeFactor;
  123. texture2D texColor;
  124. texture2D texDepth;
  125. texture2D texNoise;
  126. texture2D texPalette;
  127. texture2D texFocus; //computed focusing depth
  128. texture2D texCurr; //4*4 texture for focusing
  129. texture2D texPrev; //4*4 texture for focusing
  130. sampler2D SamplerColor = sampler_state
  131. {
  132. Texture = <texColor>;
  133. MinFilter = LINEAR;
  134. MagFilter = LINEAR;
  135. MipFilter = NONE; //LINEAR
  136. AddressU = Clamp;
  137. AddressV = Clamp;
  138. SRGBTexture=FALSE;
  139. MaxMipLevel=0; //9 //[KYO : TO DO : experiment with mipmaps]
  140. MipMapLodBias=0;
  141. };
  142. sampler2D SamplerDepth = sampler_state
  143. {
  144. Texture = <texDepth>;
  145. MinFilter = POINT;
  146. MagFilter = POINT;
  147. MipFilter = NONE;
  148. AddressU = Clamp;
  149. AddressV = Clamp;
  150. SRGBTexture=FALSE;
  151. MaxMipLevel=0;
  152. MipMapLodBias=0;
  153. };
  154. sampler2D SamplerNoise = sampler_state
  155. {
  156. Texture = <texNoise>;
  157. MinFilter = POINT;
  158. MagFilter = POINT;
  159. MipFilter = NONE;//NONE;
  160. AddressU = Wrap;
  161. AddressV = Wrap;
  162. SRGBTexture=FALSE;
  163. MaxMipLevel=0;
  164. MipMapLodBias=0;
  165. };
  166. sampler2D SamplerPalette = sampler_state
  167. {
  168. Texture = <texPalette>;
  169. MinFilter = LINEAR;
  170. MagFilter = LINEAR;
  171. MipFilter = NONE;//NONE;
  172. AddressU = Clamp;
  173. AddressV = Clamp;
  174. SRGBTexture=FALSE;
  175. MaxMipLevel=0;
  176. MipMapLodBias=0;
  177. };
  178. sampler2D SamplerCurr = sampler_state
  179. {
  180. Texture = <texCurr>;
  181. MinFilter = LINEAR;
  182. MagFilter = LINEAR;
  183. MipFilter = LINEAR;//NONE;
  184. AddressU = Clamp;
  185. AddressV = Clamp;
  186. SRGBTexture=FALSE;
  187. MaxMipLevel=0;
  188. MipMapLodBias=0;
  189. };
  190. sampler2D SamplerPrev = sampler_state
  191. {
  192. Texture = <texPrev>;
  193. MinFilter = LINEAR;
  194. MagFilter = LINEAR;
  195. MipFilter = NONE;
  196. AddressU = Clamp;
  197. AddressV = Clamp;
  198. SRGBTexture=FALSE;
  199. MaxMipLevel=0;
  200. MipMapLodBias=0;
  201. };
  202. sampler2D SamplerFocus = sampler_state
  203. {
  204. Texture = <texFocus>;
  205. MinFilter = LINEAR;
  206. MagFilter = LINEAR;
  207. MipFilter = NONE;
  208. AddressU = Clamp;
  209. AddressV = Clamp;
  210. SRGBTexture=FALSE;
  211. MaxMipLevel=0;
  212. MipMapLodBias=0;
  213. };
  214. struct VS_OUTPUT_POST
  215. {
  216. float4 vpos : POSITION;
  217. float2 txcoord : TEXCOORD0;
  218. };
  219. struct VS_INPUT_POST
  220. {
  221. float3 pos : POSITION;
  222. float2 txcoord : TEXCOORD0;
  223. };
  224. //++++++++++++++++++++++++++++++++++++++++++++
  225. VS_OUTPUT_POST VS_Focus(VS_INPUT_POST IN)
  226. {
  227. VS_OUTPUT_POST OUT;
  228. float4 pos=float4(IN.pos.x,IN.pos.y,IN.pos.z,1.0);
  229. OUT.vpos=pos;
  230. OUT.txcoord.xy=IN.txcoord.xy;
  231. return OUT;
  232. }
  233. float linearlizeDepth(float nonlinearDepth)
  234. {
  235. float2 dofProj=float2(0.0509804, 3098.0392);
  236. float2 dofDist=float2(0.0, 0.0509804);
  237. float4 depth=nonlinearDepth;
  238. depth.y=-dofProj.x + dofProj.y;
  239. depth.y=1.0/depth.y;
  240. depth.z=depth.y * dofProj.y;
  241. depth.z=depth.z * -dofProj.x;
  242. depth.x=dofProj.y * -depth.y + depth.x;
  243. depth.x=1.0/depth.x;
  244. depth.y=depth.z * depth.x;
  245. depth.x=depth.z * depth.x - dofDist.y;
  246. depth.x+=dofDist.x * -0.5;
  247. depth.x=max(depth.x, 0.0);
  248. return depth.x;
  249. }
  250. float4 PS_ReadFocus(VS_OUTPUT_POST IN) : COLOR
  251. {
  252. //++++++++++++++++++++++++++++++++++++++++++++
  253. float FocusPoint =lerp( lerp( FocusPointDay, FocusPointNight, 1 - ENightDayFactor ), FocusPointInterior, EInteriorFactor);
  254. float2 uvsrc=FocusPoint;
  255. float2 pixelSize=ScreenSize.y;
  256. pixelSize.y*=ScreenSize.z;
  257. #ifdef USE_TIGHT_OFFSETS
  258. const float2 offset[4] =
  259. {
  260. float2(0.262, 0.641),
  261. float2(0.262, -0.641),
  262. float2(0.641, 0.262),
  263. float2(-0.641, 0.262)
  264. };
  265. #endif
  266. #ifdef USE_CENTERED_OFFSETS
  267. const float2 offset[4] =
  268. {
  269. float2(0.5, 1.0),
  270. float2(0.5, -1.0),
  271. float2(1.0, 0.5),
  272. float2(-1.0, 0.5)
  273. };
  274. #endif
  275. #ifdef USE_REGULAR_OFFSETS
  276. const float2 offset[4] =
  277. {
  278. float2(0.3, 0.9),
  279. float2(0.3, -0.9),
  280. float2(0.9, 0.3),
  281. float2(-0.9, 0.3)
  282. };
  283. #endif
  284. #ifdef USE_ORIGINAL_OFFSETS
  285. const float2 offset[4]=
  286. {
  287. float2(0.0, 1.0),
  288. float2(0.0, -1.0),
  289. float2(1.0, 0.0),
  290. float2(-1.0, 0.0)
  291. };
  292. #endif
  293. #ifdef USE_WIDE_OFFSETS
  294. const float2 offset[4]=
  295. {
  296. float2(0.524, 1.282),
  297. float2(0.524, -1.282),
  298. float2(1.282, 0.524),
  299. float2(-1.282, 0.524)
  300. };
  301. #endif
  302. #ifdef USE_NATURAL_OFFSETS
  303. const float2 offset[16] = {
  304. float2(0.2007, 0.9796),
  305. float2(-0.2007, 0.9796),
  306. float2(0.2007, 0.9796),
  307. float2(-0.2007, 0.9796),
  308. float2(0.8240, 0.5665),
  309. float2(0.5665, 0.8240),
  310. float2(0.8240, 0.5665),
  311. float2(0.5665, 0.8240),
  312. float2(0.9796, 0.2007),
  313. float2(0.9796, -0.2007),
  314. float2(0.9796, 0.2007),
  315. float2(0.9796, -0.2007),
  316. float2(-0.8240, 0.5665),
  317. float2(-0.5665, 0.8240),
  318. float2(-0.8240, 0.5665),
  319. float2(-0.5665, 0.8240)
  320. };
  321. #endif
  322. float res=linearlizeDepth(tex2D(SamplerDepth, uvsrc.xy).x);
  323. for (int i=0; i<4; i++)
  324. {
  325. uvsrc.xy=uvsrc.xy;
  326. float FocusSampleRange =lerp( lerp( FocusSampleRangeDay, FocusSampleRangeNight, 1 - ENightDayFactor ), FocusSampleRangeInterior, EInteriorFactor);
  327. uvsrc.xy+=offset[i] * pixelSize.xy * FocusSampleRange;
  328. float DepthClip =lerp( lerp( DepthClipDay, DepthClipNight, 1 - ENightDayFactor ), DepthClipInterior, EInteriorFactor);
  329. #ifdef NOT_BLURRING_SKY_MODE
  330. res+=linearlizeDepth(tex2D(SamplerDepth, uvsrc).x);
  331. #else
  332. res+=min(linearlizeDepth(tex2D(SamplerDepth, uvsrc).x), DepthClip);
  333. #endif
  334. }
  335. res*=0.2; //.21 //.22
  336. return res;
  337. }
  338. float4 PS_WriteFocus(VS_OUTPUT_POST IN) : COLOR
  339. {
  340. float FocusPoint =lerp( lerp( FocusPointDay, FocusPointNight, 1 - ENightDayFactor ), FocusPointInterior, EInteriorFactor);
  341. float2 uvsrc=FocusPoint;
  342. float res=0.0;
  343. float curr=tex2D(SamplerCurr, uvsrc.xy).x;
  344. float prev=tex2D(SamplerPrev, uvsrc.xy).x;
  345. res=lerp(prev, curr, saturate(FadeFactor));//time elapsed factor
  346. return res;
  347. }
  348. technique ReadFocus
  349. {
  350. pass P0
  351. {
  352. VertexShader = compile vs_3_0 VS_Focus();
  353. PixelShader = compile ps_3_0 PS_ReadFocus();
  354. ZEnable=FALSE;
  355. CullMode=NONE;
  356. ALPHATESTENABLE=FALSE;
  357. SEPARATEALPHABLENDENABLE=FALSE;
  358. AlphaBlendEnable=FALSE;
  359. FogEnable=FALSE;
  360. SRGBWRITEENABLE=FALSE;
  361. }
  362. }
  363. technique WriteFocus
  364. {
  365. pass P0
  366. {
  367. VertexShader = compile vs_3_0 VS_Focus();
  368. PixelShader = compile ps_3_0 PS_WriteFocus();
  369. ZEnable=FALSE;
  370. CullMode=NONE;
  371. ALPHATESTENABLE=FALSE;
  372. SEPARATEALPHABLENDENABLE=FALSE;
  373. AlphaBlendEnable=FALSE;
  374. FogEnable=FALSE;
  375. SRGBWRITEENABLE=FALSE;
  376. }
  377. }
  378. VS_OUTPUT_POST VS_PostProcess(VS_INPUT_POST IN)
  379. {
  380. VS_OUTPUT_POST OUT;
  381. float4 pos=float4(IN.pos.x,IN.pos.y,IN.pos.z,1.0);
  382. OUT.vpos=pos;
  383. OUT.txcoord.xy=IN.txcoord.xy;
  384. return OUT;
  385. }
  386. float4 PS_ProcessPass1(VS_OUTPUT_POST IN, float2 vPos : VPOS) : COLOR
  387. {
  388. float4 res;
  389. float2 coord=IN.txcoord.xy;
  390. float4 origcolor=tex2D(SamplerColor, coord.xy);
  391. float scenedepth=tex2D(SamplerDepth, IN.txcoord.xy).x;
  392. float scenefocus=tex2D(SamplerFocus, 0.5).x;
  393. res.xyz=origcolor.xyz;
  394. float depth=linearlizeDepth(scenedepth);
  395. float FarBlurCurve =lerp( lerp( FarBlurCurveDay, FarBlurCurveNight, 1 - ENightDayFactor ), FarBlurCurveInterior, EInteriorFactor);
  396. float FocalPlaneDepth =lerp( lerp( FocalPlaneDepthDay, FocalPlaneDepthNight, 1 - ENightDayFactor ), FocalPlaneDepthInterior, EInteriorFactor);
  397. float FarBlurDepth =lerp( lerp( FarBlurDepthDay, FarBlurDepthNight, 1 - ENightDayFactor ), FarBlurDepthInterior, EInteriorFactor);
  398. #ifdef AUTO_FOCUS
  399. float focalPlaneDepth=scenefocus;
  400. float farBlurDepth=scenefocus*pow(4.0, FarBlurCurve);
  401. #else
  402. float focalPlaneDepth=FocalPlaneDepth;
  403. float farBlurDepth=FarBlurDepth;
  404. #endif
  405. #ifdef TILT_SHIFT
  406. float TiltShiftAngle =lerp( lerp( TiltShiftAngleDay, TiltShiftAngleNight, 1 - ENightDayFactor ), TiltShiftAngleInterior, EInteriorFactor);
  407. float shiftAngle=(frac(TiltShiftAngle / 90.0) == 0) ? 0.0 : TiltShiftAngle;
  408. float depthShift=1.0 + (0.5 - coord.x)*tan(-shiftAngle * 0.017453292);
  409. focalPlaneDepth*=depthShift;
  410. farBlurDepth*=depthShift;
  411. #endif
  412. if(depth < focalPlaneDepth)
  413. res.w=(depth - focalPlaneDepth)/focalPlaneDepth;
  414. else
  415. {
  416. res.w=(depth - focalPlaneDepth)/(farBlurDepth - focalPlaneDepth);
  417. res.w=saturate(res.w);
  418. }
  419. res.w=res.w * 0.5 + 0.5;
  420. #ifdef NOT_BLURRING_SKY_MODE
  421. #define DEPTH_OF_FIELD_QUALITY 2 //[KYO : why 0 ?]
  422. //#define DEPTH_OF_FIELD_QUALITY 0
  423. res.w=(depth > 1000.0) ? 0.5 : res.w;
  424. #endif
  425. return res;
  426. }
  427. float4 PS_ProcessPass2(VS_OUTPUT_POST IN, float2 vPos : VPOS) : COLOR
  428. {
  429. float4 res;
  430. float2 coord=IN.txcoord.xy;
  431. float4 origcolor=tex2D(SamplerColor, coord.xy);
  432. float centerDepth=origcolor.w;
  433. float2 pixelSize=ScreenSize.y;
  434. pixelSize.y*=ScreenSize.z;
  435. float blurAmount=abs(centerDepth * 2.0 - 1.0);
  436. float discRadius=blurAmount * float(DEPTH_OF_FIELD_QUALITY);
  437. float RadiusScaleMultiplier =lerp( lerp( RadiusScaleMultiplierDay, RadiusScaleMultiplierNight, 1 - ENightDayFactor ), RadiusScaleMultiplierInterior, EInteriorFactor);
  438. float NearBlurCurve =lerp( lerp( NearBlurCurveDay, NearBlurCurveNight, 1 - ENightDayFactor ), NearBlurCurveInterior, EInteriorFactor);
  439. float BokehBias =lerp( lerp( BokehBiasDay, BokehBiasNight, 1 - ENightDayFactor ), BokehBiasInterior, EInteriorFactor);
  440. float BokehBrightnessThreshold =lerp( lerp( BokehBrightnessThresholdDay, BokehBrightnessThresholdNight, 1 - ENightDayFactor ), BokehBrightnessThresholdInterior, EInteriorFactor);
  441. float BokehBrightnessMultiplier =lerp( lerp( BokehBrightnessMultiplierDay, BokehBrightnessMultiplierNight, 1 - ENightDayFactor ), BokehBrightnessMultiplierInterior, EInteriorFactor);
  442. float BokehBiasCurve =lerp( lerp( BokehBiasCurveDay, BokehBiasCurveNight, 1 - ENightDayFactor ), BokehBiasCurveInterior, EInteriorFactor);
  443. discRadius*=RadiusScaleMultiplier;
  444. #ifdef AUTO_FOCUS
  445. discRadius*=(centerDepth < 0.5) ? (1.0 / max(NearBlurCurve, 1.0)) : 1.0;
  446. #endif
  447. res.xyz=origcolor.xyz;
  448. res.w=dot(res.xyz, 0.3333);
  449. res.w=max((res.w - BokehBrightnessThreshold) * BokehBrightnessMultiplier, 0.0);
  450. res.xyz*=1.0 + res.w*blurAmount;
  451. res.w=1.0;
  452. int sampleCycle=0;
  453. int sampleCycleCounter=0;
  454. int sampleCounterInCycle=0;
  455. #ifdef POLYGONAL_BOKEH
  456. float basedAngle=360.0 / POLYGON_NUM;
  457. float2 currentVertex;
  458. float2 nextVertex;
  459. int dofTaps=DEPTH_OF_FIELD_QUALITY * (DEPTH_OF_FIELD_QUALITY + 1) * POLYGON_NUM / 2.0;
  460. #else
  461. int dofTaps=DEPTH_OF_FIELD_QUALITY * (DEPTH_OF_FIELD_QUALITY + 1) * 4;
  462. #endif
  463. for(int i=0; i < dofTaps; i++)
  464. {
  465. if(sampleCounterInCycle % sampleCycle == 0)
  466. {
  467. sampleCounterInCycle=0;
  468. sampleCycleCounter++;
  469. #ifdef POLYGONAL_BOKEH
  470. sampleCycle+=POLYGON_NUM;
  471. currentVertex.xy=float2(1.0 , 0.0);
  472. sincos(basedAngle* 0.017453292, nextVertex.y, nextVertex.x);
  473. #else
  474. sampleCycle+=8;
  475. #endif
  476. }
  477. sampleCounterInCycle++;
  478. #ifdef POLYGONAL_BOKEH
  479. float sampleAngle=basedAngle / float(sampleCycleCounter) * sampleCounterInCycle;
  480. float remainAngle=frac(sampleAngle / basedAngle) * basedAngle;
  481. if(remainAngle == 0)
  482. {
  483. currentVertex=nextVertex;
  484. sincos((sampleAngle + basedAngle) * 0.017453292, nextVertex.y, nextVertex.x);
  485. }
  486. float2 sampleOffset=lerp(currentVertex.xy, nextVertex.xy, remainAngle / basedAngle);
  487. #else
  488. float sampleAngle=0.78539816 / float(sampleCycleCounter) * sampleCounterInCycle;
  489. float2 sampleOffset;
  490. sincos(sampleAngle, sampleOffset.y, sampleOffset.x);
  491. #endif
  492. sampleOffset*=sampleCycleCounter / float(DEPTH_OF_FIELD_QUALITY);
  493. float2 coordLow=coord.xy + (pixelSize.xy * sampleOffset.xy * discRadius);
  494. float4 tap=tex2D(SamplerColor, coordLow.xy);
  495. float weight=(tap.w >= centerDepth) ? 1.0 : abs(tap.w * 2.0 - 1.0);
  496. float luma=dot(tap.xyz, 0.3333);
  497. float brightMultiplier=max((luma - BokehBrightnessThreshold) * BokehBrightnessMultiplier, 0.0);
  498. tap.xyz*=1.0 + brightMultiplier*abs(tap.w*2.0 - 1.0);
  499. tap.xyz*=1.0 + BokehBias * pow(float(sampleCycleCounter)/float(DEPTH_OF_FIELD_QUALITY), BokehBiasCurve);
  500. res.xyz+=tap.xyz * weight;
  501. res.w+=weight;
  502. }
  503. res.xyz /= res.w;
  504. res.w=centerDepth;
  505. return res;
  506. }
  507. float4 PS_ProcessPass3(VS_OUTPUT_POST IN, float2 vPos : VPOS) : COLOR
  508. {
  509. float RadiusScaleMultiplier =lerp( lerp( RadiusScaleMultiplierDay, RadiusScaleMultiplierNight, 1 - ENightDayFactor ), RadiusScaleMultiplierInterior, EInteriorFactor);
  510. float2 coord=IN.txcoord.xy;
  511. float2 pixelSize=ScreenSize.y;
  512. pixelSize.y*=ScreenSize.z;
  513. float4 origcolor=tex2D(SamplerColor, coord.xy);
  514. float depth=origcolor.w;
  515. float blurAmount=abs(depth * 2.0 - 1.0);
  516. float discRadius=blurAmount * float(DEPTH_OF_FIELD_QUALITY) * RadiusScaleMultiplier;
  517. float NearBlurCurve =lerp( lerp( NearBlurCurveDay, NearBlurCurveNight, 1 - ENightDayFactor ), NearBlurCurveInterior, EInteriorFactor);
  518. #ifdef AUTO_FOCUS
  519. discRadius*=(depth < 0.5) ? (1.0 / max(NearBlurCurve, 1.0)) : 1.0;
  520. #endif
  521. float4 res=origcolor;
  522. float3 distortion=float3(-1.0, 0.0, 1.0);
  523. float ChromaticAberrationAmount =lerp( lerp( ChromaticAberrationAmountDay, ChromaticAberrationAmountNight, 1 - ENightDayFactor ), ChromaticAberrationAmountInterior, EInteriorFactor);
  524. distortion*=ChromaticAberrationAmount*discRadius;
  525. origcolor=tex2D(SamplerColor, coord.xy + pixelSize.xy*distortion.x);
  526. origcolor.w=smoothstep(0.0, depth, origcolor.w);
  527. res.x=lerp(res.x, origcolor.x, origcolor.w);
  528. origcolor=tex2D(SamplerColor, coord.xy + pixelSize.xy*distortion.z);
  529. origcolor.w=smoothstep(0.0, depth, origcolor.w);
  530. res.z=lerp(res.z, origcolor.z, origcolor.w);
  531. return res;
  532. }
  533. float4 PS_ProcessPass4(VS_OUTPUT_POST IN, float2 vPos : VPOS) : COLOR
  534. {
  535. float2 coord=IN.txcoord.xy;
  536. float2 pixelSize=ScreenSize.y;
  537. pixelSize.y*=ScreenSize.z;
  538. float4 origcolor=tex2D(SamplerColor, coord.xy);
  539. float depth=origcolor.w;
  540. float blurAmount=abs(depth*2.0 - 1.0);
  541. float NearBlurCurve =lerp( lerp( NearBlurCurveDay, NearBlurCurveNight, 1 - ENightDayFactor ), NearBlurCurveInterior, EInteriorFactor);
  542. #if (DEPTH_OF_FIELD_QUALITY > 0)
  543. #ifdef AUTO_FOCUS
  544. blurAmount*=(depth < 0.5) ? (1.0 / max(NearBlurCurve, 1.0)) : 1.0;
  545. #endif
  546. blurAmount=smoothstep(0.15, 1.0, blurAmount);
  547. #endif
  548. float weight[5] = {0.2270270270, 0.1945945946, 0.1216216216, 0.0540540541,
  549. 0.0162162162};
  550. float4 res=origcolor * weight[0];
  551. for(int i=1; i < 5; i++)
  552. {
  553. res+=tex2D(SamplerColor, coord.xy + float2(i*pixelSize.x*blurAmount, 0)) * weight[i];
  554. res+=tex2D(SamplerColor, coord.xy - float2(i*pixelSize.x*blurAmount, 0)) * weight[i];
  555. }
  556. res.w=depth;
  557. return res;
  558. }
  559. float4 PS_ProcessPass5(VS_OUTPUT_POST IN, float2 vPos : VPOS) : COLOR
  560. {
  561. float2 coord=IN.txcoord.xy;
  562. float2 pixelSize=ScreenSize.y;
  563. pixelSize.y*=ScreenSize.z;
  564. float4 origcolor=tex2D(SamplerColor, coord.xy);
  565. float depth=origcolor.w;
  566. float blurAmount=abs(depth*2.0 - 1.0);
  567. float NearBlurCurve =lerp( lerp( NearBlurCurveDay, NearBlurCurveNight, 1 - ENightDayFactor ), NearBlurCurveInterior, EInteriorFactor);
  568. #if (DEPTH_OF_FIELD_QUALITY > 0)
  569. #ifdef AUTO_FOCUS
  570. blurAmount*=(depth < 0.5) ? (1.0 / max(NearBlurCurve, 1.0)) : 1.0;
  571. #endif
  572. blurAmount=smoothstep(0.15, 1.0, blurAmount);
  573. #endif
  574. float weight[5] = {0.2270270270, 0.1945945946, 0.1216216216, 0.0540540541,
  575. 0.0162162162};
  576. float4 res=origcolor * weight[0];
  577. for(int i=1; i < 5; i++)
  578. {
  579. res+=tex2D(SamplerColor, coord.xy + float2(0, i*pixelSize.y*blurAmount)) * weight[i];
  580. res+=tex2D(SamplerColor, coord.xy - float2(0, i*pixelSize.y*blurAmount)) * weight[i];
  581. }
  582. float origgray=dot(res.xyz, 0.3333);
  583. origgray/=origgray + 1.0;
  584. coord.xy=IN.txcoord.xy*16.0 + origgray;
  585. float4 cnoi=tex2D(SamplerNoise, coord);
  586. float noiseAmount=NoiseAmount*pow(blurAmount, NoiseCurve);
  587. //res=lerp(res, (cnoi.x+0.5)*res, noiseAmount*saturate(1.0-origgray*1.8));
  588. //res=lerp(res, (cnoi.x+0.5)*res, noiseAmount*saturate(1.0-origgray*0.5));
  589. float NoiseDiffusion =lerp( lerp( NoiseDiffusionDay, NoiseDiffusionNight, 1 - ENightDayFactor ), NoiseDiffusionInterior, EInteriorFactor);
  590. res=lerp(res, (cnoi.x+0.5)*res, noiseAmount*saturate(1.0-origgray*NoiseDiffusion));
  591. res.w=depth;
  592. return res;
  593. }
  594. technique PostProcess
  595. {
  596. pass P0
  597. {
  598. VertexShader = compile vs_3_0 VS_PostProcess();
  599. PixelShader = compile ps_3_0 PS_ProcessPass1();
  600. DitherEnable=FALSE;
  601. ZEnable=FALSE;
  602. CullMode=NONE;
  603. ALPHATESTENABLE=FALSE;
  604. SEPARATEALPHABLENDENABLE=FALSE;
  605. AlphaBlendEnable=FALSE;
  606. StencilEnable=FALSE;
  607. FogEnable=FALSE;
  608. SRGBWRITEENABLE=FALSE;
  609. }
  610. }
  611. technique PostProcess2
  612. {
  613. pass P0
  614. {
  615. VertexShader = compile vs_3_0 VS_PostProcess();
  616. PixelShader = compile ps_3_0 PS_ProcessPass2();
  617. DitherEnable=FALSE;
  618. ZEnable=FALSE;
  619. CullMode=NONE;
  620. ALPHATESTENABLE=FALSE;
  621. SEPARATEALPHABLENDENABLE=FALSE;
  622. AlphaBlendEnable=FALSE;
  623. StencilEnable=FALSE;
  624. FogEnable=FALSE;
  625. SRGBWRITEENABLE=FALSE;
  626. }
  627. }
  628. technique PostProcess3
  629. {
  630. pass P0
  631. {
  632. VertexShader = compile vs_3_0 VS_PostProcess();
  633. PixelShader = compile ps_3_0 PS_ProcessPass3();
  634. DitherEnable=FALSE;
  635. ZEnable=FALSE;
  636. CullMode=NONE;
  637. ALPHATESTENABLE=FALSE;
  638. SEPARATEALPHABLENDENABLE=FALSE;
  639. AlphaBlendEnable=FALSE;
  640. StencilEnable=FALSE;
  641. FogEnable=FALSE;
  642. SRGBWRITEENABLE=FALSE;
  643. }
  644. }
  645. technique PostProcess4
  646. {
  647. pass P0
  648. {
  649. VertexShader = compile vs_3_0 VS_PostProcess();
  650. PixelShader = compile ps_3_0 PS_ProcessPass4();
  651. DitherEnable=FALSE;
  652. ZEnable=FALSE;
  653. CullMode=NONE;
  654. ALPHATESTENABLE=FALSE;
  655. SEPARATEALPHABLENDENABLE=FALSE;
  656. AlphaBlendEnable=FALSE;
  657. StencilEnable=FALSE;
  658. FogEnable=FALSE;
  659. SRGBWRITEENABLE=FALSE;
  660. }
  661. }
  662. technique PostProcess5
  663. {
  664. pass P0
  665. {
  666. VertexShader = compile vs_3_0 VS_PostProcess();
  667. PixelShader = compile ps_3_0 PS_ProcessPass5();
  668. DitherEnable=FALSE;
  669. ZEnable=FALSE;
  670. CullMode=NONE;
  671. ALPHATESTENABLE=FALSE;
  672. SEPARATEALPHABLENDENABLE=FALSE;
  673. AlphaBlendEnable=FALSE;
  674. StencilEnable=FALSE;
  675. FogEnable=FALSE;
  676. SRGBWRITEENABLE=FALSE;
  677. }
  678. }
  679. //+++++++++++++++++++++++++++
  680. //Modified by Unreal Warfare
  681. //+++++++++++++++++++++++++++