Advertisement
luluco250

Physically-Based Bloom

Apr 18th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.82 KB | None | 0 0
  1. #include "Common.fx"
  2.  
  3. #if USE_PBB
  4.  
  5. #pragma message "MassFX: Physically-Based Bloom Initialized\n"
  6.  
  7. #define sclX (BUFFER_WIDTH*PBB_ResolutionScale)
  8. #define sclY (BUFFER_HEIGHT*PBB_ResolutionScale)
  9.  
  10. namespace MassFX {
  11.    
  12.     texture tex1 { Width=sclX/2; Height=sclY/2; Format=RGBA16F; };
  13.     texture tex2 { Width=sclX/4; Height=sclY/4; Format=RGBA16F; };
  14.     texture tex3 { Width=sclX/8; Height=sclY/8; Format=RGBA16F; };
  15.     texture tex4 { Width=sclX/16; Height=sclY/16; Format=RGBA16F; };
  16.     texture tex5 { Width=sclX/32; Height=sclY/32; Format=RGBA16F; };
  17.     texture tex6 { Width=sclX/64; Height=sclY/64; Format=RGBA16F; };
  18.     texture tex7 { Width=sclX/128; Height=sclY/128; Format=RGBA16F; };
  19.     texture tex8 { Width=sclX/256; Height=sclY/256; Format=RGBA16F; };
  20.    
  21.     sampler2D sTex1 { Texture=tex1; };
  22.     sampler2D sTex2 { Texture=tex2; };
  23.     sampler2D sTex3 { Texture=tex3; };
  24.     sampler2D sTex4 { Texture=tex4; };
  25.     sampler2D sTex5 { Texture=tex5; };
  26.     sampler2D sTex6 { Texture=tex6; };
  27.     sampler2D sTex7 { Texture=tex7; };
  28.     sampler2D sTex8 { Texture=tex8; };
  29.            
  30.     float3 Blur(int scale, sampler2D sp, float2 srcCoord) {
  31.         float3 col = float3(0,0,0);
  32.         int c = 0;
  33.         srcCoord /= scale;
  34.         [loop]
  35.         for(int i = 0; i < PBB_Samples+1; ++i) {
  36.             for(int j = 0; j < PBB_Samples+1; ++j) {
  37.                 float2 coord = float2(i - PBB_Samples/2, j - PBB_Samples/2);
  38.                 coord.x /= BUFFER_WIDTH;
  39.                 coord.y /= BUFFER_HEIGHT;
  40.                 float2 fCoord = (srcCoord + coord) * scale;
  41.                
  42.                 col += pow(saturate(tex2D(sp, fCoord)), PBB_Threshold).rgb;
  43.                
  44.                 c += 1;
  45.             }
  46.         }
  47.         return col/c;
  48.     }
  49.    
  50.     float3 Downsample1(v2f i) : SV_Target {
  51.         return Blur(2, ReShade::BackBuffer, i.uv).rgb;
  52.     }
  53.    
  54.     float3 Downsample2(v2f i) : SV_Target {
  55.         return Blur(4, ReShade::BackBuffer, i.uv).rgb;
  56.     }
  57.    
  58.     float3 Downsample3(v2f i) : SV_Target {
  59.         return Blur(8, ReShade::BackBuffer, i.uv).rgb;
  60.     }
  61.    
  62.     float3 Downsample4(v2f i) : SV_Target {
  63.         return Blur(16, ReShade::BackBuffer, i.uv).rgb;
  64.     }
  65.    
  66.     float3 Downsample5(v2f i) : SV_Target {
  67.         return Blur(32, ReShade::BackBuffer, i.uv).rgb;
  68.     }
  69.    
  70.     float3 Downsample6(v2f i) : SV_Target {
  71.         return Blur(64, ReShade::BackBuffer, i.uv).rgb;
  72.     }
  73.    
  74.     float3 Downsample7(v2f i) : SV_Target {
  75.         return Blur(128, ReShade::BackBuffer, i.uv).rgb;
  76.     }
  77.    
  78.     float3 Downsample8(v2f i) : SV_Target {
  79.         return Blur(256, ReShade::BackBuffer, i.uv).rgb;
  80.     }
  81.    
  82.     float3 Main(v2f i) : SV_Target {
  83.         return lerp(tex2D(ReShade::BackBuffer, i.uv), tex2D(ReShade::BackBuffer, i.uv)
  84.             + tex2D(sTex1, i.uv)
  85.             + tex2D(sTex2, i.uv)
  86.             + tex2D(sTex3, i.uv)
  87.             + tex2D(sTex4, i.uv)
  88.             + tex2D(sTex5, i.uv)
  89.             + tex2D(sTex6, i.uv)
  90.             + tex2D(sTex7, i.uv)
  91.             + tex2D(sTex8, i.uv)
  92.         , PBB_Power).rgb;
  93.     }
  94.    
  95.     technique PBB_Tech <bool enabled = RESHADE_START_ENABLED; int toggle = PBB_ToggleKey; > {
  96.                
  97.         pass d1 {
  98.             VertexShader = ReShade::VS_PostProcess;
  99.             PixelShader = Downsample1;
  100.             RenderTarget = tex1;
  101.         }
  102.        
  103.         pass d2 {
  104.             VertexShader = ReShade::VS_PostProcess;
  105.             PixelShader = Downsample2;
  106.             RenderTarget = tex2;
  107.         }
  108.        
  109.         pass d3 {
  110.             VertexShader = ReShade::VS_PostProcess;
  111.             PixelShader = Downsample3;
  112.             RenderTarget = tex3;
  113.         }
  114.        
  115.         pass d4 {
  116.             VertexShader = ReShade::VS_PostProcess;
  117.             PixelShader = Downsample4;
  118.             RenderTarget = tex4;
  119.         }
  120.        
  121.         pass d5 {
  122.             VertexShader = ReShade::VS_PostProcess;
  123.             PixelShader = Downsample5;
  124.             RenderTarget = tex5;
  125.         }
  126.        
  127.         pass d6 {
  128.             VertexShader = ReShade::VS_PostProcess;
  129.             PixelShader = Downsample6;
  130.             RenderTarget = tex6;
  131.         }
  132.        
  133.         pass d7 {
  134.             VertexShader = ReShade::VS_PostProcess;
  135.             PixelShader = Downsample7;
  136.             RenderTarget = tex7;
  137.         }
  138.        
  139.         pass d8 {
  140.             VertexShader = ReShade::VS_PostProcess;
  141.             PixelShader = Downsample8;
  142.             RenderTarget = tex8;
  143.         }
  144.        
  145.         pass main {
  146.             VertexShader = ReShade::VS_PostProcess;
  147.             PixelShader = Main;
  148.         }
  149.     }
  150. }
  151.  
  152. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement