| 777 | } |
| 778 | |
| 779 | void ShaderBagGLSL::LoadKeypointShader(float threshold, float edge_threshold) |
| 780 | { |
| 781 | float threshold0 = threshold* (GlobalUtil::_SubpixelLocalization?0.8f:1.0f); |
| 782 | float threshold1 = threshold; |
| 783 | float threshold2 = (edge_threshold+1)*(edge_threshold+1)/edge_threshold; |
| 784 | ostringstream out;; |
| 785 | streampos pos; |
| 786 | |
| 787 | //tex(X)(Y) |
| 788 | //X: (CLR) (CENTER 0, LEFT -1, RIGHT +1) |
| 789 | //Y: (CDU) (CENTER 0, DOWN -1, UP +1) |
| 790 | if(GlobalUtil::_DarknessAdaption) |
| 791 | { |
| 792 | out << "#define THRESHOLD0 (" << threshold0 << " * min(2.0 * cc.r + 0.1, 1.0))\n" |
| 793 | "#define THRESHOLD1 (" << threshold1 << " * min(2.0 * cc.r + 0.1, 1.0))\n" |
| 794 | "#define THRESHOLD2 " << threshold2 << "\n"; |
| 795 | }else |
| 796 | { |
| 797 | out << "#define THRESHOLD0 " << threshold0 << "\n" |
| 798 | "#define THRESHOLD1 " << threshold1 << "\n" |
| 799 | "#define THRESHOLD2 " << threshold2 << "\n"; |
| 800 | } |
| 801 | |
| 802 | out<< |
| 803 | "uniform sampler2DRect tex, texU, texD; void main ()\n" |
| 804 | "{\n" |
| 805 | " vec4 v1, v2, gg, temp;\n" |
| 806 | " vec2 TexRU = vec2(gl_TexCoord[2].x, gl_TexCoord[4].y); \n" |
| 807 | " vec4 cc = texture2DRect(tex, gl_TexCoord[0].xy);\n" |
| 808 | " temp = texture2DRect(tex, gl_TexCoord[1].xy);\n" |
| 809 | " v1.x = temp.g; gg.x = temp.r;\n" |
| 810 | " temp = texture2DRect(tex, gl_TexCoord[2].xy) ;\n" |
| 811 | " v1.y = temp.g; gg.y = temp.r;\n" |
| 812 | " temp = texture2DRect(tex, gl_TexCoord[3].xy) ;\n" |
| 813 | " v1.z = temp.g; gg.z = temp.r;\n" |
| 814 | " temp = texture2DRect(tex, gl_TexCoord[4].xy) ;\n" |
| 815 | " v1.w = temp.g; gg.w = temp.r;\n" |
| 816 | " v2.x = texture2DRect(tex, gl_TexCoord[5].xy).g;\n" |
| 817 | " v2.y = texture2DRect(tex, gl_TexCoord[6].xy).g;\n" |
| 818 | " v2.z = texture2DRect(tex, gl_TexCoord[7].xy).g;\n" |
| 819 | " v2.w = texture2DRect(tex, TexRU.xy).g;\n" |
| 820 | " vec2 dxdy = (gg.yw - gg.xz); \n" |
| 821 | " float grad = 0.5*length(dxdy);\n" |
| 822 | " float theta = grad==0.0? 0.0: atan(dxdy.y, dxdy.x);\n" |
| 823 | " gl_FragData[0] = vec4(cc.rg, grad, theta);\n" |
| 824 | |
| 825 | //test against 8 neighbours |
| 826 | //use variable to identify type of extremum |
| 827 | //1.0 for local maximum and 0.5 for minimum |
| 828 | << |
| 829 | " float dog = 0.0; \n" |
| 830 | " gl_FragData[1] = vec4(0, 0, 0, 0); \n" |
| 831 | " dog = cc.g > float(THRESHOLD0) && all(greaterThan(cc.gggg, max(v1, v2)))?1.0: 0.0;\n" |
| 832 | " dog = cc.g < float(-THRESHOLD0) && all(lessThan(cc.gggg, min(v1, v2)))?0.5: dog;\n" |
| 833 | " if(dog == 0.0) return;\n"; |
| 834 | |
| 835 | pos = out.tellp(); |
| 836 | //do edge supression first.. |