Advertisement
Guest User

Untitled

a guest
May 27th, 2018
1,234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 30.08 KB | None | 0 0
  1. // THERE IS NOTHING TO EDIT BELOW THIS POINT ++++++++++++++++++++++++++++++++++++++++++++
  2. // GUI ELEMENTS +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  3. bool Section_Options <
  4. string UIName = "------Options & Settings----";
  5. > = {false};
  6. float QUALITYLEVEL <
  7. string UIName="Bloom Quality";
  8. string UIWidget="Quality";
  9. float UIMin=0;
  10. float UIMax=2;
  11. float UIStep=1;
  12. > = {0}; //0 best compromise between quality and performance
  13. bool Section_Depth <
  14. string UIName = "------Depth-----------------";
  15. > = {false};
  16. float zfar <
  17. string UIName="Far Depth";
  18. string UIWidget="Spinner";
  19. float UIMin=0.0;
  20. float UIMax=100000.0;
  21. float UIStep=0.1;
  22. > = {50.0};
  23. float minDepthE <
  24. string UIName="Exterior: Min Depth";
  25. string UIWidget="Spinner";
  26. float UIMin=0;
  27. float UIMax=1;
  28. float UIStep=0.001;
  29. > = {0.67};
  30. float minDepthI <
  31. string UIName="Interior: Min Depth";
  32. string UIWidget="Spinner";
  33. float UIMin=0;
  34. float UIMax=1;
  35. float UIStep=0.001;
  36. > = {0.67};
  37. bool Section_Tint <
  38. string UIName = "------Tinting---------------";
  39. > = {false};
  40. bool use_tinting <
  41. string UIName="Tinting: Enable Bloom Tinting";
  42. > = {true};
  43. float tint_type <
  44. string UIName="Tinting: Tint Method";
  45. string UIWidget="Spinner";
  46. float UIMin=1;
  47. float UIMax=3;
  48. float UIStep=1;
  49. > = {1};
  50. float3 tint_colorD <
  51. string UIName="Tinting: Day Tint RGB Color";
  52. string UIWidget="Color";
  53. > = {0.6, 0.4, 1.0};
  54. float tint_levelD <
  55. string UIName="Tinting: Day Tint Level";
  56. string UIWidget="Spinner";
  57. float UIMin=0.0;
  58. float UIMax=1.0;
  59. float UIStep=0.001;
  60. > = {0.44};
  61. float tint_mixD <
  62. string UIName="Tinting: (method 3) Day Tint Mix";
  63. string UIWidget="Spinner";
  64. float UIMin=0.0;
  65. float UIMax=1.0;
  66. float UIStep=0.001;
  67. > = {0.22};
  68. float3 tint_colorN <
  69. string UIName="Tinting: Night Tint RGB Color";
  70. string UIWidget="Color";
  71. > = {0.6, 0.4, 1.0};
  72. float tint_levelN <
  73. string UIName="Tinting: Night Tint Level";
  74. string UIWidget="Spinner";
  75. float UIMin=0.0;
  76. float UIMax=1.0;
  77. float UIStep=0.001;
  78. > = {0.44};
  79. float tint_mixN <
  80. string UIName="Tinting: (method 3) Night Tint Mix";
  81. string UIWidget="Spinner";
  82. float UIMin=0.0;
  83. float UIMax=1.0;
  84. float UIStep=0.001;
  85. > = {0.22};
  86. float3 tint_colorI <
  87. string UIName="Tinting: Interior Tint RGB Color";
  88. string UIWidget="Color";
  89. > = {0.6, 0.4, 1.0};
  90. float tint_levelI <
  91. string UIName="Tinting: Interior Tint Level";
  92. string UIWidget="Spinner";
  93. float UIMin=0.0;
  94. float UIMax=1.0;
  95. float UIStep=0.001;
  96. > = {0.44};
  97. float tint_mixI <
  98. string UIName="Tinting: (method 3) Interior Tint Mix";
  99. string UIWidget="Spinner";
  100. float UIMin=0.0;
  101. float UIMax=1.0;
  102. float UIStep=0.001;
  103. > = {0.22};
  104. bool Section_BDay <
  105. string UIName = "------Bloom Day-------------";
  106. > = {false};
  107. float BinBlackD <
  108. string UIName="Day Bloom: Black Level";
  109. string UIWidget="Spinner";
  110. float UIMin=0.0;
  111. float UIMax=1.0;
  112. float UIStep=0.001;
  113. > = {0.0};
  114. float BinGammaD <
  115. string UIName="Day Bloom: Gamma Curve";
  116. string UIWidget="Spinner";
  117. float UIMin=0.0;
  118. float UIMax=5.0;
  119. float UIStep=0.001;
  120. > = {1.0};
  121. float BinWhiteD <
  122. string UIName="Day Bloom: White Level";
  123. string UIWidget="Spinner";
  124. float UIMin=0.0;
  125. float UIMax=1.0;
  126. float UIStep=0.001;
  127. > = {1.0};
  128. float BoutBlackD <
  129. string UIName="Day Bloom: Black Cutoff";
  130. string UIWidget="Spinner";
  131. float UIMin=0.0;
  132. float UIMax=1.0;
  133. float UIStep=0.001;
  134. > = {0.0};
  135. float BoutWhiteD <
  136. string UIName="Day Bloom: White Cutoff";
  137. string UIWidget="Spinner";
  138. float UIMin=0.0;
  139. float UIMax=1.0;
  140. float UIStep=0.001;
  141. > = {1.0};
  142. float bsatD <
  143. string UIName="Day Bloom: Saturation";
  144. string UIWidget="Spinner";
  145. float UIMin=0.0;
  146. float UIMax=2.0;
  147. float UIStep=0.001;
  148. > = {1.0};
  149. float BloomSigmaD <
  150. string UIName="Day Bloom: Sigma (Blur width)";
  151. string UIWidget="Spinner";
  152. float UIMin=1.2;
  153. float UIMax=64.0;
  154. float UIStep=0.001;
  155. > = {6.0};
  156. float hIntensityD <
  157. string UIName="Day Bloom: X Intensity";
  158. string UIWidget="Spinner";
  159. float UIMin=1.0;
  160. float UIMax=10.0;
  161. float UIStep=0.001;
  162. > = {1.0};
  163. float vIntensityD <
  164. string UIName="Day Bloom: X+Y Intensity";
  165. string UIWidget="Spinner";
  166. float UIMin=1.0;
  167. float UIMax=10.0;
  168. float UIStep=0.001;
  169. > = {1.0};
  170. bool Section_BNight <
  171. string UIName = "------Bloom Night-----------";
  172. > = {false};
  173. float BinBlackN <
  174. string UIName="Night Bloom: Black Level";
  175. string UIWidget="Spinner";
  176. float UIMin=0.0;
  177. float UIMax=1.0;
  178. float UIStep=0.001;
  179. > = {0.0};
  180. float BinGammaN <
  181. string UIName="Night Bloom: Gamma Curve";
  182. string UIWidget="Spinner";
  183. float UIMin=0.0;
  184. float UIMax=5.0;
  185. float UIStep=0.001;
  186. > = {1.0};
  187. float BinWhiteN <
  188. string UIName="Night Bloom: White Level";
  189. string UIWidget="Spinner";
  190. float UIMin=0.0;
  191. float UIMax=1.0;
  192. float UIStep=0.001;
  193. > = {1.0};
  194. float BoutBlackN <
  195. string UIName="Night Bloom: Black Cutoff";
  196. string UIWidget="Spinner";
  197. float UIMin=0.0;
  198. float UIMax=1.0;
  199. float UIStep=0.001;
  200. > = {0.0};
  201. float BoutWhiteN <
  202. string UIName="Night Bloom: White Cutoff";
  203. string UIWidget="Spinner";
  204. float UIMin=0.0;
  205. float UIMax=1.0;
  206. float UIStep=0.001;
  207. > = {1.0};
  208. float bsatN <
  209. string UIName="Night Bloom: Saturation";
  210. string UIWidget="Spinner";
  211. float UIMin=0.0;
  212. float UIMax=2.0;
  213. float UIStep=0.001;
  214. > = {1.0};
  215. float BloomSigmaN <
  216. string UIName="Night Bloom: Sigma (Blur width)";
  217. string UIWidget="Spinner";
  218. float UIMin=1.2;
  219. float UIMax=64.0;
  220. float UIStep=0.001;
  221. > = {6.0};
  222. float hIntensityN <
  223. string UIName="Night Bloom: X Intensity";
  224. string UIWidget="Spinner";
  225. float UIMin=1.0;
  226. float UIMax=10.0;
  227. float UIStep=0.001;
  228. > = {1.0};
  229. float vIntensityN <
  230. string UIName="Night Bloom: X+Y Intensity";
  231. string UIWidget="Spinner";
  232. float UIMin=1.0;
  233. float UIMax=10.0;
  234. float UIStep=0.001;
  235. > = {1.0};
  236. bool Section_BInterior <
  237. string UIName = "------Bloom Interior--------";
  238. > = {false};
  239. float BinBlackI <
  240. string UIName="Interior Bloom: Black Level";
  241. string UIWidget="Spinner";
  242. float UIMin=0.0;
  243. float UIMax=1.0;
  244. float UIStep=0.001;
  245. > = {0.0};
  246. float BinGammaI <
  247. string UIName="Interior Bloom: Gamma Curve";
  248. string UIWidget="Spinner";
  249. float UIMin=0.0;
  250. float UIMax=5.0;
  251. float UIStep=0.001;
  252. > = {1.0};
  253. float BinWhiteI <
  254. string UIName="Interior Bloom: White Level";
  255. string UIWidget="Spinner";
  256. float UIMin=0.0;
  257. float UIMax=1.0;
  258. float UIStep=0.001;
  259. > = {1.0};
  260. float BoutBlackI <
  261. string UIName="Interior Bloom: Black Cutoff";
  262. string UIWidget="Spinner";
  263. float UIMin=0.0;
  264. float UIMax=1.0;
  265. float UIStep=0.001;
  266. > = {0.0};
  267. float BoutWhiteI <
  268. string UIName="Interior Bloom: White Cutoff";
  269. string UIWidget="Spinner";
  270. float UIMin=0.0;
  271. float UIMax=1.0;
  272. float UIStep=0.001;
  273. > = {1.0};
  274. float bsatI <
  275. string UIName="Interior Bloom: Saturation";
  276. string UIWidget="Spinner";
  277. float UIMin=0.0;
  278. float UIMax=2.0;
  279. float UIStep=0.001;
  280. > = {1.0};
  281. float BloomSigmaI <
  282. string UIName="Interior Bloom: Sigma (Blur width)";
  283. string UIWidget="Spinner";
  284. float UIMin=1.2;
  285. float UIMax=64.0;
  286. float UIStep=0.001;
  287. > = {6.0};
  288. float hIntensityI <
  289. string UIName="Interior Bloom: X Intensity";
  290. string UIWidget="Spinner";
  291. float UIMin=1.0;
  292. float UIMax=10.0;
  293. float UIStep=0.001;
  294. > = {1.0};
  295. float vIntensityI <
  296. string UIName="Interior Bloom: X+Y Intensity";
  297. string UIWidget="Spinner";
  298. float UIMin=1.0;
  299. float UIMax=10.0;
  300. float UIStep=0.001;
  301. > = {1.0};
  302. bool Section_Textures <
  303. string UIName = "------Texture Selection-----";
  304. > = {false};
  305. bool tex_select1 <
  306. string UIName="Enable Tex 1: 512x512";
  307. > = {true};
  308. bool tex_select2 <
  309. string UIName="Enable Tex 2: 256x256";
  310. > = {true};
  311. bool tex_select3 <
  312. string UIName="Enable Tex 3: 128x128";
  313. > = {true};
  314. bool tex_select4 <
  315. string UIName="Enable Tex 4: 64x64";
  316. > = {true};
  317. bool tex_select5 <
  318. string UIName="Enable Tex 5: 32x32";
  319. > = {true};
  320. bool tex_select6 <
  321. string UIName="Enable Tex 6: 16x16";
  322. > = {true};
  323. bool tex_select7 <
  324. string UIName="Enable Tex 7: 8x8";
  325. > = {true};
  326. bool Section_SR <
  327. string UIName = "------Texture Sample Range--";
  328. > = {false};
  329. float BloomTex1SR <
  330. string UIName="Tex 1: Sample Range";
  331. string UIWidget="Spinner";
  332. float UIMin=0.0;
  333. float UIMax=0.5;
  334. float UIStep=0.001;
  335. > = {0.5};
  336. float BloomTex2SR <
  337. string UIName="Tex 2: Sample Range";
  338. string UIWidget="Spinner";
  339. float UIMin=0.0;
  340. float UIMax=0.5;
  341. float UIStep=0.001;
  342. > = {0.25};
  343. float BloomTex3SR <
  344. string UIName="Tex 3: Sample Range";
  345. string UIWidget="Spinner";
  346. float UIMin=0.0;
  347. float UIMax=0.5;
  348. float UIStep=0.001;
  349. > = {0.25};
  350. float BloomTex4SR <
  351. string UIName="Tex 4: Sample Range";
  352. string UIWidget="Spinner";
  353. float UIMin=0.0;
  354. float UIMax=0.5;
  355. float UIStep=0.001;
  356. > = {0.25};
  357. float BloomTex5SR <
  358. string UIName="Tex 5: Sample Range";
  359. string UIWidget="Spinner";
  360. float UIMin=0.0;
  361. float UIMax=0.5;
  362. float UIStep=0.001;
  363. > = {0.25};
  364. float BloomTex6SR <
  365. string UIName="Tex 6: Sample Range";
  366. string UIWidget="Spinner";
  367. float UIMin=0.0;
  368. float UIMax=0.5;
  369. float UIStep=0.001;
  370. > = {0.25};
  371. float BloomTex7SR <
  372. string UIName="Tex 7: Sample Range";
  373. string UIWidget="Spinner";
  374. float UIMin=0.0;
  375. float UIMax=0.5;
  376. float UIStep=0.001;
  377. > = {0.25};
  378. bool Section_Noise <
  379. string UIName = "------Noise-----------------";
  380. > = {false};
  381. float GrainMotion <
  382. string UIName="Noise Motion";
  383. string UIWidget="Spinner";
  384. float UIMin=0.0;
  385. float UIMax=50.0;
  386. float UIStep=0.001;
  387. > = {0.004};
  388. float GrainSaturation <
  389. string UIName="Noise Saturation";
  390. string UIWidget="Spinner";
  391. float UIMin=0.0;
  392. float UIMax=50.0;
  393. float UIStep=0.001;
  394. > = {1.0};
  395. float GrainIntensityE <
  396. string UIName="Noise Intensity Exterior";
  397. string UIWidget="Spinner";
  398. float UIMin=0.0;
  399. float UIMax=50.0;
  400. float UIStep=0.001;
  401. > = {0.004};
  402. float GrainIntensityI <
  403. string UIName="Noise Intensity Interior";
  404. string UIWidget="Spinner";
  405. float UIMin=0.0;
  406. float UIMax=50.0;
  407. float UIStep=0.001;
  408. > = {0.000};
  409.  
  410. // SOME STANDARD VARIABLES ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  411.  
  412. //float4 tempF1; // Not used //0,1,2,3
  413. //float4 tempF2; // Not used //5,6,7,8
  414. //float4 tempF3; // Not used //9,0
  415. float4 ScreenSize; // x=Width, y=1/Width, z=ScreenScaleY (Width/Height), w=1/ScreenScaleY
  416. float4 Timer; // Used for Noise
  417. float4 TempParameters; // Used to correct DIRECT3D half pixel offset correction in vertex (.xy), Screenfactor per pass 1/TextureSize (.z), Passnumber (.w)
  418. //float4 LenzParameters; // Not used
  419. float4 BloomParameters; // Not used: BloomRadius1 (GTA4) (.x), BloomRadius2(GTA4) (.y) //Used: BloomBlueShiftAmount (.z), BloomContrast (.w)
  420. float ENightDayFactor; // 0=Night, 1=Day
  421. float EInteriorFactor; // 0=Exterior, 1=Interior
  422.  
  423. // TEXTURES AND SAMPLERS ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  424.  
  425. Texture2D TextureDepth;
  426. Texture2D TextureDownsampled;
  427. Texture2D texBloom2;
  428. Texture2D texBloom3;
  429. Texture2D texBloom4;
  430. Texture2D texBloom5;
  431. Texture2D texBloom6;
  432. Texture2D texBloom7;//additional bloom tex
  433. Texture2D texBloom8;//additional bloom tex
  434.  
  435. SamplerState SamplerDepth
  436. {
  437. Texture = TextureDepth;
  438. FILTER = MIN_MAG_MIP_POINT;
  439. AddressU = Clamp;
  440. AddressV = Clamp;
  441. MAXLOD=0;
  442. MIPLODBIAS=0;
  443. };
  444.  
  445. SamplerState SamplerBloom1
  446. {
  447. Texture = TextureDownsampled;
  448. FILTER = MIN_MAG_MIP_LINEAR;
  449. AddressU = Clamp;
  450. AddressV = Clamp;
  451. MAXLOD=0;
  452. MIPLODBIAS=0;
  453. };
  454.  
  455. SamplerState SamplerBloom2
  456. {
  457. Texture = texBloom2;
  458. FILTER = MIN_MAG_MIP_LINEAR;
  459. AddressU = Clamp;
  460. AddressV = Clamp;
  461. MAXLOD=0;
  462. MIPLODBIAS=0;
  463. };
  464.  
  465. SamplerState SamplerBloom3
  466. {
  467. Texture = texBloom3;
  468. FILTER = MIN_MAG_MIP_LINEAR;
  469. AddressU = Clamp;
  470. AddressV = Clamp;
  471. MAXLOD=0;
  472. MIPLODBIAS=0;
  473. };
  474.  
  475. SamplerState SamplerBloom4
  476. {
  477. Texture = texBloom4;
  478. FILTER = MIN_MAG_MIP_LINEAR;
  479. AddressU = Clamp;
  480. MAXLOD=0;
  481. MIPLODBIAS=0;
  482. };
  483.  
  484. SamplerState SamplerBloom5
  485. {
  486. Texture = texBloom5;
  487. FILTER = MIN_MAG_MIP_LINEAR;
  488. AddressU = Clamp;
  489. AddressV = Clamp;
  490. MAXLOD=0;
  491. MIPLODBIAS=0;
  492. };
  493.  
  494. SamplerState SamplerBloom6
  495. {
  496. Texture = texBloom6;
  497. FILTER = MIN_MAG_MIP_LINEAR;
  498. AddressU = Clamp;
  499. AddressV = Clamp;
  500. MAXLOD=0;
  501. MIPLODBIAS=0;
  502. };
  503.  
  504. SamplerState SamplerBloom7
  505. {
  506. Texture = texBloom7;
  507. FILTER = MIN_MAG_MIP_LINEAR;
  508. AddressU = Clamp;
  509. AddressV = Clamp;
  510. MAXLOD=0;
  511. MIPLODBIAS=0;
  512. };
  513.  
  514. SamplerState SamplerBloom8
  515. {
  516. Texture = texBloom8;
  517. FILTER = MIN_MAG_MIP_LINEAR;
  518. AddressU = Clamp;
  519. AddressV = Clamp;
  520. MAXLOD=0;
  521. MIPLODBIAS=0;
  522. };
  523.  
  524. // STRUCTURES +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  525.  
  526. struct VS_OUTPUT_POST
  527. {
  528. float4 vpos : POSITION;
  529. float2 txcoord0 : TEXCOORD0;
  530. };
  531.  
  532. struct VS_INPUT_POST
  533. {
  534. float3 pos : POSITION;
  535. float2 txcoord0 : TEXCOORD0;
  536. };
  537.  
  538. // VERTEX SHADER ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  539.  
  540. VS_OUTPUT_POST VS_Bloom(VS_INPUT_POST IN)
  541. {
  542. VS_OUTPUT_POST OUT;
  543. OUT.vpos = float4(IN.pos.x, IN.pos.y, IN.pos.z, 1.0);
  544. OUT.txcoord0.xy = IN.txcoord0.xy + TempParameters.xy;
  545.  
  546. return OUT;
  547. };
  548.  
  549. // HELPER FUNCTIONS AND CONSTANTS +++++++++++++++++++++++++++++++++++++++++++++++++++++++
  550.  
  551. //Set loopcount limit - DO NOT CHANGE, EVER.
  552. #define LOOPCOUNT 150
  553.  
  554. // PI, required to calculate weight
  555. #define PI 3.1415926535897932384626433832795
  556.  
  557. float linearDepth(float d, float n, float f)
  558. {
  559. return (2.0 * n)/(f + n - d * (f - n));
  560. }
  561.  
  562. // Pseudo Random Number generator.
  563. float random(in float2 uv)
  564. {
  565. float2 noise = (frac(sin(dot(uv , float2(12.9898,78.233) * 2.0)) * 43758.5453));
  566. return abs(noise.x + noise.y) * 0.5;
  567. }
  568.  
  569. // SHADERS ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  570.  
  571. float4 PS_BloomPrePass(VS_OUTPUT_POST IN) : COLOR
  572. {
  573. float4 bloomuv;
  574. float4 bloom = 0.0;
  575.  
  576. float2 invtexSize = TempParameters.z;
  577. if( TempParameters.w == 0 ) invtexSize.y *= ScreenSize.z;
  578. float2 coord = IN.txcoord0.xy;
  579.  
  580. const float2 offset[4]=
  581. {
  582. float2(0.25, 0.25),
  583. float2(0.25, -0.25),
  584. float2(-0.25, 0.25),
  585. float2(-0.25, -0.25)
  586. };
  587. for( int i=0; i<4; i++ )
  588. {
  589. bloomuv.xy = offset[i];
  590. bloomuv.xy = ( bloomuv.xy * invtexSize.xy ) + coord.xy;
  591. bloom += tex2D( SamplerBloom1, bloomuv.xy );
  592. }
  593. bloom.xyz *= 0.25;
  594.  
  595. if( TempParameters.w == 1 )
  596. {
  597. float BinBlack = lerp( lerp( BinBlackN, BinBlackD, ENightDayFactor ), BinBlackI, EInteriorFactor );
  598. float BinGamma = lerp( lerp( BinGammaN, BinGammaD, ENightDayFactor ), BinGammaI, EInteriorFactor );
  599. float BinWhite = lerp( lerp( BinWhiteN, BinWhiteD, ENightDayFactor ), BinWhiteI, EInteriorFactor );
  600. float BoutWhite = lerp( lerp( BoutWhiteN, BoutWhiteD, ENightDayFactor ), BoutWhiteI, EInteriorFactor );
  601. float BoutBlack = lerp( lerp( BoutBlackN, BoutBlackD, ENightDayFactor ), BoutBlackI, EInteriorFactor );
  602. bloom.xyz = pow( max( bloom.xyz - BinBlack , 0.0f ) / max( BinWhite - BinBlack, 0.0001f ), BinGamma ) * max( BoutWhite - BoutBlack, 0.0001f ) + BoutBlack;
  603. }
  604.  
  605. bloom.xyz = min( bloom.xyz, 32768.0 );
  606. bloom.xyz = max( bloom.xyz, 0.0 );
  607. bloom.w = 1;
  608. return bloom;
  609. }
  610.  
  611. float4 PS_BloomTexture1(VS_OUTPUT_POST IN) : COLOR
  612. {
  613. // --------------------------- //
  614. // FIRST GAUSSIAN PASSES //
  615. // BLOOM TINT HAPPENS HERE //
  616. // --------------------------- //
  617.  
  618. float2 coord = IN.txcoord0.xy;
  619.  
  620. float Q = 0.0f;
  621. if ( QUALITYLEVEL == 2 )
  622. Q = 0.6f;
  623. else if ( QUALITYLEVEL == 1 )
  624. Q = 0.8f;
  625. else if ( QUALITYLEVEL == 0 ) //best
  626. Q = 0.985f;
  627.  
  628. float hIntensity = lerp( lerp( hIntensityN, hIntensityD, ENightDayFactor ), hIntensityI, EInteriorFactor );
  629. float BloomSigma = lerp( lerp( BloomSigmaN, BloomSigmaD, ENightDayFactor ), BloomSigmaI, EInteriorFactor );
  630. float minDepth = lerp( minDepthE, minDepthI, EInteriorFactor );
  631. float px = TempParameters.z;
  632. float py = px;
  633. BloomSigma = BloomSigma * (ScreenSize.y/TempParameters.z);
  634.  
  635. // Get Depth info and apply to Sigma
  636. float Depth = tex2D( SamplerDepth, float2( IN.txcoord0.xy )).x;
  637. float SigmaDepth = min( max( linearDepth( Depth, 0.5f, zfar ), minDepth ), 1.0f );
  638. BloomSigma = max( BloomSigma * SigmaDepth, 0.6f ); //limited to not give weird result
  639.  
  640. // Declare all needed variables
  641. float SigmaSum;
  642. float3 Sigma;
  643. float sampleOffset;
  644. float4 bloom;
  645. float4 bloom1;
  646. float4 bloom2;
  647. float4 srcbloom;
  648. float d;
  649. float d1;
  650. float d2;
  651. float2 q;
  652.  
  653. // Get bloom
  654. bloom = tex2D( SamplerBloom1, float2( coord.xy ));
  655. srcbloom = bloom;
  656. d = linearDepth( Depth, 0.5f, 3500.0f );
  657.  
  658. q = float2(1, 0); //horizontal, left switch for future use
  659.  
  660. SigmaSum = 0.0f;
  661. Sigma.x = 1.0f / ( sqrt( 2.0f * PI ) * BloomSigma );
  662. Sigma.y = exp( -0.5f / ( BloomSigma * BloomSigma ));
  663. Sigma.z = Sigma.y * Sigma.y;
  664.  
  665. sampleOffset = 1.0f;
  666. bloom *= Sigma.x;
  667. SigmaSum += Sigma.x;
  668. Sigma.xy *= Sigma.yz;
  669.  
  670. for(int i = 1; i < LOOPCOUNT && SigmaSum < Q; ++i) {
  671.  
  672. bloom1 = tex2Dlod( SamplerBloom1, float4( coord.xy + float2( sampleOffset*px*q.x, sampleOffset*py*q.y ), 0, 0 )) * Sigma.x;
  673. bloom2 = tex2Dlod( SamplerBloom1, float4( coord.xy - float2( sampleOffset*px*q.x, sampleOffset*py*q.y ), 0, 0 )) * Sigma.x;
  674.  
  675. d1 = tex2Dlod(SamplerDepth, float4( IN.txcoord0.xy + float2(sampleOffset*px*q.x, sampleOffset*py*q.y), 0, 0 )).x;
  676. d1 = linearDepth( d1, 0.5f, 3500.0f );
  677. d2 = tex2Dlod(SamplerDepth, float4( IN.txcoord0.xy - float2(sampleOffset*px*q.x, sampleOffset*py*q.y), 0, 0 )).x;
  678. d2 = linearDepth( d2, 0.5f, 3500.0f );
  679.  
  680. bloom += lerp( srcbloom * Sigma.x, bloom1, smoothstep( d-d1, d, d1 ));
  681. bloom += lerp( srcbloom * Sigma.x, bloom2, smoothstep( d-d2, d, d2 ));
  682.  
  683. SigmaSum += ( 2.0f * Sigma.x );
  684. sampleOffset += 1.0f;
  685. Sigma.xy *= Sigma.yz;
  686. }
  687. bloom.xyz /= SigmaSum;
  688. bloom.xyz *= hIntensity;
  689.  
  690. //Bloom Tinting
  691. if (use_tinting==true) {
  692.  
  693. float3 tint_color = lerp( lerp( tint_colorN, tint_colorD, ENightDayFactor ), tint_colorI, EInteriorFactor );
  694. float tint_level = lerp( lerp( tint_levelN, tint_levelD, ENightDayFactor ), tint_levelI, EInteriorFactor );
  695. float tint_mix = lerp( lerp( tint_mixN, tint_mixD, ENightDayFactor ), tint_mixI, EInteriorFactor );
  696.  
  697. float3 tintColor = 0.0f;
  698.  
  699. if (tint_type==1)
  700. tintColor = tint_color * tint_level;
  701. if (tint_type==2)
  702. tintColor = tex2Dlod(SamplerBloom6, float4( coord.xy, 0, 0 )).xyz * tint_level;
  703. if (tint_type==3) {
  704. float3 tcol1 = tint_color;
  705. float3 tcol2 = tex2Dlod(SamplerBloom6, float4( coord.xy, 0, 0 )).xyz;
  706. tintColor = lerp( tcol1.xyz, tcol2.xyz, tint_mix ) * tint_level;
  707. }
  708.  
  709. float ttt = max( dot( bloom.xyz, 0.33333332f ) - dot( srcbloom.xyz, 0.33333332f ), 0.0f );
  710. float gray = BloomParameters.z * ttt * 10.0f;
  711. float mixfact = gray / ( gray + 1.0f );
  712. mixfact *= 1.0f - saturate( ( TempParameters.w - 1.0f ) * 0.2f );
  713. tintColor.xy += 1.0f - saturate( ( TempParameters.w - 1.0f ) * 0.3f );
  714. tintColor.xy = saturate( tintColor.xy );
  715.  
  716. bloom.xyz *= lerp( 1.0f, tintColor.xyz, mixfact );
  717. }
  718. bloom.xyz = saturate( bloom.xyz );
  719. bloom.w = 1.0f;
  720.  
  721. return bloom;
  722. }
  723.  
  724. float4 PS_BloomTexture2(VS_OUTPUT_POST IN) : COLOR
  725. {
  726. // --------------------------- //
  727. // SECOND GAUSSIAN PASSES //
  728. // --------------------------- //
  729.  
  730. float2 coord = IN.txcoord0.xy;
  731.  
  732. float Q = 0.0f;
  733. if ( QUALITYLEVEL == 2 )
  734. Q = 0.6f;
  735. else if ( QUALITYLEVEL == 1 )
  736. Q = 0.8f;
  737. else if ( QUALITYLEVEL == 0 ) //best
  738. Q = 0.985f;
  739.  
  740. float vIntensity = lerp( lerp( vIntensityN, vIntensityD, ENightDayFactor ), vIntensityI, EInteriorFactor );
  741. float BloomSigma = lerp( lerp( BloomSigmaN, BloomSigmaD, ENightDayFactor ), BloomSigmaI, EInteriorFactor );
  742. float minDepth = lerp( minDepthE, minDepthI, EInteriorFactor );
  743. float px = TempParameters.z;
  744. float py = px;
  745. BloomSigma = BloomSigma * (ScreenSize.y/TempParameters.z) * ScreenSize.z;
  746.  
  747. // Get Depth info and apply to Sigma
  748. float Depth = tex2D( SamplerDepth, float2( IN.txcoord0.xy )).x;
  749. float SigmaDepth = min( max( linearDepth( Depth, 0.5f, zfar ), minDepth ), 1.0f );
  750. BloomSigma = max( BloomSigma * SigmaDepth, 0.6f ); //limited to not give weird result
  751.  
  752. // Declare all needed variables
  753. float SigmaSum;
  754. float3 Sigma;
  755. float sampleOffset;
  756. float4 bloom;
  757. float4 bloom1;
  758. float4 bloom2;
  759. float4 srcbloom;
  760. float d;
  761. float d1;
  762. float d2;
  763. float2 q;
  764.  
  765. // Get bloom
  766. bloom = tex2D( SamplerBloom1, float2( coord.xy ));
  767. srcbloom = bloom;
  768. d = linearDepth( Depth, 0.5f, 3500.0f );
  769.  
  770. q = float2(0, 1); //vertical, left switch for future use
  771.  
  772. SigmaSum = 0.0f;
  773. Sigma.x = 1.0f / ( sqrt( 2.0f * PI ) * BloomSigma );
  774. Sigma.y = exp( -0.5f / ( BloomSigma * BloomSigma ));
  775. Sigma.z = Sigma.y * Sigma.y;
  776.  
  777. sampleOffset = 1.0f;
  778. bloom *= Sigma.x;
  779. SigmaSum += Sigma.x;
  780. Sigma.xy *= Sigma.yz;
  781.  
  782. for(int i = 1; i < LOOPCOUNT && SigmaSum < Q; ++i) {
  783.  
  784. bloom1 = tex2Dlod( SamplerBloom1, float4( coord.xy + float2( sampleOffset*px*q.x, sampleOffset*py*q.y ), 0, 0 )) * Sigma.x;
  785. bloom2 = tex2Dlod( SamplerBloom1, float4( coord.xy - float2( sampleOffset*px*q.x, sampleOffset*py*q.y ), 0, 0 )) * Sigma.x;
  786.  
  787. d1 = tex2Dlod(SamplerDepth, float4( IN.txcoord0.xy + float2(sampleOffset*px*q.x, sampleOffset*py*q.y), 0, 0 )).x;
  788. d1 = linearDepth( d1, 0.5f, 3500.0f );
  789. d2 = tex2Dlod(SamplerDepth, float4( IN.txcoord0.xy - float2(sampleOffset*px*q.x, sampleOffset*py*q.y), 0, 0 )).x;
  790. d2 = linearDepth( d2, 0.5f, 3500.0f );
  791.  
  792. bloom += lerp( srcbloom * Sigma.x, bloom1, smoothstep( d-d1, d, d1 ));
  793. bloom += lerp( srcbloom * Sigma.x, bloom2, smoothstep( d-d2, d, d2 ));
  794.  
  795. SigmaSum += ( 2.0f * Sigma.x );
  796. sampleOffset += 1.0f;
  797. Sigma.xy *= Sigma.yz;
  798. }
  799. bloom.xyz /= SigmaSum;
  800. bloom.xyz *= vIntensity;
  801. bloom.xyz = saturate( bloom.xyz );
  802. bloom.w = 1.0f;
  803.  
  804. return bloom;
  805. }
  806.  
  807. float4 PS_BloomPostPass(VS_OUTPUT_POST IN) : COLOR
  808. {
  809. // --------------------------- //
  810. // POSTPASS TO COMBINE TEX //
  811. // --------------------------- //
  812.  
  813. // NOTES [prod80]
  814. // Filter, Mix and Match some textures
  815.  
  816. float4 bloom = 0;
  817. float4 temp = 0;
  818. float2 invtexSize = 0.001953125; //(1/512)
  819. float2 bcoord = 0;
  820. float2 steps = 0;
  821. bcoord = IN.txcoord0.xy * 512;
  822. bcoord = floor( bcoord.xy ) + 0.5;
  823. bcoord *= invtexSize.xy; //snap to texel center on 512px resolution
  824.  
  825. //Bloom Sampler 5 - 512x512 texture, result from prepass blur
  826. steps = 1; //(512/512)
  827. steps *= invtexSize.xy;
  828. temp = tex2D( SamplerBloom5, float2( -BloomTex1SR, BloomTex1SR ) * steps.xy + bcoord.xy );
  829. temp += tex2D( SamplerBloom5, float2( -BloomTex1SR, -BloomTex1SR ) * steps.xy + bcoord.xy );
  830. temp += tex2D( SamplerBloom5, float2( BloomTex1SR, -BloomTex1SR ) * steps.xy + bcoord.xy );
  831. temp += tex2D( SamplerBloom5, float2( BloomTex1SR, BloomTex1SR ) * steps.xy + bcoord.xy );
  832. bloom += 0.25 * temp * tex_select1;
  833.  
  834. //Bloom Sampler 1 - 256x256 texture
  835. steps = 2; //(512/256)
  836. steps *= invtexSize.xy;
  837. temp = tex2D( SamplerBloom1, float2( -BloomTex2SR, BloomTex2SR ) * steps.xy + bcoord.xy );
  838. temp += tex2D( SamplerBloom1, float2( -BloomTex2SR, -BloomTex2SR ) * steps.xy + bcoord.xy );
  839. temp += tex2D( SamplerBloom1, float2( BloomTex2SR, -BloomTex2SR ) * steps.xy + bcoord.xy );
  840. temp += tex2D( SamplerBloom1, float2( BloomTex2SR, BloomTex2SR ) * steps.xy + bcoord.xy );
  841. bloom += 0.25 * temp * tex_select2;
  842.  
  843. //Bloom Sampler 2 - 128x128 texture
  844. steps = 4; //(512/128)
  845. steps *= invtexSize.xy;
  846. temp = tex2D( SamplerBloom2, float2( -BloomTex3SR, BloomTex3SR ) * steps.xy + bcoord.xy );
  847. temp += tex2D( SamplerBloom2, float2( -BloomTex3SR, -BloomTex3SR ) * steps.xy + bcoord.xy );
  848. temp += tex2D( SamplerBloom2, float2( BloomTex3SR, -BloomTex3SR ) * steps.xy + bcoord.xy );
  849. temp += tex2D( SamplerBloom2, float2( BloomTex3SR, BloomTex3SR ) * steps.xy + bcoord.xy );
  850. bloom += 0.25 * temp * tex_select3;
  851.  
  852. //Bloom Sampler 3 - 64x64 texture
  853. steps = 8; //(512/64)
  854. steps *= invtexSize.xy;
  855. temp = tex2D( SamplerBloom3, float2( -BloomTex4SR, BloomTex4SR ) * steps.xy + bcoord.xy );
  856. temp += tex2D( SamplerBloom3, float2( -BloomTex4SR, -BloomTex4SR ) * steps.xy + bcoord.xy );
  857. temp += tex2D( SamplerBloom3, float2( BloomTex4SR, -BloomTex4SR ) * steps.xy + bcoord.xy );
  858. temp += tex2D( SamplerBloom3, float2( BloomTex4SR, BloomTex4SR ) * steps.xy + bcoord.xy );
  859. bloom += 0.25 * temp * tex_select4;
  860.  
  861. //Bloom Sampler 4 - 32x32 texture
  862. steps = 16; //(512/32)
  863. steps *= invtexSize.xy;
  864. temp = tex2D( SamplerBloom4, float2( -BloomTex5SR, BloomTex5SR ) * steps.xy + bcoord.xy );
  865. temp += tex2D( SamplerBloom4, float2( -BloomTex5SR, -BloomTex5SR ) * steps.xy + bcoord.xy );
  866. temp += tex2D( SamplerBloom4, float2( BloomTex5SR, -BloomTex5SR ) * steps.xy + bcoord.xy );
  867. temp += tex2D( SamplerBloom4, float2( BloomTex5SR, BloomTex5SR ) * steps.xy + bcoord.xy );
  868. bloom += 0.25 * temp * tex_select5;
  869.  
  870. //Not using Sampler 6 (Original input)
  871.  
  872. //Bloom Sampler 7 - 16x16 texture
  873. steps = 32; //(512/16)
  874. steps *= invtexSize.xy;
  875. temp = tex2D( SamplerBloom7, float2( -BloomTex6SR, BloomTex6SR ) * steps.xy + bcoord.xy );
  876. temp += tex2D( SamplerBloom7, float2( -BloomTex6SR, -BloomTex6SR ) * steps.xy + bcoord.xy );
  877. temp += tex2D( SamplerBloom7, float2( BloomTex6SR, -BloomTex6SR ) * steps.xy + bcoord.xy );
  878. temp += tex2D( SamplerBloom7, float2( BloomTex6SR, BloomTex6SR ) * steps.xy + bcoord.xy );
  879. bloom += 0.25 * temp * tex_select6;
  880.  
  881. //Bloom Sampler 8 - 8x8 texture
  882. steps = 64; //(512/8)
  883. steps *= invtexSize.xy;
  884. temp = tex2D( SamplerBloom8, float2( -BloomTex7SR, BloomTex7SR ) * steps.xy + bcoord.xy );
  885. temp += tex2D( SamplerBloom8, float2( -BloomTex7SR, -BloomTex7SR ) * steps.xy + bcoord.xy );
  886. temp += tex2D( SamplerBloom8, float2( BloomTex7SR, -BloomTex7SR ) * steps.xy + bcoord.xy );
  887. temp += tex2D( SamplerBloom8, float2( BloomTex7SR, BloomTex7SR ) * steps.xy + bcoord.xy );
  888. bloom += 0.25 * temp * tex_select7;
  889.  
  890. //Final result
  891. bloom /= ( tex_select1 + tex_select2 + tex_select3 + tex_select4 + tex_select5 + tex_select6 + tex_select7 );
  892.  
  893. //Saturation
  894. float bloomsat = lerp( lerp( bsatN, bsatD, ENightDayFactor ), bsatI, EInteriorFactor );
  895. float4 saturation = 0;
  896. saturation.xy = float2( min( min( bloom.x, bloom.y ), bloom.z ), max( max( bloom.x, bloom.y ), bloom.z ));
  897. saturation.z = saturation.y - saturation.x;
  898. saturation.w = dot( bloom.xyz, float3( 0.2125, 0.7154, 0.0721 ));
  899. float3 min_sat = lerp( saturation.w, bloom.xyz, bloomsat );
  900. //Below math may produce negatives when color close to pure, ie 0.75, 0.01, 0.025 or 0.95, 0.75, 0.03 Compensating by giving correct return to add negative(s) to positive(s)
  901. float3 max_sat = lerp( saturation.w, bloom.xyz, 1 + ( bloomsat - 1 ) * ( 1 - saturation.z ));
  902. float3 neg = min( max_sat.xyz + 1, 1 );
  903. neg.xyz = saturate( 1 - neg.xyz );
  904. float negsum = dot( neg.xyz, 1 );
  905. max_sat.xyz = max( max_sat.xyz, 0 );
  906. max_sat.xyz = max_sat.xyz + saturate( sign( max_sat.xyz )) * negsum.xxx;
  907. bloom.xyz = lerp( min_sat.xyz, max_sat.xyz, step( 1, bloomsat ));
  908.  
  909. //Adding noice to fight off banding
  910. float GrainTimerSeed = Timer.x * GrainMotion;
  911. float2 GrainTexCoordSeed = IN.txcoord0.xy * 1.0;
  912.  
  913. //Generate grain seeds
  914. float2 GrainSeed1 = GrainTexCoordSeed + float2( 0.0, GrainTimerSeed );
  915. float2 GrainSeed2 = GrainTexCoordSeed + float2( GrainTimerSeed, 0.0 );
  916. float2 GrainSeed3 = GrainTexCoordSeed + float2( GrainTimerSeed, GrainTimerSeed );
  917.  
  918. //Generate pseudo random noise
  919. float GrainNoise1 = random( GrainSeed1 );
  920. float GrainNoise2 = random( GrainSeed2 );
  921. float GrainNoise3 = random( GrainSeed3 );
  922. float GrainNoise4 = ( GrainNoise1 + GrainNoise2 + GrainNoise3 ) * 0.333333333;
  923.  
  924. //Combine results
  925. float GrainIntensity= lerp( GrainIntensityE, GrainIntensityI, EInteriorFactor );
  926. float3 GrainNoise = float3( GrainNoise4, GrainNoise4, GrainNoise4 );
  927. float3 GrainColor = float3( GrainNoise1, GrainNoise2, GrainNoise3 );
  928. float3 Noise = ( lerp( GrainNoise, GrainColor, GrainSaturation ) * GrainIntensity ) - ( GrainIntensity * 0.5);
  929.  
  930. //Add noise to color
  931. bloom.xyz += Noise.xyz;
  932.  
  933. bloom.xyz = saturate( bloom.xyz );
  934. bloom.w = 1.0f;
  935.  
  936. //Final output of shader is 512x512 texture
  937. return bloom;
  938. }
  939.  
  940. // TECHNIQUES +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  941.  
  942. technique BloomPrePass
  943. {
  944. pass p0
  945. {
  946. SetVertexShader(CompileShader(vs_5_0, VS_Bloom()));
  947. SetPixelShader(CompileShader(ps_5_0, PS_BloomPrePass()));
  948.  
  949. ColorWriteEnable = ALPHA|RED|GREEN|BLUE;
  950. CullMode = NONE;
  951. AlphaBlendEnable = FALSE;
  952. AlphaTestEnable = FALSE;
  953. SEPARATEALPHABLENDENABLE = FALSE;
  954. FogEnable = FALSE;
  955. SRGBWRITEENABLE = FALSE;
  956. }
  957. }
  958.  
  959. technique BloomTexture1
  960. {
  961. pass p0
  962. {
  963. SetVertexShader(CompileShader(vs_5_0, VS_Bloom()));
  964. SetPixelShader(CompileShader(ps_5_0, PS_BloomTexture1()));
  965.  
  966. ColorWriteEnable = ALPHA|RED|GREEN|BLUE;
  967. CullMode = NONE;
  968. AlphaBlendEnable = FALSE;
  969. AlphaTestEnable = FALSE;
  970. SEPARATEALPHABLENDENABLE = FALSE;
  971. FogEnable = FALSE;
  972. SRGBWRITEENABLE = FALSE;
  973. }
  974. }
  975.  
  976. technique BloomTexture2
  977. {
  978. pass p0
  979. {
  980. SetVertexShader(CompileShader(vs_5_0, VS_Bloom()));
  981. SetPixelShader(CompileShader(ps_5_0, PS_BloomTexture2()));
  982.  
  983. ColorWriteEnable = ALPHA|RED|GREEN|BLUE;
  984. CullMode = NONE;
  985. AlphaBlendEnable = FALSE;
  986. AlphaTestEnable = FALSE;
  987. SEPARATEALPHABLENDENABLE = FALSE;
  988. FogEnable = FALSE;
  989. SRGBWRITEENABLE = FALSE;
  990. }
  991. }
  992.  
  993. technique BloomPostPass
  994. {
  995. pass p0
  996. {
  997. SetVertexShader(CompileShader(vs_5_0, VS_Bloom()));
  998. SetPixelShader(CompileShader(ps_5_0, PS_BloomPostPass()));
  999.  
  1000. ColorWriteEnable = ALPHA|RED|GREEN|BLUE;
  1001. CullMode = NONE;
  1002. AlphaBlendEnable = FALSE;
  1003. AlphaTestEnable = FALSE;
  1004. SEPARATEALPHABLENDENABLE = FALSE;
  1005. FogEnable = FALSE;
  1006. SRGBWRITEENABLE = FALSE;
  1007. }
  1008. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement