File: picker.glsl

package info (click to toggle)
python-moderngl-window 2.4.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 69,260 kB
  • sloc: python: 11,225; makefile: 20
file content (33 lines) | stat: -rw-r--r-- 959 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#version 330
//
// Picks a point from the depth buffer and returns the world position
//

#if defined VERTEX_SHADER

uniform sampler2D position_texture;
uniform sampler2D normal_texture;
uniform sampler2D diffuse_texture;

uniform mat4 modelview;
uniform ivec2 texel_pos;

out vec3 out_position;
out vec3 out_normal;
out float out_temperature;

void main() {
    vec3 viewpos = texelFetch(position_texture, texel_pos, 0).rgb;
    if (viewpos.z == 0.0) {
        // A 0.0 z value means we missed the mesh. Just write out 0.0 as the result
        out_position = vec3(0.0);
        out_normal = vec3(0.0);
        out_temperature = 0.0;
    } else {
        // Reverse translations and rotations aligning the point with the original mesh
        out_position = (inverse(modelview) * vec4(viewpos, 1.0)).xyz;
        out_normal = texelFetch(normal_texture, texel_pos, 0).xyz;
        out_temperature = texelFetch(diffuse_texture, texel_pos, 0).r;
    }
}
#endif