| 1 |
/* -*- Mode: C -*- */ |
|---|
| 2 |
uniform sampler2DRect textureID0; |
|---|
| 3 |
uniform sampler2DRect textureID1; |
|---|
| 4 |
uniform int min_disparity; |
|---|
| 5 |
uniform int max_disparity; |
|---|
| 6 |
uniform int window_size; |
|---|
| 7 |
|
|---|
| 8 |
float SADWindow(in int disparity, in int half_window_size, in vec2 texCoord) |
|---|
| 9 |
{ |
|---|
| 10 |
float sad = 0.0; |
|---|
| 11 |
|
|---|
| 12 |
float gain = 1.0; |
|---|
| 13 |
float offset = 0.0; |
|---|
| 14 |
|
|---|
| 15 |
for (int y=-half_window_size; y<=half_window_size; y++) { |
|---|
| 16 |
float ygo = (y*gain)+(sign(y)*offset); |
|---|
| 17 |
for (int x=-half_window_size; x<=half_window_size; x++) { |
|---|
| 18 |
float xgo = (x*gain)+(sign(x)*offset); |
|---|
| 19 |
vec2 l_coord = texCoord + vec2(xgo, ygo); |
|---|
| 20 |
vec2 r_coord = texCoord + vec2(xgo-disparity, ygo); |
|---|
| 21 |
vec4 l_val = texture2DRect(textureID0, l_coord); |
|---|
| 22 |
vec4 r_val = texture2DRect(textureID1, r_coord); |
|---|
| 23 |
sad = sad + abs(l_val - r_val); |
|---|
| 24 |
} |
|---|
| 25 |
} |
|---|
| 26 |
return sad; |
|---|
| 27 |
} |
|---|
| 28 |
|
|---|
| 29 |
void main(void) |
|---|
| 30 |
{ |
|---|
| 31 |
float sad=100; |
|---|
| 32 |
|
|---|
| 33 |
float disp = min_disparity; |
|---|
| 34 |
|
|---|
| 35 |
int halfsz = window_size/2; |
|---|
| 36 |
|
|---|
| 37 |
for (int i=min_disparity; i < max_disparity; i++) { |
|---|
| 38 |
float temp_sad = SADWindow(i, halfsz, gl_TexCoord[0].xy); |
|---|
| 39 |
if (temp_sad < sad) { |
|---|
| 40 |
sad = temp_sad; |
|---|
| 41 |
disp = i; |
|---|
| 42 |
} |
|---|
| 43 |
} |
|---|
| 44 |
|
|---|
| 45 |
if (sad > 2.3+100) { |
|---|
| 46 |
gl_FragColor = vec4(1,0,0,1); |
|---|
| 47 |
} else { |
|---|
| 48 |
gl_FragColor = (disp-min_disparity)/(float)(max_disparity-min_disparity); |
|---|
| 49 |
} |
|---|
| 50 |
} |
|---|