Advertisement
Guest User

Untitled

a guest
Aug 13th, 2014
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 18.81 KB | None | 0 0
  1. // Post processing effect file
  2. // most shader code taken from SweetFX 1.5
  3.  
  4. // -------------------- Settings -----------------------------------------------
  5.  
  6. // Set to 1 for ON or 0 for OFF
  7. #define USE_BLOOM         0  // [0 or 1] Bloom : Makes bright lights bleed their light into their surroundings (relatively high performance cost)
  8. #define USE_HDR           0  // [0 or 1] HDR : Not actual HDR - It just tries to mimic an HDR look (relatively high performance cost)
  9. #define USE_LUMASHARPEN   0  // [0 or 1] LumaSharpen
  10. #define USE_VIBRANCE      0  // [0 or 1] Vibrance : Intelligently saturates (or desaturates if you use negative values) the pixels depending on their original saturation.
  11. #define USE_TONEMAP       1 //[0 or 1] Tonemap : Adjust gamma, exposure, saturation, bleach and defog. (may cause clipping)
  12.  
  13. // Bloom settings
  14. #define BloomThreshold 20.25 // [0.00 to 50.00] Threshold for what is a bright light (that causes bloom) and what isn't.
  15. #define BloomPower 1.600     // [0.00 to  8.00] Strength of the bloom
  16. #define BloomWidth 0.035     // [0.00 to  1.00] Width of the bloom
  17.  
  18. // HDR settings
  19. #define HDRPower 1.15        // [0.00 to 8.00] Strangely lowering this makes the image brighter
  20. #define radius2  0.80        // [0.00 to 8.00] Raising this seems to make the effect stronger and also brighter
  21.  
  22. // LumaSharpen settings
  23. #define sharp_strength 0.35   // [0.10 to 3.00] Strength of the sharpening
  24. #define sharp_clamp    0.035  // [0.00 to 1.00] Limits maximum amount of sharpening a pixel recieves - Default is 0.035
  25. #define pattern 2             // [1|2|3|4] Choose a sample pattern. 1 = Fast, 2 = Normal, 3 = Wider, 4 = Pyramid shaped.
  26.  
  27. // Vibrance settings
  28. #define Vibrance     0.08     // [-1.00 to 1.00] Intelligently saturates (or desaturates if you use negative values) the pixels depending on their original saturation.
  29. #define Vibrance_RGB_balance float3(1.00, 1.00, 1.00) // [-10.00 to 10.00,-10.00 to 10.00,-10.00 to 10.00] A per channel multiplier to the Vibrance strength so you can give more boost to certain colors over others
  30.  
  31. // Tonemap settings
  32. #define Gamma       1.000  //[0.000 to 2.000] Adjust midtones. 1.000 is neutral. This setting does exactly the same as the one in Lift Gamma Gain, only with less control.
  33. #define Exposure    0.000  //[-1.000 to 1.000] Adjust exposure
  34. #define Saturation  0.000  //[-1.000 to 1.000] Adjust saturation
  35. #define Bleach      0.000  //[0.000 to 1.000] Brightens the shadows and fades the colors
  36. #define Defog       0.000  //[0.000 to 1.000] How much of the color tint to remove
  37. #define FogColor float3(2.55, 2.55, 2.55) //[0.00 to 2.55, 0.00 to 2.55, 0.00 to 2.55] What color to remove - default is blue
  38.  
  39. // -------------------- Interface -----------------------------------------------
  40.  
  41. texture2D thisframeTex;
  42.  
  43. static float2 rcpres = PIXEL_SIZE;
  44.  
  45. #ifndef USE_SRGB
  46. #define USE_SRGB true
  47. #endif
  48.  
  49. sampler s0 = sampler_state
  50. {
  51.     texture = <thisframeTex>;
  52.     AddressU = CLAMP;
  53.     AddressV = CLAMP;
  54.     MINFILTER = LINEAR;
  55.     MAGFILTER = LINEAR;
  56.     SRGBTexture = USE_SRGB;
  57. };
  58.  
  59. struct VSOUT
  60. {
  61.     float4 vertPos : POSITION;
  62.     float2 UVCoord : TEXCOORD0;
  63. };
  64.  
  65. struct VSIN
  66. {
  67.     float4 vertPos : POSITION0;
  68.     float2 UVCoord : TEXCOORD0;
  69. };
  70.  
  71. VSOUT FrameVS(VSIN IN)
  72. {
  73.     VSOUT OUT;
  74.     OUT.vertPos = IN.vertPos;
  75.     OUT.UVCoord = IN.UVCoord;
  76.     return OUT;
  77. }
  78.  
  79. // -------------------- Effects -----------------------------------------------
  80.  
  81. /*
  82.    _____________________
  83.  
  84.      LumaSharpen 1.4.1
  85.    _____________________
  86.  
  87.   by Christian Cann Schuldt Jensen ~ CeeJay.dk
  88.  
  89.   It blurs the original pixel with the surrounding pixels and then subtracts this blur to sharpen the image.
  90.   It does this in luma to avoid color artifacts and allows limiting the maximum sharpening to avoid or lessen halo artifacts.
  91.  
  92.   This is similar to using Unsharp Mask in Photoshop.
  93.  
  94.   Compiles with 3.0
  95. */
  96.  
  97. #ifndef offset_bias
  98. #define offset_bias 1.0
  99. #endif
  100.  
  101. #define px (rcpres.x)
  102. #define py (rcpres.y)
  103.  
  104.    /*-----------------------------------------------------------.
  105.   /                      Developer settings                     /
  106.   '-----------------------------------------------------------*/
  107. #define CoefLuma float3(0.2126, 0.7152, 0.0722)      // BT.709 & sRBG luma coefficient (Monitors and HD Television)
  108. //#define CoefLuma float3(0.299, 0.587, 0.114)       // BT.601 luma coefficient (SD Television)
  109. //#define CoefLuma float3(1.0/3.0, 1.0/3.0, 1.0/3.0) // Equal weight coefficient
  110.  
  111.    /*-----------------------------------------------------------.
  112.   /                          Main code                          /
  113.   '-----------------------------------------------------------*/
  114.  
  115. float4 LumaSharpenPass(float4 inputcolor, float2 tex )
  116. {
  117.   // -- Get the original pixel --
  118.   float3 ori = tex2D(s0, tex).rgb;       // ori = original pixel
  119.  
  120.   // -- Combining the strength and luma multipliers --
  121.   float3 sharp_strength_luma = (CoefLuma * sharp_strength); //I'll be combining even more multipliers with it later on
  122.  
  123.    /*-----------------------------------------------------------.
  124.   /                       Sampling patterns                     /
  125.   '-----------------------------------------------------------*/
  126.   //   [ NW,   , NE ] Each texture lookup (except ori)
  127.   //   [   ,ori,    ] samples 4 pixels
  128.   //   [ SW,   , SE ]
  129.  
  130.   // -- Pattern 1 -- A (fast) 7 tap gaussian using only 2+1 texture fetches.
  131.   #if pattern == 1
  132.  
  133.     // -- Gaussian filter --
  134.     //   [ 1/9, 2/9,    ]     [ 1 , 2 ,   ]
  135.     //   [ 2/9, 8/9, 2/9]  =  [ 2 , 8 , 2 ]
  136.     //   [    , 2/9, 1/9]     [   , 2 , 1 ]
  137.  
  138.     float3 blur_ori = tex2D(s0, tex + (float2(px,py) / 3.0) * offset_bias).rgb;  // North West
  139.     blur_ori += tex2D(s0, tex + (float2(-px,-py) / 3.0) * offset_bias).rgb; // South East
  140.  
  141.     //blur_ori += tex2D(s0, tex + float2(px,py) / 3.0 * offset_bias); // North East
  142.     //blur_ori += tex2D(s0, tex + float2(-px,-py) / 3.0 * offset_bias); // South West
  143.  
  144.     blur_ori /= 2;  //Divide by the number of texture fetches
  145.  
  146.     sharp_strength_luma *= 1.5; // Adjust strength to aproximate the strength of pattern 2
  147.  
  148.   #endif
  149.  
  150.   // -- Pattern 2 -- A 9 tap gaussian using 4+1 texture fetches.
  151.   #if pattern == 2
  152.  
  153.     // -- Gaussian filter --
  154.     //   [ .25, .50, .25]     [ 1 , 2 , 1 ]
  155.     //   [ .50,   1, .50]  =  [ 2 , 4 , 2 ]
  156.     //   [ .25, .50, .25]     [ 1 , 2 , 1 ]
  157.  
  158.  
  159.     float3 blur_ori = tex2D(s0, tex + float2(px,-py) * 0.5 * offset_bias).rgb; // South East
  160.     blur_ori += tex2D(s0, tex + float2(-px,-py) * 0.5 * offset_bias).rgb;  // South West
  161.     blur_ori += tex2D(s0, tex + float2(px,py) * 0.5 * offset_bias).rgb; // North East
  162.     blur_ori += tex2D(s0, tex + float2(-px,py) * 0.5 * offset_bias).rgb; // North West
  163.  
  164.     blur_ori *= 0.25;  // ( /= 4) Divide by the number of texture fetches
  165.  
  166.   #endif
  167.  
  168.   // -- Pattern 3 -- An experimental 17 tap gaussian using 4+1 texture fetches.
  169.   #if pattern == 3
  170.  
  171.     // -- Gaussian filter --
  172.     //   [   , 4 , 6 ,   ,   ]
  173.     //   [   ,16 ,24 ,16 , 4 ]
  174.     //   [ 6 ,24 ,   ,24 , 6 ]
  175.     //   [ 4 ,16 ,24 ,16 ,   ]
  176.     //   [   ,   , 6 , 4 ,   ]
  177.  
  178.     float3 blur_ori = tex2D(s0, tex + float2(0.4*px,-1.2*py)* offset_bias).rgb;  // South South East
  179.     blur_ori += tex2D(s0, tex + float2(-1.2*px,-0.4*py) * offset_bias).rgb; // West South West
  180.     blur_ori += tex2D(s0, tex + float2(1.2*px,0.4*py) * offset_bias).rgb; // East North East
  181.     blur_ori += tex2D(s0, tex + float2(-0.4*px,1.2*py) * offset_bias).rgb; // North North West
  182.  
  183.     blur_ori *= 0.25;  // ( /= 4) Divide by the number of texture fetches
  184.  
  185.     sharp_strength_luma *= 0.51;
  186.   #endif
  187.  
  188.   // -- Pattern 4 -- A 9 tap high pass (pyramid filter) using 4+1 texture fetches.
  189.   #if pattern == 4
  190.  
  191.     // -- Gaussian filter --
  192.     //   [ .50, .50, .50]     [ 1 , 1 , 1 ]
  193.     //   [ .50,    , .50]  =  [ 1 ,   , 1 ]
  194.     //   [ .50, .50, .50]     [ 1 , 1 , 1 ]
  195.  
  196.     float3 blur_ori = tex2D(s0, tex + float2(0.5 * px,-py * offset_bias)).rgb;  // South South East
  197.     blur_ori += tex2D(s0, tex + float2(offset_bias * -px,0.5 * -py)).rgb; // West South West
  198.     blur_ori += tex2D(s0, tex + float2(offset_bias * px,0.5 * py)).rgb; // East North East
  199.     blur_ori += tex2D(s0, tex + float2(0.5 * -px,py * offset_bias)).rgb; // North North West
  200.  
  201.     //blur_ori += (2 * ori); // Probably not needed. Only serves to lessen the effect.
  202.  
  203.     blur_ori /= 4.0;  //Divide by the number of texture fetches
  204.  
  205.     sharp_strength_luma *= 0.666; // Adjust strength to aproximate the strength of pattern 2
  206.   #endif
  207.  
  208.   // -- Pattern 8 -- A (slower) 9 tap gaussian using 9 texture fetches.
  209.   #if pattern == 8
  210.  
  211.     // -- Gaussian filter --
  212.     //   [ 1 , 2 , 1 ]
  213.     //   [ 2 , 4 , 2 ]
  214.     //   [ 1 , 2 , 1 ]
  215.  
  216.     half3 blur_ori = tex2D(s0, tex + float2(-px,py) * offset_bias).rgb; // North West
  217.     blur_ori += tex2D(s0, tex + float2(px,-py) * offset_bias).rgb;     // South East
  218.     blur_ori += tex2D(s0, tex + float2(-px,-py)  * offset_bias).rgb;  // South West
  219.     blur_ori += tex2D(s0, tex + float2(px,py) * offset_bias).rgb;    // North East
  220.  
  221.     half3 blur_ori2 = tex2D(s0, tex + float2(0,py) * offset_bias).rgb; // North
  222.     blur_ori2 += tex2D(s0, tex + float2(0,-py) * offset_bias).rgb;    // South
  223.     blur_ori2 += tex2D(s0, tex + float2(-px,0) * offset_bias).rgb;   // West
  224.     blur_ori2 += tex2D(s0, tex + float2(px,0) * offset_bias).rgb;   // East
  225.     blur_ori2 *= 2.0;
  226.  
  227.     blur_ori += blur_ori2;
  228.     blur_ori += (ori * 4); // Probably not needed. Only serves to lessen the effect.
  229.  
  230.     // dot()s with gaussian strengths here?
  231.  
  232.     blur_ori /= 16.0;  //Divide by the number of texture fetches
  233.  
  234.     //sharp_strength_luma *= 0.75; // Adjust strength to aproximate the strength of pattern 2
  235.   #endif
  236.  
  237.   // -- Pattern 9 -- A (slower) 9 tap high pass using 9 texture fetches.
  238.   #if pattern == 9
  239.  
  240.     // -- Gaussian filter --
  241.     //   [ 1 , 1 , 1 ]
  242.     //   [ 1 , 1 , 1 ]
  243.     //   [ 1 , 1 , 1 ]
  244.  
  245.     float3 blur_ori = tex2D(s0, tex + float2(-px,py) * offset_bias).rgb; // North West
  246.     blur_ori += tex2D(s0, tex + float2(px,-py) * offset_bias).rgb;     // South East
  247.     blur_ori += tex2D(s0, tex + float2(-px,-py)  * offset_bias).rgb;  // South West
  248.     blur_ori += tex2D(s0, tex + float2(px,py) * offset_bias).rgb;    // North East
  249.  
  250.     blur_ori += ori.rgb; // Probably not needed. Only serves to lessen the effect.
  251.  
  252.     blur_ori += tex2D(s0, tex + float2(0,py) * offset_bias).rgb;    // North
  253.     blur_ori += tex2D(s0, tex + float2(0,-py) * offset_bias).rgb;  // South
  254.     blur_ori += tex2D(s0, tex + float2(-px,0) * offset_bias).rgb; // West
  255.     blur_ori += tex2D(s0, tex + float2(px,0) * offset_bias).rgb; // East
  256.  
  257.     blur_ori /= 9;  //Divide by the number of texture fetches
  258.  
  259.     //sharp_strength_luma *= (8.0/9.0); // Adjust strength to aproximate the strength of pattern 2
  260.   #endif
  261.  
  262.  
  263.    /*-----------------------------------------------------------.
  264.   /                            Sharpen                          /
  265.   '-----------------------------------------------------------*/
  266.  
  267.   // -- Calculate the sharpening --
  268.   float3 sharp = ori - blur_ori;  //Subtracting the blurred image from the original image
  269.  
  270.   #if 0 //New experimental limiter .. not yet finished
  271.     float sharp_luma = dot(sharp, sharp_strength_luma); //Calculate the luma
  272.     sharp_luma = (abs(sharp_luma)*8.0) * exp(1.0-(abs(sharp_luma)*8.0)) * sign(sharp_luma) / 16.0; //I should probably move the strength modifier here
  273.  
  274.   #elif 0 //SweetFX 1.4 code
  275.     // -- Adjust strength of the sharpening --
  276.     float sharp_luma = dot(sharp, sharp_strength_luma); //Calculate the luma and adjust the strength
  277.  
  278.     // -- Clamping the maximum amount of sharpening to prevent halo artifacts --
  279.     sharp_luma = clamp(sharp_luma, -sharp_clamp, sharp_clamp);  //TODO Try a curve function instead of a clamp
  280.  
  281.   #else //SweetFX 1.5.1 code
  282.     // -- Adjust strength of the sharpening and clamp it--
  283.     float4 sharp_strength_luma_clamp = float4(sharp_strength_luma * (0.5 / sharp_clamp),0.5); //Roll part of the clamp into the dot
  284.  
  285.     //sharp_luma = saturate((0.5 / sharp_clamp) * sharp_luma + 0.5); //scale up and clamp
  286.     float sharp_luma = saturate(dot(float4(sharp,1.0), sharp_strength_luma_clamp)); //Calculate the luma, adjust the strength, scale up and clamp
  287.     sharp_luma = (sharp_clamp * 2.0) * sharp_luma - sharp_clamp; //scale down
  288.   #endif
  289.  
  290.   // -- Combining the values to get the final sharpened pixel   --
  291.   //float4 done = ori + sharp_luma;    // Add the sharpening to the original.
  292.   inputcolor.rgb = inputcolor.rgb + sharp_luma;    // Add the sharpening to the input color.
  293.  
  294.    /*-----------------------------------------------------------.
  295.   /                     Returning the output                    /
  296.   '-----------------------------------------------------------*/
  297.   #ifndef show_sharpen
  298.   #define show_sharpen 0
  299.   #endif
  300.   #if show_sharpen == 1
  301.     //inputcolor.rgb = abs(sharp * 4.0);
  302.     inputcolor.rgb = saturate(0.5 + (sharp_luma * 4)).rrr;
  303.   #endif
  304.  
  305.   return saturate(inputcolor);
  306.  
  307. }
  308.  
  309. // -------------------- Bloom -----------------------------------------------
  310.  
  311. float4 BloomPass(float4 ColorInput2, float2 Tex)
  312. {
  313.     float3 BlurColor2 = 0;
  314.     float3 Blurtemp = 0;
  315.     float MaxDistance = 8*BloomWidth;
  316.     float CurDistance = 0;
  317.    
  318.     float Samplecount = 25.0;
  319.    
  320.     float2 blurtempvalue = Tex * rcpres * BloomWidth;
  321.    
  322.     float2 BloomSample = float2(2.5,-2.5);
  323.     float2 BloomSampleValue;
  324.    
  325.     for(BloomSample.x = (2.5); BloomSample.x > -2.0; BloomSample.x = BloomSample.x - 1.0) // runs 5 times
  326.     {
  327.         BloomSampleValue.x = BloomSample.x * blurtempvalue.x;
  328.         float2 distancetemp = BloomSample.x * BloomSample.x * BloomWidth;
  329.        
  330.         for(BloomSample.y = (- 2.5); BloomSample.y < 2.0; BloomSample.y = BloomSample.y + 1.0) // runs 5 ( * 5) times
  331.         {
  332.             distancetemp.y = BloomSample.y * BloomSample.y;
  333.             CurDistance = (distancetemp.y * BloomWidth) + distancetemp.x;
  334.            
  335.             BloomSampleValue.y = BloomSample.y * blurtempvalue.y;
  336.             Blurtemp.rgb = tex2D(s0, float2(Tex + BloomSampleValue)).rgb;
  337.  
  338.             BlurColor2.rgb += lerp(Blurtemp.rgb,ColorInput2.rgb, sqrt(CurDistance / MaxDistance));
  339.         }
  340.     }
  341.     BlurColor2.rgb = (BlurColor2.rgb / (Samplecount - (BloomPower - BloomThreshold*5)));
  342.     float Bloomamount = (dot(ColorInput2.rgb,float3(0.299f, 0.587f, 0.114f)));
  343.     float3 BlurColor = BlurColor2.rgb * (BloomPower + 4.0);
  344.  
  345.     ColorInput2.rgb = lerp(ColorInput2.rgb,BlurColor.rgb, Bloomamount);
  346.     return saturate(ColorInput2);
  347. }
  348.  
  349. // -------------------- HDR -----------------------------------------------
  350.  
  351. float4 HDRPass(float4 colorInput, float2 Tex)
  352. {
  353.     float3 c_center = tex2D(s0, Tex).rgb;
  354.    
  355.     float radius1 = 0.793;
  356.     float3 bloom_sum1 = tex2D(s0, Tex + float2(1.5, -1.5) * radius1).rgb;
  357.     bloom_sum1 += tex2D(s0, Tex + float2(-1.5, -1.5) * radius1).rgb;
  358.     bloom_sum1 += tex2D(s0, Tex + float2(1.5, 1.5) * radius1).rgb;
  359.     bloom_sum1 += tex2D(s0, Tex + float2(-1.5, 1.5) * radius1).rgb;
  360.    
  361.     bloom_sum1 += tex2D(s0, Tex + float2(0, -2.5) * radius1).rgb;
  362.     bloom_sum1 += tex2D(s0, Tex + float2(0, 2.5) * radius1).rgb;
  363.     bloom_sum1 += tex2D(s0, Tex + float2(-2.5, 0) * radius1).rgb;
  364.     bloom_sum1 += tex2D(s0, Tex + float2(2.5, 0) * radius1).rgb;
  365.    
  366.     bloom_sum1 *= 0.005;
  367.    
  368.     float3 bloom_sum2 = tex2D(s0, Tex + float2(1.5, -1.5) * radius2).rgb;
  369.     bloom_sum2 += tex2D(s0, Tex + float2(-1.5, -1.5) * radius2).rgb;
  370.     bloom_sum2 += tex2D(s0, Tex + float2(1.5, 1.5) * radius2).rgb;
  371.     bloom_sum2 += tex2D(s0, Tex + float2(-1.5, 1.5) * radius2).rgb;
  372.  
  373.  
  374.     bloom_sum2 += tex2D(s0, Tex + float2(0, -2.5) * radius2).rgb;  
  375.     bloom_sum2 += tex2D(s0, Tex + float2(0, 2.5) * radius2).rgb;
  376.     bloom_sum2 += tex2D(s0, Tex + float2(-2.5, 0) * radius2).rgb;
  377.     bloom_sum2 += tex2D(s0, Tex + float2(2.5, 0) * radius2).rgb;
  378.  
  379.     bloom_sum2 *= 0.010;
  380.    
  381.     float dist = radius2 - radius1;
  382.    
  383.     float3 HDR = (c_center + (bloom_sum2 - bloom_sum1)) * dist;
  384.     float3 blend = HDR + colorInput.rgb;
  385.     colorInput.rgb = HDR + pow(blend, HDRPower); // pow - don't use fractions for HDRpower
  386.    
  387.     return saturate(colorInput);
  388. }
  389.  
  390. // -------------------- Vibrance -----------------------------------------------
  391.  
  392. float4 VibrancePass(float4 colorInput)
  393. {  
  394.     #define Vibrance_coeff float3(Vibrance_RGB_balance * Vibrance)
  395.  
  396.     float4 color = colorInput; //original input color
  397.     float3 lumCoeff = float3(0.212656, 0.715158, 0.072186);  //Values to calculate luma with
  398.  
  399.     float luma = dot(lumCoeff, color.rgb); //calculate luma (grey)
  400.  
  401.     float max_color = max(colorInput.r, max(colorInput.g,colorInput.b)); //Find the strongest color
  402.     float min_color = min(colorInput.r, min(colorInput.g,colorInput.b)); //Find the weakest color
  403.  
  404.     float color_saturation = max_color - min_color; //The difference between the two is the saturation
  405.  
  406.     color.rgb = lerp(luma, color.rgb, (1.0 + (Vibrance_coeff * (1.0 - (sign(Vibrance_coeff) * color_saturation)))));
  407.     return color;
  408. }
  409.  
  410. // -------------------------Tonemap--------------------------------------------
  411.  
  412. float4 TonemapPass(float4 colorInput)
  413. {
  414.     float3 color = colorInput.rgb;
  415.  
  416.     color = saturate(color - Defog * FogColor); // Defog
  417.    
  418.     color *= pow(2.0f, Exposure); // Exposure
  419.    
  420.     color = pow(color, Gamma);    // Gamma -- roll into the first gamma correction in main.h ?
  421.  
  422.     //#define BlueShift 0.00    //Blueshift
  423.     //float4 d = color * float4(1.05f, 0.97f, 1.27f, color.a);
  424.     //color = lerp(color, d, BlueShift);
  425.    
  426.     float3 lumCoeff = float3(0.2126, 0.7152, 0.0722);
  427.     float lum = dot(lumCoeff, color.rgb);
  428.    
  429.     float3 blend = lum.rrr; //dont use float3
  430.    
  431.     float L = saturate( 10.0 * (lum - 0.45) );
  432.    
  433.     float3 result1 = 2.0f * color.rgb * blend;
  434.     float3 result2 = 1.0f - 2.0f * (1.0f - blend) * (1.0f - color.rgb);
  435.    
  436.     float3 newColor = lerp(result1, result2, L);
  437.     float A2 = Bleach * color.rgb; //why use a float for A2 here and then multiply by color.rgb (a float3)?
  438.     //float3 A2 = Bleach * color.rgb; //
  439.     float3 mixRGB = A2 * newColor;
  440.    
  441.     color.rgb += ((1.0f - A2) * mixRGB);
  442.    
  443.     //float3 middlegray = float(color.r + color.g + color.b) / 3;
  444.     float3 middlegray = dot(color,(1.0/3.0)); //1fps slower than the original on nvidia, 2 fps faster on AMD
  445.    
  446.     float3 diffcolor = color - middlegray; //float 3 here
  447.     colorInput.rgb = (color + diffcolor * Saturation)/(1+(diffcolor*Saturation)); //saturation
  448.    
  449.     return colorInput;
  450. }
  451.  
  452. // -------------------- Main -----------------------------------------------
  453.  
  454. float4 postProcessing(VSOUT IN) : COLOR0
  455. {
  456.     float2 tex = IN.UVCoord;
  457.     float4 c0 = tex2D(s0, tex);
  458.  
  459. #if (USE_BLOOM == 1)
  460.     c0 = BloomPass(c0, tex);
  461. #endif
  462.    
  463. #if (USE_HDR == 1)
  464.     c0 = HDRPass(c0, tex);
  465. #endif
  466.  
  467. #if (USE_LUMASHARPEN == 1)
  468.     c0 = LumaSharpenPass(c0, tex);
  469. #endif
  470.  
  471. #if (USE_VIBRANCE == 1)
  472.     c0 = VibrancePass(c0);
  473. #endif
  474.  
  475. #if (USE_TONEMAP == 1)
  476.     c0 = TonemapPass(c0, tex);
  477. #endif
  478.  
  479.     c0.w = 1.0;
  480.     return saturate(c0);
  481. }
  482.  
  483. technique t0
  484. {
  485.     pass P0
  486.     {
  487.         VertexShader = compile vs_3_0 FrameVS();
  488.         PixelShader = compile ps_3_0 postProcessing();
  489.         ZEnable = false;        
  490.         SRGBWriteEnable = USE_SRGB;
  491.         AlphaBlendEnable = false;
  492.         AlphaTestEnable = false;
  493.         ColorWriteEnable = RED|GREEN|BLUE|ALPHA;
  494.     }
  495. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement