niri
Clone
https://git.tahinli.com/Tahinli/niri.git
0 watching0 forksRustGPL-3.012.1 MiB055a94dIvan Molodetskikh1 year ago2247 commits
| 1 | #version 100 |
| 2 | |
| 3 | //_DEFINES_ |
| 4 | |
| 5 | #if defined(EXTERNAL) |
| 6 | #extension GL_OES_EGL_image_external : require |
| 7 | #endif |
| 8 | |
| 9 | precision highp float; |
| 10 | #if defined(EXTERNAL) |
| 11 | uniform samplerExternalOES tex; |
| 12 | #else |
| 13 | uniform sampler2D tex; |
| 14 | #endif |
| 15 | |
| 16 | uniform float alpha; |
| 17 | varying vec2 v_coords; |
| 18 | |
| 19 | #if defined(DEBUG_FLAGS) |
| 20 | uniform float tint; |
| 21 | #endif |
| 22 | |
| 23 | uniform float niri_scale; |
| 24 | |
| 25 | uniform vec2 geo_size; |
| 26 | uniform vec4 corner_radius; |
| 27 | uniform mat3 input_to_geo; |
| 28 | |
| 29 | float rounding_alpha(vec2 coords, vec2 size) { |
| 30 | vec2 center; |
| 31 | float radius; |
| 32 | |
| 33 | if (coords.x < corner_radius.x && coords.y < corner_radius.x) { |
| 34 | radius = corner_radius.x; |
| 35 | center = vec2(radius, radius); |
| 36 | } else if (size.x - corner_radius.y < coords.x && coords.y < corner_radius.y) { |
| 37 | radius = corner_radius.y; |
| 38 | center = vec2(size.x - radius, radius); |
| 39 | } else if (size.x - corner_radius.z < coords.x && size.y - corner_radius.z < coords.y) { |
| 40 | radius = corner_radius.z; |
| 41 | center = vec2(size.x - radius, size.y - radius); |
| 42 | } else if (coords.x < corner_radius.w && size.y - corner_radius.w < coords.y) { |
| 43 | radius = corner_radius.w; |
| 44 | center = vec2(radius, size.y - radius); |
| 45 | } else { |
| 46 | return 1.0; |
| 47 | } |
| 48 | |
| 49 | float dist = distance(coords, center); |
| 50 | float half_px = 0.5 / niri_scale; |
| 51 | return 1.0 - smoothstep(radius - half_px, radius + half_px, dist); |
| 52 | } |
| 53 | |
| 54 | void main() { |
| 55 | vec3 coords_geo = input_to_geo * vec3(v_coords, 1.0); |
| 56 | |
| 57 | // Sample the texture. |
| 58 | vec4 color = texture2D(tex, v_coords); |
| 59 | #if defined(NO_ALPHA) |
| 60 | color = vec4(color.rgb, 1.0); |
| 61 | #endif |
| 62 | |
| 63 | if (coords_geo.x < 0.0 || 1.0 < coords_geo.x || coords_geo.y < 0.0 || 1.0 < coords_geo.y) { |
| 64 | // Clip outside geometry. |
| 65 | color = vec4(0.0); |
| 66 | } else { |
| 67 | // Apply corner rounding inside geometry. |
| 68 | color = color * rounding_alpha(coords_geo.xy * geo_size, geo_size); |
| 69 | } |
| 70 | |
| 71 | // Apply final alpha and tint. |
| 72 | color = color * alpha; |
| 73 | |
| 74 | #if defined(DEBUG_FLAGS) |
| 75 | if (tint == 1.0) |
| 76 | color = vec4(0.0, 0.2, 0.0, 0.2) + color * 0.8; |
| 77 | #endif |
| 78 | |
| 79 | gl_FragColor = color; |
| 80 | } |