fix(wayland surface): simula text shader
This commit is contained in:
@@ -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");
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -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<f32> =
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user