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
|
/* Shader for color correction of RGB and Luminance textures by 3D CLUT lookup.
*
* Uses a RGB color lookup table, encoded in a 3D texture, to lookup
* corresponding remapped output red, green and blue intensity values
* for given input red, green or blue intensity values in the input texture.
*
* Input is basically a 3D color vector (red, green, blue) whose components
* define the 3D texture coordinate in the 3D LUT texture of the color corrected
* RGB texel. Trilinear interpolation is used to find interpolated colors.
*
* This shader is used by PsychColorCorrection() in 'LookupTable3D' mode,
* as part of PTB's built-in stimulus color correction.
*
* (w) 2012 by Mario Kleiner. Licensed under MIT license.
*/
#extension GL_EXT_texture3D : enable
uniform sampler3D ICMCLUT;
uniform float ICMPrescale;
uniform float ICMMaxInputValue;
/* 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 0-ICMMaxInputValue range: */
incolor.rgb = clamp(incolor.rgb, vec3(0.0), vec3(ICMMaxInputValue));
/* Remap them to index in resolution range: */
incolor.rgb = incolor.rgb * ICMPrescale;
/* Look up in 3D texture at location incolor.rgb: */
outcolor.rgb = texture3D(ICMCLUT, incolor.rgb).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;
/* Clamp input to valid 0-ICMMaxInputValue range: */
incolor = clamp(incolor, 0.0, ICMMaxInputValue);
/* Remap to index in resolution range: */
incolor = incolor * ICMPrescale;
/* Look up in 3D texture at 3D location (incolor, incolor, incolor): */
outcolor = texture3D(ICMCLUT, vec3(incolor)).r;
/* Clamp outcolor to range given by ICMClampToColorRange: */
outcolor = clamp(outcolor, ICMClampToColorRange[0], ICMClampToColorRange[1]);
return(outcolor);
}
|