root/OpenSceneGraph-Data/trunk/shaders/stereomatch_aggregate.frag

Revision 8081 (checked in by robert, 9 months ago)

From Jose Delport, shaders for osgsterematch example

Line 
1 /* -*- Mode: C -*- */
2 uniform sampler2DRect textureDiff0;
3 uniform sampler2DRect textureDiff1;
4 uniform sampler2DRect textureDiff2;
5 uniform sampler2DRect textureDiff3;
6 uniform sampler2DRect textureAggIn;
7 uniform int start_disparity;
8 uniform int window_size;
9
10 void main(void)
11 {
12     int half_window_size = window_size/2;
13
14     vec2 texCoord = gl_TexCoord[0].xy;
15     sampler2DRect tdiff[4];
16     tdiff[0] = textureDiff0;
17     tdiff[1] = textureDiff1;
18     tdiff[2] = textureDiff2;
19     tdiff[3] = textureDiff3;
20      
21     float smallest_sum = 100;
22     float sum;
23     float disparity = 0;
24    
25     for (int t=0; t<4; t++) { // four textures
26         for (int c=0; c<4; c++) { // four channels
27             sum = 0.0;
28             for (int y=-half_window_size; y<=half_window_size; y++) {
29                 for (int x=-half_window_size; x<=half_window_size; x++) {
30                     vec2 coord = texCoord + vec2(x,y);
31                     vec4 val = texture2DRect(tdiff[t], coord)[c];
32                     sum+=val;
33                 }
34             }
35             if (sum < smallest_sum) {
36                 smallest_sum = sum;
37                 disparity = start_disparity + ((t*4)+c);
38             }
39         }
40     }
41
42     float old_best_sum = texture2DRect(textureAggIn, texCoord)[0];
43     float old_disparity = texture2DRect(textureAggIn, texCoord)[1];
44     if (smallest_sum < old_best_sum) {
45         gl_FragData[0][0] = smallest_sum;
46         gl_FragData[0][1] = disparity;
47     } else {
48         gl_FragData[0][0] = old_best_sum;
49         gl_FragData[0][1] = old_disparity;
50     }
51 }
Note: See TracBrowser for help on using the browser.