/usr/share/psychtoolbox-3/PsychOpenGL/PsychGLSLShaders/MinMaxMeanReduceShader.frag.txt is in psychtoolbox-3-common 3.0.11.20131230.dfsg1-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | /* Reduction shader to compute a 2D rectangle textures global
// maximum, minimum and mean value.
//
// For each output fragment (x,y), the shader computes the local
// average, minimum and maximum of the red (or luminance) channel
// of the input texture in the 2x2 neighbourhood around (2*x,2*y),
// effectively reducing the problem size to a quarter sized texture.
//
// One needs to iteratively run this shader on its own output for
// log2(imagesize) runs to get a final single pixel with the global
// result. This is known as reduction operation.
//
// (w)2006 by Mario Kleiner. Licensed under MIT license.
*/
#extension GL_ARB_texture_rectangle : enable
float neighboursize = 2.0;
uniform sampler2DRect Image;
void main()
{
float dx, dy;
float sum = 0.0;
float maximum = 0.0;
float minimum = 1000.0;
vec4 tmp;
vec2 basepos;
/* Compute base lookup position in texture: It is the
* position of the current fragment multiplied by 2: */
basepos = vec2(floor(gl_FragCoord)) * neighboursize;
/* Iterate over a 'neighboursize' by 'neighboursize' neighbourship: */
for (dx = 0.0; dx < neighboursize; dx++) {
for (dy = 0.0; dy < neighboursize; dy++) {
/* Lookup texel color value at current sampling position: */
tmp = texture2DRect(Image, basepos + vec2(dx, dy));
/* Update local average: */
sum += tmp.r;
/* Update local minimum: */
minimum = min(tmp.b, minimum);
/* Update local maximum: */
maximum = max(tmp.g, maximum);
}
}
gl_FragColor.r = sum / neighboursize / neighboursize;
gl_FragColor.g = maximum;
gl_FragColor.b = minimum;
gl_FragColor.a = 0.0;
}
|