Skip to content

Instantly share code, notes, and snippets.

@crishoj
Created May 31, 2012 07:18
Show Gist options
  • Save crishoj/2841624 to your computer and use it in GitHub Desktop.
Save crishoj/2841624 to your computer and use it in GitHub Desktop.
SiftGPU Mac OS X build patch adapted from http://www.cs.unc.edu/~ccwu/siftgpu/ProgramGLSL.cpp.patch
Index: ProgramGLSL.cpp
===================================================================
--- src/SiftGPU/ProgramGLSL.cpp (revision 400)
+++ src/SiftGPU/ProgramGLSL.cpp (working copy)
@@ -458,7 +458,7 @@
{
out<<"coord = gl_TexCoord[0].xy + vec2(float("<<i-nhpixel<<"),0);\n";
out<<"pc=texture2DRect(tex, coord);\n";
- if(GlobalUtil::_PreciseBorder) out<<"if(coord.x < 0) pc = pc.rrbb;\n";
+ if(GlobalUtil::_PreciseBorder) out<<"if(coord.x < 0.0) pc = pc.rrbb;\n";
//for each sub-pixel j in center, the weight of sub-pixel k
xw = (i - nhpixel)*2;
for( j = 0; j < 3; j++)
@@ -508,7 +508,7 @@
{
out<<"coord = gl_TexCoord[0].xy + vec2(0, float("<<i-nhpixel<<"));\n";
out<<"pc=texture2DRect(tex, coord);\n";
- if(GlobalUtil::_PreciseBorder) out<<"if(coord.y < 0) pc = pc.rgrg;\n";
+ if(GlobalUtil::_PreciseBorder) out<<"if(coord.y < 0.0) pc = pc.rgrg;\n";
//for each sub-pixel j in center, the weight of sub-pixel k
yw = (i - nhpixel)*2;
@@ -832,8 +832,8 @@
<<
" float dog = 0.0; \n"
" gl_FragData[1] = vec4(0, 0, 0, 0); \n"
- " dog = cc.g > THRESHOLD0 && all(greaterThan(cc.gggg, max(v1, v2)))?1.0: 0.0;\n"
- " dog = cc.g < -THRESHOLD0 && all(lessThan(cc.gggg, min(v1, v2)))?0.5: dog;\n"
+ " dog = cc.g > float(THRESHOLD0) && all(greaterThan(cc.gggg, max(v1, v2)))?1.0: 0.0;\n"
+ " dog = cc.g < float(-THRESHOLD0) && all(lessThan(cc.gggg, min(v1, v2)))?0.5: dog;\n"
" if(dog == 0.0) return;\n";
pos = out.tellp();
@@ -851,7 +851,7 @@
" float fxx_plus_fyy = fxx + fyy;\n"
" float score_up = fxx_plus_fyy*fxx_plus_fyy; \n"
" float score_down = (fxx*fyy - fxy*fxy);\n"
- " if( score_down <= 0 || score_up > THRESHOLD2 * score_down)return;\n";
+ " if( score_down <= 0.0 || score_up > THRESHOLD2 * score_down)return;\n";
//...
out<<" \n"
@@ -970,7 +970,7 @@
//one more threshold which I forgot in versions prior to 286
<<
- " bool dog_test = (abs(cc.g + 0.5*dot(vec3(fx, fy, fs), dxys ))<= THRESHOLD1) ;\n"
+ " bool dog_test = (abs(cc.g + 0.5*dot(vec3(fx, fy, fs), dxys ))<= float(THRESHOLD1)) ;\n"
" if(dog_test || any(greaterThan(abs(dxys), vec3(1.0)))) dog = 0;\n"
" }\n"
" }\n"
@@ -1178,7 +1178,7 @@
" bins[6] = vec4(0.0);bins[7] = vec4(0.0);bins[8] = vec4(0.0); \n"
" vec4 loc = texture2DRect(tex, gl_TexCoord[0].xy); \n"
" vec2 pos = loc.xy; \n"
- " bool orientation_mode = (size.z != 0); \n"
+ " bool orientation_mode = (size.z != 0.0); \n"
" float sigma = orientation_mode? abs(size.z) : loc.w; \n";
if(GlobalUtil::_SubpixelLocalization || GlobalUtil::_KeepExtremumSign)
{
@@ -1194,7 +1194,7 @@
}
out<<
" //bool fixed_orientation = (size.z < 0); \n"
- " if(size.z < 0) {gl_FragData[0] = vec4(pos, 0, sigma); return;}"
+ " if(size.z < 0.0) {gl_FragData[0] = vec4(pos, 0, sigma); return;}"
" float gsigma = sigma * GAUSSIAN_WF; \n"
" vec2 win = abs(vec2(sigma)) * (SAMPLE_WF * GAUSSIAN_WF); \n"
" vec2 dim = size.xy; \n"
@@ -1440,7 +1440,7 @@
out<<"\n"
" vec4 hh = maxh * ORIENTATION_THRESHOLD; bvec4 test; \n"
" bins[9] = bins[0]; \n"
- " float npeaks = 0.0, k = 0; \n"
+ " float npeaks = 0.0, k = 0.0; \n"
" float prevb = bins[8].w; \n"
" for (int i = 0; i <9 ; i++) \n"
" {\n"
@@ -1682,7 +1682,7 @@
"uniform sampler2DRect tex; uniform vec4 truncate; void main(){\n"
"vec4 cc = texture2DRect(tex, min(gl_TexCoord[0].xy, truncate.xy)); \n"
"bvec2 ob = lessThan(gl_TexCoord[0].xy, truncate.xy);\n"
- "if(ob.y) { gl_FragColor = (truncate.z ==0 ? cc.rrbb : cc.ggaa); } \n"
+ "if(ob.y) { gl_FragColor = (truncate.z ==0.0 ? cc.rrbb : cc.ggaa); } \n"
"else if(ob.x) {gl_FragColor = (truncate.w <1.5 ? cc.rgrg : cc.baba);} \n"
"else { vec4 weights = vec4(vec4(0, 1, 2, 3) == truncate.wwww);\n"
"float v = dot(weights, cc); gl_FragColor = vec4(v);}}");
@@ -1836,19 +1836,19 @@
" bins[6] = vec4(0.0);bins[7] = vec4(0.0);bins[8] = vec4(0.0); \n"
" vec4 sift = texture2DRect(tex, gl_TexCoord[0].xy); \n"
" vec2 pos = sift.xy; \n"
- " bool orientation_mode = (size.z != 0); \n"
+ " bool orientation_mode = (size.z != 0.0); \n"
" float sigma = orientation_mode? (abs(size.z) * pow(size.w, sift.w) * sift.z) : (sift.w); \n"
" //bool fixed_orientation = (size.z < 0); \n"
- " if(size.z < 0) {gl_FragData[0] = vec4(pos, 0, sigma); return;}"
- " float gsigma = sigma * GAUSSIAN_WF; \n"
- " vec2 win = abs(vec2(sigma)) * (SAMPLE_WF * GAUSSIAN_WF); \n"
+ " if(size.z < 0.0) {gl_FragData[0] = vec4(pos, 0, sigma); return;}"
+ " float gsigma = sigma * float(GAUSSIAN_WF); \n"
+ " vec2 win = abs(vec2(sigma)) * (float(SAMPLE_WF) * float(GAUSSIAN_WF)); \n"
" vec2 dim = size.xy; \n"
" vec4 dist_threshold = vec4(win.x*win.x+0.5); \n"
" float factor = -0.5/(gsigma*gsigma); \n"
" vec4 sz; vec2 spos; \n"
- " //if(any(pos.xy <= 1)) discard; \n"
+ " //if(any(pos.xy <= float(1))) discard; \n"
" sz.xy = max( pos - win, vec2(2,2)); \n"
- " sz.zw = min( pos + win, dim-3); \n"
+ " sz.zw = min( pos + win, dim-float(3)); \n"
" sz = floor(sz*0.5) + 0.5; ";
//loop to get the histogram
@@ -1857,8 +1857,8 @@
" { \n"
" for(spos.x = sz.x; spos.x <= sz.z; spos.x+=1.0) \n"
" { \n"
- " vec2 offset = 2* spos - pos - 0.5; \n"
- " vec4 off = vec4(offset, offset + 1); \n"
+ " vec2 offset = 2.0 * spos - pos - vec2(0.5); \n"
+ " vec4 off = vec4(offset, offset + vec2(1)); \n"
" vec4 distsq = off.xzxz * off.xzxz + off.yyww * off.yyww; \n"
" bvec4 inside = lessThan(distsq, dist_threshold); \n"
" if(any(inside)) \n"
@@ -1900,26 +1900,26 @@
" {\n"
" float idx = idxv[i]; \n"
" vec4 inc = weight[i] * vec4(equal(vec4(vidx[i]), vec4(0,1,2,3))); \n"
- " if(idx < 16) \n"
+ " if(idx < 16.0) \n"
" { \n"
- " if(idx < 8) \n"
+ " if(idx < 8.0) \n"
" { \n"
- " if(idx < 4) { bins[0]+=inc;} \n"
+ " if(idx < 4.0) { bins[0]+=inc;} \n"
" else { bins[1]+=inc;} \n"
" }else \n"
" { \n"
- " if(idx < 12){ bins[2]+=inc;} \n"
+ " if(idx < 12.0){ bins[2]+=inc;} \n"
" else { bins[3]+=inc;} \n"
" } \n"
- " }else if(idx < 32) \n"
+ " }else if(idx < 32.0) \n"
" { \n"
- " if(idx < 24) \n"
+ " if(idx < 24.0) \n"
" { \n"
- " if(idx <20) { bins[4]+=inc;} \n"
+ " if(idx <20.0) { bins[4]+=inc;} \n"
" else { bins[5]+=inc;} \n"
" }else \n"
" { \n"
- " if(idx < 28){ bins[6]+=inc;} \n"
+ " if(idx < 28.0){ bins[6]+=inc;} \n"
" else { bins[7]+=inc;} \n"
" } \n"
" }else \n"
@@ -2135,8 +2135,8 @@
" #define KEYTEST_STEP0(i) \\\n"
" {\\\n"
" bvec4 test1 = greaterThan(vec4(cc[i]), max(v1[i], v2[i])), test2 = lessThan(vec4(cc[i]), min(v1[i], v2[i]));\\\n"
- " key[i] = cc[i] > THRESHOLD0(i) && all(test1)?1.0: 0.0;\\\n"
- " key[i] = cc[i] < -THRESHOLD0(i) && all(test2)? -1.0: key[i];\\\n"
+ " key[i] = cc[i] > float(THRESHOLD0(i)) && all(test1)?1.0: 0.0;\\\n"
+ " key[i] = cc[i] < float(-THRESHOLD0(i)) && all(test2)? -1.0: key[i];\\\n"
" }\n"
" REPEAT4(KEYTEST_STEP0);\n"
" if(gl_TexCoord[0].x < 1.0) {key.rb = vec2(0.0);}\n"
@@ -2151,7 +2151,7 @@
out<<
" float fxx[4], fyy[4], fxy[4], fx[4], fy[4];\n"
" #define EDGE_SUPPRESION(i) \\\n"
- " if(key[i] != 0)\\\n"
+ " if(key[i] != 0.0)\\\n"
" {\\\n"
" vec4 D2 = v1[i].xyzw - cc[i];\\\n"
" vec2 D4 = v2[i].xw - v2[i].yz;\\\n"
@@ -2163,7 +2163,7 @@
" float fxx_plus_fyy = fxx[i] + fyy[i];\\\n"
" float score_up = fxx_plus_fyy*fxx_plus_fyy; \\\n"
" float score_down = (fxx[i]*fyy[i] - fxy[i]*fxy[i]);\\\n"
- " if( score_down <= 0 || score_up > THRESHOLD2 * score_down)key[i] = 0;\\\n"
+ " if( score_down <= 0.0 || score_up > THRESHOLD2 * score_down)key[i] = 0.0;\\\n"
" }\n"
" REPEAT4(EDGE_SUPPRESION);\n"
" if(any(notEqual(key, vec4(0.0)))) {\n";
@@ -2244,7 +2244,7 @@
out <<
" vec3 offset = vec3(0, 0, 0); \n"
" #define TESTMOVE_KEYPOINT(idx) \\\n"
- " if(key[idx] != 0) \\\n"
+ " if(key[idx] != 0.0) \\\n"
" {\\\n"
" cu[0] = cu[idx]; cd[0] = cd[idx]; cc[0] = cc[idx]; \\\n"
" v4[0] = v4[idx]; v5[0] = v5[idx]; \\\n"
@@ -2293,7 +2293,7 @@
" offset.z = A2.w /A2.z; \n"
" offset.y = A1.w - offset.z*A1.z; \n"
" offset.x = A0.w - offset.z*A0.z - offset.y*A0.y; \n"
- " bool test = (abs(cc[0] + 0.5*dot(vec3(fx[0], fy[0], fs), offset ))>THRESHOLD1) ;\n"
+ " bool test = (abs(cc[0] + 0.5*dot(vec3(fx[0], fy[0], fs), offset ))>float(THRESHOLD1)) ;\n"
" if(!test || any( greaterThan(abs(offset), vec3(1.0)))) key = vec4(0.0);\n"
" }\n"
" }\n"
@@ -2408,7 +2408,7 @@
out<<
" vec4 sz; \n"
" sz.xy = max(pt - spt, vec2(2,2));\n"
- " sz.zw = min(pt + spt, dim - 3); \n"
+ " sz.zw = min(pt + spt, dim - vec2(3.0)); \n"
" sz = floor(sz * 0.5)+0.5;"; //move sample point to pixel center
//get voting for two box
@@ -2436,7 +2436,7 @@
" vec4 theta0 = (- oo)*RPI;\n"
" vec4 theta = 8.0 * fract(1.0 + 0.125 * theta0); \n"
" vec4 theta1 = floor(theta); \n"
- " vec4 weight = (1 - nxn) * (1 - nyn) * gg; \n"
+ " vec4 weight = (vec4(1) - nxn) * (vec4(1) - nyn) * gg; \n"
" vec4 weight2 = (theta - theta1) * weight; \n"
" vec4 weight1 = weight - weight2; \n"
" #define ADD_DESCRIPTOR(i) \\\n"
@@ -2545,7 +2545,7 @@
" float bsz = bwin.x + bwin.y; \n"
" vec4 sz; \n"
" sz.xy = max(pt - vec2(bsz), vec2(2,2));\n"
- " sz.zw = min(pt + vec2(bsz), dim - 3); \n"
+ " sz.zw = min(pt + vec2(bsz), dim - vec2(3)); \n"
" sz = floor(sz * 0.5)+0.5;"; //move sample point to pixel center
//get voting for two box
@@ -2574,7 +2574,7 @@
" vec4 theta1 = floor(theta); \n"
" vec4 diffx = nx + offsetpt.x, diffy = ny + offsetpt.y; \n"
" vec4 ww = exp(-0.125 * (diffx * diffx + diffy * diffy )); \n"
- " vec4 weight = (1 - nxn) * (1 - nyn) * gg * ww; \n"
+ " vec4 weight = (vec4(1) - nxn) * (vec4(1) - nyn) * gg * ww; \n"
" vec4 weight2 = (theta - theta1) * weight; \n"
" vec4 weight1 = weight - weight2; \n"
" #define ADD_DESCRIPTOR(i) \\\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment