mirror of
https://github.com/Zenithsiz/zsw.git
synced 2026-02-07 11:59:19 +00:00
Swapped fade point with a fade duration.
This commit is contained in:
parent
7acbfbdf13
commit
3e69e2c853
@ -6,5 +6,5 @@ geometry = "1920x1080+960+0"
|
||||
geometry = "960x1080+2880+0"
|
||||
|
||||
[state]
|
||||
duration = 300
|
||||
fade_point = 250
|
||||
duration = 300
|
||||
fade_duration = 50
|
||||
|
||||
@ -2,5 +2,5 @@
|
||||
geometry = "1366x768+0+0"
|
||||
|
||||
[state]
|
||||
duration = 300
|
||||
fade_point = 250
|
||||
duration = 300
|
||||
fade_duration = 50
|
||||
|
||||
@ -5,8 +5,8 @@ geometry = "960x540+0+540"
|
||||
geometry = "960x1080+960+0"
|
||||
|
||||
[state]
|
||||
duration = 300
|
||||
fade_point = 250
|
||||
duration = 300
|
||||
fade_duration = 50
|
||||
|
||||
[shader]
|
||||
type = "fade-out"
|
||||
|
||||
@ -2,8 +2,8 @@
|
||||
geometry = "960x540+0+0"
|
||||
|
||||
[state]
|
||||
duration = 300
|
||||
fade_point = 250
|
||||
duration = 300
|
||||
fade_duration = 50
|
||||
|
||||
[shader]
|
||||
type = "fade-white"
|
||||
|
||||
@ -45,14 +45,17 @@ fn main(in: VertexOutput) -> FragOutput {
|
||||
var out: FragOutput;
|
||||
|
||||
let p = uniforms.progress;
|
||||
let f = uniforms.fade_point;
|
||||
let f = uniforms.fade_duration;
|
||||
|
||||
let progress_prev = 1.0 - max((1.0 - p - f) / (3.0 - 2.0 * f), 0.0);
|
||||
let progress_cur = (p + 1.0 - f) / (3.0 - 2.0 * f);
|
||||
let progress_next = max((p - f) / (3.0 - 2.0 * f), 0.0);
|
||||
// Full duration an image is on screen (including the fades)
|
||||
let d = 1.0 + 2.0 * f;
|
||||
|
||||
let alpha_prev = 0.5 * saturate(1.0 - ( p) / (1.0 - f));
|
||||
let alpha_next = 0.5 * saturate(1.0 - (1.0 - p) / (1.0 - f));
|
||||
let progress_prev = 1.0 - max((f - p) / d, 0.0);
|
||||
let progress_cur = (p + f) / d;
|
||||
let progress_next = max((p - 1.0 + f) / d, 0.0);
|
||||
|
||||
let alpha_prev = 0.5 * saturate(1.0 - ( p) / f);
|
||||
let alpha_next = 0.5 * saturate(1.0 - (1.0 - p) / f);
|
||||
let alpha_cur = 1.0 - max(alpha_prev, alpha_next);
|
||||
|
||||
// Sample the textures
|
||||
|
||||
@ -12,7 +12,7 @@ struct Uniforms {
|
||||
prev: ImageUniforms,
|
||||
cur: ImageUniforms,
|
||||
next: ImageUniforms,
|
||||
fade_point: f32,
|
||||
fade_duration: f32,
|
||||
progress: f32,
|
||||
|
||||
// TODO: Reduce this repetition
|
||||
|
||||
@ -57,7 +57,7 @@ impl Panel {
|
||||
fn max_duration(images: &PanelImages, state: &PanelState) -> u64 {
|
||||
match (images.cur.is_loaded(), images.next.is_loaded()) {
|
||||
(false, false) => 0,
|
||||
(true, false) => state.fade_point,
|
||||
(true, false) => state.fade_duration,
|
||||
(_, true) => state.duration,
|
||||
}
|
||||
}
|
||||
@ -73,7 +73,7 @@ impl Panel {
|
||||
image_requester: &ImageRequester,
|
||||
) {
|
||||
match images.step_next(wgpu_shared, renderer_layouts).await {
|
||||
Ok(()) => self.state.progress = self.state.duration.saturating_sub(self.state.fade_point),
|
||||
Ok(()) => self.state.progress = self.state.duration.saturating_sub(self.state.fade_duration),
|
||||
Err(()) => self.state.progress = Self::max_duration(images, &self.state),
|
||||
}
|
||||
|
||||
|
||||
@ -4,11 +4,11 @@
|
||||
use {
|
||||
super::{Panel, PanelName, PanelShader, PanelState, ser},
|
||||
crate::AppError,
|
||||
app_error::Context,
|
||||
futures::lock::Mutex,
|
||||
std::{collections::HashMap, path::PathBuf, sync::Arc},
|
||||
tokio::sync::OnceCell,
|
||||
zsw_util::PathAppendExt,
|
||||
app_error::Context,
|
||||
};
|
||||
|
||||
/// Panel storage
|
||||
@ -61,10 +61,10 @@ impl Panels {
|
||||
// Finally convert it
|
||||
let geometries = panel.geometries.into_iter().map(|geometry| geometry.geometry).collect();
|
||||
let state = PanelState {
|
||||
paused: false,
|
||||
progress: 0,
|
||||
duration: panel.state.duration,
|
||||
fade_point: panel.state.fade_point,
|
||||
paused: false,
|
||||
progress: 0,
|
||||
duration: panel.state.duration,
|
||||
fade_duration: panel.state.fade_duration,
|
||||
};
|
||||
|
||||
// Get the shader
|
||||
|
||||
@ -12,6 +12,7 @@ use {
|
||||
self::uniform::PanelImageUniforms,
|
||||
super::{Panel, PanelImage, PanelImages, PanelName, Panels},
|
||||
crate::{config_dirs::ConfigDirs, panel::PanelGeometry},
|
||||
app_error::Context,
|
||||
cgmath::Vector2,
|
||||
core::{
|
||||
future::Future,
|
||||
@ -27,9 +28,8 @@ use {
|
||||
tokio::fs,
|
||||
wgpu::{naga, util::DeviceExt},
|
||||
winit::dpi::PhysicalSize,
|
||||
zsw_util::Rect,
|
||||
zsw_util::{AppError, Rect},
|
||||
zsw_wgpu::{FrameRender, WgpuRenderer, WgpuShared},
|
||||
app_error::Context, zsw_util::AppError,
|
||||
};
|
||||
|
||||
/// Panels renderer layouts
|
||||
@ -265,7 +265,7 @@ impl PanelsRenderer {
|
||||
write_uniforms(bytemuck::bytes_of(&$uniforms))
|
||||
}
|
||||
|
||||
let fade_point = panel.state.fade_point_norm();
|
||||
let fade_duration = panel.state.fade_duration_norm();
|
||||
let progress = panel.state.progress_norm();
|
||||
match panel.shader {
|
||||
PanelShader::None { background_color } => write_uniforms!(uniform::None {
|
||||
@ -277,7 +277,7 @@ impl PanelsRenderer {
|
||||
prev,
|
||||
cur,
|
||||
next,
|
||||
fade_point,
|
||||
fade_duration,
|
||||
progress,
|
||||
_unused: [0; 2],
|
||||
}),
|
||||
@ -286,7 +286,7 @@ impl PanelsRenderer {
|
||||
prev,
|
||||
cur,
|
||||
next,
|
||||
fade_point,
|
||||
fade_duration,
|
||||
progress,
|
||||
strength,
|
||||
_unused: 0,
|
||||
@ -296,7 +296,7 @@ impl PanelsRenderer {
|
||||
prev,
|
||||
cur,
|
||||
next,
|
||||
fade_point,
|
||||
fade_duration,
|
||||
progress,
|
||||
strength,
|
||||
_unused: 0,
|
||||
@ -306,7 +306,7 @@ impl PanelsRenderer {
|
||||
prev,
|
||||
cur,
|
||||
next,
|
||||
fade_point,
|
||||
fade_duration,
|
||||
progress,
|
||||
strength,
|
||||
_unused: 0,
|
||||
|
||||
@ -55,12 +55,12 @@ pub struct None {
|
||||
#[derive(Zeroable, Pod)]
|
||||
#[repr(C)]
|
||||
pub struct Fade {
|
||||
pub pos_matrix: Matrix4x4,
|
||||
pub prev: PanelImageUniforms,
|
||||
pub cur: PanelImageUniforms,
|
||||
pub next: PanelImageUniforms,
|
||||
pub fade_point: f32,
|
||||
pub progress: f32,
|
||||
pub pos_matrix: Matrix4x4,
|
||||
pub prev: PanelImageUniforms,
|
||||
pub cur: PanelImageUniforms,
|
||||
pub next: PanelImageUniforms,
|
||||
pub fade_duration: f32,
|
||||
pub progress: f32,
|
||||
|
||||
pub _unused: [u32; 2],
|
||||
}
|
||||
@ -70,13 +70,13 @@ pub struct Fade {
|
||||
#[derive(Zeroable, Pod)]
|
||||
#[repr(C)]
|
||||
pub struct FadeWhite {
|
||||
pub pos_matrix: Matrix4x4,
|
||||
pub prev: PanelImageUniforms,
|
||||
pub cur: PanelImageUniforms,
|
||||
pub next: PanelImageUniforms,
|
||||
pub fade_point: f32,
|
||||
pub progress: f32,
|
||||
pub strength: f32,
|
||||
pub pos_matrix: Matrix4x4,
|
||||
pub prev: PanelImageUniforms,
|
||||
pub cur: PanelImageUniforms,
|
||||
pub next: PanelImageUniforms,
|
||||
pub fade_duration: f32,
|
||||
pub progress: f32,
|
||||
pub strength: f32,
|
||||
|
||||
pub _unused: u32,
|
||||
}
|
||||
@ -86,13 +86,13 @@ pub struct FadeWhite {
|
||||
#[derive(Zeroable, Pod)]
|
||||
#[repr(C)]
|
||||
pub struct FadeOut {
|
||||
pub pos_matrix: Matrix4x4,
|
||||
pub prev: PanelImageUniforms,
|
||||
pub cur: PanelImageUniforms,
|
||||
pub next: PanelImageUniforms,
|
||||
pub fade_point: f32,
|
||||
pub progress: f32,
|
||||
pub strength: f32,
|
||||
pub pos_matrix: Matrix4x4,
|
||||
pub prev: PanelImageUniforms,
|
||||
pub cur: PanelImageUniforms,
|
||||
pub next: PanelImageUniforms,
|
||||
pub fade_duration: f32,
|
||||
pub progress: f32,
|
||||
pub strength: f32,
|
||||
|
||||
pub _unused: u32,
|
||||
}
|
||||
@ -102,13 +102,13 @@ pub struct FadeOut {
|
||||
#[derive(Zeroable, Pod)]
|
||||
#[repr(C)]
|
||||
pub struct FadeIn {
|
||||
pub pos_matrix: Matrix4x4,
|
||||
pub prev: PanelImageUniforms,
|
||||
pub cur: PanelImageUniforms,
|
||||
pub next: PanelImageUniforms,
|
||||
pub fade_point: f32,
|
||||
pub progress: f32,
|
||||
pub strength: f32,
|
||||
pub pos_matrix: Matrix4x4,
|
||||
pub prev: PanelImageUniforms,
|
||||
pub cur: PanelImageUniforms,
|
||||
pub next: PanelImageUniforms,
|
||||
pub fade_duration: f32,
|
||||
pub progress: f32,
|
||||
pub strength: f32,
|
||||
|
||||
pub _unused: u32,
|
||||
}
|
||||
|
||||
@ -29,8 +29,8 @@ pub struct PanelGeometry {
|
||||
#[derive(Debug)]
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
pub struct PanelState {
|
||||
pub duration: u64,
|
||||
pub fade_point: u64,
|
||||
pub duration: u64,
|
||||
pub fade_duration: u64,
|
||||
}
|
||||
|
||||
/// Configuration shader
|
||||
|
||||
@ -12,8 +12,8 @@ pub struct PanelState {
|
||||
/// Duration (in frames)
|
||||
pub duration: u64,
|
||||
|
||||
/// Fade point (in frames)
|
||||
pub fade_point: u64,
|
||||
/// Fade duration (in frames)
|
||||
pub fade_duration: u64,
|
||||
}
|
||||
|
||||
impl PanelState {
|
||||
@ -24,9 +24,9 @@ impl PanelState {
|
||||
self.progress as f32 / self.duration as f32
|
||||
}
|
||||
|
||||
/// Returns the fade point normalized
|
||||
pub fn fade_point_norm(&self) -> f32 {
|
||||
/// Returns the fade duration normalized
|
||||
pub fn fade_duration_norm(&self) -> f32 {
|
||||
// Note: Image progress is linear throughout the full cycle
|
||||
self.fade_point as f32 / self.duration as f32
|
||||
self.fade_duration as f32 / self.duration as f32
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,19 +127,21 @@ fn draw_panels_editor(ui: &mut egui::Ui, shared: &Shared, shared_window: &Shared
|
||||
let cur_max = match panels_images.get(&panel.name) {
|
||||
Some(panel_images) => match (panel_images.cur.is_loaded(), panel_images.next.is_loaded()) {
|
||||
(false, false) => 0,
|
||||
(true, false) => panel.state.fade_point,
|
||||
(true, false) => panel.state.fade_duration,
|
||||
(_, true) => panel.state.duration,
|
||||
},
|
||||
None => 0,
|
||||
};
|
||||
|
||||
// TODO: This should be done elsewhere.
|
||||
panel.state.progress = panel.state.progress.clamp(0, cur_max);
|
||||
});
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Fade Point");
|
||||
let min = panel.state.duration / 2;
|
||||
let max = panel.state.duration;
|
||||
egui::Slider::new(&mut panel.state.fade_point, min..=max)
|
||||
ui.label("Fade Duration");
|
||||
let min = 0;
|
||||
let max = panel.state.duration / 2;
|
||||
egui::Slider::new(&mut panel.state.fade_duration, min..=max)
|
||||
.clamping(egui::SliderClamping::Edits)
|
||||
.ui(ui);
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user