diff --git a/dash-frontend/src/tab/monado.rs b/dash-frontend/src/tab/monado.rs index 14407744..4a9d1b95 100644 --- a/dash-frontend/src/tab/monado.rs +++ b/dash-frontend/src/tab/monado.rs @@ -18,7 +18,7 @@ use wgui::{ }; use wlx_common::{ config::GeneralConfig, - dash_interface::{self, MonadoDumpSessionFrame}, + dash_interface::{self, ConfigChangeKind, MonadoDumpSessionFrame}, }; use crate::{ @@ -175,7 +175,7 @@ impl Tab for TabMonado { Task::GeneralSettingsChromaUpdate => { if let Subtab::GeneralSettings(tab) = &mut self.subtab { tab.chroma_update(frontend.interface.general_config(data)); - frontend.interface.config_changed(data); + frontend.interface.config_changed(data, ConfigChangeKind::EnvironmentBlend); } } Task::SetBrightness(brightness) => self.set_brightness(frontend, data, brightness), diff --git a/dash-frontend/src/tab/settings/mod.rs b/dash-frontend/src/tab/settings/mod.rs index 3718fb43..d604abed 100644 --- a/dash-frontend/src/tab/settings/mod.rs +++ b/dash-frontend/src/tab/settings/mod.rs @@ -19,7 +19,7 @@ use wgui::{ }, windowing::context_menu::{self, Blueprint, ContextMenu, TickResult}, }; -use wlx_common::{config::GeneralConfig, config_io::ConfigRoot, dash_interface::RecenterMode}; +use wlx_common::{config::GeneralConfig, config_io::ConfigRoot, dash_interface::{ConfigChangeKind, RecenterMode}}; use crate::{ frontend::{Frontend, FrontendTask, FrontendTasks}, @@ -224,7 +224,7 @@ impl Tab for TabSettings { // Notify overlays of the change if changed { - frontend.interface.config_changed(data); + frontend.interface.config_changed(data, ConfigChangeKind::OverlayConfig); } Ok(()) diff --git a/wayvr/src/backend/openxr/helpers.rs b/wayvr/src/backend/openxr/helpers.rs index 56ed80ca..5f85a094 100644 --- a/wayvr/src/backend/openxr/helpers.rs +++ b/wayvr/src/backend/openxr/helpers.rs @@ -212,9 +212,9 @@ pub(super) fn posef_to_transform(pose: &xr::Posef) -> Affine3A { Affine3A::from_rotation_translation(rotation, translation) } -pub(super) fn reconfigure_chroma_key(app: &AppState) { +pub(super) fn try_apply_chroma_key(app: &AppState) -> bool { let Some(monado) = app.monado_state.as_ref() else { - return; + return false; }; let params = &app.session.config.chroma_key_params; @@ -226,6 +226,10 @@ pub(super) fn reconfigure_chroma_key(app: &AppState) { params.curve, params.despill, ) { - log::warn!("Could not set Chroma Key: {e:?}") + log::warn!("Could not set Chroma Key: {e:?}"); + return false; } + + // if all values were non-0, assume we're in chroma key mode + params.hsv_max[0] * params.hsv_max[1] * params.hsv_max[2] * params.curve > 0.001 } diff --git a/wayvr/src/backend/openxr/mod.rs b/wayvr/src/backend/openxr/mod.rs index 57a6506b..7e44dd45 100644 --- a/wayvr/src/backend/openxr/mod.rs +++ b/wayvr/src/backend/openxr/mod.rs @@ -17,7 +17,7 @@ use crate::{ backend::{ BackendError, XrBackend, input::interact, - openxr::{helpers::reconfigure_chroma_key, lines::LinePool, overlay::OpenXrOverlayData}, + openxr::{helpers::try_apply_chroma_key, lines::LinePool, overlay::OpenXrOverlayData}, task::{OpenXrTask, OverlayTask, TaskType}, }, config::{save_settings, save_state}, @@ -94,8 +94,6 @@ pub fn openxr_run(show_by_default: bool, headless: bool) -> Result<(), BackendEr .ok() }); - reconfigure_chroma_key(&app); - let mut blocker = app .monado_state .as_ref() @@ -482,7 +480,7 @@ pub fn openxr_run(show_by_default: bool, headless: bool) -> Result<(), BackendEr } } TaskType::OpenXR(task) => { - if matches!(task, OpenXrTask::SettingsChanged) { + if matches!(task, OpenXrTask::EnvironmentChanged) { reconfigure_environment_blend( &app, &xr_state, @@ -491,7 +489,6 @@ pub fn openxr_run(show_by_default: bool, headless: bool) -> Result<(), BackendEr &mut environment_blend_mode, main_session_visible, ); - reconfigure_chroma_key(&app); } } #[cfg(feature = "openvr")] @@ -532,6 +529,9 @@ pub(super) enum CompositionLayer<'a> { Equirect2(xr::CompositionLayerEquirect2KHR<'a, xr::Vulkan>), } +// applies chroma key settings. +// if chroma key or passthrough is enabled, use alpha env blend +// if alpha blend is not used and skybox is enabled, use skybox fn reconfigure_environment_blend( app: &AppState, xr_state: &XrState, @@ -540,9 +540,11 @@ fn reconfigure_environment_blend( environment_blend_mode: &mut xr::EnvironmentBlendMode, main_session_visible: bool, ) { + let has_chroma_key = try_apply_chroma_key(app); + *environment_blend_mode = { if modes.contains(&xr::EnvironmentBlendMode::ALPHA_BLEND) - && app.session.config.use_passthrough + && (app.session.config.use_passthrough || has_chroma_key) { xr::EnvironmentBlendMode::ALPHA_BLEND } else { @@ -554,13 +556,14 @@ fn reconfigure_environment_blend( && app.session.config.use_skybox && !main_session_visible; - if want_skybox == skybox.is_some() { - return; - } - if want_skybox { - log::debug!("Allocating skybox."); - *skybox = create_skybox(xr_state, app); + if let Some(curr_skybox) = skybox.as_ref() { + if curr_skybox.needs_recreate(app) { + *skybox = None; + log::debug!("Allocating skybox."); + *skybox = create_skybox(xr_state, app); + } + } } else { log::debug!("Destroying skybox."); *skybox = None; diff --git a/wayvr/src/backend/openxr/skybox.rs b/wayvr/src/backend/openxr/skybox.rs index 06b2e970..1ca0c072 100644 --- a/wayvr/src/backend/openxr/skybox.rs +++ b/wayvr/src/backend/openxr/skybox.rs @@ -29,6 +29,7 @@ pub(super) struct Skybox { grid: Option, grid_pose: xr::Posef, grid_color_scale_bias_khr: Option>, + current_skybox: Arc, } impl Skybox { @@ -66,6 +67,12 @@ impl Skybox { } } + let current_skybox = if maybe_image.is_some() { + app.session.config.skybox_texture.clone() + } else { + "".into() + }; + if maybe_image.is_none() { let p = include_bytes!("../../res/table_mountain_2.dds"); maybe_image = Some(command_buffer.upload_image_dds(p.as_slice())?); @@ -99,9 +106,14 @@ impl Skybox { grid: None, grid_pose: translation_rotation_to_posef(Vec3A::ZERO, Quat::from_rotation_x(PI * -0.5)), grid_color_scale_bias_khr, + current_skybox, }) } + pub(super) fn needs_recreate(&self, app: &AppState) -> bool { + *self.current_skybox != *app.session.config.skybox_texture + } + fn prepare_sky<'a>( &'a mut self, xr: &'a XrState, diff --git a/wayvr/src/backend/task.rs b/wayvr/src/backend/task.rs index 002881e5..2bc86886 100644 --- a/wayvr/src/backend/task.rs +++ b/wayvr/src/backend/task.rs @@ -56,7 +56,7 @@ pub enum OpenVrTask { #[cfg(feature = "openxr")] pub enum OpenXrTask { - SettingsChanged, + EnvironmentChanged, } pub enum PlayspaceTask { diff --git a/wayvr/src/overlays/dashboard.rs b/wayvr/src/overlays/dashboard.rs index 4d0b7958..9dc2f88e 100644 --- a/wayvr/src/overlays/dashboard.rs +++ b/wayvr/src/overlays/dashboard.rs @@ -16,7 +16,7 @@ use wgui::{ widget::EventResult, }; use wlx_common::{ - dash_interface::{self, DashInterface, RecenterMode}, + dash_interface::{self, ConfigChangeKind, DashInterface, RecenterMode}, locale::WayVRLangProvider, overlays::{BackendAttrib, BackendAttribValue}, }; @@ -444,16 +444,22 @@ impl DashInterface for DashInterfaceLive { &mut data.session.config } - fn config_changed(&mut self, data: &mut AppState) { + fn config_changed(&mut self, data: &mut AppState, kind: ConfigChangeKind) { data.session.config_dirty = true; - #[cfg(feature = "openxr")] - { - use crate::backend::task::OpenXrTask; - data.tasks - .enqueue(TaskType::OpenXR(OpenXrTask::SettingsChanged)); + + match kind { + ConfigChangeKind::OverlayConfig => data + .tasks + .enqueue(TaskType::Overlay(OverlayTask::SettingsChanged)), + ConfigChangeKind::EnvironmentBlend => { + #[cfg(feature = "openxr")] + { + use crate::backend::task::OpenXrTask; + data.tasks + .enqueue(TaskType::OpenXR(OpenXrTask::EnvironmentChanged)); + } + } } - data.tasks - .enqueue(TaskType::Overlay(OverlayTask::SettingsChanged)); } fn restart(&mut self, _data: &mut AppState) { diff --git a/wlx-common/src/dash_interface.rs b/wlx-common/src/dash_interface.rs index 7f80d557..bf9544ae 100644 --- a/wlx-common/src/dash_interface.rs +++ b/wlx-common/src/dash_interface.rs @@ -65,9 +65,15 @@ pub trait DashInterface { fn recenter_playspace(&mut self, data: &mut T, mode: RecenterMode) -> anyhow::Result<()>; fn desktop_finder<'a>(&'a mut self, data: &'a mut T) -> &'a mut DesktopFinder; fn general_config<'a>(&'a mut self, data: &'a mut T) -> &'a mut GeneralConfig; - fn config_changed(&mut self, data: &mut T); + fn config_changed(&mut self, data: &mut T, kind: ConfigChangeKind); fn restart(&mut self, data: &mut T); fn toggle_dashboard(&mut self, data: &mut T); } +#[derive(Clone, Copy)] +pub enum ConfigChangeKind { + OverlayConfig, + EnvironmentBlend, +} + pub type BoxDashInterface = Box>; diff --git a/wlx-common/src/dash_interface_emulated.rs b/wlx-common/src/dash_interface_emulated.rs index 3526de94..d2479e86 100644 --- a/wlx-common/src/dash_interface_emulated.rs +++ b/wlx-common/src/dash_interface_emulated.rs @@ -5,7 +5,7 @@ use wayvr_ipc::{ use crate::{ config::GeneralConfig, - dash_interface::{self, DashInterface, RecenterMode}, + dash_interface::{self, ConfigChangeKind, DashInterface, RecenterMode}, desktop_finder::DesktopFinder, gen_id, }; @@ -230,7 +230,7 @@ impl DashInterface<()> for DashInterfaceEmulated { &mut self.general_config } - fn config_changed(&mut self, _: &mut ()) {} + fn config_changed(&mut self, _: &mut (), _: ConfigChangeKind) {} fn restart(&mut self, _data: &mut ()) {}