float mul_nonIEEE(float a, float b){ if( a == 0.0 || b == 0.0 ) return 0.0; return a*b; }
/**
* Levels version 1.2
* by Christian Cann Schuldt Jensen ~ CeeJay.dk
*
* Allows you to set a new black and a white level.
* This increases contrast, but clips any colors outside the new range to either black or white
* and so some details in the shadows or highlights can be lost.
*
* The shader is very useful for expanding the 16-235 TV range to 0-255 PC range.
* You might need it if you're playing a game meant to display on a TV with an emulator that does not do this.
* But it's also a quick and easy way to uniformly increase the contrast of an image.
*
* -- Version 1.0 --
* First release
* -- Version 1.1 --
* Optimized to only use 1 instruction (down from 2 - a 100% performance increase :) )
* -- Version 1.2 --
* Added the ability to highlight clipping regions of the image with #define HighlightClipping 1
*/
vec3 LevelsPass(vec3 inputColor) {
float black_point_float = BlackPoint / 255.0;
float white_point_float = WhitePoint == BlackPoint ? (255.0 / 0.00025) : (255.0 / (WhitePoint - BlackPoint)); // Avoid division by zero if the white and black point are the same
vec3 color = inputColor;
color = color * white_point_float - (black_point_float * white_point_float);
return color;
}
/**
* Curves
* by Christian Cann Schuldt Jensen ~ CeeJay.dk
*
* Curves, uses S-curves to increase contrast, without clipping highlights and shadows.
*/
vec3 CurvesPass(vec3 inputColor) {
vec3 colorInput = inputColor;
float Contrast_blend = Contrast * 2.0; //I multiply by two to give it a strength closer to the other curves.
vec3 x = colorInput.rgb; //if the curve should be applied to both Luma and Chroma
x = x * (x * (1.5 - x) + 0.5); //horner form - fastest version
vec3 color = x; //if the curve should be applied to both Luma and Chroma
colorInput.rgb = mix(colorInput.rgb, color, Contrast_blend); //Blend by Contrast
return colorInput;
}
//LumaSharpening
#define px (1.0/1280.0*uf_fragCoordScale.x)
#define py (1.0/720.0*uf_fragCoordScale.y)
#define CoefLuma vec3(0.2126, 0.7152, 0.0722)
float lumaSharpening(sampler2D tex, vec2 pos){
vec4 colorInput = texture(tex, pos);
vec3 ori = colorInput.rgb;
// -- Combining the strength and luma multipliers --