Advertisement
Guest User

bloom thing shit

a guest
Jul 10th, 2016
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.25 KB | None | 0 0
  1. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. // ReShade effect file
  3. // visit facebook.com/MartyMcModding for news/updates
  4. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  5. // Fallout 4 ENB multipass bloom by Boris Vorontsov
  6. // "Natural Bloom" modification by MaxTheUniqueGamer
  7. // Port to ReShade and further code modifications by Marty McFly
  8. // Copyright © 2008-2016 Marty McFly
  9. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  10.  
  11.  
  12. #define BLOOM_BLEND_MODE 1 //[1 to 5] Different bloom blending algorithms
  13. #define ECC_IN_BLACK 0.80 //[0.00 to 1.00] Input black level, everything darker than this gets mapped to black.
  14. #define ECC_IN_WHITE 1.00 //[0.00 to 1.00] Input white level, a pixel of this brightness value is mapped to pure white.
  15. #define ECC_OUT_BLACK 0.00 //[0.00 to 1.00] Output black level, black output gets mapped to this value.
  16. #define ECC_OUT_WHITE 1.00 //[0.00 to 10.00] Output white level, white output gets mapped to this value.
  17. #define BLOOM_CONTRAST 1.00 //[0.50 to 4.00] Bloom contrast, higher values increase strong bloom and decrease weak bloom.
  18. #define BLOOM_SATURATION 1.00 //[0.0 to 5.00] Bloom saturation curve. HSV based so no saturation clipping.
  19.  
  20. #define BLOOM_MULT_1024 0.015 //[0.000 to 1.000] Mult of 1024x1024 bloom tile. Note that this is only relative mult, a setting of 0.1 for all tiles looks same as 10.0.
  21. #define BLOOM_MULT_512 0.000 //[0.000 to 1.000] Mult of 512x512 bloom tile. Note that this is only relative mult, a setting of 0.1 for all tiles looks same as 10.0.
  22. #define BLOOM_MULT_256 0.010 //[0.000 to 1.000] Mult of 256x256 bloom tile. Note that this is only relative mult, a setting of 0.1 for all tiles looks same as 10.0.
  23. #define BLOOM_MULT_128 0.200 //[0.000 to 1.000] Mult of 128x128 bloom tile. Note that this is only relative mult, a setting of 0.1 for all tiles looks same as 10.0.
  24. #define BLOOM_MULT_64 0.400 //[0.000 to 1.000] Mult of 64x64 bloom tile. Note that this is only relative mult, a setting of 0.1 for all tiles looks same as 10.0.
  25. #define BLOOM_MULT_32 1.000 //[0.000 to 1.000] Mult of 32x32 bloom tile. Note that this is only relative mult, a setting of 0.1 for all tiles looks same as 10.0.
  26.  
  27. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  28. //
  29. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  30.  
  31. #pragma reshade showfps
  32. uniform float Timer < source = "timer"; >;
  33. #define PixelSize float2(BUFFER_RCP_WIDTH, BUFFER_RCP_HEIGHT)
  34.  
  35. //textures
  36. texture2D TextureBackbuffer : COLOR;
  37. texture2D TextureDownsampled {Width = 1024; Height = 1024;Format = RGBA16F;};
  38. texture2D RenderTarget1024 {Width = 1024; Height = 1024;Format = RGBA16F;};
  39. texture2D RenderTarget512 {Width = 512; Height = 512; Format = RGBA16F;};
  40. texture2D RenderTarget256 {Width = 256; Height = 256; Format = RGBA16F;};
  41. texture2D RenderTarget128 {Width = 128; Height = 128; Format = RGBA16F;};
  42. texture2D RenderTarget64 {Width = 64; Height = 64; Format = RGBA16F;};
  43. texture2D RenderTarget32 {Width = 32; Height = 32; Format = RGBA16F;};
  44.  
  45. //samplers
  46. sampler2D sTextureBackbuffer { Texture = TextureBackbuffer; };
  47. sampler2D sTextureDownsampled { Texture = TextureDownsampled; };
  48. sampler2D sRenderTarget1024 { Texture = RenderTarget1024; };
  49. sampler2D sRenderTarget512 { Texture = RenderTarget512; };
  50. sampler2D sRenderTarget256 { Texture = RenderTarget256; };
  51. sampler2D sRenderTarget128 { Texture = RenderTarget128; };
  52. sampler2D sRenderTarget64 { Texture = RenderTarget64; };
  53. sampler2D sRenderTarget32 { Texture = RenderTarget32; };
  54.  
  55.  
  56. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  57. //
  58. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  59.  
  60. void VS_PostProcess(in uint id : SV_VertexID, out float4 pos : SV_Position, out float2 texcoord : TEXCOORD)
  61. {
  62. texcoord.x = (id == 2) ? 2.0 : 0.0;
  63. texcoord.y = (id == 1) ? 2.0 : 0.0;
  64. pos = float4(texcoord * float2(2.0, -2.0) + float2(-1.0, 1.0), 0.0, 1.0);
  65. }
  66.  
  67. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  68. //
  69. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  70.  
  71. //replace with some more efficient algorithm
  72. float4 BorisVorontsovFuncBlur(sampler2D sRenderTargetX, float2 uvsrc, float srcsize, float destsize)
  73. {
  74. const float scale=8.0;
  75.  
  76. float2 invtargetsize=scale/srcsize;
  77. invtargetsize.y*=BUFFER_WIDTH * BUFFER_RCP_HEIGHT;
  78.  
  79. float2 fstepcount=srcsize;
  80.  
  81. fstepcount*=invtargetsize;
  82. fstepcount=clamp(fstepcount,8.0,48.0);
  83.  
  84. int2 istepcount=round(fstepcount.xy+0.4999.xx);
  85.  
  86. fstepcount=1.0/fstepcount;
  87. float4 curr=0.0;
  88. curr.w=0.000001;
  89. float2 pos = 0.0;
  90. float2 halfstep=0.5*fstepcount.xy;
  91. pos.x=-0.5+halfstep.x;
  92. invtargetsize *= 2.0;
  93. for (int x=0; x<istepcount.x; x++)
  94. {
  95. pos.y=-0.5+halfstep.y;
  96. for (int y=0; y<istepcount.y; y++)
  97. {
  98. float2 coord=pos.xy * invtargetsize + uvsrc.xy;
  99. float3 tempcurr=tex2Dlod(sRenderTargetX, float4(coord.xy,0,0)).xyz;
  100. float rangefactor=dot(pos.xy, pos.xy) * 4.0;
  101. float tempweight=saturate(1001.0 - 1000.0*rangefactor);//arithmetic version to cut circle from square
  102. tempweight*=saturate(1.0 - rangefactor); //softness, without it bloom looks like bokeh dof
  103. curr.xyz+=tempcurr.xyz * tempweight;
  104. curr.w+=tempweight;
  105. pos.y+=fstepcount.y;
  106. }
  107. pos.x+=fstepcount.x;
  108. }
  109. curr.xyz/=curr.w;
  110.  
  111. return float4(curr.xyz,1.0);
  112. }
  113.  
  114. float3 RGB2HSV(float3 RGB)
  115. {
  116. float4 K = float4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
  117. float4 p = RGB.g < RGB.b ? float4(RGB.bg, K.wz) : float4(RGB.gb, K.xy);
  118. float4 q = RGB.r < p.x ? float4(p.xyw, RGB.r) : float4(RGB.r, p.yzx);
  119.  
  120. float d = q.x - min(q.w, q.y);
  121. float e = 1.0e-10;
  122. return float3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
  123. }
  124.  
  125. float3 HSV2RGB(float3 HSV)
  126. {
  127. float4 K = float4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
  128. float3 p = abs(frac(HSV.xxx + K.xyz) * 6.0 - K.www);
  129. return HSV.z * lerp(K.xxx, saturate(p - K.xxx), HSV.y);
  130. }
  131.  
  132. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  133. //
  134. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  135.  
  136. void PS_Bloom_ToDownsampled(float4 vpos : SV_Position, float2 texcoord : TEXCOORD, out float4 bloom : SV_Target0)
  137. {
  138. float4 res = tex2D(sTextureBackbuffer, texcoord.xy);
  139.  
  140. //no hue shift here
  141. res.xyz = RGB2HSV(res.xyz);
  142. res.z=max(res.z-ECC_IN_BLACK, 0.0) / max(ECC_IN_WHITE-ECC_IN_BLACK, 0.0001);
  143. res.z=pow(res.z, BLOOM_CONTRAST);
  144. res.z=res.z*(ECC_OUT_WHITE-ECC_OUT_BLACK) + ECC_OUT_BLACK;
  145. res.y=pow(saturate(res.y),1.0 / (BLOOM_SATURATION + 0.00001));
  146. res.xyz = HSV2RGB(res.xyz);
  147.  
  148. bloom = res;
  149. }
  150.  
  151. void PS_Bloom_To1024(float4 vpos : SV_Position, float2 texcoord : TEXCOORD, out float4 bloom : SV_Target0)
  152. {
  153. bloom = BorisVorontsovFuncBlur(sTextureDownsampled, texcoord.xy, 1024.0, 1024.0);
  154. }
  155.  
  156. void PS_Bloom_To512(float4 vpos : SV_Position, float2 texcoord : TEXCOORD, out float4 bloom : SV_Target0)
  157. {
  158. bloom = BorisVorontsovFuncBlur(sTextureDownsampled, texcoord.xy, 1024.0, 512.0);
  159. }
  160.  
  161. void PS_Bloom_To256(float4 vpos : SV_Position, float2 texcoord : TEXCOORD, out float4 bloom : SV_Target0)
  162. {
  163. bloom = BorisVorontsovFuncBlur(sRenderTarget512, texcoord.xy, 512.0, 256.0);
  164. }
  165.  
  166. void PS_Bloom_To128(float4 vpos : SV_Position, float2 texcoord : TEXCOORD, out float4 bloom : SV_Target0)
  167. {
  168. bloom = BorisVorontsovFuncBlur(sRenderTarget256, texcoord.xy, 256.0, 128.0);
  169. }
  170.  
  171. void PS_Bloom_To64(float4 vpos : SV_Position, float2 texcoord : TEXCOORD, out float4 bloom : SV_Target0)
  172. {
  173. bloom = BorisVorontsovFuncBlur(sRenderTarget128, texcoord.xy, 128.0, 64.0);
  174. }
  175.  
  176. void PS_Bloom_To32(float4 vpos : SV_Position, float2 texcoord : TEXCOORD, out float4 bloom : SV_Target0)
  177. {
  178. bloom = BorisVorontsovFuncBlur(sRenderTarget64, texcoord.xy, 64.0, 32.0);
  179. }
  180.  
  181. void PS_Bloom_Combine(float4 vpos : SV_Position, float2 texcoord : TEXCOORD, out float4 res : SV_Target0)
  182. {
  183.  
  184. float3 bloom = 0.0;
  185. float3 color = tex2D(sTextureBackbuffer, texcoord.xy).xyz;
  186.  
  187. bloom.xyz = BLOOM_MULT_1024 * tex2D(sRenderTarget1024, texcoord.xy).xyz
  188. + BLOOM_MULT_512 * tex2D(sRenderTarget512, texcoord.xy).xyz
  189. + BLOOM_MULT_256 * tex2D(sRenderTarget256, texcoord.xy).xyz
  190. + BLOOM_MULT_128 * tex2D(sRenderTarget128, texcoord.xy).xyz
  191. + BLOOM_MULT_64 * tex2D(sRenderTarget64, texcoord.xy).xyz
  192. + BLOOM_MULT_32 * tex2D(sRenderTarget32, texcoord.xy).xyz;
  193.  
  194. bloom.xyz /= BLOOM_MULT_1024
  195. + BLOOM_MULT_512
  196. + BLOOM_MULT_256
  197. + BLOOM_MULT_128
  198. + BLOOM_MULT_64
  199. + BLOOM_MULT_32
  200. + 0.000001; //equalize the result
  201.  
  202. if(BLOOM_BLEND_MODE == 1) color.xyz = color.xyz + bloom.xyz;
  203. if(BLOOM_BLEND_MODE == 2) color.xyz = 1-(1-color.xyz)*(1-bloom.xyz);
  204. if(BLOOM_BLEND_MODE == 3) color.xyz = max(0.0f,max(color.xyz,lerp(color.xyz,(1.0f - (1.0f - saturate(bloom.xyz)) *(1.0f - saturate(bloom.xyz * 1.0))),1.0)));
  205. if(BLOOM_BLEND_MODE == 4) color.xyz = max(color.xyz, bloom.xyz);
  206. if(BLOOM_BLEND_MODE == 5) color.xyz += max(bloom.xyz-color.xyz,0.0);
  207.  
  208. res.xyz = color.xyz;
  209. res.w = 1.0;
  210.  
  211. }
  212. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  213. //
  214. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  215.  
  216. technique PostProcess < bool enabled = 1;toggle = 0x20;>
  217. {
  218. pass P0
  219. {
  220. VertexShader = VS_PostProcess;
  221. PixelShader = PS_Bloom_ToDownsampled;
  222. RenderTarget = TextureDownsampled;
  223. }
  224. pass P1
  225. {
  226. VertexShader = VS_PostProcess;
  227. PixelShader = PS_Bloom_To1024;
  228. RenderTarget = RenderTarget1024;
  229. }
  230. pass P2
  231. {
  232. VertexShader = VS_PostProcess;
  233. PixelShader = PS_Bloom_To512;
  234. RenderTarget = RenderTarget512;
  235. }
  236. pass P3
  237. {
  238. VertexShader = VS_PostProcess;
  239. PixelShader = PS_Bloom_To256;
  240. RenderTarget = RenderTarget256;
  241. }
  242. pass P4
  243. {
  244. VertexShader = VS_PostProcess;
  245. PixelShader = PS_Bloom_To128;
  246. RenderTarget = RenderTarget128;
  247. }
  248. pass P5
  249. {
  250. VertexShader = VS_PostProcess;
  251. PixelShader = PS_Bloom_To64;
  252. RenderTarget = RenderTarget64;
  253. }
  254. pass P6
  255. {
  256. VertexShader = VS_PostProcess;
  257. PixelShader = PS_Bloom_To32;
  258. RenderTarget = RenderTarget32;
  259. }
  260. pass Combine
  261. {
  262. VertexShader = VS_PostProcess;
  263. PixelShader = PS_Bloom_Combine;
  264. }
  265. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement