~hitmuri/rouages/trunk

« back to all changes in this revision

Viewing changes to data/materials/programs/RefletsCamCutVS.glsl

  • Committer: Florent Berthaut
  • Date: 2015-06-29 17:20:33 UTC
  • mfrom: (188.1.5 intersect)
  • Revision ID: flo@localhost.localdomain-20150629172033-wogpcewg4z0l3p8s
Merged intersect branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#version 120
 
2
uniform mat4 kinect_to_world_matrix;
 
3
uniform mat4 view_matrix;
 
4
uniform mat4 projection_matrix;
 
5
uniform sampler2D camTexture;
 
6
uniform float camXReso;
 
7
uniform float camYReso;
 
8
uniform float camXZFactor;
 
9
uniform float camYZFactor;
 
10
uniform float mirrored;
 
11
 
 
12
in vec3 vertex;
 
13
varying vec3 viewRay;
 
14
varying float kept;
 
15
varying float fragTest;
 
16
 
 
17
void main()     {
 
18
    //color
 
19
    gl_FrontColor = gl_FrontMaterial.diffuse;
 
20
    //texture
 
21
    gl_TexCoord[0] = gl_MultiTexCoord0;
 
22
 
 
23
    //get depth pixel in camera texture 
 
24
    float depth = float(texture2D(camTexture, vec2(vertex.x/camXReso, 
 
25
                                                   vertex.y/camYReso)).r) 
 
26
                  * 65535.0;
 
27
    kept=1.0;
 
28
 
 
29
    //keep only if non zero and if distance to neighbours is small enough
 
30
    if(depth<=500.0 || depth>5000.0) {
 
31
        kept=0.0;
 
32
    }
 
33
    else {
 
34
        float dist=0.0;
 
35
        float depth2 = float(texture2D(camTexture, 
 
36
                                        vec2((vertex.x+1.0)/camXReso, 
 
37
                                             vertex.y/camYReso)).r) 
 
38
                       * 65535.0;
 
39
        float depth3 = float(texture2D(camTexture, 
 
40
                                        vec2((vertex.x+1.0)/camXReso, 
 
41
                                             (vertex.y+1.0)/camYReso)).r) 
 
42
                       * 65535.0;
 
43
        float max=100.0;
 
44
        if(abs(depth-depth2)>max || abs(depth-depth3)>max) {
 
45
            kept=0.0;
 
46
        }
 
47
    }
 
48
 
 
49
    //compute position in world coords 
 
50
    vec4 depthPos = vec4((vertex.x/camXReso-0.5)
 
51
                            *depth*camXZFactor/1000.0,
 
52
                         (0.5-(vertex.y/camYReso))
 
53
                            *depth*camYZFactor/1000.0,
 
54
                         depth/1000.0,
 
55
                         1.0);
 
56
    //multiply by kinect to projector matrix and projection matrix
 
57
    vec4 posWS = kinect_to_world_matrix * depthPos;
 
58
    if(mirrored>0.0) {
 
59
        posWS.x = -posWS.x;
 
60
    }
 
61
    gl_Position = projection_matrix * view_matrix * posWS;
 
62
    //gl_Position = vec4(vertex.x/camXReso, vertex.y/camYReso, 0.0, 1.0);
 
63
    viewRay = posWS.xyz - vec3(-view_matrix[3][0],
 
64
                             -view_matrix[3][1],
 
65
                             -view_matrix[3][2]);
 
66
}
 
67