diff --git a/src/wayland/shaders/mod.rs b/src/wayland/shaders/mod.rs index 5acd8e7..178d192 100644 --- a/src/wayland/shaders/mod.rs +++ b/src/wayland/shaders/mod.rs @@ -1,7 +1,7 @@ #![allow(dead_code)] // Basic gamma correction shader -pub const PANEL_SHADER_BYTES: &[u8] = include_bytes!("shader_unlit_gamma.sks"); +// pub const PANEL_SHADER_BYTES: &[u8] = include_bytes!("shader_unlit_gamma.sks"); // Simula shader with fancy lanzcos sampling -// pub const PANEL_SHADER_BYTES: &[u8] = include_bytes!("shader_unlit_simula.sks"); +pub const PANEL_SHADER_BYTES: &[u8] = include_bytes!("shader_unlit_simula.sks"); diff --git a/src/wayland/shaders/shader_unlit_simula.hlsl b/src/wayland/shaders/shader_unlit_simula.hlsl index a246965..a27c063 100644 --- a/src/wayland/shaders/shader_unlit_simula.hlsl +++ b/src/wayland/shaders/shader_unlit_simula.hlsl @@ -6,16 +6,19 @@ //--diffuse = white //--fcFactor = 1.0 //--ripple = 4.0 -//--size = 256, 256 //--uv_offset = 0.0, 0.0 //--uv_scale = 1.0, 1.0 +//--alpha_min = 0.0 +//--alpha_max = 1.0 Texture2D diffuse : register(t0); SamplerState diffuse_s : register(s0); -int2 size; +float4 diffuse_i; float fcFactor; float ripple; float2 uv_scale; float2 uv_offset; +float alpha_min; +float alpha_max; struct vsIn { float4 pos : SV_Position; @@ -40,6 +43,10 @@ psIn vs(vsIn input, uint id : SV_InstanceID) { return o; } +float map(float value, float min1, float max1, float min2, float max2) { + return min2 + (value - min1) * (max2 - min2) / (max1 - min1); +} + // float gaussian(float x, float t) { // float PI = 3.14159265358; // return exp(-x*x/(2.0 * t*t))/(sqrt(2.0*PI)*t); @@ -66,10 +73,10 @@ float4 lowpassFilter(Texture2D tex, sampler2D texSampler, float2 uv, float alpha //float width = sqrt(max(dot(dx_uv, dx_uv), dot(dy_uv, dy_uv))); float2 width = abs(float2(dx_uv.x, dy_uv.y)); - float2 pixelWidth = floor(width * float2(size)); + float2 pixelWidth = floor(width * diffuse_i.xy); float2 aspectRatio = normalize(pixelWidth); - float2 xyf = uv * float2(size); + float2 xyf = uv * diffuse_i.xy; int2 xy = int2(xyf); pixelWidth = clamp(pixelWidth, float2(1.0), float2(2.0)); @@ -89,7 +96,7 @@ float4 lowpassFilter(Texture2D tex, sampler2D texSampler, float2 uv, float alpha //float lanczosValue = gaussian(kx, fcx); float lanczosValue = kaiser(sqrt(kx*kx + ky*ky), alpha); - q += tex.Sample(texSampler, (float2(u, v)+float2(0.5))/float2(size)) * lanczosValue; + q += tex.Sample(texSampler, (float2(u, v)+float2(0.5))/diffuse_i.xy) * lanczosValue; // q += tex.Load(int3(u, v, 0)) * lanczosValue; qSum += lanczosValue; } @@ -106,6 +113,7 @@ float4 ps(psIn input) : SV_TARGET { float4 col = lowpassFilter(diffuse, diffuse_s, input.uv, ripple); // float4 col = diffuse.Sample(diffuse_s, input.uv); col.rgb = pow(col.rgb, float3(gamma)); + col.a = map(col.a, 0, 1, alpha_min, alpha_max); return col; } diff --git a/src/wayland/shaders/shader_unlit_simula.sks b/src/wayland/shaders/shader_unlit_simula.sks index 1e0a7c8..2a5e526 100644 Binary files a/src/wayland/shaders/shader_unlit_simula.sks and b/src/wayland/shaders/shader_unlit_simula.sks differ diff --git a/src/wayland/surface.rs b/src/wayland/surface.rs index 0f7b90c..8b26e44 100644 --- a/src/wayland/surface.rs +++ b/src/wayland/surface.rs @@ -3,7 +3,6 @@ use crate::{ core::{destroy_queue, registry::Registry}, nodes::model::Model, }; -use glam::vec2; use mint::Vector2; use parking_lot::Mutex; use send_wrapper::SendWrapper; @@ -68,7 +67,6 @@ impl CoreSurfaceData { .map(SendWrapper::new); if let Some(smithay_tex) = self.wl_tex.as_ref() { let sk_tex = self.sk_tex.as_ref().unwrap(); - let sk_mat = self.sk_mat.as_ref().unwrap(); unsafe { sk_tex.set_native( smithay_tex.tex_id() as usize, @@ -78,9 +76,6 @@ impl CoreSurfaceData { smithay_tex.height(), false, ); - let size: mint::Vector2 = - vec2(smithay_tex.width() as f32, smithay_tex.height() as f32).into(); - sk_mat.set_parameter("size", &size); sk_tex.set_sample(TextureSample::Point); sk_tex.set_address_mode(TextureAddress::Clamp); }