Vibrance.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*-----------------------------------------------------------.
  2. / Vibrance /
  3. '-----------------------------------------------------------*/
  4. /*
  5. by Christian Cann Schuldt Jensen ~ CeeJay.dk
  6. Vibrance intelligently boosts the saturation of pixels
  7. so pixels that had little color get a larger boost than pixels that had a lot.
  8. This avoids oversaturation of pixels that were already very saturated.
  9. */
  10. float4 VibrancePass( float4 colorInput )
  11. {
  12. #ifndef Vibrance_RGB_balance //for backwards compatibility with setting presets for older version.
  13. #define Vibrance_RGB_balance float3(1.00, 1.00, 1.00)
  14. #endif
  15. #define Vibrance_coeff float3(Vibrance_RGB_balance * Vibrance)
  16. float4 color = colorInput; //original input color
  17. float3 lumCoeff = float3(0.212656, 0.715158, 0.072186); //Values to calculate luma with
  18. float luma = dot(lumCoeff, color.rgb); //calculate luma (grey)
  19. float max_color = max(colorInput.r, max(colorInput.g,colorInput.b)); //Find the strongest color
  20. float min_color = min(colorInput.r, min(colorInput.g,colorInput.b)); //Find the weakest color
  21. float color_saturation = max_color - min_color; //The difference between the two is the saturation
  22. //color.rgb = lerp(luma, color.rgb, (1.0 + (Vibrance * (1.0 - color_saturation)))); //extrapolate between luma and original by 1 + (1-saturation) - simple
  23. //color.rgb = lerp(luma, color.rgb, (1.0 + (Vibrance * (1.0 - (sign(Vibrance) * color_saturation))))); //extrapolate between luma and original by 1 + (1-saturation) - current
  24. color.rgb = lerp(luma, color.rgb, (1.0 + (Vibrance_coeff * (1.0 - (sign(Vibrance_coeff) * color_saturation))))); //extrapolate between luma and original by 1 + (1-saturation) - current
  25. //color.rgb = lerp(luma, color.rgb, 1.0 + (1.0-pow(color_saturation, 1.0 - (1.0-Vibrance))) ); //pow version
  26. return color; //return the result
  27. //return color_saturation.xxxx; //Visualize the saturation
  28. }