]> git.tdb.fi Git - libs/gl.git/blob - shaderlib/occluder.glsl
Check the flat qualifier from the correct member
[libs/gl.git] / shaderlib / occluder.glsl
1 import msp_interface;
2
3 layout(set=1) uniform AlphaCutoff
4 {
5         float alpha_cutoff;
6 };
7
8 layout(set=1) uniform sampler2D alpha_map;
9
10 layout(constant_id=auto) const bool use_alpha_cutoff = false;
11 layout(constant_id=auto) const bool use_instancing = false;
12
13 #pragma MSP stage(vertex)
14 virtual vec4 get_vertex_position()
15 {
16         return vertex;
17 }
18
19 virtual mat4 get_vertex_transform()
20 {
21         if(use_instancing)
22                 return transpose(mat4(instance_transform[0], instance_transform[1], instance_transform[2], vec4(0.0, 0.0, 0.0, 1.0)));
23         else
24                 return world_obj_matrix;
25 }
26
27 virtual void clipping(vec3 eye_vertex)
28 {
29 }
30
31 void main()
32 {
33         vec4 eye_vertex = eye_world_matrix*get_vertex_transform()*get_vertex_position();
34         clipping(eye_vertex.xyz);
35         gl_Position = clip_eye_matrix*eye_vertex;
36         passthrough;
37 }
38
39 #pragma MSP stage(fragment)
40 layout(location=0) out vec4 frag_color;
41
42 void main()
43 {
44         if(use_alpha_cutoff)
45         {
46                 float alpha = texture(alpha_map, texcoord.xy).a;
47                 if(alpha<alpha_cutoff)
48                         discard;
49                 frag_color = vec4(1.0);
50         }
51 }