| 1512 | |
| 1513 | |
| 1514 | void ShaderBagGLSL::LoadDescriptorShaderF2() |
| 1515 | { |
| 1516 | //one shader outpout 128/8 = 16 , each fragout encodes 4 |
| 1517 | //const double twopi = 2.0*3.14159265358979323846; |
| 1518 | //const double rpi = 8.0/twopi; |
| 1519 | ostringstream out; |
| 1520 | out<<setprecision(8); |
| 1521 | |
| 1522 | out<<"\n" |
| 1523 | "#define M_PI 3.14159265358979323846\n" |
| 1524 | "#define TWO_PI (2.0*M_PI)\n" |
| 1525 | "#define RPI 1.2732395447351626861510701069801\n" |
| 1526 | "#define WF size.z\n" |
| 1527 | "uniform sampler2DRect tex; \n" |
| 1528 | "uniform sampler2DRect gradTex; \n" |
| 1529 | "uniform vec4 dsize; \n" |
| 1530 | "uniform vec3 size; \n" |
| 1531 | "void main() \n" |
| 1532 | "{\n" |
| 1533 | " vec2 dim = size.xy; //image size \n" |
| 1534 | " float index = dsize.x*floor(gl_TexCoord[0].y * 0.5) + gl_TexCoord[0].x;\n" |
| 1535 | " float idx = 8.0 * fract(index * 0.125) + 8.0 * floor(2.0 * fract(gl_TexCoord[0].y * 0.5)); \n" |
| 1536 | " index = floor(index*0.125) + 0.49; \n" |
| 1537 | " vec2 coord = floor( vec2( mod(index, dsize.z), index*dsize.w)) + 0.5 ;\n" |
| 1538 | " vec2 pos = texture2DRect(tex, coord).xy; \n" |
| 1539 | " if(any(lessThanEqual(pos.xy, vec2(1.0))) || any(greaterThanEqual(pos.xy, dim-1.0)))// discard; \n" |
| 1540 | " { gl_FragData[0] = gl_FragData[1] = vec4(0.0); return; }\n" |
| 1541 | " float anglef = texture2DRect(tex, coord).z;\n" |
| 1542 | " if(anglef > M_PI) anglef -= TWO_PI;\n" |
| 1543 | " float sigma = texture2DRect(tex, coord).w; \n" |
| 1544 | " float spt = abs(sigma * WF); //default to be 3*sigma \n"; |
| 1545 | |
| 1546 | //rotation |
| 1547 | out<< |
| 1548 | " vec4 cscs, rots; \n" |
| 1549 | " cscs.y = sin(anglef); cscs.x = cos(anglef); \n" |
| 1550 | " cscs.zw = - cscs.xy; \n" |
| 1551 | " rots = cscs /spt; \n" |
| 1552 | " cscs *= spt; \n"; |
| 1553 | |
| 1554 | //here cscs is actually (cos, sin, -cos, -sin) * (factor: 3)*sigma |
| 1555 | //and rots is (cos, sin, -cos, -sin ) /(factor*sigma) |
| 1556 | //devide the 4x4 sift grid into 16 1x1 block, and each corresponds to a shader thread |
| 1557 | //To use linear interoplation, 1x1 is increased to 2x2, by adding 0.5 to each side |
| 1558 | |
| 1559 | out<< |
| 1560 | "vec4 temp; vec2 pt, offsetpt; \n" |
| 1561 | " /*the fraction part of idx is .5*/ \n" |
| 1562 | " offsetpt.x = 4.0* fract(idx*0.25) - 2.0; \n" |
| 1563 | " offsetpt.y = floor(idx*0.25) - 1.5; \n" |
| 1564 | " temp = cscs.xwyx*offsetpt.xyxy; \n" |
| 1565 | " pt = pos + temp.xz + temp.yw; \n"; |
| 1566 | |
| 1567 | //get a horizontal bounding box of the rotated rectangle |
| 1568 | out<< |
| 1569 | " vec2 bwin = abs(cscs.xy); \n" |
| 1570 | " float bsz = bwin.x + bwin.y; \n" |
| 1571 | " vec4 sz; \n" |