mirror of
https://github.com/italicsjenga/slang-shaders.git
synced 2024-11-23 00:01:31 +11:00
46 lines
1.3 KiB
C
46 lines
1.3 KiB
C
|
#ifndef MONCURVE
|
||
|
#define MONCURVE
|
||
|
|
||
|
float moncurve_f( float color, float gamma, float offs)
|
||
|
{
|
||
|
// Forward monitor curve
|
||
|
color = clamp(color, 0.0, 1.0);
|
||
|
float fs = (( gamma - 1.0) / offs) * pow( offs * gamma / ( ( gamma - 1.0) * ( 1.0 + offs)), gamma);
|
||
|
float xb = offs / ( gamma - 1.0);
|
||
|
|
||
|
color = ( color > xb) ? pow( ( color + offs) / ( 1.0 + offs), gamma) : color * fs;
|
||
|
return color;
|
||
|
}
|
||
|
|
||
|
|
||
|
vec3 moncurve_f_f3( vec3 color, float gamma, float offs)
|
||
|
{
|
||
|
color.r = moncurve_f( color.r, gamma, offs);
|
||
|
color.g = moncurve_f( color.g, gamma, offs);
|
||
|
color.b = moncurve_f( color.b, gamma, offs);
|
||
|
return color.rgb;
|
||
|
}
|
||
|
|
||
|
|
||
|
float moncurve_r( float color, float gamma, float offs)
|
||
|
{
|
||
|
// Reverse monitor curve
|
||
|
color = clamp(color, 0.0, 1.0);
|
||
|
float yb = pow( offs * gamma / ( ( gamma - 1.0) * ( 1.0 + offs)), gamma);
|
||
|
float rs = pow( ( gamma - 1.0) / offs, gamma - 1.0) * pow( ( 1.0 + offs) / gamma, gamma);
|
||
|
|
||
|
color = ( color > yb) ? ( 1.0 + offs) * pow( color, 1.0 / gamma) - offs : color * rs;
|
||
|
return color;
|
||
|
}
|
||
|
|
||
|
|
||
|
vec3 moncurve_r_f3( vec3 color, float gamma, float offs)
|
||
|
{
|
||
|
color.r = moncurve_r( color.r, gamma, offs);
|
||
|
color.g = moncurve_r( color.g, gamma, offs);
|
||
|
color.b = moncurve_r( color.b, gamma, offs);
|
||
|
return color.rgb;
|
||
|
}
|
||
|
|
||
|
#endif
|