Advertisement
Guest User

bloom darken headache killer

a guest
Mar 16th, 2017
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.83 KB | None | 0 0
  1. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. // ReShade effect file
  3. // visit facebook.com/MartyMcModding for news/updates
  4. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  5. //bloom shit test
  6. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7. #include "ReShade.fxh"
  8.  
  9.  
  10. uniform float BLOOM_CONTRAST <
  11. ui_type = "drag";
  12. ui_min = 0.00; ui_max = 10.00;
  13. ui_tooltip = "Bloom : Bloom contrast, higher values restrict bloom to bright areas.";
  14. > = 1.00;
  15.  
  16. uniform float BLOOM_AMOUNT <
  17. ui_type = "drag";
  18. ui_min = 0.00; ui_max = 10.00;
  19. ui_tooltip = "Bloom : Amount of darkening.";
  20. > = 1.00;
  21.  
  22. uniform float BLOOM_MULT_1024 <
  23. ui_type = "drag";
  24. ui_min = 0.00; ui_max = 5.00;
  25. ui_tooltip = "Bloom : Multiplicator of 1024x1024 texture.";
  26. > = 0.00;
  27.  
  28. uniform float BLOOM_MULT_512 <
  29. ui_type = "drag";
  30. ui_min = 0.00; ui_max = 5.00;
  31. ui_tooltip = "Bloom : Multiplicator of 512x512 texture.";
  32. > = 0.00;
  33.  
  34. uniform float BLOOM_MULT_256 <
  35. ui_type = "drag";
  36. ui_min = 0.00; ui_max = 5.00;
  37. ui_tooltip = "Bloom : Multiplicator of 256x256 texture.";
  38. > = 1.00;
  39.  
  40. uniform float BLOOM_MULT_128 <
  41. ui_type = "drag";
  42. ui_min = 0.00; ui_max = 5.00;
  43. ui_tooltip = "Bloom : Multiplicator of 128x128 texture.";
  44. > = 1.00;
  45.  
  46. uniform float BLOOM_MULT_64 <
  47. ui_type = "drag";
  48. ui_min = 0.00; ui_max = 5.00;
  49. ui_tooltip = "Bloom : Multiplicator of 64x64 texture.";
  50. > = 1.00;
  51.  
  52. uniform float BLOOM_MULT_32 <
  53. ui_type = "drag";
  54. ui_min = 0.00; ui_max = 5.00;
  55. ui_tooltip = "Bloom : Multiplicator of 32x32 texture.";
  56. > = 1.00;
  57.  
  58. uniform float BLOOM_BLUR_MULT <
  59. ui_type = "drag";
  60. ui_min = 0.00; ui_max = 16.00;
  61. ui_tooltip = "Bloom : Multiplicator of 32x32 texture.";
  62. > = 1.00;
  63.  
  64. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  65. //
  66. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  67.  
  68.  
  69. //textures
  70. texture2D TextureDownsampled {Width = 1024; Height = 1024;Format = RGBA16F;};
  71. texture2D RenderTarget1024 {Width = 1024; Height = 1024;Format = RGBA16F;};
  72. texture2D RenderTarget512 {Width = 512; Height = 512; Format = RGBA16F;};
  73. texture2D RenderTarget256 {Width = 256; Height = 256; Format = RGBA16F;};
  74. texture2D RenderTarget128 {Width = 128; Height = 128; Format = RGBA16F;};
  75. texture2D RenderTarget64 {Width = 64; Height = 64; Format = RGBA16F;};
  76. texture2D RenderTarget32 {Width = 32; Height = 32; Format = RGBA16F; MipLevels = 5;};
  77.  
  78. //samplers
  79. sampler2D sTextureDownsampled { Texture = TextureDownsampled; };
  80. sampler2D sRenderTarget1024 { Texture = RenderTarget1024; };
  81. sampler2D sRenderTarget512 { Texture = RenderTarget512; };
  82. sampler2D sRenderTarget256 { Texture = RenderTarget256; };
  83. sampler2D sRenderTarget128 { Texture = RenderTarget128; };
  84. sampler2D sRenderTarget64 { Texture = RenderTarget64; };
  85. sampler2D sRenderTarget32 { Texture = RenderTarget32; };
  86.  
  87.  
  88. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  89. //
  90. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  91.  
  92. float4 LinearGaussianBlurSmall(sampler2D sRenderTargetX, float2 texcoord, float texSize)
  93. {
  94. float offset[3] = { 0.0, 1.3846153846, 3.2307692308 };
  95. float weight[3] = { 0.2270270270, 0.3162162162, 0.0702702703 };
  96.  
  97. float4 tempBloom;
  98. float2 tempOffset;
  99. float tempWeight;
  100. float4 bloom = 0.0;
  101.  
  102. float2 SampleRadiusScaled = float2(1.0,ReShade::AspectRatio) * rcp(texSize) * BLOOM_BLUR_MULT;
  103.  
  104. [loop]
  105. for(int x = -2; x <= 2; ++x)
  106. [loop]
  107. for(int y = -2; y <= 2; ++y)
  108. {
  109. int2 index = abs(int2(x,y));
  110. tempOffset = texcoord.xy + float2(offset[index.x] * sign(x),offset[index.y] * sign(y)) * SampleRadiusScaled;
  111. bloom += tex2Dlod(sRenderTargetX, float4(tempOffset.xy,0,0)) * weight[index.x] * weight[index.y];
  112. }
  113. return bloom;
  114. }
  115.  
  116. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  117.  
  118. float4 LinearGaussianBlurMedium(sampler2D sRenderTargetX, float2 texcoord, float texSize)
  119. {
  120. float offset[6] = { 0.0, 1.4584295168, 3.40398480678, 5.3518057801, 7.302940716, 9.2581597095 };
  121. float weight[6] = { 0.13298, 0.23227575, 0.1353261595, 0.0511557427, 0.01253922, 0.0019913644 };
  122.  
  123. float4 tempBloom;
  124. float2 tempOffset;
  125. float tempWeight;
  126. float4 bloom = 0.0;
  127.  
  128. float2 SampleRadiusScaled = float2(1.0,ReShade::AspectRatio) * rcp(texSize) * BLOOM_BLUR_MULT;
  129.  
  130. [loop]
  131. for(int x = -5; x <= 5; ++x)
  132. [loop]
  133. for(int y = -5; y <= 5; ++y)
  134. {
  135. int2 index = abs(int2(x,y));
  136. tempOffset = texcoord.xy + float2(offset[index.x] * sign(x),offset[index.y] * sign(y)) * SampleRadiusScaled;
  137. bloom += tex2Dlod(sRenderTargetX, float4(tempOffset.xy,0,0)) * weight[index.x] * weight[index.y];
  138. }
  139. return bloom;
  140. }
  141.  
  142. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  143.  
  144. float4 tex2Dbicub(sampler tex, float2 texcoord, float2 textureDimensions)
  145. {
  146. texcoord *= textureDimensions;
  147.  
  148. float2 texelCenter = floor(texcoord - 0.5) + 0.5;
  149. float2 dist1 = texcoord - texelCenter;
  150. float2 dist2 = dist1 * dist1;
  151. float2 dist3 = dist1 * dist2;
  152.  
  153. float2 weight0 = dist2 - 0.5 * (dist3 + dist1);
  154. float2 weight1 = 1.5 * dist3 - 2.5 * dist2 + 1.0;
  155. float2 weight3 = 0.5 * ( dist3 - dist2 );
  156. float2 weight2 = 1.0 - weight0 - weight1 - weight3;
  157.  
  158. float4 scalingFactor01 = float4(weight0 + weight1,weight2 + weight3);
  159. float4 texCoord01 = texelCenter.xyxy + float4(- 1.0 + weight1 / scalingFactor01.xy,
  160. 1.0 + weight3 / scalingFactor01.zw);
  161. texCoord01 /= textureDimensions.xyxy;
  162.  
  163. return tex2Dlod(tex, float4(texCoord01.xy, 0,0)) * scalingFactor01.x*scalingFactor01.y +
  164. tex2Dlod(tex, float4(texCoord01.zy, 0,0)) * scalingFactor01.z*scalingFactor01.y +
  165. tex2Dlod(tex, float4(texCoord01.xw, 0,0)) * scalingFactor01.x*scalingFactor01.w +
  166. tex2Dlod(tex, float4(texCoord01.zw, 0,0)) * scalingFactor01.z*scalingFactor01.w;
  167. }
  168.  
  169. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  170. //
  171. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  172.  
  173. void PS_Bloom_ToDownsampled(float4 vpos : SV_Position, float2 texcoord : TEXCOORD, out float4 bloom : SV_Target0)
  174. {
  175. float4 scenecolor = tex2D(ReShade::BackBuffer, texcoord.xy);
  176.  
  177. bloom = scenecolor;
  178. bloom.w = max(max(bloom.x,bloom.y),bloom.z);
  179. bloom.xyz = pow(saturate(bloom.xyz),BLOOM_CONTRAST);
  180.  
  181. }
  182.  
  183. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  184.  
  185.  
  186. void PS_Bloom_To1024(float4 vpos : SV_Position, float2 texcoord : TEXCOORD, out float4 bloom : SV_Target0)
  187. {
  188. bloom = LinearGaussianBlurSmall(sTextureDownsampled, texcoord.xy, 1024.0);
  189. }
  190.  
  191. void PS_Bloom_To512(float4 vpos : SV_Position, float2 texcoord : TEXCOORD, out float4 bloom : SV_Target0)
  192. {
  193. bloom = LinearGaussianBlurSmall(sRenderTarget1024, texcoord.xy, 1024.0);
  194. }
  195.  
  196. void PS_Bloom_To256(float4 vpos : SV_Position, float2 texcoord : TEXCOORD, out float4 bloom : SV_Target0)
  197. {
  198. bloom = LinearGaussianBlurMedium(sRenderTarget512, texcoord.xy, 512.0);
  199. }
  200.  
  201. void PS_Bloom_To128(float4 vpos : SV_Position, float2 texcoord : TEXCOORD, out float4 bloom : SV_Target0)
  202. {
  203. bloom = LinearGaussianBlurMedium(sRenderTarget256, texcoord.xy, 256.0);
  204. }
  205.  
  206. void PS_Bloom_To64(float4 vpos : SV_Position, float2 texcoord : TEXCOORD, out float4 bloom : SV_Target0)
  207. {
  208. bloom = LinearGaussianBlurSmall(sRenderTarget128, texcoord.xy, 128.0);
  209. }
  210.  
  211. void PS_Bloom_To32(float4 vpos : SV_Position, float2 texcoord : TEXCOORD, out float4 bloom : SV_Target0)
  212. {
  213. bloom = LinearGaussianBlurSmall(sRenderTarget64, texcoord.xy, 64.0);
  214. }
  215.  
  216. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  217.  
  218. void PS_Bloom_Combine(float4 vpos : SV_Position, float2 texcoord : TEXCOORD, out float4 res : SV_Target0)
  219. {
  220. float3 bloom = 0.0;
  221. float3 color = tex2D(ReShade::BackBuffer, texcoord.xy).xyz;
  222.  
  223. float3 bloomTextures[6] = { tex2Dbicub(sRenderTarget1024, texcoord.xy, float2(1024.0,1024.0)).xyz,
  224. tex2Dbicub(sRenderTarget512, texcoord.xy, float2(512.0,512.0)).xyz,
  225. tex2Dbicub(sRenderTarget256, texcoord.xy, float2(256.0,256.0)).xyz,
  226. tex2Dbicub(sRenderTarget128, texcoord.xy, float2(128.0,128.0)).xyz,
  227. tex2Dbicub(sRenderTarget64, texcoord.xy, float2(64.0,64.0)).xyz,
  228. tex2Dbicub(sRenderTarget32, texcoord.xy, float2(32.0,32.0)).xyz};
  229.  
  230. bloom.xyz = BLOOM_MULT_1024 * bloomTextures[0]
  231. + BLOOM_MULT_512 * bloomTextures[1]
  232. + BLOOM_MULT_256 * bloomTextures[2]
  233. + BLOOM_MULT_128 * bloomTextures[3]
  234. + BLOOM_MULT_64 * bloomTextures[4]
  235. + BLOOM_MULT_32 * bloomTextures[5];
  236.  
  237.  
  238. color.xyz *= 1.0 - dot(bloom.xyz,0.333) * BLOOM_AMOUNT;
  239. //color.xyz = bloom.xyz;
  240.  
  241. res.xyz = color.xyz;
  242. res.w = 1.0;
  243.  
  244. }
  245. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  246. //
  247. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  248.  
  249. technique Bloom
  250. {
  251. pass P0
  252. {
  253. VertexShader = PostProcessVS;
  254. PixelShader = PS_Bloom_ToDownsampled;
  255. RenderTarget0 = TextureDownsampled;
  256. }
  257. pass P1
  258. {
  259. VertexShader = PostProcessVS;
  260. PixelShader = PS_Bloom_To1024;
  261. RenderTarget = RenderTarget1024;
  262. }
  263. pass P2
  264. {
  265. VertexShader = PostProcessVS;
  266. PixelShader = PS_Bloom_To512;
  267. RenderTarget = RenderTarget512;
  268. }
  269. pass P3
  270. {
  271. VertexShader = PostProcessVS;
  272. PixelShader = PS_Bloom_To256;
  273. RenderTarget = RenderTarget256;
  274. }
  275. pass P4
  276. {
  277. VertexShader = PostProcessVS;
  278. PixelShader = PS_Bloom_To128;
  279. RenderTarget = RenderTarget128;
  280. }
  281. pass P5
  282. {
  283. VertexShader = PostProcessVS;
  284. PixelShader = PS_Bloom_To64;
  285. RenderTarget = RenderTarget64;
  286. }
  287. pass P6
  288. {
  289. VertexShader = PostProcessVS;
  290. PixelShader = PS_Bloom_To32;
  291. RenderTarget = RenderTarget32;
  292. }
  293. pass Combine
  294. {
  295. VertexShader = PostProcessVS;
  296. PixelShader = PS_Bloom_Combine;
  297. }
  298. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement