"uniform sampler2D myTexture;"
"uniform int uWidth;"
"uniform int uHeight;"
""
"float pixH = 1.0/float(uWidth);"
"float pixV = 1.0/float(uHeight);"
""
"float graythresh(float aArea[49])"
" {"
" float hist[256];"
" int v;"
"#pragma optionNV(unroll none)"
" for(int i = 0; i < 49; i++)"
" for(v = int(aArea[i]*255.0); v < 256; v++)"
" hist[v]+= 0.020408;"//adding ~1/49 to all histogram bins greater than actual value
""
" return 0.5;"//just a test, to check if the shader passed
" }"
""
"void main (void)"
"{"
"vec4 comp = vec4(0.0, 0.0, 0.0, 0.0);"
"float area[49];"
"float sum;"
"float maxf;"
"float current;"
"for(int k = 0; k <3; k++)"
" {"
" sum = 0.0;"
" maxf = 0.0;"
" current = 0.0;"
" for(int i = 0; i < 7; i++)"
" {"
" for(int j = 0; j < 7; j++)"
" {"
" current = texture2D(myTexture, vec2(gl_TexCoord[0].x+float(i-3)*pixH, gl_TexCoord[0].y+float(j-3)*pixV))[k];"
" sum += current;"
" maxf = max(maxf, abs(current));"
" area[i*7+j] = current;"
" }"
" }"
" if(maxf > 0.0)"
" {"
" for(int i = 0; i < 49; i++)"
" area[i] /= maxf;"
" }"
" comp[k] = graythresh(area);"
" }"
"gl_FragColor = comp;"
"}"