From 641db4face339a12e6d7c88a2656e5b2fba5410f Mon Sep 17 00:00:00 2001 From: Nova Date: Mon, 26 Jun 2023 20:49:21 -0400 Subject: [PATCH] refactor: disable shader injection --- src/wayland/shaders/gamma.frag | 16 ++++++ src/wayland/shaders/mod.rs | 4 +- src/wayland/shaders/simula.frag | 69 ++++++++++++++++++++++++-- src/wayland/shaders/simula_old.frag | 75 ----------------------------- src/wayland/surface.rs | 15 +++--- 5 files changed, 88 insertions(+), 91 deletions(-) create mode 100644 src/wayland/shaders/gamma.frag delete mode 100644 src/wayland/shaders/simula_old.frag diff --git a/src/wayland/shaders/gamma.frag b/src/wayland/shaders/gamma.frag new file mode 100644 index 0000000..0752cbb --- /dev/null +++ b/src/wayland/shaders/gamma.frag @@ -0,0 +1,16 @@ +#version 320 es +precision mediump float; +precision highp int; + +layout(binding = 0) uniform highp sampler2D diffuse; + +layout(location = 0) in highp vec2 fs_uv; +layout(location = 0) out highp vec4 _entryPointOutput; + +void main() +{ + highp vec4 _101 = texture(diffuse, fs_uv); + highp vec3 _104 = pow(_101.xyz, vec3(2.2000000476837158203125)); + _entryPointOutput = vec4(_104.x, _104.y, _104.z, _101.w); +} + diff --git a/src/wayland/shaders/mod.rs b/src/wayland/shaders/mod.rs index 911cb57..c199917 100644 --- a/src/wayland/shaders/mod.rs +++ b/src/wayland/shaders/mod.rs @@ -7,7 +7,7 @@ pub const PANEL_SHADER_BYTES: &[u8] = include_bytes!("shader_unlit_simula.sks"); // Simula text shader (fragment) -pub const SIMULA_FRAG_STR: &str = include_str!("simula.frag"); +// pub const SIMULA_FRAG_STR: &str = include_str!("simula.frag"); // Simula text shader (vertex) -pub const SIMULA_VERT_STR: &str = include_str!("simula.vert"); +// pub const SIMULA_VERT_STR: &str = include_str!("simula.vert"); diff --git a/src/wayland/shaders/simula.frag b/src/wayland/shaders/simula.frag index 0752cbb..c0b310f 100644 --- a/src/wayland/shaders/simula.frag +++ b/src/wayland/shaders/simula.frag @@ -1,16 +1,75 @@ #version 320 es +#extension GL_OES_EGL_image_external : require precision mediump float; precision highp int; -layout(binding = 0) uniform highp sampler2D diffuse; +layout(binding = 0, std140) uniform _Global +{ + highp vec4 diffuse_i; + highp vec2 uv_scale; + highp vec2 uv_offset; + highp float fcFactor; + highp float ripple; + highp float alpha_min; + highp float alpha_max; +} uniforms; + +layout(binding = 0) uniform highp samplerExternalOES diffuse; layout(location = 0) in highp vec2 fs_uv; -layout(location = 0) out highp vec4 _entryPointOutput; +layout(location = 0) out highp vec4 fragColor; void main() { - highp vec4 _101 = texture(diffuse, fs_uv); - highp vec3 _104 = pow(_101.xyz, vec3(2.2000000476837158203125)); - _entryPointOutput = vec4(_104.x, _104.y, _104.z, _101.w); + highp vec2 dx_uv = dFdx(fs_uv); + highp vec2 dy_uv = dFdy(fs_uv); + highp vec2 width = fs_uv * uniforms.diffuse_i.xy; + ivec2 _475 = ivec2(width); + highp vec2 _477 = clamp(floor(abs(vec2(dx_uv.x, dy_uv.y)) * uniforms.diffuse_i.xy), vec2(1.0), vec2(2.0)); + ivec2 _480 = ivec2(_477); + ivec2 _481 = _475 - _480; + ivec2 _485 = _475 + _480; + int _487 = _481.y; + highp vec4 _671; + highp float _672; + _672 = 0.0; + _671 = vec4(0.0); + highp vec4 _679; + highp float _681; + for (int _670 = _487; _670 <= _485.y; _672 = _681, _671 = _679, _670++) + { + int _496 = _481.x; + _681 = _672; + _679 = _671; + highp vec4 _553; + highp float _556; + for (int _673 = _496; _673 <= _485.x; _681 = _556, _679 = _553, _673++) + { + highp float _509 = float(_673); + highp float _514 = (uniforms.fcFactor * (width.x - _509)) / _477.x; + highp float _520 = float(_670); + highp float _525 = (uniforms.fcFactor * (width.y - _520)) / _477.y; + highp float _533 = sqrt((_514 * _514) + (_525 * _525)); + highp float _675; + do + { + if (_533 > 1.0) + { + _675 = 0.0; + break; + } + highp float _592 = pow(uniforms.ripple * sqrt(1.0 - (_533 * _533)), 2.0); + _675 = 1.0 + (_592 * (0.25 + (_592 * (0.015625 + (_592 * (0.00043402801384218037128448486328125 + (_592 * (6.7816799855791032314300537109375e-06 + (_592 * (6.7816799287356843706220388412476e-08 + (_592 * (4.709500012189948847662890329957e-10 + (_592 * (2.4028099388645474121517509047408e-12 + (_592 * (9.3859703944590075486154034933861e-15 + (_592 * (2.8968999943407451927966655969016e-17 + (7.242260299760125752555485045131e-20 * _592))))))))))))))))))); + break; + } while(false); + _553 = _679 + (texture2D(diffuse, (vec2(_509, _520) + vec2(0.5)) / uniforms.diffuse_i.xy) * _675); + _556 = _681 + _675; + } + } + highp vec4 _568 = _671 / vec4(_672); + highp vec3 _417 = pow(_568.xyz, vec3(2.2000000476837158203125)); + highp vec4 _669 = vec4(_417.x, _417.y, _417.z, _568.w); + _669.w = uniforms.alpha_min + (_568.w * (uniforms.alpha_max - uniforms.alpha_min)); + fragColor = _669; } diff --git a/src/wayland/shaders/simula_old.frag b/src/wayland/shaders/simula_old.frag deleted file mode 100644 index c0b310f..0000000 --- a/src/wayland/shaders/simula_old.frag +++ /dev/null @@ -1,75 +0,0 @@ -#version 320 es -#extension GL_OES_EGL_image_external : require -precision mediump float; -precision highp int; - -layout(binding = 0, std140) uniform _Global -{ - highp vec4 diffuse_i; - highp vec2 uv_scale; - highp vec2 uv_offset; - highp float fcFactor; - highp float ripple; - highp float alpha_min; - highp float alpha_max; -} uniforms; - -layout(binding = 0) uniform highp samplerExternalOES diffuse; - -layout(location = 0) in highp vec2 fs_uv; -layout(location = 0) out highp vec4 fragColor; - -void main() -{ - highp vec2 dx_uv = dFdx(fs_uv); - highp vec2 dy_uv = dFdy(fs_uv); - highp vec2 width = fs_uv * uniforms.diffuse_i.xy; - ivec2 _475 = ivec2(width); - highp vec2 _477 = clamp(floor(abs(vec2(dx_uv.x, dy_uv.y)) * uniforms.diffuse_i.xy), vec2(1.0), vec2(2.0)); - ivec2 _480 = ivec2(_477); - ivec2 _481 = _475 - _480; - ivec2 _485 = _475 + _480; - int _487 = _481.y; - highp vec4 _671; - highp float _672; - _672 = 0.0; - _671 = vec4(0.0); - highp vec4 _679; - highp float _681; - for (int _670 = _487; _670 <= _485.y; _672 = _681, _671 = _679, _670++) - { - int _496 = _481.x; - _681 = _672; - _679 = _671; - highp vec4 _553; - highp float _556; - for (int _673 = _496; _673 <= _485.x; _681 = _556, _679 = _553, _673++) - { - highp float _509 = float(_673); - highp float _514 = (uniforms.fcFactor * (width.x - _509)) / _477.x; - highp float _520 = float(_670); - highp float _525 = (uniforms.fcFactor * (width.y - _520)) / _477.y; - highp float _533 = sqrt((_514 * _514) + (_525 * _525)); - highp float _675; - do - { - if (_533 > 1.0) - { - _675 = 0.0; - break; - } - highp float _592 = pow(uniforms.ripple * sqrt(1.0 - (_533 * _533)), 2.0); - _675 = 1.0 + (_592 * (0.25 + (_592 * (0.015625 + (_592 * (0.00043402801384218037128448486328125 + (_592 * (6.7816799855791032314300537109375e-06 + (_592 * (6.7816799287356843706220388412476e-08 + (_592 * (4.709500012189948847662890329957e-10 + (_592 * (2.4028099388645474121517509047408e-12 + (_592 * (9.3859703944590075486154034933861e-15 + (_592 * (2.8968999943407451927966655969016e-17 + (7.242260299760125752555485045131e-20 * _592))))))))))))))))))); - break; - } while(false); - _553 = _679 + (texture2D(diffuse, (vec2(_509, _520) + vec2(0.5)) / uniforms.diffuse_i.xy) * _675); - _556 = _681 + _675; - } - } - highp vec4 _568 = _671 / vec4(_672); - highp vec3 _417 = pow(_568.xyz, vec3(2.2000000476837158203125)); - highp vec4 _669 = vec4(_417.x, _417.y, _417.z, _568.w); - _669.w = uniforms.alpha_min + (_568.w * (uniforms.alpha_max - uniforms.alpha_min)); - fragColor = _669; -} - diff --git a/src/wayland/surface.rs b/src/wayland/surface.rs index a25d871..45c3030 100644 --- a/src/wayland/surface.rs +++ b/src/wayland/surface.rs @@ -1,10 +1,7 @@ -use super::{ - shaders::{PANEL_SHADER_BYTES, SIMULA_FRAG_STR, SIMULA_VERT_STR}, - state::WaylandState, -}; +use super::{shaders::PANEL_SHADER_BYTES, state::WaylandState}; use crate::{ core::{delta::Delta, destroy_queue, registry::Registry}, - nodes::drawable::{model::ModelPart, shaders::shader_inject}, + nodes::drawable::model::ModelPart, }; use mint::Vector2; use once_cell::sync::OnceCell; @@ -98,10 +95,10 @@ impl CoreSurface { SendWrapper::new(sk.tex_create(TextureType::IMAGE_NO_MIPS, TextureFormat::RGBA32)) }); self.sk_mat.get_or_init(|| { - let mut shader = sk.shader_create_mem(&PANEL_SHADER_BYTES).unwrap(); - let _ = renderer.with_context(|c| unsafe { - shader_inject(c, &mut shader, SIMULA_VERT_STR, SIMULA_FRAG_STR) - }); + let shader = sk.shader_create_mem(&PANEL_SHADER_BYTES).unwrap(); + // let _ = renderer.with_context(|c| unsafe { + // shader_inject(c, &mut shader, SIMULA_VERT_STR, SIMULA_FRAG_STR) + // }); let mat = sk.material_create(&shader); sk.material_set_texture(&mat, "diffuse", sk_tex.as_ref());