None shader now allows selecting a background color.

This commit is contained in:
Filipe Rodrigues 2025-08-22 00:22:03 +01:00
parent aa26578747
commit eaa6946ddb
Signed by: zenithsiz
SSH Key Fingerprint: SHA256:Mb5ppb3Sh7IarBO/sBTXLHbYEOz37hJAlslLQPPAPaU
6 changed files with 39 additions and 11 deletions

View File

@ -3,6 +3,7 @@
/// Uniforms
struct Uniforms {
pos_matrix: mat4x4<f32>,
background_color: vec4<f32>,
};
// Uniforms
@ -16,5 +17,5 @@ fn vs_main(@location(0) pos: vec2<f32>) -> @builtin(position) vec4<f32> {
@fragment
fn fs_main() -> @location(0) vec4<f32> {
return vec4(0.0, 0.0, 0.0, 0.0);
return uniforms.background_color;
}

View File

@ -139,9 +139,13 @@ pub struct ConfigPanel {
#[derive(Clone, Copy, Debug)]
#[derive(serde::Serialize, serde::Deserialize)]
#[serde(tag = "type")]
#[expect(variant_size_differences, reason = "16 bytes is still reasonable for this type")]
pub enum ConfigShader {
#[serde(rename = "none")]
None,
None {
#[serde(default)]
background_color: [f32; 4],
},
#[serde(rename = "fade")]
Fade,

View File

@ -365,7 +365,7 @@ async fn load_default_panel(default_panel: &config::ConfigPanel, shared: &Shared
// Set the shader
let panel_shader = match default_panel.shader {
Some(config::ConfigShader::None) => PanelShader::None,
Some(config::ConfigShader::None { background_color }) => PanelShader::None { background_color },
Some(config::ConfigShader::Fade) => PanelShader::Fade,
Some(config::ConfigShader::FadeWhite { strength }) => PanelShader::FadeWhite { strength },
Some(config::ConfigShader::FadeOut { strength }) => PanelShader::FadeOut { strength },

View File

@ -255,7 +255,10 @@ impl PanelsRenderer {
let fade_point = panel.state.fade_point_norm();
let progress = panel.state.progress_norm();
match panel.shader {
PanelShader::None => write_uniforms!(uniform::None { pos_matrix }),
PanelShader::None { background_color } => write_uniforms!(uniform::None {
pos_matrix,
background_color: uniform::Vec4(background_color),
}),
PanelShader::Fade => write_uniforms!(uniform::Fade {
pos_matrix,
prev,
@ -421,7 +424,7 @@ async fn parse_shader(shader_path: &Path, shader: PanelShader) -> Result<naga::M
let mut shader_defs = HashSet::new();
#[expect(unused_results, reason = "We don't care about whether it exists or not")]
match shader {
PanelShader::None => {},
PanelShader::None { .. } => {},
PanelShader::Fade => {
shader_defs.insert("FADE_BASIC");
},
@ -599,8 +602,9 @@ fn create_image_bind_group_layout(wgpu_shared: &WgpuShared) -> wgpu::BindGroupLa
/// Shader
#[derive(PartialEq, Clone, Copy, Debug)]
#[expect(variant_size_differences, reason = "16 bytes is still reasonable for this type")]
pub enum PanelShader {
None,
None { background_color: [f32; 4] },
Fade,
FadeWhite { strength: f32 },
FadeOut { strength: f32 },
@ -610,7 +614,7 @@ impl PanelShader {
/// Returns this shader's path, relative to the shaders path
pub fn path(self) -> &'static str {
match self {
Self::None => "panels/none.wgsl",
Self::None { .. } => "panels/none.wgsl",
Self::Fade | Self::FadeWhite { .. } | Self::FadeOut { .. } | Self::FadeIn { .. } => "panels/fade.wgsl",
}
}
@ -618,7 +622,7 @@ impl PanelShader {
/// Returns this shader's name
pub fn name(self) -> &'static str {
match self {
Self::None => "None",
Self::None { .. } => "None",
Self::Fade => "Fade",
Self::FadeWhite { .. } => "Fade white",
Self::FadeOut { .. } => "Fade out",

View File

@ -9,6 +9,12 @@ use bytemuck::{Pod, Zeroable};
#[repr(C, align(8))]
pub struct Vec2(pub [f32; 2]);
/// `vec4<f32>`
#[derive(PartialEq, Clone, Copy, Default, Debug)]
#[derive(Zeroable, Pod)]
#[repr(C, align(16))]
pub struct Vec4(pub [f32; 4]);
/// `mat4x4<f32>`
#[derive(PartialEq, Clone, Copy, Default, Debug)]
#[derive(Zeroable, Pod)]
@ -40,7 +46,8 @@ impl PanelImageUniforms {
#[derive(Zeroable, Pod)]
#[repr(C)]
pub struct None {
pub pos_matrix: Matrix4x4,
pub pos_matrix: Matrix4x4,
pub background_color: Vec4,
}
/// Fade

View File

@ -235,7 +235,9 @@ fn draw_shader_select(ui: &mut egui::Ui, cur_shader: &mut PanelShader) {
.show_ui(ui, |ui| {
// TODO: Not have default values here?
let shaders = [
PanelShader::None,
PanelShader::None {
background_color: [0.0; 4],
},
PanelShader::Fade,
PanelShader::FadeWhite { strength: 1.0 },
PanelShader::FadeOut { strength: 0.2 },
@ -247,7 +249,17 @@ fn draw_shader_select(ui: &mut egui::Ui, cur_shader: &mut PanelShader) {
});
match &mut *cur_shader {
PanelShader::None | PanelShader::Fade => (),
PanelShader::None {
background_color: bg_color,
} => {
ui.horizontal(|ui| {
ui.label("Background color");
let mut color = egui::Rgba::from_rgba_premultiplied(bg_color[0], bg_color[1], bg_color[2], bg_color[3]);
egui::color_picker::color_edit_button_rgba(ui, &mut color, egui::color_picker::Alpha::OnlyBlend);
*bg_color = color.to_array();
});
},
PanelShader::Fade => (),
PanelShader::FadeWhite { strength } => {
ui.horizontal(|ui| {
ui.label("Strength");