forge
Explore
Log in

Don't you dare go Hollow

niri

Clone
★ 0

0 watching0 forksRustGPL-3.012.1 MiB9d8f4f8Ivan Molodetskikh1 month ago2997 commits

open_custom_shader.frag128 lines, 4.2 KiBHistoryRawDownload
1// Your shader must contain one function (see the bottom of this file).
2//
3// It should not contain any uniform definitions or anything else, as niri
4// provides them for you.
5//
6// All symbols defined by niri will have a niri_ prefix, so don't use it for
7// your own variables and functions.
8
9// The function that you must define looks like this:
10vec4 open_color(vec3 coords_geo, vec3 size_geo) {
11 vec4 color = /* ...compute the color... */;
12 return color;
13}
14
15// It takes as input:
16//
17// * coords_geo: coordinates of the current pixel relative to the window
18// geometry.
19//
20// These are homogeneous (the Z component is equal to 1) and scaled in such a
21// way that the 0 to 1 coordinates lie within the window geometry. Pixels
22// outside the window geometry will have coordinates below 0 or above 1.
23//
24// The window geometry is its "visible bounds" from the user's perspective.
25//
26// The shader runs over an area of unspecified size and location, so you must
27// expect and handle coordinates outside the [0, 1] range. The area will be
28// larger than the final window size to accommodate more varied effects.
29//
30// * size_geo: size of the window geometry in logical pixels.
31//
32// It is homogeneous (the Z component is equal to 1).
33//
34// The function must return the color of the pixel (with premultiplied alpha).
35// The pixel color will be further processed by niri (for example, to apply the
36// final opacity from window rules).
37
38// Now let's go over the uniforms that niri defines.
39//
40// You should only rely on the uniforms documented here. Any other uniforms can
41// change or be removed without notice.
42
43// The window texture.
44uniform sampler2D niri_tex;
45
46// Matrix that converts geometry coordinates into the window texture
47// coordinates.
48//
49// The window texture can and will go outside the geometry (for client-side
50// decoration shadows for example), which is why this matrix is necessary.
51uniform mat3 niri_geo_to_tex;
52
53
54// Unclamped progress of the animation.
55//
56// Goes from 0 to 1 but may overshoot and oscillate.
57uniform float niri_progress;
58
59// Clamped progress of the animation.
60//
61// Goes from 0 to 1, but will stop at 1 as soon as it first reaches 1. Will not
62// overshoot or oscillate.
63uniform float niri_clamped_progress;
64
65// Random float in [0; 1), consistent for the duration of the animation.
66uniform float niri_random_seed;
67
68// Now let's look at some examples. You can copy everything below this line
69// into your custom-shader to experiment.
70
71// Example: fill the current geometry with a solid vertical gradient and
72// gradually make opaque.
73vec4 solid_gradient(vec3 coords_geo, vec3 size_geo) {
74 vec4 color = vec4(0.0);
75
76 // Paint only the area inside the current geometry.
77 if (0.0 <= coords_geo.x && coords_geo.x <= 1.0
78 && 0.0 <= coords_geo.y && coords_geo.y <= 1.0)
79 {
80 vec4 from = vec4(1.0, 0.0, 0.0, 1.0);
81 vec4 to = vec4(0.0, 1.0, 0.0, 1.0);
82 color = mix(from, to, coords_geo.y);
83 }
84
85 // Make it opaque.
86 color *= niri_clamped_progress;
87
88 return color;
89}
90
91// Example: gradually scale up and make opaque, equivalent to the default
92// opening animation.
93vec4 default_open(vec3 coords_geo, vec3 size_geo) {
94 // Scale up the window.
95 float scale = max(0.0, (niri_progress / 2.0 + 0.5));
96 coords_geo = vec3((coords_geo.xy - vec2(0.5)) / scale + vec2(0.5), 1.0);
97
98 // Get color from the window texture.
99 vec3 coords_tex = niri_geo_to_tex * coords_geo;
100 vec4 color = texture2D(niri_tex, coords_tex.st);
101
102 // Make the window opaque.
103 color *= niri_clamped_progress;
104
105 return color;
106}
107
108// Example: show the window as an expanding circle.
109// Recommended setting: duration-ms 250
110vec4 expanding_circle(vec3 coords_geo, vec3 size_geo) {
111 vec3 coords_tex = niri_geo_to_tex * coords_geo;
112 vec4 color = texture2D(niri_tex, coords_tex.st);
113
114 vec2 coords = (coords_geo.xy - vec2(0.5, 0.5)) * size_geo.xy * 2.0;
115 coords = coords / length(size_geo.xy);
116 float p = niri_clamped_progress;
117 if (p * p <= dot(coords, coords))
118 color = vec4(0.0);
119
120 return color;
121}
122
123// This is the function that you must define.
124vec4 open_color(vec3 coords_geo, vec3 size_geo) {
125 // You can pick one of the example functions or write your own.
126 return expanding_circle(coords_geo, size_geo);
127}
128