Advertisement
Guest User

Enbbloom

a guest
May 24th, 2012
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.18 KB | None | 0 0
  1. //++++++++++++++++++++++++++++++++++++++++++++
  2. // ENBSeries effect file
  3. // visit http://enbdev.com for updates
  4. // Copyright (c) 2007-2011 Boris Vorontsov
  5. //++++++++++++++++++++++++++++++++++++++++++++
  6.  
  7.  
  8.  
  9. //+++++++++++++++++++++++++++++
  10. //internal parameters, can be modified
  11. //+++++++++++++++++++++++++++++
  12. //none
  13.  
  14.  
  15.  
  16. //+++++++++++++++++++++++++++++
  17. //external parameters, do not modify
  18. //+++++++++++++++++++++++++++++
  19. //keyboard controlled temporary variables (in some versions exists in the config file). Press and hold key 1,2,3...8 together with PageUp or PageDown to modify. By default all set to 1.0
  20. float4 tempF1; //0,1,2,3
  21. float4 tempF2; //5,6,7,8
  22. float4 tempF3; //9,0
  23. //x=Width, y=1/Width, z=ScreenScaleY, w=1/ScreenScaleY
  24. float4 ScreenSize;
  25. //x=generic timer in range 0..1, period of 16777216 ms (4.6 hours), w=frame time elapsed (in seconds)
  26. float4 Timer;
  27. //additional info for computations
  28. float4 TempParameters;
  29. //Lenz reflection intensity, lenz reflection power
  30. float4 LenzParameters;
  31. //BloomRadius1, BloomRadius2, BloomBlueShiftAmount, BloomContrast
  32. float4 BloomParameters;
  33.  
  34.  
  35.  
  36. texture2D texBloom1;
  37. texture2D texBloom2;
  38. texture2D texBloom3;
  39. texture2D texBloom4;
  40. texture2D texBloom5;
  41. texture2D texBloom6;
  42. texture2D texBloom7;//additional bloom tex
  43. texture2D texBloom8;//additional bloom tex
  44.  
  45. sampler2D SamplerBloom1 = sampler_state
  46. {
  47. Texture = <texBloom1>;
  48. MinFilter = LINEAR;
  49. MagFilter = LINEAR;
  50. MipFilter = NONE;//NONE;
  51. AddressU = Clamp;
  52. AddressV = Clamp;
  53. SRGBTexture=FALSE;
  54. MaxMipLevel=0;
  55. MipMapLodBias=0;
  56. };
  57.  
  58. sampler2D SamplerBloom2 = sampler_state
  59. {
  60. Texture = <texBloom2>;
  61. MinFilter = LINEAR;
  62. MagFilter = LINEAR;
  63. MipFilter = NONE;//NONE;
  64. AddressU = Clamp;
  65. AddressV = Clamp;
  66. SRGBTexture=FALSE;
  67. MaxMipLevel=0;
  68. MipMapLodBias=0;
  69. };
  70.  
  71. sampler2D SamplerBloom3 = sampler_state
  72. {
  73. Texture = <texBloom3>;
  74. MinFilter = LINEAR;
  75. MagFilter = LINEAR;
  76. MipFilter = NONE;//NONE;
  77. AddressU = Clamp;
  78. AddressV = Clamp;
  79. SRGBTexture=FALSE;
  80. MaxMipLevel=0;
  81. MipMapLodBias=0;
  82. };
  83.  
  84. sampler2D SamplerBloom4 = sampler_state
  85. {
  86. Texture = <texBloom4>;
  87. MinFilter = LINEAR;
  88. MagFilter = LINEAR;
  89. MipFilter = NONE;//NONE;
  90. AddressU = Clamp;
  91. AddressV = Clamp;
  92. SRGBTexture=FALSE;
  93. MaxMipLevel=0;
  94. MipMapLodBias=0;
  95. };
  96.  
  97. sampler2D SamplerBloom5 = sampler_state
  98. {
  99. Texture = <texBloom5>;
  100. MinFilter = LINEAR;
  101. MagFilter = LINEAR;
  102. MipFilter = NONE;//NONE;
  103. AddressU = Clamp;
  104. AddressV = Clamp;
  105. SRGBTexture=FALSE;
  106. MaxMipLevel=0;
  107. MipMapLodBias=0;
  108. };
  109.  
  110. sampler2D SamplerBloom6 = sampler_state
  111. {
  112. Texture = <texBloom6>;
  113. MinFilter = LINEAR;
  114. MagFilter = LINEAR;
  115. MipFilter = NONE;//NONE;
  116. AddressU = Clamp;
  117. AddressV = Clamp;
  118. SRGBTexture=FALSE;
  119. MaxMipLevel=0;
  120. MipMapLodBias=0;
  121. };
  122.  
  123. sampler2D SamplerBloom7 = sampler_state
  124. {
  125. Texture = <texBloom7>;
  126. MinFilter = LINEAR;
  127. MagFilter = LINEAR;
  128. MipFilter = NONE;//NONE;
  129. AddressU = Clamp;
  130. AddressV = Clamp;
  131. SRGBTexture=FALSE;
  132. MaxMipLevel=0;
  133. MipMapLodBias=0;
  134. };
  135.  
  136. sampler2D SamplerBloom8 = sampler_state
  137. {
  138. Texture = <texBloom8>;
  139. MinFilter = LINEAR;
  140. MagFilter = LINEAR;
  141. MipFilter = NONE;//NONE;
  142. AddressU = Clamp;
  143. AddressV = Clamp;
  144. SRGBTexture=FALSE;
  145. MaxMipLevel=0;
  146. MipMapLodBias=0;
  147. };
  148.  
  149. struct VS_OUTPUT_POST
  150. {
  151. float4 vpos : POSITION;
  152. float2 txcoord0 : TEXCOORD0;
  153. };
  154. struct VS_INPUT_POST
  155. {
  156. float3 pos : POSITION;
  157. float2 txcoord0 : TEXCOORD0;
  158. };
  159.  
  160.  
  161.  
  162. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  163. //
  164. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  165. VS_OUTPUT_POST VS_Bloom(VS_INPUT_POST IN)
  166. {
  167. VS_OUTPUT_POST OUT;
  168.  
  169. OUT.vpos=float4(IN.pos.x,IN.pos.y,IN.pos.z,1.0);
  170.  
  171. OUT.txcoord0.xy=IN.txcoord0.xy+TempParameters.xy;//1.0/(bloomtexsize*2.0)
  172.  
  173. return OUT;
  174. }
  175.  
  176.  
  177. //zero pass HQ, input texture is fullscreen
  178. //SamplerBloom1 - fullscreen texture
  179. float4 PS_BloomPrePass(VS_OUTPUT_POST In) : COLOR
  180. {
  181. float4 bloomuv;
  182.  
  183. float4 bloom=0.0;//tex2D(SamplerBloom1, In.txcoord0);
  184. const float2 offset[4]=
  185. {
  186. float2(0.25, 1.25),
  187. float2(0.25, -0.25),
  188. float2(-0.25, 0.25),
  189. float2(-0.25, -0.25)
  190. };
  191. //TempParameters.w==1 if first pass, ==2 is second pass
  192. float2 screenfact=TempParameters.z;
  193. screenfact.y*=ScreenSize.z;
  194. float4 srcbloom=bloom;
  195. for (int i=0; i<4; i++)
  196. {
  197. bloomuv.xy=offset[i];
  198. bloomuv.xy=(bloomuv.xy*screenfact.xy)+In.txcoord0.xy;
  199. float4 tempbloom=tex2D(SamplerBloom1, bloomuv.xy);
  200. bloom.xyz+=tempbloom.xyz;
  201. }
  202. bloom.xyz*=0.25;
  203.  
  204. bloom.xyz=min(bloom.xyz, 32768.0);
  205. bloom.xyz=max(bloom.xyz, 0.0);
  206.  
  207. return bloom;
  208. }
  209.  
  210.  
  211.  
  212. //first and second passes draw to every texture
  213. //twice, after computations of these two passes,
  214. //result is set as input to next cycle
  215.  
  216. //first pass
  217. //SamplerBloom1 is result of prepass or second pass from cycle
  218. float4 PS_BloomTexture1(VS_OUTPUT_POST In) : COLOR
  219. {
  220. float4 bloomuv;
  221.  
  222. float4 bloom=tex2D(SamplerBloom1, In.txcoord0);
  223. const float2 offset[8]=
  224. {
  225. float2(1.0, 1.0),
  226. float2(1.0, -1.0),
  227. float2(-1.0, 1.0),
  228. float2(-1.0, -1.0),
  229. float2(0.0, 1.0),
  230. float2(0.0, -1.0),
  231. float2(1.0, 0.0),
  232. float2(-1.0, 0.0)
  233. };
  234. float2 screenfact=0.00135;
  235. //float2 screenfact=TempParameters.z*0.00135;
  236. screenfact.y*=ScreenSize.z;
  237. float4 srcbloom=bloom;
  238. //TempParameters.w == (1+passnumber)
  239. float step=BloomParameters.x;//*pow(2.0, BloomParameters.x * (TempParameters.w-1.0));//*0.5
  240. // float step=(TempParameters.w-0.25);//
  241. screenfact.xy*=step;//====================================================
  242.  
  243. float4 bloomadd=bloom;
  244.  
  245. for (int i=0; i<8; i++)
  246. {
  247. bloomuv.xy=offset[i];
  248. bloomuv.xy=(bloomuv.xy*screenfact.xy)+In.txcoord0.xy;//-(1.0/256.0);//-(1.0/512.0);
  249. float4 tempbloom=tex2D(SamplerBloom1, bloomuv.xy);
  250. bloom+=tempbloom;
  251. }
  252. bloom*=0.111111;
  253.  
  254.  
  255. //float3 violet=float3(0.78, 0.5, 1.0);
  256. //float3 violet=float3(0.6, 0.4, 1.0);//v2
  257. float3 violet=float3(0.6, 0.4, 1.0);//v3
  258. // float3 violet=float3(0.27, 0.52, 1.0);//v4
  259.  
  260. //this applies when white
  261. //float gray=0.104*dot(srcbloom.xyz, 0.333);//max(srcbloom.x, max(srcbloom.y, srcbloom.z));
  262. //this applies on dark and when contrast
  263. float ttt=dot(bloom.xyz, 0.333)-dot(srcbloom.xyz, 0.333);
  264. ttt=max(ttt, 0.0);
  265. float gray=BloomParameters.z*ttt*10;//max(srcbloom.x, max(srcbloom.y, srcbloom.z));
  266. float mixfact=(gray/(1.0+gray));
  267. mixfact*=1.0-saturate((TempParameters.w-1.0)*0.2);
  268. violet.xy+=saturate((TempParameters.w-1.0)*0.3);
  269. violet.xy=saturate(violet.xy);
  270. bloom.xyz*=lerp(1.0, violet.xyz, mixfact);
  271.  
  272. bloom.w=1.0;
  273. return bloom;
  274. }
  275.  
  276.  
  277. //second pass
  278. //SamplerBloom1 is result of first pass
  279. float4 PS_BloomTexture2(VS_OUTPUT_POST In) : COLOR
  280. {
  281. float4 bloomuv;
  282.  
  283. float4 bloom=tex2D(SamplerBloom1, In.txcoord0);
  284. const float2 offset[8]=
  285. {
  286. float2(1.0, 1.0),
  287. float2(1.0, -1.0),
  288. float2(-1.0, 1.0),
  289. float2(-1.0, -1.0),
  290. float2(0.0, 1.0),
  291. float2(0.0, -1.0),
  292. float2(1.0, 0.0),
  293. float2(-1.0, 0.0)
  294. };
  295. float2 screenfact=0.00135;
  296. //float2 screenfact=TempParameters.z*0.00135;
  297. screenfact.y*=ScreenSize.z;
  298. float4 srcbloom=bloom;
  299.  
  300. //TempParameters.w == (1+passnumber)
  301. // float step=(TempParameters.w-0.25);
  302. float step=BloomParameters.y;//*pow(2.0, BloomParameters.y * (TempParameters.w-1.0))*2.0;//*0.5
  303. screenfact.xy*=step;//*0.25====================================================
  304. float4 rotvec=0.0;
  305. sincos(0.3927, rotvec.x, rotvec.y);
  306. for (int i=0; i<8; i++)
  307. {
  308. bloomuv.xy=offset[i];
  309. bloomuv.xy=reflect(bloomuv.xy, rotvec.xy);
  310. bloomuv.xy=(bloomuv.xy*screenfact.xy)+In.txcoord0.xy;
  311. float4 tempbloom=tex2D(SamplerBloom1, bloomuv.xy);
  312. bloom+=tempbloom;
  313. }
  314. bloom*=0.111111;
  315.  
  316. bloom.w=1.0;
  317. return bloom;
  318. }
  319.  
  320.  
  321.  
  322. //last pass, mix several bloom textures
  323. //SamplerBloom5 is the result of prepass
  324. //float4 PS_BloomPostPass(float2 vPos : VPOS ) : COLOR
  325. float4 PS_BloomPostPass(VS_OUTPUT_POST In) : COLOR
  326. {
  327. float4 bloom;
  328.  
  329. //v1
  330. bloom =tex2D(SamplerBloom1, In.txcoord0);
  331. bloom+=tex2D(SamplerBloom2, In.txcoord0);
  332. bloom+=tex2D(SamplerBloom3, In.txcoord0);
  333. bloom+=tex2D(SamplerBloom4, In.txcoord0);
  334. bloom+=tex2D(SamplerBloom7, In.txcoord0);
  335. bloom+=tex2D(SamplerBloom8, In.txcoord0);
  336. bloom+=tex2D(SamplerBloom5, In.txcoord0);
  337. // bloom+=tex2D(SamplerBloom6, In.txcoord0);
  338. bloom*=0.142857;
  339.  
  340. float3 lenz=0;
  341. float2 lenzuv=0.0;
  342. //deepness, curvature, inverse size
  343. const float3 offset[4]=
  344. {
  345. float3(1.6, 4.0, 1.0),
  346. float3(0.7, 0.25, 2.0),
  347. float3(0.3, 1.5, 0.5),
  348. float3(-0.5, 1.0, 1.0)
  349. };
  350. //color filter per reflection
  351. const float3 factors[4]=
  352. {
  353. float3(0.3, 0.4, 0.4),
  354. float3(0.2, 0.4, 0.5),
  355. float3(0.5, 0.3, 0.7),
  356. float3(0.1, 0.2, 0.7)
  357. };
  358.  
  359. //lenzuv.xy=0.5-lenzuv.xy;
  360. //distfact=0.5-lenzuv.xy-0.5;
  361.  
  362. if (LenzParameters.x>0.00001)
  363. {
  364. for (int i=0; i<4; i++)
  365. {
  366. float2 distfact=(In.txcoord0.xy-0.5);
  367. lenzuv.xy=offset[i].x*distfact;
  368. lenzuv.xy*=pow(2.0*length(float2(distfact.x*ScreenSize.z,distfact.y)), offset[i].y);
  369. lenzuv.xy*=offset[i].z;
  370. lenzuv.xy=0.5-lenzuv.xy;//v1
  371. // lenzuv.xy=In.txcoord0.xy-lenzuv.xy;//v2
  372. float3 templenz=tex2D(SamplerBloom2, lenzuv.xy);
  373. templenz=templenz*factors[i];
  374. distfact=(lenzuv.xy-0.5);
  375. distfact*=2.0;
  376. templenz*=saturate(1.0-dot(distfact,distfact));//limit by uv 0..1
  377. // templenz=factors[i] * (1.0-dot(distfact,distfact));
  378. float maxlenz=max(templenz.x, max(templenz.y, templenz.z));
  379. /* float3 tempnor=(templenz.xyz/maxlenz);
  380. tempnor=pow(tempnor, tempF1.z);
  381. templenz.xyz=tempnor.xyz*maxlenz;
  382. */
  383. float tempnor=(maxlenz/(1.0+maxlenz));
  384. tempnor=pow(tempnor, LenzParameters.y);
  385. templenz.xyz*=tempnor;
  386.  
  387. // templenz*=maxlenz*maxlenz;
  388. lenz+=templenz;
  389. // lenz.xyz=max(lenz.xyz, templenz.xyz*0.99);
  390. }
  391. lenz.xyz*=0.25*LenzParameters.x;
  392.  
  393. bloom.xyz+=lenz.xyz;
  394. // bloom.w=dot(lenz.xyz, 0.333);
  395. bloom.w=max(lenz.xyz, max(lenz.y, lenz.z));
  396. }
  397. return bloom;
  398. }
  399.  
  400.  
  401.  
  402. technique BloomPrePass
  403. {
  404. pass p0
  405. {
  406. VertexShader = compile vs_3_0 VS_Bloom();
  407. PixelShader = compile ps_3_0 PS_BloomPrePass();
  408.  
  409. ColorWriteEnable=ALPHA|RED|GREEN|BLUE;
  410. CullMode=NONE;
  411. AlphaBlendEnable=FALSE;
  412. AlphaTestEnable=FALSE;
  413. SEPARATEALPHABLENDENABLE=FALSE;
  414. FogEnable=FALSE;
  415. SRGBWRITEENABLE=FALSE;
  416. }
  417. }
  418.  
  419. technique BloomTexture1
  420. {
  421. pass p0
  422. {
  423. VertexShader = compile vs_3_0 VS_Bloom();
  424. PixelShader = compile ps_3_0 PS_BloomTexture1();
  425.  
  426. ColorWriteEnable=ALPHA|RED|GREEN|BLUE;
  427. CullMode=NONE;
  428. AlphaBlendEnable=FALSE;
  429. AlphaTestEnable=FALSE;
  430. SEPARATEALPHABLENDENABLE=FALSE;
  431. FogEnable=FALSE;
  432. SRGBWRITEENABLE=FALSE;
  433. }
  434. }
  435.  
  436.  
  437. technique BloomTexture2
  438. {
  439. pass p0
  440. {
  441. VertexShader = compile vs_3_0 VS_Bloom();
  442. PixelShader = compile ps_3_0 PS_BloomTexture2();
  443.  
  444. ColorWriteEnable=ALPHA|RED|GREEN|BLUE;
  445. CullMode=NONE;
  446. AlphaBlendEnable=FALSE;
  447. AlphaTestEnable=FALSE;
  448. SEPARATEALPHABLENDENABLE=FALSE;
  449. FogEnable=FALSE;
  450. SRGBWRITEENABLE=FALSE;
  451. }
  452. }
  453.  
  454. technique BloomPostPass
  455. {
  456. pass p0
  457. {
  458. VertexShader = compile vs_3_0 VS_Bloom();
  459. PixelShader = compile ps_3_0 PS_BloomPostPass();
  460.  
  461. ColorWriteEnable=ALPHA|RED|GREEN|BLUE;
  462. CullMode=NONE;
  463. AlphaBlendEnable=FALSE;
  464. AlphaTestEnable=FALSE;
  465. SEPARATEALPHABLENDENABLE=FALSE;
  466. FogEnable=FALSE;
  467. SRGBWRITEENABLE=FALSE;
  468. }
  469. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement