Hitmantb

Untitled

Mar 19th, 2023
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 42.25 KB | None | 0 0
  1. //----------------------------------------------------------------------------------------------//
  2. // DYNAMIC GAUSSIAN BLOOM 2.2 //
  3. //----------------------------------------------------------------------------------------------//
  4. // //
  5. // enbbloom.fx file by LonelyKitsuune aka Skratzer //
  6. // for ENB (DirectX 11 Shader Model 5) //
  7. // //
  8. // Copyright (c) 2018-2020 LoneKitsuune / T.Thanner - CC BY-NC-ND 4.0 //
  9. // //
  10. //-------------------------------------------CREDITS--------------------------------------------//
  11. // //
  12. // Boris Vorontsov for ENBSeries //
  13. // //
  14. //------------------------------------------THANKS TO-------------------------------------------//
  15. // //
  16. // prod80, Sonic Ether, Sandvich Maker and Marty McFly for inspiration //
  17. // //
  18. //----------------------------------------------------------------------------------------------//
  19. // ================================== //
  20. // // Silent Horizons ENB // //
  21. // // // //
  22. // // by LonelyKitsuune // //
  23. // ================================== //
  24. //----------------------------------------------------------------------------------------------//
  25.  
  26.  
  27. /*¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯\
  28. | Multipass Bloom Flow Chart: |
  29. | |
  30. | |
  31. |PREPASS ---> Horizontal Gaussian Blur |-------> Horizontal Gaussian Blur |-------> Horizontal Gaussian Blur |
  32. | \ / | \ / | \ / |
  33. | Vertical Gaussian Blur | Vertical Gaussian Blur | Vertical Gaussian Blur |
  34. | \ / | \ / | \ / |
  35. | RenderTarget1024 -------| RenderTarget512 -----------| RenderTarget256 ------- ... |
  36. | | | | |
  37. | | | | |
  38. | | | | |
  39. | ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯Load in all RenderTargets¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ ... |
  40. | | | |
  41. | | | |
  42. | \ / |
  43. | MIX |
  44. | \ / |
  45. | BLOOM OUTPUT |
  46. \______________________________________________________________________________________________________________________________*/
  47.  
  48. //Boris' comment on ENB bloom files:
  49. //Works with hdr input and output
  50. //Bloom texture is always forced to 1024*1024 resolution
  51.  
  52.  
  53. //This file needs my helper and UI files to work!
  54. //Some options could be made UI tweakable instead
  55.  
  56.  
  57. //--------------------------------------------------------------------------------
  58. //Enables full local control over this shader file
  59. #define LOCAL_OVERRIDE 0 //[0-1]
  60.  
  61.  
  62. //--------------------------------------------------------------------------------
  63. //GENERAL OPTIONS
  64. //--------------------------------------------------------------------------------
  65. //Enable additional debugging tools
  66. #define ENABLE_TOOLS 0 //[0-1]
  67.  
  68.  
  69. //--------------------------------------------------------------------------------
  70. //PREPASS OPTIONS
  71. //--------------------------------------------------------------------------------
  72. //Switch the prepass variant
  73. #define BLOOM_PREPASS_STYLE 2 //[1-2]
  74. // 1 = Levels
  75. // 2 = Thresholds
  76.  
  77.  
  78. //UI seperation mode for the prepass
  79. #define UI_SEP_MODE_PRE 1 //[1-2]
  80. // 1 = TODIE seperated UI
  81. // 2 = DNI seperated UI
  82.  
  83.  
  84. //--------------------------------------------------------------------------------
  85. //MAIN BLOOM OPTIONS
  86. //--------------------------------------------------------------------------------
  87. //UI seperation mode for the main pass
  88. #define UI_SEP_MODE_MAIN 1 //[1-2]
  89. // 1 = TODIE seperated UI
  90. // 2 = DNI seperated UI
  91.  
  92.  
  93. //Enables a more agressive correction method that gets rid of
  94. //bright bloom flares at screen borders.
  95. // -> Can produces small visual artifacts!
  96. #define ENABLE_AGRESSIVE_BORDER_CORRECTION 0 //[0-1]
  97.  
  98.  
  99. //Enables depth based bloom width/intensity manipulation
  100. #define ENABLE_DEPTH_TESTING 0 //[0-1]-G
  101.  
  102.  
  103. //--------------------------------------------------------------------------------
  104. //BLOOM MIX OPTIONS
  105. //--------------------------------------------------------------------------------
  106. //Use automatic pass weighting
  107. #define ENABLE_AUTOMATIC_WEIGHTING 0 //[0-1]
  108.  
  109.  
  110. //Use bicubic filtering to upsample bloom pass textures
  111. #define USE_BICUBIC_FILTERING 0 //[0-1]
  112.  
  113.  
  114. //Activate per pass Bloom tinting
  115. #define ENBALE_BLOOM_TINTING 0 //[0-1]
  116.  
  117.  
  118. //Enables a additional small scale bloom for very bright objects
  119. #define ENABLE_TINYBLOOM 0 //[0-1]
  120.  
  121.  
  122. //Enables the option to mask out the bloom source
  123. #define ENABLE_SOURCE_MASKING 0 //[0-1]-G
  124.  
  125.  
  126. //Enable lens-dirt bloom reflections
  127. #define ENABLE_DIRT_REFLECTION 0 //[0-1]-G
  128.  
  129.  
  130. //Enable graining of the bloom output to reduce possible banding visiblity
  131. // -> If you dither after mixing in the bloom texture you probably don't need it
  132. #define ENABLE_BLOOM_GRAIN 0 //[0-1]
  133.  
  134.  
  135. //UI seperation mode for the mix pass
  136. #define UI_SEP_MODE_MIX 1 //[1-2]
  137. // 1 = TODIE seperated UI
  138. // 2 = DNI seperated UI
  139.  
  140.  
  141. //----------------------------------------------------------------------------------------------//
  142. // Global Parameters //
  143. //----------------------------------------------------------------------------------------------//
  144.  
  145. #if !LOCAL_OVERRIDE
  146. #undef ENABLE_DEPTH_TESTING
  147. #undef ENABLE_SOURCE_MASKING
  148. #undef ENABLE_DIRT_REFLECTION
  149. #include "enbglobals.fxh"
  150. #endif //LOCAL_OVERRIDE
  151.  
  152.  
  153. //----------------------------------------------------------------------------------------------//
  154. // Internal Parameters //
  155. //----------------------------------------------------------------------------------------------//
  156.  
  157. #include "UI/enbUI_Primer.fxh"
  158.  
  159. //Tools
  160. #define SHADERGROUP 0
  161. #include "UI/enbUI_Bloom.fxh"
  162. #undef SHADERGROUP
  163. UI_WHITESPACE(7)
  164.  
  165. //--------------------------------------------Prepass-------------------------------------------//
  166.  
  167. #if BLOOM_PREPASS_STYLE != 0
  168. #if UI_SEP_MODE_PRE == 1 //Prepass (TODIE)
  169. #define SHADERGROUP 1
  170. #define TODIE Dawn
  171. #include "UI/enbUI_Bloom.fxh"
  172. UI_SPECIAL_WHITESPACE(7)
  173.  
  174. #define TODIE Sunrise
  175. #include "UI/enbUI_Bloom.fxh"
  176. UI_SPECIAL_WHITESPACE(8)
  177.  
  178. #define TODIE Day
  179. #include "UI/enbUI_Bloom.fxh"
  180. UI_SPECIAL_WHITESPACE(9)
  181.  
  182. #define TODIE Sunset
  183. #include "UI/enbUI_Bloom.fxh"
  184. UI_SPECIAL_WHITESPACE(10)
  185.  
  186. #define TODIE Dusk
  187. #include "UI/enbUI_Bloom.fxh"
  188. UI_SPECIAL_WHITESPACE(11)
  189.  
  190. #define TODIE Night
  191. #include "UI/enbUI_Bloom.fxh"
  192. UI_SPECIAL_WHITESPACE(12)
  193.  
  194. #define TODIE Interior
  195. #include "UI/enbUI_Bloom.fxh"
  196.  
  197. UI_WHITESPACE(8)
  198. UI_WHITESPACE(9)
  199.  
  200. #undef SHADERGROUP
  201. #undef NOTFIRSTTIME
  202.  
  203.  
  204. #elif UI_SEP_MODE_PRE == 2 //Prepass (DNI)
  205. #define SHADERGROUP 1
  206.  
  207. #define TODIE Day
  208. #include "UI/enbUI_Bloom.fxh"
  209. UI_SPECIAL_WHITESPACE(7)
  210.  
  211. #define TODIE Night
  212. #include "UI/enbUI_Bloom.fxh"
  213. UI_SPECIAL_WHITESPACE(8)
  214.  
  215. #define TODIE Interior
  216. #include "UI/enbUI_Bloom.fxh"
  217.  
  218. UI_WHITESPACE(8)
  219. UI_WHITESPACE(9)
  220.  
  221. #undef SHADERGROUP
  222. #undef NOTFIRSTTIME
  223.  
  224. #endif //UI_SEP_MODE_PRE
  225. #endif //BLOOM_PREPASS_STYLE
  226.  
  227. //---------------------------------------------Main---------------------------------------------//
  228.  
  229. #if UI_SEP_MODE_MAIN == 1 //Main Bloom (TODIE)
  230. #define SHADERGROUP 2
  231. #define TODIE Dawn
  232. #include "UI/enbUI_Bloom.fxh"
  233. UI_SPECIAL_WHITESPACE(13)
  234.  
  235. #define TODIE Sunrise
  236. #include "UI/enbUI_Bloom.fxh"
  237. UI_SPECIAL_WHITESPACE(14)
  238.  
  239. #define TODIE Day
  240. #include "UI/enbUI_Bloom.fxh"
  241. UI_SPECIAL_WHITESPACE(15)
  242.  
  243. #define TODIE Sunset
  244. #include "UI/enbUI_Bloom.fxh"
  245. UI_SPECIAL_WHITESPACE(16)
  246.  
  247. #define TODIE Dusk
  248. #include "UI/enbUI_Bloom.fxh"
  249. UI_SPECIAL_WHITESPACE(17)
  250.  
  251. #define TODIE Night
  252. #include "UI/enbUI_Bloom.fxh"
  253. UI_SPECIAL_WHITESPACE(18)
  254.  
  255. #define LASTTIME
  256. #define TODIE Interior
  257. #include "UI/enbUI_Bloom.fxh"
  258.  
  259. UI_WHITESPACE(10)
  260. UI_WHITESPACE(11)
  261.  
  262. #undef SHADERGROUP
  263. #undef NOTFIRSTTIME
  264.  
  265.  
  266. #elif UI_SEP_MODE_MAIN == 2 //Main Bloom (DNI)
  267. #define SHADERGROUP 2
  268. #define TODIE Day
  269. #include "UI/enbUI_Bloom.fxh"
  270. UI_SPECIAL_WHITESPACE(13)
  271.  
  272. #define TODIE Night
  273. #include "UI/enbUI_Bloom.fxh"
  274. UI_SPECIAL_WHITESPACE(14)
  275.  
  276. #define LASTTIME
  277. #define TODIE Interior
  278. #include "UI/enbUI_Bloom.fxh"
  279.  
  280. UI_WHITESPACE(10)
  281. UI_WHITESPACE(11)
  282.  
  283. #undef SHADERGROUP
  284. #undef NOTFIRSTTIME
  285.  
  286. #endif //UI_SEP_MODE_MAIN
  287.  
  288. //----------------------------------------------Mix---------------------------------------------//
  289.  
  290. #if !ENABLE_AUTOMATIC_WEIGHTING
  291. #if UI_SEP_MODE_MIX == 1 //Bloom Mix (TODIE)
  292. #define SHADERGROUP 3
  293. #define TODIE Dawn
  294. #define SWSN 19
  295. #include "UI/enbUI_Bloom.fxh"
  296. UI_SPECIAL_WHITESPACE(28)
  297.  
  298. #define TODIE Sunrise
  299. #define SWSN 20
  300. #include "UI/enbUI_Bloom.fxh"
  301. UI_SPECIAL_WHITESPACE(29)
  302.  
  303. #define TODIE Day
  304. #define SWSN 21
  305. #include "UI/enbUI_Bloom.fxh"
  306. UI_SPECIAL_WHITESPACE(30)
  307.  
  308. #define TODIE Sunset
  309. #define SWSN 24
  310. #include "UI/enbUI_Bloom.fxh"
  311. UI_SPECIAL_WHITESPACE(31)
  312.  
  313. #define TODIE Dusk
  314. #define SWSN 25
  315. #include "UI/enbUI_Bloom.fxh"
  316. UI_SPECIAL_WHITESPACE(32)
  317.  
  318. #define TODIE Night
  319. #define SWSN 26
  320. #include "UI/enbUI_Bloom.fxh"
  321. UI_SPECIAL_WHITESPACE(33)
  322.  
  323. #define TODIE Interior
  324. #define SWSN 27
  325. #include "UI/enbUI_Bloom.fxh"
  326.  
  327. //UI_WHITESPACE(12)
  328. //UI_WHITESPACE(13)
  329.  
  330. #undef SHADERGROUP
  331. #undef NOTFIRSTTIME
  332.  
  333.  
  334. #elif UI_SEP_MODE_MIX == 2 //Bloom Mix (DNI)
  335. #define SHADERGROUP 3
  336. #define TODIE Day
  337. #define SWSN 19
  338. #include "UI/enbUI_Bloom.fxh"
  339. UI_SPECIAL_WHITESPACE(28)
  340.  
  341. #define TODIE Night
  342. #define SWSN 20
  343. #include "UI/enbUI_Bloom.fxh"
  344. UI_SPECIAL_WHITESPACE(29)
  345.  
  346. #define TODIE Interior
  347. #define SWSN 21
  348. #include "UI/enbUI_Bloom.fxh"
  349.  
  350. //UI_WHITESPACE(12)
  351. //UI_WHITESPACE(13)
  352.  
  353. #undef SHADERGROUP
  354. #undef NOTFIRSTTIME
  355.  
  356. #endif //UI_SEP_MODE_MIX
  357.  
  358. #else
  359.  
  360. #if UI_SEP_MODE_MIX == 1 //Bloom Mix (TODIE)
  361. #define SHADERGROUP 3
  362. #define TODIE Dawn
  363. #define SWSN 19
  364. #include "UI/enbUI_Bloom.fxh"
  365.  
  366. #define TODIE Sunrise
  367. #define SWSN 20
  368. #include "UI/enbUI_Bloom.fxh"
  369.  
  370. #define TODIE Day
  371. #define SWSN 21
  372. #include "UI/enbUI_Bloom.fxh"
  373.  
  374. #define TODIE Sunset
  375. #define SWSN 24
  376. #include "UI/enbUI_Bloom.fxh"
  377.  
  378. #define TODIE Dusk
  379. #define SWSN 25
  380. #include "UI/enbUI_Bloom.fxh"
  381.  
  382. #define TODIE Night
  383. #define SWSN 26
  384. #include "UI/enbUI_Bloom.fxh"
  385.  
  386. #define TODIE Interior
  387. #define SWSN 27
  388. #include "UI/enbUI_Bloom.fxh"
  389.  
  390. #undef SHADERGROUP
  391. #undef NOTFIRSTTIME
  392.  
  393.  
  394. #elif UI_SEP_MODE_MIX == 2 //Bloom Mix (DNI)
  395. #define SHADERGROUP 3
  396. #define TODIE Day
  397. #define SWSN 19
  398. #include "UI/enbUI_Bloom.fxh"
  399.  
  400. #define TODIE Night
  401. #define SWSN 20
  402. #include "UI/enbUI_Bloom.fxh"
  403.  
  404. #define TODIE Interior
  405. #define SWSN 21
  406. #include "UI/enbUI_Bloom.fxh"
  407.  
  408. #undef SHADERGROUP
  409. #undef NOTFIRSTTIME
  410.  
  411. #endif //UI_SEP_MODE_MIX
  412. #endif //ENABLE_AUTOMATIC_WEIGHTING
  413.  
  414. //----------------------------------------------------------------------------------------------//
  415. // External enb parameters, do not modify //
  416. // //
  417. //----------------------------------------------------------------------------------------------//
  418. float4 Timer; // x = generic timer in range 0..1, period of 16777216 ms (4.6 hours), y = average fps,
  419. // z = frame number (cyclically wraps to 0 after 9999 frames passed), w = frame time elapsed (in seconds)
  420. float4 ScreenSize; // x = Width, y = 1/Width, z = aspect, w = 1/aspect, aspect is Width/Height
  421. float AdaptiveQuality; // changes in range 0..1, 0 means full quality, 1 lowest dynamic quality (0.33, 0.66 are limits for quality levels)
  422. float4 TimeOfDay1; // x = dawn, y = sunrise, z = day, w = sunset. Interpolators range from 0..1
  423. float4 TimeOfDay2; // x = dusk, y = night. Interpolators range from 0..1
  424. float ENightDayFactor; // changes in range 0..1, 0 means that night time, 1 - day time
  425. float EInteriorFactor; // changes 0 or 1. 0 means that exterior, 1 - interior
  426. float FieldOfView; // FOV in degrees
  427. float4 Weather; // x = current weather index, y = outgoing weather index, z = weather transition, w = time of the day in 24 standard hours.
  428. // Weather index is value from weather ini file, for example WEATHER002 means index==2, but index==0 means that weather not captured.
  429. // -> Needs ENB Helper skse64 plugin to work correctly!
  430.  
  431.  
  432. //----------------------------------------------------------------------------------------------//
  433. // External enb debugging parameters for //
  434. // shader programmers, do not modify //
  435. //----------------------------------------------------------------------------------------------//
  436. float4 tempF1; //0,1,2,3
  437. float4 tempF2; //5,6,7,8
  438. float4 tempF3; //9,0
  439. //keyboard controlled temporary variables. Press and hold key 1,2,3...8 together with PageUp or PageDown to modify.
  440. //By default all set to 1.0
  441.  
  442. float4 tempInfo1;
  443. // xy = cursor position in range 0..1 of screen;
  444. // z = is shader editor window active;
  445. // w = mouse buttons with values 0..7 as follows:
  446. // 0 = none
  447. // 1 = left
  448. // 2 = right
  449. // 3 = left+right
  450. // 4 = middle
  451. // 5 = left+middle
  452. // 6 = right+middle
  453. // 7 = left+right+middle (or rather cat is sitting on your mouse)
  454.  
  455. float4 tempInfo2;
  456. // xy = cursor position of previous left mouse button click
  457. // zw = cursor position of previous right mouse button click
  458.  
  459.  
  460. //----------------------------------------------------------------------------------------------//
  461. // Game and mod parameters, do not modify //
  462. // //
  463. //----------------------------------------------------------------------------------------------//
  464.  
  465. Texture2D TextureDownsampled; //color R16B16G16A16 64 bit or R11G11B10 32 bit hdr format. 1024*1024 size
  466. Texture2D TextureColor; //color which is output of previous technique (except when drawed to temporary render target), R16B16G16A16 64 bit hdr format. 1024*1024 size
  467. Texture2D TextureOriginal; //color R16B16G16A16 64 bit or R11G11B10 32 bit hdr format, screen size. PLEASE AVOID USING IT BECAUSE OF ALIASING ARTIFACTS, UNLESS YOU FIX THEM
  468. Texture2D TextureDepth; //scene depth R32F 32 bit hdr format, screen size. PLEASE AVOID USING IT BECAUSE OF ALIASING ARTIFACTS, UNLESS YOU FIX THEM
  469. Texture2D TextureAperture; //this frame aperture 1*1 R32F hdr red channel only. computed in PS_Aperture of enbdepthoffield.fx
  470.  
  471. //temporary textures which can be set as render target for techniques via annotations like <string RenderTarget="RenderTargetRGBA32";>
  472. Texture2D RenderTarget1024; //R16B16G16A16F 64 bit hdr format, 1024*1024 size -- Used as bloom texture
  473. Texture2D RenderTarget512; //R16B16G16A16F 64 bit hdr format, 512*512 size -- Used as bloom texture
  474. Texture2D RenderTarget256; //R16B16G16A16F 64 bit hdr format, 256*256 size -- Used as bloom texture
  475. Texture2D RenderTarget128; //R16B16G16A16F 64 bit hdr format, 128*128 size -- Used as bloom texture
  476. Texture2D RenderTarget64; //R16B16G16A16F 64 bit hdr format, 64*64 size -- Used as bloom texture
  477. Texture2D RenderTarget32; //R16B16G16A16F 64 bit hdr format, 32*32 size -- Used as bloom texture
  478. Texture2D RenderTarget16; //R16B16G16A16F 64 bit hdr format, 16*16 size -- Used as bloom texture
  479. Texture2D RenderTargetRGBA32; //R8G8B8A8 32 bit ldr format, screen size
  480. Texture2D RenderTargetRGBA64F; //R16B16G16A16F 64 bit hdr format, screen size -- 1/4 Used as source passthrough if activated
  481.  
  482. #if ENABLE_DIRT_REFLECTION
  483. //Atlas with 4 different lensdirt textures
  484. Texture2D LensDirtAtlas <string ResourceName="Textures/LensDirtTexAtlas.png";>;
  485. #endif
  486.  
  487. SamplerState Point_Sampler
  488. {
  489. Filter = MIN_MAG_MIP_POINT;
  490. AddressU = Clamp;
  491. AddressV = Clamp;
  492. };
  493.  
  494. SamplerState Linear_Sampler
  495. {
  496. Filter = MIN_MAG_MIP_LINEAR;
  497. AddressU = Clamp;
  498. AddressV = Clamp;
  499. };
  500.  
  501.  
  502. //Helper with some useful macros, variables and functions
  503. #include "Helper/enbHelper_Common.fxh"
  504.  
  505.  
  506. //----------------------------------------------------------------------------------------------//
  507. // Structs //
  508. // //
  509. //----------------------------------------------------------------------------------------------//
  510.  
  511. struct VertexShaderInput
  512. {
  513. float3 pos : POSITION;
  514. float2 txcoord : TEXCOORD0;
  515. };
  516.  
  517. struct VertexShaderOutputBasic
  518. {
  519. float4 pos : SV_POSITION;
  520. float2 texcoord : TEXCOORD;
  521. };
  522.  
  523. struct VertexShaderOutputPrePass
  524. {
  525. float4 pos : SV_POSITION;
  526. float2 texcoord : TEXCOORD0;
  527. #if BLOOM_PREPASS_STYLE == 1
  528. NI float UI_InBlack : TODIE0;
  529. NI float UI_InWhite : TODIE1;
  530. NI float UI_OutBlack : TODIE2;
  531. NI float UI_OutWhite : TODIE3;
  532. NI float UI_Saturation : TODIE4;
  533. NI float UI_SkinAttenu : TODIE5;
  534. #elif BLOOM_PREPASS_STYLE == 2
  535. NI float UI_Brightness : TODIE0;
  536. NI float UI_Contrast : TODIE1;
  537. NI float UI_Saturation : TODIE2;
  538. NI float UI_ThresholdLower : TODIE3;
  539. NI float UI_ThresholdUpper : TODIE4;
  540. NI float UI_SkinAttenu : TODIE5;
  541. #endif
  542. };
  543.  
  544. struct VertexShaderOutputMain
  545. {
  546. float4 pos : SV_POSITION;
  547. float2 texcoord : TEXCOORD0;
  548. #if ENABLE_DEPTH_TESTING
  549. float2 origtexcoord : TEXCOORD1;
  550. #endif
  551. NI bool Hori : PRECALC0;
  552. NI bool SkipPS : PRECALC1;
  553. NI float2 ScaledPixelSize : PRECALC2;
  554. NI float4 NewScreenSize : PRECALC3;
  555. NI float Intensity : PRECALC4;
  556. NI float Sigma : PRECALC5;
  557. NI float WeightFactor : PRECALC6;
  558. NI float LoopCount : PRECALC7;
  559. };
  560.  
  561. struct VertexShaderOutputMix
  562. {
  563. float4 pos : SV_POSITION;
  564. float2 texcoord : TEXCOORD0;
  565. #if ENABLE_DIRT_REFLECTION
  566. float2 DirtCoords : TEXCOORD1;
  567. #endif
  568. NI float UI_RenderTargetStrength1024 : BSTRE0;
  569. NI float UI_RenderTargetStrength512 : BSTRE1;
  570. NI float UI_RenderTargetStrength256 : BSTRE2;
  571. NI float UI_RenderTargetStrength128 : BSTRE3;
  572. NI float UI_RenderTargetStrength64 : BSTRE4;
  573. NI float UI_RenderTargetStrength32 : BSTRE5;
  574. NI float UI_RenderTargetStrength16 : BSTRE6;
  575. #if ENBALE_BLOOM_TINTING
  576. NI float3 UI_RenderTargetTint1024 : BTINT0;
  577. NI float3 UI_RenderTargetTint512 : BTINT1;
  578. NI float3 UI_RenderTargetTint256 : BTINT2;
  579. NI float3 UI_RenderTargetTint128 : BTINT3;
  580. NI float3 UI_RenderTargetTint64 : BTINT4;
  581. NI float3 UI_RenderTargetTint32 : BTINT5;
  582. NI float3 UI_RenderTargetTint16 : BTINT6;
  583. #endif
  584. };
  585.  
  586.  
  587. //----------------------------------------------------------------------------------------------//
  588. // Variables and Macros //
  589. // //
  590. //----------------------------------------------------------------------------------------------//
  591.  
  592. //Maximum allowed output HDR brightness
  593. #define MAXHDR 16384.0
  594.  
  595. //Hardcoded resolutions for bicubic filtering and render scaling - DON'T CHANGE!
  596. #define MAX_BLOOM_RENDER_RES 1024.0
  597. #define OUTPUTRES float2(1024, 1024)
  598.  
  599. //Maximum loop limit per pass (only change it if you know what you're doing)
  600. #define MAXLOOP 30
  601.  
  602. //Global variable for gaussian weight calculation
  603. static const float SqrtTwoPI = sqrt(2.0 * PI);
  604.  
  605. //Array for the different quality level multipliers [VERYHIGH, HIGH, MEDIUM, LOW]
  606. static const float QualityLevel[4] = {1.8, 1.6, 1.2, 1.0};
  607.  
  608.  
  609. //----------------------------------------------------------------------------------------------//
  610. // Shaders //
  611. // //
  612. //----------------------------------------------------------------------------------------------//
  613.  
  614. //--------------------------------------------Prepass-------------------------------------------//
  615.  
  616. VertexShaderOutputPrePass VS_BloomPrePass(VertexShaderInput IN)
  617. {
  618. VertexShaderOutputPrePass OUT;
  619. OUT.pos = float4(IN.pos.xyz,1.0);
  620. OUT.texcoord.xy = IN.txcoord.xy;
  621.  
  622. #if UI_SEP_MODE_PRE == 1
  623.  
  624. #if BLOOM_PREPASS_STYLE == 1
  625. OUT.UI_InBlack = TODIE_SEPARATION(UI_InBlack);
  626. OUT.UI_InWhite = TODIE_SEPARATION(UI_InWhite);
  627. OUT.UI_OutBlack = TODIE_SEPARATION(UI_OutBlack);
  628. OUT.UI_OutWhite = TODIE_SEPARATION(UI_OutWhite);
  629. OUT.UI_Saturation = TODIE_SEPARATION(UI_Saturation);
  630.  
  631. #elif BLOOM_PREPASS_STYLE == 2
  632. OUT.UI_Brightness = TODIE_SEPARATION(UI_Brightness);
  633. OUT.UI_Contrast = TODIE_SEPARATION(UI_Contrast);
  634. OUT.UI_Saturation = TODIE_SEPARATION(UI_Saturation);
  635. OUT.UI_ThresholdLower = TODIE_SEPARATION(UI_ThresholdLower);
  636. OUT.UI_ThresholdUpper = TODIE_SEPARATION(UI_ThresholdUpper);
  637. #endif //BLOOM_PREPASS_STYLE
  638.  
  639. #if ENABLE_SKIN_ATTENUATION
  640. OUT.UI_SkinAttenu = TODIE_SEPARATION(UI_SkinAttenu);
  641. #endif
  642.  
  643. #elif UI_SEP_MODE_PRE == 2
  644.  
  645. #if BLOOM_PREPASS_STYLE == 1
  646. OUT.UI_InBlack = DNI_SEPARATION(UI_InBlack);
  647. OUT.UI_InWhite = DNI_SEPARATION(UI_InWhite);
  648. OUT.UI_OutBlack = DNI_SEPARATION(UI_OutBlack);
  649. OUT.UI_OutWhite = DNI_SEPARATION(UI_OutWhite);
  650. OUT.UI_Saturation = DNI_SEPARATION(UI_Saturation);
  651.  
  652. #elif BLOOM_PREPASS_STYLE == 2
  653. OUT.UI_Brightness = DNI_SEPARATION(UI_Brightness);
  654. OUT.UI_Contrast = DNI_SEPARATION(UI_Contrast);
  655. OUT.UI_Saturation = DNI_SEPARATION(UI_Saturation);
  656. OUT.UI_ThresholdLower = DNI_SEPARATION(UI_ThresholdLower);
  657. OUT.UI_ThresholdUpper = DNI_SEPARATION(UI_ThresholdUpper);
  658. #endif //BLOOM_PREPASS_STYLE
  659.  
  660. #if ENABLE_SKIN_ATTENUATION
  661. OUT.UI_SkinAttenu = DNI_SEPARATION(UI_SkinAttenu);
  662. #endif
  663.  
  664. #endif //UI_SEP_MODE_PRE
  665.  
  666. return OUT;
  667. }
  668.  
  669. float4 PS_BloomPrePass(VertexShaderOutputPrePass IN) : SV_Target
  670. {
  671. float3 Bloom = TextureDownsampled.Sample(Linear_Sampler, IN.texcoord);
  672.  
  673. //Use prepass alpha mask to attenuate bloom from skins
  674. #if ENABLE_SKIN_ATTENUATION
  675. float SkinMask = TextureOriginal.Sample(Linear_Sampler, IN.texcoord).a;
  676. Bloom *= lerp(1.0, IN.UI_SkinAttenu, saturate(1.0 - SkinMask));
  677. #endif
  678.  
  679. //Seperate luma and chroma to prevent hue/saturation shifting
  680. float BloomLuma = dot(Bloom.rgb, K_LUM);
  681. float3 BloomChroma = Bloom.rgb / BloomLuma;
  682.  
  683. #if BLOOM_PREPASS_STYLE == 1 //Levels prepass variant
  684. BloomLuma = zerolim(BloomLuma - IN.UI_InBlack) / deltalim(IN.UI_InWhite - IN.UI_InBlack);
  685. BloomLuma = mad(deltalim(IN.UI_OutWhite - IN.UI_OutBlack), BloomLuma, IN.UI_OutBlack);
  686. Bloom.rgb = zerolim(lerp(BloomLuma, BloomLuma * BloomChroma, IN.UI_Saturation));
  687.  
  688. #elif BLOOM_PREPASS_STYLE == 2 //Thresholds prepass variant
  689. BloomLuma = mad(BloomLuma, IN.UI_Brightness, 0.18) - 0.18 * IN.UI_Contrast;
  690. Bloom.rgb = zerolim(lerp(BloomLuma, BloomLuma * BloomChroma, IN.UI_Saturation));
  691.  
  692. [branch]
  693. if(UI_Smooth_Threshold) Bloom.rgb *= smoothstep(IN.UI_ThresholdLower, IN.UI_ThresholdUpper, BloomLuma);
  694. else Bloom.rgb *= LinearStep(IN.UI_ThresholdLower, IN.UI_ThresholdUpper, BloomLuma);
  695. #endif //BLOOM_PREPASS_STYLE
  696.  
  697. #if ENABLE_SOURCE_MASKING
  698. return float4(Bloom.rgb, dot(Bloom, K_LUM));
  699. #else
  700. return float4(Bloom.rgb, 1.0);
  701. #endif
  702. }
  703.  
  704.  
  705. //-----------------------------------Main Bloom Pass - Dynamic------------------------------------//
  706.  
  707. VertexShaderOutputMain VS_GaussBloomMainDynamic(VertexShaderInput IN, uniform float TexSize,
  708. uniform bool Hori,
  709. uniform float MaxLoop)
  710. {
  711. VertexShaderOutputMain OUT;
  712.  
  713. //Horizontal mode: Scales down the entire screen to the resolution of the next rendertarget
  714. //Vertical mode: Scales texture coordinates to the new screen size
  715. // -> without scaling, lower res rendertargets will have a fullres
  716. // horizontal blur and waste performance that way
  717.  
  718. float2 Transform; Transform.x = MAX_BLOOM_RENDER_RES / TexSize;
  719. Transform.y = (Transform.x - 1.0) / Transform.x;
  720.  
  721. //Screen quad and texcoord scaling
  722. OUT.pos.xy = Hori ? IN.pos.xy / Transform.x + float2(-Transform.y, Transform.y) : IN.pos.xy;
  723. OUT.pos.zw = float2(IN.pos.z, 1.0);
  724. OUT.texcoord.xy = Hori ? IN.txcoord.xy : IN.txcoord.xy / Transform.x;
  725.  
  726. //Pixelsize scaling and screen boundary computation
  727. OUT.ScaledPixelSize = rcp(TexSize) * (Hori ? float2(1.0, 0.0) : float2(0.0, ScreenSize.z / Transform.x));
  728. OUT.NewScreenSize = (Hori ? 1.0 : rcp(Transform.x)) + float4(-OUT.ScaledPixelSize, OUT.ScaledPixelSize);
  729. OUT.ScaledPixelSize *= min(Transform.x / 4.0, 2.0);
  730.  
  731. #if UI_SEP_MODE_MAIN == 1
  732. OUT.Sigma = TODIE_SEPARATION(UI_Sigma);
  733. float UI_HoriIntensity = TODIE_SEPARATION(UI_HoriIntensity);
  734. float UI_VertIntensity = TODIE_SEPARATION(UI_VertIntensity);
  735.  
  736. #elif UI_SEP_MODE_MAIN == 2
  737. OUT.Sigma = DNI_SEPARATION(UI_Sigma);
  738. float UI_HoriIntensity = DNI_SEPARATION(UI_HoriIntensity);
  739. float UI_VertIntensity = DNI_SEPARATION(UI_VertIntensity);
  740. #endif //UI_SEP_MODE_MAIN
  741.  
  742. //Skips pixel shader of low res rendertargets when bloom sigma is too small
  743. // -> saves performance and helps against aliasing artifacts
  744. OUT.SkipPS = 0.0 > (max(OUT.Sigma, 1.0) - pow(Transform.x, 0.2));
  745.  
  746. if(!OUT.SkipPS)
  747. {
  748. OUT.Sigma = min(OUT.Sigma, MaxLoop - 1.5);
  749. OUT.Intensity = Hori ? UI_HoriIntensity : UI_VertIntensity;
  750. OUT.Hori = Hori;
  751.  
  752. #if ENABLE_DEPTH_TESTING
  753. OUT.origtexcoord = IN.txcoord.xy;
  754. #else
  755. OUT.WeightFactor = rcp(OUT.Sigma * SqrtTwoPI);
  756. OUT.LoopCount = ceil(OUT.Sigma * QualityLevel[UI_Quality+1]);
  757. OUT.LoopCount = min(OUT.LoopCount, MAXLOOP);
  758. OUT.Sigma = -rcp(OUT.Sigma * OUT.Sigma);
  759. #endif
  760. }
  761.  
  762. return OUT;
  763. }
  764.  
  765. float4 PS_GaussBloomMainDynamic(VertexShaderOutputMain IN, uniform Texture2D InputTex, uniform bool HQ_Pass) : SV_Target
  766. {
  767. if(IN.SkipPS) return 0.0; //Don't use clip operation!
  768.  
  769. #if ENABLE_DEPTH_TESTING
  770. bool EnableDepthTesting = UI_Depth_Calc && !EInteriorFactor && HQ_Pass;
  771. float Depth = 1.0;
  772.  
  773. //Simple depth test to manipulate bloom sigma and intensity
  774. [branch] if(EnableDepthTesting)
  775. {
  776. Depth = TextureDepth.Sample(Linear_Sampler, IN.origtexcoord).x;
  777. Depth = FastLinDepth(Depth, UI_FarDepth);
  778. Depth = abs(UI_DepthInvert - Depth) + 1.0;
  779. IN.Sigma = lerp(IN.Sigma, IN.Sigma * Depth, UI_DepthWidth);
  780. }
  781.  
  782. IN.WeightFactor = rcp(IN.Sigma * SqrtTwoPI);
  783. IN.LoopCount = ceil(IN.Sigma * QualityLevel[UI_Quality+1]);
  784. IN.LoopCount = min(IN.LoopCount, MAXLOOP);
  785. IN.Sigma = -rcp(IN.Sigma * IN.Sigma);
  786. #endif
  787.  
  788. //Gaussian based bloom/blur with realtime adjustable kernel
  789. float3 Bloom = IN.WeightFactor * InputTex.Sample(Linear_Sampler, IN.texcoord).rgb;
  790. float WeightSum = IN.WeightFactor;
  791.  
  792. [loop] for(float i=1.0; i <= IN.LoopCount; i++)
  793. {
  794. float4 Offset = IN.texcoord.xyxy + IN.ScaledPixelSize.xyxy * float4(i.xx, -i.xx);
  795.  
  796. #if ENABLE_AGRESSIVE_BORDER_CORRECTION
  797. //Fixes wrongly weighted pixels at screen borders by ignoring out of bound samples
  798. float2 GaussWeight = IN.WeightFactor * exp(i*i*IN.Sigma);
  799. float2 OffsetTest = IN.Hori ? Offset.xz : Offset.yw;
  800. GaussWeight *= ceil(OffsetTest - DELTA) * abs(floor(OffsetTest - IN.NewScreenSize.yw));
  801. Bloom += GaussWeight.x * InputTex.SampleLevel(Linear_Sampler, Offset.xy, 0).rgb;
  802. Bloom += GaussWeight.y * InputTex.SampleLevel(Linear_Sampler, Offset.zw, 0).rgb;
  803. WeightSum += GaussWeight.x + GaussWeight.y;
  804. #else
  805. //Fixes pixels at the new screen borders by clamping offset coords to the new size
  806. float GaussWeight = IN.WeightFactor * exp(i*i*IN.Sigma);
  807. Offset = saturate(min(Offset, IN.NewScreenSize));
  808. Bloom += GaussWeight * InputTex.SampleLevel(Linear_Sampler, Offset.xy, 0).rgb;
  809. Bloom += GaussWeight * InputTex.SampleLevel(Linear_Sampler, Offset.zw, 0).rgb;
  810. WeightSum += GaussWeight * 2.0;
  811. #endif
  812. }
  813.  
  814. Bloom /= WeightSum;
  815.  
  816. #if ENABLE_DEPTH_TESTING
  817. [branch] if(EnableDepthTesting)
  818. Bloom *= lerp(IN.Intensity, IN.Intensity * Depth, UI_DepthInt); else
  819. #endif
  820. Bloom *= IN.Intensity;
  821.  
  822. return float4(Bloom, 1.0);
  823. }
  824.  
  825.  
  826. //----------------------------------------SourceGrab Pass---------------------------------------//
  827.  
  828. #if ENABLE_SOURCE_MASKING
  829. //Grab and write bloomsource at half screen res to the rendertarget
  830. VertexShaderOutputBasic VS_GrabSource (VertexShaderInput IN)
  831. {
  832. VertexShaderOutputBasic OUT;
  833. OUT.pos.xy = IN.pos.xy * 0.5 + float2(-0.5, 0.5);
  834. OUT.pos.zw = float2(IN.pos.z, 1.0);
  835. OUT.texcoord.xy = IN.txcoord.xy;
  836. return OUT;
  837. }
  838.  
  839. float4 PS_GrabSource(VertexShaderOutputBasic IN) : SV_Target
  840. {
  841. if(UI_Mask_BloomSource) return TextureColor.Sample(Linear_Sampler, IN.texcoord);
  842. else return 0.0;
  843. }
  844. #endif
  845.  
  846.  
  847. //----------------------------------------Bloom Mix Pass----------------------------------------//
  848.  
  849. VertexShaderOutputMix VS_BloomMix(VertexShaderInput IN)
  850. {
  851. VertexShaderOutputMix OUT;
  852. OUT.pos = float4(IN.pos.xyz,1.0);
  853. OUT.texcoord.xy = IN.txcoord.xy;
  854.  
  855. #if ENABLE_DIRT_REFLECTION
  856. OUT.DirtCoords = AtlasFetch_4(IN.txcoord, UI_DirtSelect);
  857. #endif
  858.  
  859. #if ENABLE_AUTOMATIC_WEIGHTING
  860. #if UI_SEP_MODE_MIX == 1
  861. float UI_AutoWeight_Bias = TODIE_SEPARATION(UI_AutoWeight_Bias);
  862. #elif UI_SEP_MODE_MIX == 2
  863. float UI_AutoWeight_Bias = DNI_SEPARATION(UI_AutoWeight_Bias);
  864. #endif
  865.  
  866. float PassStrength[7];
  867.  
  868. float WeightFactor = rcp(UI_AutoWeight_Bias * SqrtTwoPI);
  869. float Sigma = rcp(UI_AutoWeight_Bias * UI_AutoWeight_Bias);
  870.  
  871. [unroll] for(int i=0; i<7; i++)
  872. PassStrength[i] = WeightFactor * exp(i*i*-Sigma);
  873.  
  874. OUT.UI_RenderTargetStrength1024 = PassStrength[0];
  875. OUT.UI_RenderTargetStrength512 = PassStrength[1];
  876. OUT.UI_RenderTargetStrength256 = PassStrength[2];
  877. OUT.UI_RenderTargetStrength128 = PassStrength[3];
  878. OUT.UI_RenderTargetStrength64 = PassStrength[4];
  879. OUT.UI_RenderTargetStrength32 = PassStrength[5];
  880. OUT.UI_RenderTargetStrength16 = PassStrength[6];
  881.  
  882. #else
  883.  
  884. #if UI_SEP_MODE_MIX == 1
  885. OUT.UI_RenderTargetStrength1024 = TODIE_SEPARATION(UI_RenderTargetStrength1024);
  886. OUT.UI_RenderTargetStrength512 = TODIE_SEPARATION(UI_RenderTargetStrength512);
  887. OUT.UI_RenderTargetStrength256 = TODIE_SEPARATION(UI_RenderTargetStrength256);
  888. OUT.UI_RenderTargetStrength128 = TODIE_SEPARATION(UI_RenderTargetStrength128);
  889. OUT.UI_RenderTargetStrength64 = TODIE_SEPARATION(UI_RenderTargetStrength64);
  890. OUT.UI_RenderTargetStrength32 = TODIE_SEPARATION(UI_RenderTargetStrength32);
  891. OUT.UI_RenderTargetStrength16 = TODIE_SEPARATION(UI_RenderTargetStrength16);
  892.  
  893. #elif UI_SEP_MODE_MIX == 2
  894. OUT.UI_RenderTargetStrength1024 = DNI_SEPARATION(UI_RenderTargetStrength1024);
  895. OUT.UI_RenderTargetStrength512 = DNI_SEPARATION(UI_RenderTargetStrength512);
  896. OUT.UI_RenderTargetStrength256 = DNI_SEPARATION(UI_RenderTargetStrength256);
  897. OUT.UI_RenderTargetStrength128 = DNI_SEPARATION(UI_RenderTargetStrength128);
  898. OUT.UI_RenderTargetStrength64 = DNI_SEPARATION(UI_RenderTargetStrength64);
  899. OUT.UI_RenderTargetStrength32 = DNI_SEPARATION(UI_RenderTargetStrength32);
  900. OUT.UI_RenderTargetStrength16 = DNI_SEPARATION(UI_RenderTargetStrength16);
  901. #endif //UI_SEP_MODE_MIX
  902. #endif //ENABLE_AUTOMATIC_WEIGHTING
  903.  
  904.  
  905. #if ENBALE_BLOOM_TINTING
  906. #if UI_SEP_MODE_MIX == 1
  907. OUT.UI_RenderTargetTint1024 = TODIE_SEPARATION(UI_RenderTargetTint1024);
  908. OUT.UI_RenderTargetTint512 = TODIE_SEPARATION(UI_RenderTargetTint512);
  909. OUT.UI_RenderTargetTint256 = TODIE_SEPARATION(UI_RenderTargetTint256);
  910. OUT.UI_RenderTargetTint128 = TODIE_SEPARATION(UI_RenderTargetTint128);
  911. OUT.UI_RenderTargetTint64 = TODIE_SEPARATION(UI_RenderTargetTint64);
  912. OUT.UI_RenderTargetTint32 = TODIE_SEPARATION(UI_RenderTargetTint32);
  913. OUT.UI_RenderTargetTint16 = TODIE_SEPARATION(UI_RenderTargetTint16);
  914.  
  915. #elif UI_SEP_MODE_MIX == 2
  916. OUT.UI_RenderTargetTint1024 = DNI_SEPARATION(UI_RenderTargetTint1024);
  917. OUT.UI_RenderTargetTint512 = DNI_SEPARATION(UI_RenderTargetTint512);
  918. OUT.UI_RenderTargetTint256 = DNI_SEPARATION(UI_RenderTargetTint256);
  919. OUT.UI_RenderTargetTint128 = DNI_SEPARATION(UI_RenderTargetTint128);
  920. OUT.UI_RenderTargetTint64 = DNI_SEPARATION(UI_RenderTargetTint64);
  921. OUT.UI_RenderTargetTint32 = DNI_SEPARATION(UI_RenderTargetTint32);
  922. OUT.UI_RenderTargetTint16 = DNI_SEPARATION(UI_RenderTargetTint16);
  923. #endif //UI_SEP_MODE_MIX
  924.  
  925. OUT.UI_RenderTargetTint1024 = ColorToChroma(OUT.UI_RenderTargetTint1024);
  926. OUT.UI_RenderTargetTint512 = ColorToChroma(OUT.UI_RenderTargetTint512);
  927. OUT.UI_RenderTargetTint256 = ColorToChroma(OUT.UI_RenderTargetTint256);
  928. OUT.UI_RenderTargetTint128 = ColorToChroma(OUT.UI_RenderTargetTint128);
  929. OUT.UI_RenderTargetTint64 = ColorToChroma(OUT.UI_RenderTargetTint64);
  930. OUT.UI_RenderTargetTint32 = ColorToChroma(OUT.UI_RenderTargetTint32);
  931. OUT.UI_RenderTargetTint16 = ColorToChroma(OUT.UI_RenderTargetTint16);
  932. #endif //ENBALE_BLOOM_TINTING
  933.  
  934. //Check if RenderTarget got skipped (helps with normalization later)
  935. OUT.UI_RenderTargetStrength1024 *= RenderTarget1024.Load(0).a;
  936. OUT.UI_RenderTargetStrength512 *= RenderTarget512. Load(0).a;
  937. OUT.UI_RenderTargetStrength256 *= RenderTarget256. Load(0).a;
  938. OUT.UI_RenderTargetStrength128 *= RenderTarget128. Load(0).a;
  939. OUT.UI_RenderTargetStrength64 *= RenderTarget64. Load(0).a;
  940. OUT.UI_RenderTargetStrength32 *= RenderTarget32. Load(0).a;
  941. OUT.UI_RenderTargetStrength16 *= RenderTarget16. Load(0).a;
  942.  
  943. return OUT;
  944. }
  945.  
  946.  
  947. float4 PS_BloomMix(VertexShaderOutputMix IN) : SV_Target
  948. {
  949. float3 Bloom, Bloom1024, Bloom512, Bloom256, Bloom128, Bloom64, Bloom32, Bloom16;
  950.  
  951. #if USE_BICUBIC_FILTERING
  952. Bloom1024 = RenderTarget1024.Sample(Linear_Sampler, IN.texcoord).rgb * IN.UI_RenderTargetStrength1024;
  953. Bloom512 = BicubicFilter(RenderTarget512, IN.texcoord, OUTPUTRES).rgb * IN.UI_RenderTargetStrength512;
  954. Bloom256 = BicubicFilter(RenderTarget256, IN.texcoord, OUTPUTRES).rgb * IN.UI_RenderTargetStrength256;
  955. Bloom128 = BicubicFilter(RenderTarget128, IN.texcoord, OUTPUTRES).rgb * IN.UI_RenderTargetStrength128;
  956. Bloom64 = BicubicFilter(RenderTarget64, IN.texcoord, OUTPUTRES).rgb * IN.UI_RenderTargetStrength64;
  957. Bloom32 = BicubicFilter(RenderTarget32, IN.texcoord, OUTPUTRES).rgb * IN.UI_RenderTargetStrength32;
  958. Bloom16 = BicubicFilter(RenderTarget16, IN.texcoord, OUTPUTRES).rgb * IN.UI_RenderTargetStrength16;
  959. #else
  960. Bloom1024 = RenderTarget1024.Sample(Linear_Sampler, IN.texcoord).rgb * IN.UI_RenderTargetStrength1024;
  961. Bloom512 = RenderTarget512. Sample(Linear_Sampler, IN.texcoord).rgb * IN.UI_RenderTargetStrength512;
  962. Bloom256 = RenderTarget256. Sample(Linear_Sampler, IN.texcoord).rgb * IN.UI_RenderTargetStrength256;
  963. Bloom128 = RenderTarget128. Sample(Linear_Sampler, IN.texcoord).rgb * IN.UI_RenderTargetStrength128;
  964. Bloom64 = RenderTarget64. Sample(Linear_Sampler, IN.texcoord).rgb * IN.UI_RenderTargetStrength64;
  965. Bloom32 = RenderTarget32. Sample(Linear_Sampler, IN.texcoord).rgb * IN.UI_RenderTargetStrength32;
  966. Bloom16 = RenderTarget16. Sample(Linear_Sampler, IN.texcoord).rgb * IN.UI_RenderTargetStrength16;
  967. #endif
  968.  
  969. #if ENBALE_BLOOM_TINTING
  970. Bloom1024 *= IN.UI_RenderTargetTint1024;
  971. Bloom512 *= IN.UI_RenderTargetTint512;
  972. Bloom256 *= IN.UI_RenderTargetTint256;
  973. Bloom128 *= IN.UI_RenderTargetTint128;
  974. Bloom64 *= IN.UI_RenderTargetTint64;
  975. Bloom32 *= IN.UI_RenderTargetTint32;
  976. Bloom16 *= IN.UI_RenderTargetTint16;
  977. #endif
  978.  
  979. #if ENABLE_TOOLS
  980. [branch] switch (UI_PASSOUTPUT)
  981. {
  982. case 1: return float4(clamp(Bloom1024,0.0,MAXHDR),1.0);
  983. case 2: return float4(clamp(Bloom512, 0.0,MAXHDR),1.0);
  984. case 3: return float4(clamp(Bloom256, 0.0,MAXHDR),1.0);
  985. case 4: return float4(clamp(Bloom128, 0.0,MAXHDR),1.0);
  986. case 5: return float4(clamp(Bloom64, 0.0,MAXHDR),1.0);
  987. case 6: return float4(clamp(Bloom32, 0.0,MAXHDR),1.0);
  988. case 7: return float4(clamp(Bloom16, 0.0,MAXHDR),1.0);
  989. default: break; //case 0
  990. }
  991.  
  992. #if ENABLE_DEPTH_TESTING
  993. [branch] if (UI_Visualize_Depth)
  994. {
  995. float Depth = TextureDepth.Sample(Linear_Sampler, IN.texcoord).x;
  996. Depth = FastLinDepth(Depth, UI_FarDepth);
  997. return abs(UI_DepthInvert - Depth) + 1.0;
  998. }
  999. #endif //ENABLE_DEPTH_TESTING
  1000. #endif //ENABLE_TOOLS
  1001.  
  1002. Bloom = Bloom1024 + Bloom512 + Bloom256 + Bloom128 + Bloom64 + Bloom32 + Bloom16;
  1003.  
  1004. if(UI_Normalize_BloomSum)
  1005. Bloom /= IN.UI_RenderTargetStrength1024 + IN.UI_RenderTargetStrength512 +
  1006. IN.UI_RenderTargetStrength256 + IN.UI_RenderTargetStrength128 +
  1007. IN.UI_RenderTargetStrength64 + IN.UI_RenderTargetStrength32 +
  1008. IN.UI_RenderTargetStrength16;
  1009.  
  1010. #if ENABLE_TINYBLOOM
  1011. if(UI_TinyBloom) Bloom += pow(dot(zerolim(Bloom512 - Bloom1024 * 0.5), K_LUM) * 0.5, 1.5);
  1012. #endif
  1013.  
  1014. #if ENABLE_SOURCE_MASKING
  1015. [branch] if (UI_Mask_BloomSource)
  1016. {
  1017. float4 Source = RenderTargetRGBA64F.Sample(Linear_Sampler, IN.texcoord*0.5);
  1018. Bloom = lerp (Bloom, Bloom - Source.rgb, Source.a * UI_Mask_Weight);
  1019. }
  1020. #endif
  1021.  
  1022. #if ENABLE_DIRT_REFLECTION
  1023. [branch] if (UI_EnableDirtRef)
  1024. {
  1025. float2 RefCoords = 1.0 - IN.texcoord;
  1026. float3 DirtRef = 0.5 * (RenderTarget32.Sample(Linear_Sampler, RefCoords).rgb +
  1027. RenderTarget16.Sample(Linear_Sampler, RefCoords).rgb);
  1028. DirtRef += DirtRef * LensDirtAtlas.Sample(Linear_Sampler, IN.DirtCoords).rgb;
  1029. DirtRef *= smoothstep(0.0, UI_DirtRefThresh * 30.0, dot(DirtRef, K_LUM));
  1030. Bloom += DirtRef * UI_DirtRef * pow(length(IN.texcoord * 2.0 - 1.0), UI_DirtRefCurve);
  1031. }
  1032. #endif
  1033.  
  1034. #if ENABLE_BLOOM_GRAIN //Simple bloom restricted grain
  1035. [branch] if(UI_Enable_Grain)
  1036. {
  1037. //Grain is here to obscure banding a bit, but if you want to get rid of it more effectively
  1038. //add dithering after mixing in the bloom texture
  1039. float3 Grain;
  1040. float3 TimerSeed = Timer.x * UI_GrainMotion + float3(0.01, 0.02, 0.03);
  1041.  
  1042. Grain.r = RandomGauss(IN.texcoord + float2(0.0, TimerSeed.x));
  1043. Grain.g = RandomGauss(IN.texcoord + float2(TimerSeed.y, 0.0));
  1044. Grain.b = RandomGauss(IN.texcoord + TimerSeed.z);
  1045. Grain = lerp(dot(Grain, N_LUM), Grain, UI_GrainSaturation);
  1046.  
  1047. float GrainInt = saturate(max3(Bloom) * 4.0) * UI_GrainIntensity;
  1048. Bloom += Grain * GrainInt - GrainInt * 0.5;
  1049. }
  1050. #endif
  1051.  
  1052. return float4(clamp(Bloom, 0.0, MAXHDR), 1.0);
  1053. }
  1054.  
  1055.  
  1056. //----------------------------------------------------------------------------------------------//
  1057. // Techniques //
  1058. // //
  1059. //----------------------------------------------------------------------------------------------//
  1060.  
  1061. #define BLOOMTECH11(NAME, VS_VALUES, PS_VALUES) technique11 NAME { pass p0 { \
  1062. SetVertexShader(CompileShader(vs_5_0, VS_GaussBloomMainDynamic##VS_VALUES));\
  1063. SetPixelShader(CompileShader(ps_5_0, PS_GaussBloomMainDynamic##PS_VALUES)); } }
  1064.  
  1065.  
  1066. #if !ENABLE_SOURCE_MASKING
  1067. TECH11 (KitsuuneGaussianBloom <string UIName="Dynamic Multipass Bloom - Kitsuune";>, VS_BloomPrePass(), PS_BloomPrePass())
  1068. BLOOMTECH11 (KitsuuneGaussianBloom1, (1024.0, true, 256.0), (TextureColor, true))
  1069. BLOOMTECH11 (KitsuuneGaussianBloom2 <string RenderTarget="RenderTarget1024";>, (1024.0, false, 256.0), (TextureColor, true))
  1070. BLOOMTECH11 (KitsuuneGaussianBloom3, (512.0, true, 128.0), (RenderTarget1024, true))
  1071. BLOOMTECH11 (KitsuuneGaussianBloom4 <string RenderTarget="RenderTarget512";>, (512.0, false, 128.0), (TextureColor, true))
  1072. BLOOMTECH11 (KitsuuneGaussianBloom5, (256.0, true, 64.0), (RenderTarget512, false))
  1073. BLOOMTECH11 (KitsuuneGaussianBloom6 <string RenderTarget="RenderTarget256";>, (256.0, false, 64.0), (TextureColor, false))
  1074. BLOOMTECH11 (KitsuuneGaussianBloom7, (128.0, true, 32.0), (RenderTarget256, false))
  1075. BLOOMTECH11 (KitsuuneGaussianBloom8 <string RenderTarget="RenderTarget128";>, (128.0, false, 32.0), (TextureColor, false))
  1076. BLOOMTECH11 (KitsuuneGaussianBloom9, (64.0, true, 16.0), (RenderTarget128, false))
  1077. BLOOMTECH11 (KitsuuneGaussianBloom10 <string RenderTarget="RenderTarget64";>, (64.0, false, 16.0), (TextureColor, false))
  1078. BLOOMTECH11 (KitsuuneGaussianBloom11, (32.0, true, 8.0), (RenderTarget64, false))
  1079. BLOOMTECH11 (KitsuuneGaussianBloom12 <string RenderTarget="RenderTarget32";>, (32.0, false, 8.0), (TextureColor, false))
  1080. BLOOMTECH11 (KitsuuneGaussianBloom13, (16.0, true, 4.0), (RenderTarget32, false))
  1081. BLOOMTECH11 (KitsuuneGaussianBloom14 <string RenderTarget="RenderTarget16";>, (16.0, false, 4.0), (TextureColor, false))
  1082. TECH11 (KitsuuneGaussianBloom15, VS_BloomMix(), PS_BloomMix())
  1083.  
  1084. #else
  1085.  
  1086. TECH11 (KitsuuneGaussianBloom <string UIName="Dynamic Multipass Bloom - Kitsuune";>, VS_BloomPrePass(), PS_BloomPrePass())
  1087. TECH11 (KitsuuneGaussianBloom1 <string RenderTarget="RenderTargetRGBA64F";>, VS_GrabSource(), PS_GrabSource())
  1088. BLOOMTECH11 (KitsuuneGaussianBloom2, (1024.0, true, 256.0), (TextureColor, true))
  1089. BLOOMTECH11 (KitsuuneGaussianBloom3 <string RenderTarget="RenderTarget1024";>, (1024.0, false, 256.0), (TextureColor, true))
  1090. BLOOMTECH11 (KitsuuneGaussianBloom4, (512.0, true, 128.0), (RenderTarget1024, true))
  1091. BLOOMTECH11 (KitsuuneGaussianBloom5 <string RenderTarget="RenderTarget512";>, (512.0, false, 128.0), (TextureColor, true))
  1092. BLOOMTECH11 (KitsuuneGaussianBloom6, (256.0, true, 64.0), (RenderTarget512, false))
  1093. BLOOMTECH11 (KitsuuneGaussianBloom7 <string RenderTarget="RenderTarget256";>, (256.0, false, 64.0), (TextureColor, false))
  1094. BLOOMTECH11 (KitsuuneGaussianBloom8, (128.0, true, 32.0), (RenderTarget256, false))
  1095. BLOOMTECH11 (KitsuuneGaussianBloom9 <string RenderTarget="RenderTarget128";>, (128.0, false, 32.0), (TextureColor, false))
  1096. BLOOMTECH11 (KitsuuneGaussianBloom10, (64.0, true, 16.0), (RenderTarget128, false))
  1097. BLOOMTECH11 (KitsuuneGaussianBloom11 <string RenderTarget="RenderTarget64";>, (64.0, false, 16.0), (TextureColor, false))
  1098. BLOOMTECH11 (KitsuuneGaussianBloom12, (32.0, true, 8.0), (RenderTarget64, false))
  1099. BLOOMTECH11 (KitsuuneGaussianBloom13 <string RenderTarget="RenderTarget32";>, (32.0, false, 8.0), (TextureColor, false))
  1100. BLOOMTECH11 (KitsuuneGaussianBloom14, (16.0, true, 4.0), (RenderTarget32, false))
  1101. BLOOMTECH11 (KitsuuneGaussianBloom15 <string RenderTarget="RenderTarget16";>, (16.0, false, 4.0), (TextureColor, false))
  1102. TECH11 (KitsuuneGaussianBloom16, VS_BloomMix(), PS_BloomMix())
  1103. #endif
  1104.  
  1105.  
Advertisement
Add Comment
Please, Sign In to add comment