diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2025-11-16 11:26:40 +0300 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2025-11-16 22:36:01 +0300 |
| commit | b774fc1bafd3f9c612ad117986510f8710fd7cc6 (patch) | |
| tree | 5c849941e364c48f49708f722649e3c610e92eac /src/render_helpers/shaders/gradient_fade.frag | |
| parent | 661fcd42ad284bf4cf68581ae0979fe04b0f2838 (diff) | |
| download | niri-b774fc1bafd3f9c612ad117986510f8710fd7cc6.tar.gz niri-b774fc1bafd3f9c612ad117986510f8710fd7cc6.tar.bz2 niri-b774fc1bafd3f9c612ad117986510f8710fd7cc6.zip | |
render_helpers: Add GradientFadeTexture
Diffstat (limited to 'src/render_helpers/shaders/gradient_fade.frag')
| -rw-r--r-- | src/render_helpers/shaders/gradient_fade.frag | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/render_helpers/shaders/gradient_fade.frag b/src/render_helpers/shaders/gradient_fade.frag new file mode 100644 index 00000000..eccc7066 --- /dev/null +++ b/src/render_helpers/shaders/gradient_fade.frag @@ -0,0 +1,47 @@ +#version 100 + +//_DEFINES_ + +#if defined(EXTERNAL) +#extension GL_OES_EGL_image_external : require +#endif + +precision highp float; +#if defined(EXTERNAL) +uniform samplerExternalOES tex; +#else +uniform sampler2D tex; +#endif + +uniform float alpha; +varying vec2 v_coords; + +#if defined(DEBUG_FLAGS) +uniform float tint; +#endif + +// x is left edge, y is right edge of the gradient. +uniform vec2 cutoff; + +void main() { + // Sample the texture. + vec4 color = texture2D(tex, v_coords); +#if defined(NO_ALPHA) + color = vec4(color.rgb, 1.0); +#endif + + if (cutoff.x < cutoff.y) { + float fade = clamp((cutoff.y - v_coords.x) / (cutoff.y - cutoff.x), 0.0, 1.0); + color = color * fade; + } + + // Apply final alpha and tint. + color = color * alpha; + +#if defined(DEBUG_FLAGS) + if (tint == 1.0) + color = vec4(0.0, 0.2, 0.0, 0.2) + color * 0.8; +#endif + + gl_FragColor = color; +} |
