Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- // ReShade effect file
- // visit facebook.com/MartyMcModding for news/updates
- //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- // Fallout 4 ENB multipass bloom by Boris Vorontsov
- // "Natural Bloom" modification by MaxTheUniqueGamer
- // Port to ReShade and further code modifications by Marty McFly
- // Copyright © 2008-2016 Marty McFly
- //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- #define BLOOM_BLEND_MODE 1 //[1 to 5] Different bloom blending algorithms
- #define ECC_IN_BLACK 0.80 //[0.00 to 1.00] Input black level, everything darker than this gets mapped to black.
- #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.
- #define ECC_OUT_BLACK 0.00 //[0.00 to 1.00] Output black level, black output gets mapped to this value.
- #define ECC_OUT_WHITE 1.00 //[0.00 to 10.00] Output white level, white output gets mapped to this value.
- #define BLOOM_CONTRAST 1.00 //[0.50 to 4.00] Bloom contrast, higher values increase strong bloom and decrease weak bloom.
- #define BLOOM_SATURATION 1.00 //[0.0 to 5.00] Bloom saturation curve. HSV based so no saturation clipping.
- #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.
- #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.
- #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.
- #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.
- #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.
- #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.
- //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- //
- //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- #pragma reshade showfps
- uniform float Timer < source = "timer"; >;
- #define PixelSize float2(BUFFER_RCP_WIDTH, BUFFER_RCP_HEIGHT)
- //textures
- texture2D TextureBackbuffer : COLOR;
- texture2D TextureDownsampled {Width = 1024; Height = 1024;Format = RGBA16F;};
- texture2D RenderTarget1024 {Width = 1024; Height = 1024;Format = RGBA16F;};
- texture2D RenderTarget512 {Width = 512; Height = 512; Format = RGBA16F;};
- texture2D RenderTarget256 {Width = 256; Height = 256; Format = RGBA16F;};
- texture2D RenderTarget128 {Width = 128; Height = 128; Format = RGBA16F;};
- texture2D RenderTarget64 {Width = 64; Height = 64; Format = RGBA16F;};
- texture2D RenderTarget32 {Width = 32; Height = 32; Format = RGBA16F;};
- //samplers
- sampler2D sTextureBackbuffer { Texture = TextureBackbuffer; };
- sampler2D sTextureDownsampled { Texture = TextureDownsampled; };
- sampler2D sRenderTarget1024 { Texture = RenderTarget1024; };
- sampler2D sRenderTarget512 { Texture = RenderTarget512; };
- sampler2D sRenderTarget256 { Texture = RenderTarget256; };
- sampler2D sRenderTarget128 { Texture = RenderTarget128; };
- sampler2D sRenderTarget64 { Texture = RenderTarget64; };
- sampler2D sRenderTarget32 { Texture = RenderTarget32; };
- //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- //
- //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- void VS_PostProcess(in uint id : SV_VertexID, out float4 pos : SV_Position, out float2 texcoord : TEXCOORD)
- {
- texcoord.x = (id == 2) ? 2.0 : 0.0;
- texcoord.y = (id == 1) ? 2.0 : 0.0;
- pos = float4(texcoord * float2(2.0, -2.0) + float2(-1.0, 1.0), 0.0, 1.0);
- }
- //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- //
- //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- //replace with some more efficient algorithm
- float4 BorisVorontsovFuncBlur(sampler2D sRenderTargetX, float2 uvsrc, float srcsize, float destsize)
- {
- const float scale=8.0;
- float2 invtargetsize=scale/srcsize;
- invtargetsize.y*=BUFFER_WIDTH * BUFFER_RCP_HEIGHT;
- float2 fstepcount=srcsize;
- fstepcount*=invtargetsize;
- fstepcount=clamp(fstepcount,8.0,48.0);
- int2 istepcount=round(fstepcount.xy+0.4999.xx);
- fstepcount=1.0/fstepcount;
- float4 curr=0.0;
- curr.w=0.000001;
- float2 pos = 0.0;
- float2 halfstep=0.5*fstepcount.xy;
- pos.x=-0.5+halfstep.x;
- invtargetsize *= 2.0;
- for (int x=0; x<istepcount.x; x++)
- {
- pos.y=-0.5+halfstep.y;
- for (int y=0; y<istepcount.y; y++)
- {
- float2 coord=pos.xy * invtargetsize + uvsrc.xy;
- float3 tempcurr=tex2Dlod(sRenderTargetX, float4(coord.xy,0,0)).xyz;
- float rangefactor=dot(pos.xy, pos.xy) * 4.0;
- float tempweight=saturate(1001.0 - 1000.0*rangefactor);//arithmetic version to cut circle from square
- tempweight*=saturate(1.0 - rangefactor); //softness, without it bloom looks like bokeh dof
- curr.xyz+=tempcurr.xyz * tempweight;
- curr.w+=tempweight;
- pos.y+=fstepcount.y;
- }
- pos.x+=fstepcount.x;
- }
- curr.xyz/=curr.w;
- return float4(curr.xyz,1.0);
- }
- float3 RGB2HSV(float3 RGB)
- {
- float4 K = float4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
- float4 p = RGB.g < RGB.b ? float4(RGB.bg, K.wz) : float4(RGB.gb, K.xy);
- float4 q = RGB.r < p.x ? float4(p.xyw, RGB.r) : float4(RGB.r, p.yzx);
- float d = q.x - min(q.w, q.y);
- float e = 1.0e-10;
- return float3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
- }
- float3 HSV2RGB(float3 HSV)
- {
- float4 K = float4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
- float3 p = abs(frac(HSV.xxx + K.xyz) * 6.0 - K.www);
- return HSV.z * lerp(K.xxx, saturate(p - K.xxx), HSV.y);
- }
- //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- //
- //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- void PS_Bloom_ToDownsampled(float4 vpos : SV_Position, float2 texcoord : TEXCOORD, out float4 bloom : SV_Target0)
- {
- float4 res = tex2D(sTextureBackbuffer, texcoord.xy);
- //no hue shift here
- res.xyz = RGB2HSV(res.xyz);
- res.z=max(res.z-ECC_IN_BLACK, 0.0) / max(ECC_IN_WHITE-ECC_IN_BLACK, 0.0001);
- res.z=pow(res.z, BLOOM_CONTRAST);
- res.z=res.z*(ECC_OUT_WHITE-ECC_OUT_BLACK) + ECC_OUT_BLACK;
- res.y=pow(saturate(res.y),1.0 / (BLOOM_SATURATION + 0.00001));
- res.xyz = HSV2RGB(res.xyz);
- bloom = res;
- }
- void PS_Bloom_To1024(float4 vpos : SV_Position, float2 texcoord : TEXCOORD, out float4 bloom : SV_Target0)
- {
- bloom = BorisVorontsovFuncBlur(sTextureDownsampled, texcoord.xy, 1024.0, 1024.0);
- }
- void PS_Bloom_To512(float4 vpos : SV_Position, float2 texcoord : TEXCOORD, out float4 bloom : SV_Target0)
- {
- bloom = BorisVorontsovFuncBlur(sTextureDownsampled, texcoord.xy, 1024.0, 512.0);
- }
- void PS_Bloom_To256(float4 vpos : SV_Position, float2 texcoord : TEXCOORD, out float4 bloom : SV_Target0)
- {
- bloom = BorisVorontsovFuncBlur(sRenderTarget512, texcoord.xy, 512.0, 256.0);
- }
- void PS_Bloom_To128(float4 vpos : SV_Position, float2 texcoord : TEXCOORD, out float4 bloom : SV_Target0)
- {
- bloom = BorisVorontsovFuncBlur(sRenderTarget256, texcoord.xy, 256.0, 128.0);
- }
- void PS_Bloom_To64(float4 vpos : SV_Position, float2 texcoord : TEXCOORD, out float4 bloom : SV_Target0)
- {
- bloom = BorisVorontsovFuncBlur(sRenderTarget128, texcoord.xy, 128.0, 64.0);
- }
- void PS_Bloom_To32(float4 vpos : SV_Position, float2 texcoord : TEXCOORD, out float4 bloom : SV_Target0)
- {
- bloom = BorisVorontsovFuncBlur(sRenderTarget64, texcoord.xy, 64.0, 32.0);
- }
- void PS_Bloom_Combine(float4 vpos : SV_Position, float2 texcoord : TEXCOORD, out float4 res : SV_Target0)
- {
- float3 bloom = 0.0;
- float3 color = tex2D(sTextureBackbuffer, texcoord.xy).xyz;
- bloom.xyz = BLOOM_MULT_1024 * tex2D(sRenderTarget1024, texcoord.xy).xyz
- + BLOOM_MULT_512 * tex2D(sRenderTarget512, texcoord.xy).xyz
- + BLOOM_MULT_256 * tex2D(sRenderTarget256, texcoord.xy).xyz
- + BLOOM_MULT_128 * tex2D(sRenderTarget128, texcoord.xy).xyz
- + BLOOM_MULT_64 * tex2D(sRenderTarget64, texcoord.xy).xyz
- + BLOOM_MULT_32 * tex2D(sRenderTarget32, texcoord.xy).xyz;
- bloom.xyz /= BLOOM_MULT_1024
- + BLOOM_MULT_512
- + BLOOM_MULT_256
- + BLOOM_MULT_128
- + BLOOM_MULT_64
- + BLOOM_MULT_32
- + 0.000001; //equalize the result
- if(BLOOM_BLEND_MODE == 1) color.xyz = color.xyz + bloom.xyz;
- if(BLOOM_BLEND_MODE == 2) color.xyz = 1-(1-color.xyz)*(1-bloom.xyz);
- 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)));
- if(BLOOM_BLEND_MODE == 4) color.xyz = max(color.xyz, bloom.xyz);
- if(BLOOM_BLEND_MODE == 5) color.xyz += max(bloom.xyz-color.xyz,0.0);
- res.xyz = color.xyz;
- res.w = 1.0;
- }
- //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- //
- //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- technique PostProcess < bool enabled = 1;toggle = 0x20;>
- {
- pass P0
- {
- VertexShader = VS_PostProcess;
- PixelShader = PS_Bloom_ToDownsampled;
- RenderTarget = TextureDownsampled;
- }
- pass P1
- {
- VertexShader = VS_PostProcess;
- PixelShader = PS_Bloom_To1024;
- RenderTarget = RenderTarget1024;
- }
- pass P2
- {
- VertexShader = VS_PostProcess;
- PixelShader = PS_Bloom_To512;
- RenderTarget = RenderTarget512;
- }
- pass P3
- {
- VertexShader = VS_PostProcess;
- PixelShader = PS_Bloom_To256;
- RenderTarget = RenderTarget256;
- }
- pass P4
- {
- VertexShader = VS_PostProcess;
- PixelShader = PS_Bloom_To128;
- RenderTarget = RenderTarget128;
- }
- pass P5
- {
- VertexShader = VS_PostProcess;
- PixelShader = PS_Bloom_To64;
- RenderTarget = RenderTarget64;
- }
- pass P6
- {
- VertexShader = VS_PostProcess;
- PixelShader = PS_Bloom_To32;
- RenderTarget = RenderTarget32;
- }
- pass Combine
- {
- VertexShader = VS_PostProcess;
- PixelShader = PS_Bloom_Combine;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement