Wayland compositor (wlroots)
git clone https://git.lucas.co/cce-compositor.git
scenefx/render/fx_renderer/shaders/tex.frag (2K)
1 #define SOURCE %d
2 #define EFFECTS %d
3
4 #define SOURCE_TEXTURE_RGBA 1
5 #define SOURCE_TEXTURE_RGBX 2
6 #define SOURCE_TEXTURE_EXTERNAL 3
7
8 #if !defined(SOURCE) || !defined(EFFECTS)
9 #error "Missing shader preamble"
10 #endif
11
12 #if SOURCE == SOURCE_TEXTURE_EXTERNAL
13 #extension GL_OES_EGL_image_external : require
14 #endif
15
16 #ifdef GL_FRAGMENT_PRECISION_HIGH
17 precision highp float;
18 #else
19 precision mediump float;
20 #endif
21
22 varying vec2 v_texcoord;
23
24 #if SOURCE == SOURCE_TEXTURE_EXTERNAL
25 uniform samplerExternalOES tex;
26 #elif SOURCE == SOURCE_TEXTURE_RGBA || SOURCE == SOURCE_TEXTURE_RGBX
27 uniform sampler2D tex;
28 #endif
29
30 uniform float alpha;
31
32 #if EFFECTS
33 uniform vec2 size;
34 uniform vec2 position;
35 uniform float radius_top_left;
36 uniform float radius_top_right;
37 uniform float radius_bottom_left;
38 uniform float radius_bottom_right;
39
40 uniform vec2 clip_size;
41 uniform vec2 clip_position;
42 uniform float clip_radius_top_left;
43 uniform float clip_radius_top_right;
44 uniform float clip_radius_bottom_left;
45 uniform float clip_radius_bottom_right;
46 #endif
47
48 uniform bool discard_transparent;
49
50 vec4 sample_texture() {
51 #if SOURCE == SOURCE_TEXTURE_RGBA || SOURCE == SOURCE_TEXTURE_EXTERNAL
52 return texture2D(tex, v_texcoord);
53 #elif SOURCE == SOURCE_TEXTURE_RGBX
54 return vec4(texture2D(tex, v_texcoord).rgb, 1.0);
55 #endif
56 }
57
58 #if EFFECTS
59 float corner_alpha(vec2 size, vec2 position, bool is_cutout,
60 float radius_tl, float radius_tr, float radius_bl, float radius_br);
61 #endif
62
63 void main() {
64 #if EFFECTS
65 float quad_corner_alpha = corner_alpha(
66 size - 0.5,
67 position + 0.25,
68 false,
69 radius_top_left,
70 radius_top_right,
71 radius_bottom_left,
72 radius_bottom_right
73 );
74
75 // Clipping
76 float clip_corner_alpha = corner_alpha(
77 clip_size - 1.0,
78 clip_position + 0.5,
79 true,
80 clip_radius_top_left,
81 clip_radius_top_right,
82 clip_radius_bottom_left,
83 clip_radius_bottom_right
84 );
85
86 gl_FragColor = sample_texture() * alpha * quad_corner_alpha * clip_corner_alpha;
87 #else
88 gl_FragColor = sample_texture() * alpha;
89 #endif
90
91 if (discard_transparent && gl_FragColor.a == 0.0) {
92 discard;
93 }
94 }