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);
}
|