aboutsummaryrefslogtreecommitdiff
path: root/src/render_helpers/shaders
diff options
context:
space:
mode:
Diffstat (limited to 'src/render_helpers/shaders')
-rw-r--r--src/render_helpers/shaders/crossfade.frag31
-rw-r--r--src/render_helpers/shaders/mod.rs24
-rw-r--r--src/render_helpers/shaders/texture.vert25
3 files changed, 79 insertions, 1 deletions
diff --git a/src/render_helpers/shaders/crossfade.frag b/src/render_helpers/shaders/crossfade.frag
new file mode 100644
index 00000000..56280ad2
--- /dev/null
+++ b/src/render_helpers/shaders/crossfade.frag
@@ -0,0 +1,31 @@
+#version 100
+
+precision mediump float;
+
+uniform sampler2D tex_from;
+uniform vec2 tex_from_loc;
+uniform vec2 tex_from_size;
+
+uniform sampler2D tex_to;
+uniform vec2 tex_to_loc;
+uniform vec2 tex_to_size;
+
+uniform float alpha;
+uniform float amount;
+
+uniform vec2 size;
+varying vec2 v_coords;
+
+void main() {
+ vec2 coords_from = (v_coords - tex_from_loc) / tex_from_size;
+ vec2 coords_to = (v_coords - tex_to_loc) / tex_to_size;
+
+ vec4 color_from = texture2D(tex_from, coords_from);
+ vec4 color_to = texture2D(tex_to, coords_to);
+
+ vec4 color = mix(color_from, color_to, amount);
+ color = color * alpha;
+
+ gl_FragColor = color;
+}
+
diff --git a/src/render_helpers/shaders/mod.rs b/src/render_helpers/shaders/mod.rs
index 1adbaf82..ebe0d08c 100644
--- a/src/render_helpers/shaders/mod.rs
+++ b/src/render_helpers/shaders/mod.rs
@@ -1,9 +1,11 @@
use smithay::backend::renderer::gles::{GlesPixelProgram, GlesRenderer, UniformName, UniformType};
+use super::primary_gpu_pixel_shader_with_textures::PixelWithTexturesProgram;
use super::renderer::NiriRenderer;
pub struct Shaders {
pub gradient_border: Option<GlesPixelProgram>,
+ pub crossfade: Option<PixelWithTexturesProgram>,
}
impl Shaders {
@@ -26,7 +28,27 @@ impl Shaders {
})
.ok();
- Self { gradient_border }
+ let crossfade = PixelWithTexturesProgram::compile(
+ renderer,
+ include_str!("crossfade.frag"),
+ &[
+ UniformName::new("tex_from_loc", UniformType::_2f),
+ UniformName::new("tex_from_size", UniformType::_2f),
+ UniformName::new("tex_to_loc", UniformType::_2f),
+ UniformName::new("tex_to_size", UniformType::_2f),
+ UniformName::new("amount", UniformType::_1f),
+ ],
+ &["tex_from", "tex_to"],
+ )
+ .map_err(|err| {
+ warn!("error compiling crossfade shader: {err:?}");
+ })
+ .ok();
+
+ Self {
+ gradient_border,
+ crossfade,
+ }
}
pub fn get(renderer: &mut impl NiriRenderer) -> &Self {
diff --git a/src/render_helpers/shaders/texture.vert b/src/render_helpers/shaders/texture.vert
new file mode 100644
index 00000000..a59870b8
--- /dev/null
+++ b/src/render_helpers/shaders/texture.vert
@@ -0,0 +1,25 @@
+#version 100
+
+uniform mat3 matrix;
+uniform mat3 tex_matrix;
+
+attribute vec2 vert;
+attribute vec4 vert_position;
+
+varying vec2 v_coords;
+
+mat2 scale(vec2 scale_vec){
+ return mat2(
+ scale_vec.x, 0.0,
+ 0.0, scale_vec.y
+ );
+}
+
+void main() {
+ vec2 vert_transform_translation = vert_position.xy;
+ vec2 vert_transform_scale = vert_position.zw;
+ vec3 position = vec3(vert * scale(vert_transform_scale) + vert_transform_translation, 1.0);
+ v_coords = (tex_matrix * position).xy;
+ gl_Position = vec4(matrix * position, 1.0);
+}
+