| 2338 | } |
| 2339 | |
| 2340 | ProgramGLSL* ShaderBagPKSL::LoadDescriptorProgramRECT() |
| 2341 | { |
| 2342 | //one shader outpout 128/8 = 16 , each fragout encodes 4 |
| 2343 | //const double twopi = 2.0*3.14159265358979323846; |
| 2344 | //const double rpi = 8.0/twopi; |
| 2345 | ostringstream out; |
| 2346 | out<<setprecision(8); |
| 2347 | if(GlobalUtil::_KeepShaderLoop) |
| 2348 | { |
| 2349 | out << "#define REPEAT4(FUNCTION)\\\n" |
| 2350 | "for(int i = 0; i < 4; ++i)\\\n" |
| 2351 | "{\\\n" |
| 2352 | " FUNCTION(i);\\\n" |
| 2353 | "}\n"; |
| 2354 | }else |
| 2355 | { |
| 2356 | //loop unroll for ATI |
| 2357 | out << "#define REPEAT4(FUNCTION)\\\n" |
| 2358 | "FUNCTION(0);\\\n" |
| 2359 | "FUNCTION(1);\\\n" |
| 2360 | "FUNCTION(2);\\\n" |
| 2361 | "FUNCTION(3);\n"; |
| 2362 | } |
| 2363 | |
| 2364 | out<<"\n" |
| 2365 | "#define M_PI 3.14159265358979323846\n" |
| 2366 | "#define TWO_PI (2.0*M_PI)\n" |
| 2367 | "#define RPI 1.2732395447351626861510701069801\n" |
| 2368 | "#define WF size.z\n" |
| 2369 | "uniform sampler2DRect tex; \n" |
| 2370 | "uniform sampler2DRect gtex; \n" |
| 2371 | "uniform sampler2DRect otex; \n" |
| 2372 | "uniform vec4 dsize; \n" |
| 2373 | "uniform vec3 size; \n" |
| 2374 | "void main() \n" |
| 2375 | "{\n" |
| 2376 | " vec2 dim = size.xy; //image size \n" |
| 2377 | " float index = dsize.x*floor(gl_TexCoord[0].y * 0.5) + gl_TexCoord[0].x;\n" |
| 2378 | " float idx = 8.0* fract(index * 0.125) + 8.0 * floor(2.0* fract(gl_TexCoord[0].y * 0.5)); \n" |
| 2379 | " index = floor(index*0.125)+ 0.49; \n" |
| 2380 | " vec2 coord = floor( vec2( mod(index, dsize.z), index*dsize.w)) + 0.5 ;\n" |
| 2381 | " vec2 pos = texture2DRect(tex, coord).xy; \n" |
| 2382 | " vec2 wsz = texture2DRect(tex, coord).zw;\n" |
| 2383 | " float aspect_ratio = wsz.y / wsz.x;\n" |
| 2384 | " float aspect_sq = aspect_ratio * aspect_ratio; \n" |
| 2385 | " vec2 spt = wsz * 0.25; vec2 ispt = 1.0 / spt; \n"; |
| 2386 | |
| 2387 | //here cscs is actually (cos, sin, -cos, -sin) * (factor: 3)*sigma |
| 2388 | //and rots is (cos, sin, -cos, -sin ) /(factor*sigma) |
| 2389 | //devide the 4x4 sift grid into 16 1x1 block, and each corresponds to a shader thread |
| 2390 | //To use linear interoplation, 1x1 is increased to 2x2, by adding 0.5 to each side |
| 2391 | out<< |
| 2392 | " vec4 temp; vec2 pt; \n" |
| 2393 | " pt.x = pos.x + fract(idx*0.25) * wsz.x; \n" |
| 2394 | " pt.y = pos.y + (floor(idx*0.25) + 0.5) * spt.y; \n"; |
| 2395 | |
| 2396 | //get a horizontal bounding box of the rotated rectangle |
| 2397 | out<< |