File: ICMSimpleGammaCorrectionShader.frag.txt

package info (click to toggle)
psychtoolbox-3 3.0.19.14.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 86,796 kB
  • sloc: ansic: 176,245; cpp: 20,103; objc: 5,393; sh: 2,753; python: 1,397; php: 384; makefile: 193; java: 113
file content (68 lines) | stat: -rw-r--r-- 2,720 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* Shader for gamma correction of RGB and Luminance textures.
 * Uses extended formula for gamma correction:
 * out = bias + gain * ( ( (in - Lmin) / (Lmax - Lmin) ) ^ Gamma ).
 * 'Gamma' is the factor to apply, ie. the inverse gamma 1/G,
 * if applying correction for a display with gamma G.
 * 'in' is the input value (e.g., luminance), Lmin and Lmax are the expected
 * minimum and maximum values for 'in', 'gain' is a gain to post-multiply,
 * 'bias' is an offset to add to the final result.
 *
 * This shader is used by PsychColorCorrection() in 'SimpleGammaXXX' mode,
 * as part of PTB's built-in stimulus gamma correction.
 *
 * (w)2008, 2009 by Mario Kleiner. Licensed under MIT license.
*/

/* (RedGamma, GreenGamma, BlueGamma) vector of encoding gammas: */
/* To be initialized by PsychColorCorrection() typically: */
uniform vec3    ICMEncodingGamma;
uniform vec3    ICMMinInLuminance;
uniform vec3    ICMMaxInLuminance;
uniform vec3    ICMReciprocalLuminanceRange;
uniform vec3    ICMOutputGain;
uniform vec3    ICMOutputBias;

/* Allowable range for output values: To be initialized by PsychColorCorrection() typically: */
uniform vec2    ICMClampToColorRange;

vec4 icmTransformColor(vec4 incolor)
{
    vec4 outcolor;

    /* Return alpha component unmodified: */
    outcolor.a = incolor.a;

    /* Clamp input to valid [ICMMinInLuminance ; ICMMaxInLuminance] range: */
    incolor.rgb = clamp(incolor.rgb, ICMMinInLuminance, ICMMaxInLuminance);

    /* Convert clamped input to normalized 0-1 interval: */
    incolor.rgb = (incolor.rgb - ICMMinInLuminance) * ICMReciprocalLuminanceRange;

    /* Map RGB components through power function with Gamma coeff.: */
    outcolor.rgb = (pow(incolor.rgb, ICMEncodingGamma) * ICMOutputGain) + ICMOutputBias;

    /* Clamp outcolor to range given by ICMClampToColorRange: */
    outcolor.rgb = clamp(outcolor.rgb, vec3(ICMClampToColorRange[0]), vec3(ICMClampToColorRange[1]));

    return(outcolor);
}


float icmTransformColor1(float incolor)
{
    float outcolor;

    /* Clamp input to valid [ICMMinInLuminance ; ICMMaxInLuminance] range: */
    incolor = clamp(incolor, ICMMinInLuminance.r, ICMMaxInLuminance.r);

    /* Convert clamped input to normalized 0-1 interval: */
    incolor = (incolor - ICMMinInLuminance.r) * ICMReciprocalLuminanceRange.r;

    /* Map luminance component through power function with Gamma coeff.: */
    outcolor = (pow(incolor, ICMEncodingGamma.r) * ICMOutputGain.r) + ICMOutputBias.r;

    /* Clamp outcolor to range given by ICMClampToColorRange: */
    outcolor = clamp(outcolor, ICMClampToColorRange[0], ICMClampToColorRange[1]);

    return(outcolor);
}