File: ICM2DGainCorrectionShader.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 (55 lines) | stat: -rw-r--r-- 1,813 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
/* Shader for per-pixel color gain correction of RGB textures by 2D matrix lookup.
 *
 * Multiplies per color channel (R,G,B) input values with corresponding
 * gain factors (Rg,Gg,Bg) in 2D gain matrix at position "pos".
 *
 * out(x,y).rgb = in(x,y).rgb * gain(x,y).rgb
 * The alpha channel is passed through unmodified.
 *
 * This is, e.g., useful for display devignetting (aka shading correction).
 *
 * This shader is used by PsychColorCorrection() in 'GainMatrix' mode,
 * as part of PTB's built-in stimulus color correction.
 *
 * (w)2010 by Mario Kleiner. Licensed under MIT license.
 */

#extension GL_ARB_texture_rectangle : enable

uniform sampler2DRect   ICMGainField;

/* 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;

    /* Lookup gain matrix RGB values for pixel location and multiply
     * input pixel with it.
     */
    outcolor.rgb  = incolor.rgb * texture2DRect(ICMGainField, gl_TexCoord[0].xy).rgb;

    /* 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;

    /* Lookup gain matrix gain value for pixel location and multiply
     * input pixel with it.
     */
    outcolor = incolor * texture2DRect(ICMGainField, gl_TexCoord[0].xy).r;

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

    return(outcolor);
}