Advertisement
Guest User

ReShade.fx

a guest
Dec 18th, 2015
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 23.00 KB | None | 0 0
  1. /**
  2.  * This shader is based on physiological characteristics of the human eye and it is designed to
  3.  * provide a natural look of dark scenes or low light environments. It is also a good prevention
  4.  * of the abuse of the gamma and brightness settings without restricting these settings themselfs.
  5.  *
  6.  * For further information goto:
  7.  * https://feedback.dayz.com/view.php?id=1294
  8.  *
  9.  *
  10.  * Installation and use:
  11.  *
  12.  * IMPORTANT NOTE: The shader hooks into the renderer and thus it might modify the memory
  13.  * of the running game. This could be classified as a sign of cheating/hacking and because
  14.  * of this it is recommended to test the shader in singleplayer/editor with disconnected
  15.  * networking. After testing and before reconnecting you should uninstall it by deleting
  16.  * the two files you copied during the installation. That might sound a bit paranoid,
  17.  * but better safe than sorry... :)
  18.  *
  19.  *
  20.  * During the installation you need to rename two files and change their file extensions too.
  21.  * For this you need to activate/show the file extensions in the windows explorer, if you
  22.  * haven't done it already:
  23.  * http://windows.microsoft.com/en-us/windows/show-hide-file-name-extensions
  24.  *
  25.  * 1. Download ReShade
  26.  *    During the testing Reshade is needed for hooking into the renderer and
  27.  *    loading/starting/toggeling the shader. It is available at http://reshade.me/
  28.  *
  29.  * 2. Copy ReShade32.dll from the downloaded archive into ArmAs main directory
  30.  *    (the same directory like the arma2.exe/ArmA2OA.exe/arma3.exe)
  31.  *
  32.  * 3. For ArmA 2 (OA/CO) rename the copied ReShade32.dll to d3d9.dll, for ArmA 3
  33.  *    rename it to dxgi.dll
  34.  *
  35.  * 4. If the shader file (the one you are reading now) isn't named ReShade.fx
  36.  *    rename it ReShade.fx
  37.  *
  38.  * 5. Copy this ReShade.fx into ArmAs main directory too.
  39.  *
  40.  *
  41.  * That's it. If you now start ArmA, ReShade should load the shader.
  42.  * Press [Insert] to toggle the shader on/off
  43.  * Press [Home] to toggle gamma 1.0/2.0
  44.  *
  45.  * It might be helpfull to note that ReShade is not compatible with software like screen
  46.  * capturing or overlays and you would need to deactivate them in order to test the shader.
  47.  * To take screenshots nevertheless ReShade brings its own screenshot functionality:
  48.  * Press [Print] to take a screenshot (they are saved to the same directory where you put
  49.  * the shader files)
  50.  *
  51.  */
  52.  
  53. #define max_radius            0.011   // [0.005 to 0.05]  Ratio of filter radius and screen width. The default is max_radius=0.011 and
  54.                                       //                  this means the max. blur radius will be 1.1% of the screen width.
  55.                                       //                  The bigger the radius, the stronger the blur. But at some point the quality of
  56.                                       //                  the blur gets worse and you might need to increase the kernel radius too.
  57.  
  58. #define kernel_radius         8       // [2|3|4|5|6|7|8]  Size of the gaussian kernel: (2n+1)x(2n+1)-kernel. If you set kernel_radius=3
  59.                                       //                  you will get a 7x7-kernel (gaussian blur)
  60.                                       //                  The performance of the shader is mainly determined by the kernel radius.
  61.                                       //                  A higher kernel radius leads to a smoother blur but a lower performance.
  62.  
  63. #define blur_const_a          6.0     // [3.5 to 7.0]     To calculate the amount of blur applied to each pixel based on its luminance a
  64. #define blur_const_b          4.0     // [2.0 to 5.0]     function similar to 1/x is used. A good starting point for understanding the
  65.                                       //                  function is to plot it with the given constants. This can be done with the
  66.                                       //                  help of e.g. wolframalpha.com. You would just need to put
  67.                                       //                    plot 1/((2^blur_const_a*x)^blur_const_b+1), x=0 to x=1, y=0 to y=1
  68.                                       //                  into the input field and replace the constants names with the chosen values and
  69.                                       //                  submit the input.
  70.                                       //                  The x-axis defines the given luminance and the y-axis the according normalized
  71.                                       //                  blur radius. This needs to be multiplied with the max_radius defined above to
  72.                                       //                  get the actual blur radius.
  73.  
  74. #define debloom               1       // [0|1]            Debloom reduces the bloom applied around small, bright objects and the blur in
  75.                                       //                  semi-dark areas. That comes at the expense of some performance but might be
  76.                                       //                  interesting for players who are prone to gaming sickness or who want the gfx to
  77.                                       //                  be as clean as possible.
  78. #define debloom_const_a       6.0     // [3.5 to 7.0]     It uses the same function like above but with the absolute difference of the
  79. #define debloom_const_b       4.0     // [2.0 to 5.0]     luminances of two instead of the ablolute luminance of one pixel.
  80.                                       //                  The constants can but don't need to be the same like the ones above.
  81.                                       //
  82. #define debloom_interpol      1       // [0|1]            To improve the quality even further, debloom can be used with linear
  83.                                       //                  interpolation but that costs a bit more performance too.
  84.  
  85. #define integrate_lum_pass    0       // [0|1]            If activated the calculation of the luminance is integrated into the bluring of
  86.                                       //                  these values. This reduces the number of passes but might increase the overall
  87.                                       //                  number of instructions. (The ideal setting might be different for each gfx-card
  88.                                       //                  vendor, gfx-card series or even driver version.)
  89.  
  90. #define integrate_bm_pass     0       // [0|1]            If activated the calculation of the blurmap is integrated into the bluring of
  91.                                       //                  the actual frame. This reduces the number of passes but might increase the
  92.                                       //                  overall number of instructions. (The ideal setting might be different for each
  93.                                       //                  gfx-card vendor, gfx-card series or even driver version.)
  94.  
  95.  
  96. #if kernel_radius < 2
  97. #define kernel_radius 2
  98. #elif 8 < kernel_radius
  99. #define kernel_radius 8
  100. #endif
  101.  
  102. #pragma message "\n"
  103. #pragma message "Press [Insert] to toggle the shader on/off\n"
  104. #pragma message "Press [Home] to toggle gamma 1.0/2.0\n"
  105. #pragma message "Press [Print] to take a screenshot\n"
  106.  
  107. #pragma reshade showstatistics
  108. #pragma reshade screenshot_format png
  109.  
  110.  
  111. static const float3 lumcoeff = float3(0.2126, 0.7152, 0.0722);
  112.  
  113. texture texColorBuffer : COLOR;
  114.  
  115. texture texTarget
  116. {
  117.   Width = BUFFER_WIDTH;
  118.   Height = BUFFER_HEIGHT;
  119.  
  120.   MipLevels = 1;
  121.   Format = R8;
  122. };
  123.  
  124. texture texTarget2
  125. {
  126.   Width = BUFFER_WIDTH;
  127.   Height = BUFFER_HEIGHT;
  128.  
  129.   MipLevels = 1;
  130.   Format = R8;
  131. };
  132.  
  133. texture texTarget3
  134. {
  135.   Width = BUFFER_WIDTH;
  136.   Height = BUFFER_HEIGHT;
  137.  
  138.   MipLevels = 1;
  139.   Format = RGBA8;
  140. };
  141.  
  142.  
  143. sampler samplerColor
  144. {
  145.   Texture = texColorBuffer;
  146.   AddressU = CLAMP;
  147.   AddressV = CLAMP;
  148.   AddressW = CLAMP;
  149.   MinFilter = LINEAR;
  150.   MagFilter = LINEAR;
  151.   MipFilter = LINEAR;
  152.   MipLODBias = 0.0f;
  153.   MinLOD = -1000.0f;
  154.   MaxLOD = 1000.0f;
  155.   MaxAnisotropy = 1;
  156.   SRGBTexture = FALSE;
  157. };
  158.  
  159. sampler samplerTarget
  160. {
  161.   Texture = texTarget;
  162. };
  163.  
  164. sampler samplerTarget2
  165. {
  166.   Texture = texTarget2;
  167. };
  168.  
  169. sampler samplerTarget3
  170. {
  171.   Texture = texTarget3;
  172. };
  173.  
  174.  
  175. /**
  176.  * Vertex shader to generate a simple fullscreen triangle with the three vertices
  177.  * provided by ReShade (http://redd.it/2j17wk):
  178.  */
  179. void PostProcessingVS(
  180.   in uint id : SV_VertexID,
  181.   out float4 position : SV_Position,
  182.   out float2 texcoord : TEXCOORD0)
  183. {
  184.   texcoord = float2((id << 1) & 2, id & 2);
  185.   position = float4(texcoord * float2(2, -2) + float2(-1, 1), 0, 1);
  186. }
  187.  
  188.  
  189. /**
  190.  * Pixel shader to calculate the luminance.
  191.  * It can be integrated into BlurLuminanceHorizontalPS.
  192.  */
  193. void CalcLuminancePS(
  194.   in float4 pos : SV_Position,
  195.   in float2 texcoord : TEXCOORD0,
  196.   out float lum : SV_Target)
  197. {
  198.   lum = dot( tex2D(samplerColor, texcoord).rgb, lumcoeff );
  199. }
  200.  
  201.  
  202. /**
  203.  * BlurLuminanceHorizontalPS and BlurLuminanceVerticalPS blur the calculated luminance values
  204.  * to get the gaussian-weighted average luminance of the neighborhood of each pixel.
  205.  */
  206. void BlurLuminanceHorizontalPS(
  207.   in float4 pos : SV_Position,
  208.   in float2 texcoord : TEXCOORD0,
  209.   out float lum : SV_Target)
  210. {
  211. #if kernel_radius == 2
  212.   static const float gauss[5] = {0.044844, 0.242423, 0.425466, 0.242423, 0.044844};
  213. #elif kernel_radius == 3
  214.   static const float gauss[7] = {0.030078, 0.104984, 0.22225, 0.285375, 0.22225, 0.104984, 0.030078};
  215. #elif kernel_radius == 4
  216.   static const float gauss[9] = {0.022656, 0.060631, 0.122478, 0.186757, 0.214956, 0.186757, 0.122478, 0.060631, 0.022656};
  217. #elif kernel_radius == 5
  218.   static const float gauss[11] = {0.01818, 0.040867, 0.076732, 0.120339, 0.15764, 0.172486, 0.15764, 0.120339, 0.076732,
  219.                                   0.040867, 0.01818};
  220. #elif kernel_radius == 6
  221.   static const float gauss[13] = {0.015183, 0.030196, 0.052995, 0.08208, 0.11219, 0.135328, 0.144055, 0.135328, 0.11219,
  222.                                   0.08208, 0.052995, 0.030196, 0.015183};
  223. #elif kernel_radius == 7
  224.   static const float gauss[15] = {0.013036, 0.023681, 0.039242, 0.059325, 0.081814, 0.102929, 0.118132, 0.123682, 0.118132,
  225.                                   0.102929, 0.081814, 0.059325, 0.039242, 0.023681, 0.013036};
  226. #elif kernel_radius == 8
  227.   static const float gauss[17] = {0.011421, 0.019353, 0.030565, 0.044996, 0.061744, 0.078971, 0.094148, 0.10462, 0.108363,
  228.                                   0.10462, 0.094148, 0.078971, 0.061744, 0.044996, 0.030565, 0.019353, 0.011421};
  229. #endif
  230.  
  231. #if integrate_lum_pass == 1
  232.   float4 color = tex2D(samplerColor, texcoord);
  233.  
  234.   float blur_stepsize_x = max_radius/kernel_radius;
  235.   float3 sum = float3(0.0, 0.0, 0.0);
  236.   for (int db_x1=-kernel_radius; db_x1<=kernel_radius; db_x1++)
  237.     sum += gauss[db_x1+kernel_radius] * tex2D(samplerColor, float2(texcoord + float2(blur_stepsize_x*db_x1, 0.0))).rgb;
  238.  
  239.   float lum_sum = dot(sum, lumcoeff);
  240.   float lum_color = dot(color.rgb, lumcoeff);
  241.  
  242.   // This "max(..." is needed to preserve small, bright objects like stars or other distant lightsources on a dark background.
  243.   // These pixels contain important information but they have too little influence on the weighted average luminance
  244.   // of their neighborhood and would get "blured away" otherwise. In adition it reduces the bloom around these objects comparable,
  245.   // but not as effective as the dedicated "debloom"
  246.   lum = max(lum_sum, lum_color);
  247.  
  248. #else
  249.   float blur_stepsize_x = max_radius/kernel_radius;
  250.   float sum = 0.0;
  251.   for (int db_x1=-kernel_radius; db_x1<=kernel_radius; db_x1++)
  252.     sum += gauss[db_x1+kernel_radius] * tex2D(samplerTarget, float2(texcoord + float2(blur_stepsize_x*db_x1, 0.0))).r;
  253.  
  254.   // This "max(..." is needed to preserve small, bright objects like stars or other distant lightsources on a dark background.
  255.   // These pixels contain important information but they have too little influence on the weighted average luminance
  256.   // of their neighborhood and would get "blured away" otherwise. In adition it reduces the bloom around these objects comparable,
  257.   // but not as effective as the dedicated "debloom"
  258.   lum = max(sum, tex2D(samplerTarget, texcoord).r);
  259. #endif
  260. }
  261.  
  262.  
  263. /**
  264.  * BlurLuminanceHorizontalPS and BlurLuminanceVerticalPS blur the calculated luminance values
  265.  * to get the gaussian-weighted average luminance of the neighborhood of each pixel.
  266.  */
  267. void BlurLuminanceVerticalPS(
  268.   in float4 pos : SV_Position,
  269.   in float2 texcoord : TEXCOORD0,
  270.   out float lum : SV_Target)
  271. {
  272. #if kernel_radius == 2
  273.   static const float gauss[5] = {0.044844, 0.242423, 0.425466, 0.242423, 0.044844};
  274. #elif kernel_radius == 3
  275.   static const float gauss[7] = {0.030078, 0.104984, 0.22225, 0.285375, 0.22225, 0.104984, 0.030078};
  276. #elif kernel_radius == 4
  277.   static const float gauss[9] = {0.022656, 0.060631, 0.122478, 0.186757, 0.214956, 0.186757, 0.122478, 0.060631, 0.022656};
  278. #elif kernel_radius == 5
  279.   static const float gauss[11] = {0.01818, 0.040867, 0.076732, 0.120339, 0.15764, 0.172486, 0.15764, 0.120339, 0.076732,
  280.                                   0.040867, 0.01818};
  281. #elif kernel_radius == 6
  282.   static const float gauss[13] = {0.015183, 0.030196, 0.052995, 0.08208, 0.11219, 0.135328, 0.144055, 0.135328, 0.11219,
  283.                                   0.08208, 0.052995, 0.030196, 0.015183};
  284. #elif kernel_radius == 7
  285.   static const float gauss[15] = {0.013036, 0.023681, 0.039242, 0.059325, 0.081814, 0.102929, 0.118132, 0.123682, 0.118132,
  286.                                   0.102929, 0.081814, 0.059325, 0.039242, 0.023681, 0.013036};
  287. #elif kernel_radius == 8
  288.   static const float gauss[17] = {0.011421, 0.019353, 0.030565, 0.044996, 0.061744, 0.078971, 0.094148, 0.10462, 0.108363,
  289.                                   0.10462, 0.094148, 0.078971, 0.061744, 0.044996, 0.030565, 0.019353, 0.011421};
  290. #endif
  291.  
  292.   float blur_stepsize_y = max_radius/kernel_radius * BUFFER_WIDTH/BUFFER_HEIGHT;
  293.   float sum = 0.0;
  294.   for (int db_y1=-kernel_radius; db_y1<=kernel_radius; db_y1++)
  295.     sum += gauss[db_y1+kernel_radius] * tex2D(samplerTarget2, float2(texcoord + float2(0.0, blur_stepsize_y*db_y1))).r;
  296.  
  297.   // This "max(..." is needed to preserve small, bright objects like stars or other distant lightsources on a dark background.
  298.   // These pixels contain important information but they have too little influence on the weighted average luminance
  299.   // of their neighborhood and would get "blured away" otherwise. In adition it reduces the bloom around these objects comparable,
  300.   // but not as effective as the dedicated "debloom"
  301.   lum = max(sum, tex2D(samplerTarget2, texcoord).r);
  302. }
  303.  
  304.  
  305. /**
  306.  * This PS calculates the amount of blur which needs to be applied to each pixel based
  307.  * on its luminance. ("blurmap")
  308.  * It can be integrated into BlurFrameHorizontalPS and BlurFrameVerticalPS.
  309.  */
  310. void CalcBlurMapPS(
  311.   in float4 pos : SV_Position,
  312.   in float2 texcoord : TEXCOORD0,
  313.   out float blur : SV_Target)
  314. {
  315.   blur = 1.0/(pow( exp2(blur_const_a) * tex2D(samplerTarget, texcoord).r, blur_const_b ) + 1.0);
  316. }
  317.  
  318.  
  319. /**
  320.  * BlurFrameHorizontalPS and BlurFrameVerticalPS blur the actual frame according to the
  321.  * calculated blurmap.
  322.  */
  323. void BlurFrameHorizontalPS(
  324.   in float4 pos : SV_Position,
  325.   in float2 texcoord : TEXCOORD0,
  326.   out float4 color : SV_Target)
  327. {
  328. #if kernel_radius == 2
  329.   static const float gauss[5] = {0.044844, 0.242423, 0.425466, 0.242423, 0.044844};
  330. #elif kernel_radius == 3
  331.   static const float gauss[7] = {0.030078, 0.104984, 0.22225, 0.285375, 0.22225, 0.104984, 0.030078};
  332. #elif kernel_radius == 4
  333.   static const float gauss[9] = {0.022656, 0.060631, 0.122478, 0.186757, 0.214956, 0.186757, 0.122478, 0.060631, 0.022656};
  334. #elif kernel_radius == 5
  335.   static const float gauss[11] = {0.01818, 0.040867, 0.076732, 0.120339, 0.15764, 0.172486, 0.15764, 0.120339, 0.076732,
  336.                                   0.040867, 0.01818};
  337. #elif kernel_radius == 6
  338.   static const float gauss[13] = {0.015183, 0.030196, 0.052995, 0.08208, 0.11219, 0.135328, 0.144055, 0.135328, 0.11219,
  339.                                   0.08208, 0.052995, 0.030196, 0.015183};
  340. #elif kernel_radius == 7
  341.   static const float gauss[15] = {0.013036, 0.023681, 0.039242, 0.059325, 0.081814, 0.102929, 0.118132, 0.123682, 0.118132,
  342.                                   0.102929, 0.081814, 0.059325, 0.039242, 0.023681, 0.013036};
  343. #elif kernel_radius == 8
  344.   static const float gauss[17] = {0.011421, 0.019353, 0.030565, 0.044996, 0.061744, 0.078971, 0.094148, 0.10462, 0.108363,
  345.                                   0.10462, 0.094148, 0.078971, 0.061744, 0.044996, 0.030565, 0.019353, 0.011421};
  346. #endif
  347.  
  348. #if integrate_bm_pass == 1
  349.   float blur = 1.0/(pow( exp2(blur_const_a)*tex2D(samplerTarget, texcoord).r, blur_const_b ) + 1.0);
  350. #else
  351.   float blur = tex2D(samplerTarget2, texcoord).r;
  352. #endif
  353.  
  354.   color = tex2D(samplerColor, texcoord);
  355.   float lum_color = dot(color.rgb, lumcoeff);
  356.  
  357.   float blur_stepsize_x = max_radius/kernel_radius * blur;
  358.   float3 sum = float3(0.0, 0.0, 0.0);
  359.   float3 color2;
  360.   float lum_color2;
  361.   float debloom_val;
  362.   for (int db_x2=-kernel_radius; db_x2<=kernel_radius; db_x2++)
  363.   {
  364.     color2 = tex2D( samplerColor, texcoord+float2(blur_stepsize_x*db_x2, 0.0) ).rgb;
  365.  
  366. // Debloom reduces the influence bright pixels in the neighborhood have on dark pixels.
  367. #if debloom == 1
  368.     lum_color2 = dot(color2, lumcoeff);
  369.    
  370.     // This is done by calculating a scalar based on the difference of the luminances of the original pixel and the neighbor pixel...
  371.     debloom_val = 1.0/(pow( exp2(debloom_const_a)*abs(lum_color-lum_color2), debloom_const_b ) + 1.0);
  372.    
  373.   #if debloom_interpol == 0
  374.     // ...then multiply the neighbor pixels value by the scalar in addition to the gaussian weighting.
  375.     sum += gauss[db_x2+kernel_radius] * color2 * debloom_val;
  376.    
  377.   #else
  378.     // If interpolation is activated use a linear interpolation of the original pixel and the neighbor pixel instead of the scaled
  379.     // neighbor pixel alone. The more the two pixels differ in luminance the more scale in favor of the original pixel.
  380.     sum += gauss[db_x2+kernel_radius] * lerp(color.rgb, color2, debloom_val);
  381.  
  382.   #endif
  383. #else
  384.     // If debloom is deactivated a simple gaussian blur is used.
  385.     sum += gauss[db_x2+kernel_radius] * color2;
  386.  
  387. #endif
  388.  
  389.   }
  390.   color.rgb = sum;
  391. }
  392.  
  393.  
  394. /**
  395.  * BlurFrameHorizontalPS and BlurFrameVerticalPS blur the actual frame according to the
  396.  * calculated blurmap.
  397.  */
  398. void BlurFrameVerticalPS(
  399.   in float4 pos : SV_Position,
  400.   in float2 texcoord : TEXCOORD0,
  401.   out float4 color : SV_Target)
  402. {
  403. #if kernel_radius == 2
  404.   static const float gauss[5] = {0.044844, 0.242423, 0.425466, 0.242423, 0.044844};
  405. #elif kernel_radius == 3
  406.   static const float gauss[7] = {0.030078, 0.104984, 0.22225, 0.285375, 0.22225, 0.104984, 0.030078};
  407. #elif kernel_radius == 4
  408.   static const float gauss[9] = {0.022656, 0.060631, 0.122478, 0.186757, 0.214956, 0.186757, 0.122478, 0.060631, 0.022656};
  409. #elif kernel_radius == 5
  410.   static const float gauss[11] = {0.01818, 0.040867, 0.076732, 0.120339, 0.15764, 0.172486, 0.15764, 0.120339, 0.076732,
  411.                                   0.040867, 0.01818};
  412. #elif kernel_radius == 6
  413.   static const float gauss[13] = {0.015183, 0.030196, 0.052995, 0.08208, 0.11219, 0.135328, 0.144055, 0.135328, 0.11219,
  414.                                   0.08208, 0.052995, 0.030196, 0.015183};
  415. #elif kernel_radius == 7
  416.   static const float gauss[15] = {0.013036, 0.023681, 0.039242, 0.059325, 0.081814, 0.102929, 0.118132, 0.123682, 0.118132,
  417.                                   0.102929, 0.081814, 0.059325, 0.039242, 0.023681, 0.013036};
  418. #elif kernel_radius == 8
  419.   static const float gauss[17] = {0.011421, 0.019353, 0.030565, 0.044996, 0.061744, 0.078971, 0.094148, 0.10462, 0.108363,
  420.                                   0.10462, 0.094148, 0.078971, 0.061744, 0.044996, 0.030565, 0.019353, 0.011421};
  421. #endif
  422.  
  423. #if integrate_bm_pass == 1
  424.   float blur = 1.0/(pow( exp2(blur_const_a)*tex2D(samplerTarget, texcoord).r, blur_const_b ) + 1.0);
  425. #else
  426.   float blur = tex2D(samplerTarget2, texcoord).r;
  427. #endif
  428.  
  429.   color = tex2D(samplerTarget3, texcoord);
  430.   float lum_color = dot(color.rgb, lumcoeff);
  431.  
  432.   float blur_stepsize_y = max_radius/kernel_radius * BUFFER_WIDTH/BUFFER_HEIGHT * blur;
  433.   float3 sum = float3(0.0, 0.0, 0.0);
  434.   float3 color2;
  435.   float lum_color2;
  436.   float debloom_val;
  437.   for (int db_y2=-kernel_radius; db_y2<=kernel_radius; db_y2++)
  438.   {
  439.     color2 = tex2D( samplerTarget3, texcoord+float2(0.0, blur_stepsize_y*db_y2) ).rgb;
  440.  
  441. // Debloom reduces the influence bright pixels in the neighborhood have on dark pixels.
  442. #if debloom == 1
  443.     lum_color2 = dot(color2, lumcoeff);
  444.    
  445.     // This is done by calculating a scalar based on the difference of the luminances of the original pixel and the neighbor pixel...
  446.     debloom_val = 1.0/(pow( exp2(debloom_const_a)*abs(lum_color-lum_color2), debloom_const_b ) + 1.0);
  447.    
  448.   #if debloom_interpol == 0
  449.     // ...then multiply the neighbor pixels value by the scalar in addition to the gaussian weighting.
  450.     sum += gauss[db_y2+kernel_radius] * color2 * debloom_val;
  451.    
  452.   #else
  453.     // If interpolation is activated use a linear interpolation of the original pixel and the neighbor pixel instead of the scaled
  454.     // neighbor pixel alone. The more the two pixels differ in luminance the more scale in favor of the original pixel.
  455.     sum += gauss[db_y2+kernel_radius] * lerp(color.rgb, color2, debloom_val);
  456.  
  457.   #endif
  458. #else
  459.     // If debloom is deactivated a simple gaussian blur is used.
  460.     sum += gauss[db_y2+kernel_radius] * color2;
  461.  
  462. #endif
  463.  
  464.   }
  465.   color.rgb = sum;
  466. }
  467.  
  468.  
  469. /**
  470.  * Gamma correction with gamma=0.5 to increase the brightness.
  471.  */
  472. void GammaCorrectionPS(
  473.   in float4 pos : SV_Position,
  474.   in float2 texcoord : TEXCOORD0,
  475.   out float4 color : SV_Target)
  476. {
  477.   color = tex2D(samplerColor, texcoord);
  478.   float lum = dot(color.rgb, lumcoeff);
  479.   color.rgb *= ( pow(lum, 0.5)/lum );
  480.  
  481.   saturate(color);
  482. }
  483.  
  484.  
  485. /**
  486.  * Definition of the complete effect/shader.
  487.  * Press [Insert] to toggle the shader on/off
  488.  */
  489. technique Blur < toggle = 0x2D; >
  490. {
  491. #if integrate_lum_pass == 0
  492.   pass CalcLuminance
  493.   {
  494.     VertexShader = PostProcessingVS;
  495.     PixelShader = CalcLuminancePS;
  496.     RenderTarget = texTarget;
  497.   }
  498. #endif
  499.  
  500.   pass BlurLuminanceHorizontal
  501.   {
  502.     VertexShader = PostProcessingVS;
  503.     PixelShader = BlurLuminanceHorizontalPS;
  504.     RenderTarget = texTarget2;
  505.   }
  506.  
  507.   pass BlurLuminanceVertical
  508.   {
  509.     VertexShader = PostProcessingVS;
  510.     PixelShader = BlurLuminanceVerticalPS;
  511.     RenderTarget = texTarget;
  512.   }
  513.  
  514. #if integrate_bm_pass == 0
  515.   pass CalcBlurMap
  516.   {
  517.     VertexShader = PostProcessingVS;
  518.     PixelShader = CalcBlurMapPS;
  519.     RenderTarget = texTarget2;
  520.   }
  521. #endif
  522.  
  523.   pass BlurFrameHorizontal
  524.   {
  525.     VertexShader = PostProcessingVS;
  526.     PixelShader = BlurFrameHorizontalPS;
  527.     RenderTarget = texTarget3;
  528.   }
  529.  
  530.   pass BlurFrameVertical
  531.   {
  532.     VertexShader = PostProcessingVS;
  533.     PixelShader = BlurFrameVerticalPS;
  534.   }
  535.  
  536. }
  537.  
  538.  
  539. /**
  540.  * Definition of the gamma correction.
  541.  * Press [Home] to toggle gamma 1.0/2.0
  542.  */
  543. technique Gamma < toggle = 0x24; >
  544. {
  545.   pass GammaCorrection
  546.   {
  547.     VertexShader = PostProcessingVS;
  548.     PixelShader = GammaCorrectionPS;
  549.   }
  550.  
  551. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement