reconfigure_environment_blend to handle chroma + skybox + alpha

This commit is contained in:
galister 2026-04-17 14:44:25 +09:00
parent 0d8937ff80
commit 266b0fd507
9 changed files with 63 additions and 32 deletions

View File

@ -18,7 +18,7 @@ use wgui::{
}; };
use wlx_common::{ use wlx_common::{
config::GeneralConfig, config::GeneralConfig,
dash_interface::{self, MonadoDumpSessionFrame}, dash_interface::{self, ConfigChangeKind, MonadoDumpSessionFrame},
}; };
use crate::{ use crate::{
@ -175,7 +175,7 @@ impl<T> Tab<T> for TabMonado<T> {
Task::GeneralSettingsChromaUpdate => { Task::GeneralSettingsChromaUpdate => {
if let Subtab::GeneralSettings(tab) = &mut self.subtab { if let Subtab::GeneralSettings(tab) = &mut self.subtab {
tab.chroma_update(frontend.interface.general_config(data)); 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), Task::SetBrightness(brightness) => self.set_brightness(frontend, data, brightness),

View File

@ -19,7 +19,7 @@ use wgui::{
}, },
windowing::context_menu::{self, Blueprint, ContextMenu, TickResult}, 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::{ use crate::{
frontend::{Frontend, FrontendTask, FrontendTasks}, frontend::{Frontend, FrontendTask, FrontendTasks},
@ -224,7 +224,7 @@ impl<T> Tab<T> for TabSettings<T> {
// Notify overlays of the change // Notify overlays of the change
if changed { if changed {
frontend.interface.config_changed(data); frontend.interface.config_changed(data, ConfigChangeKind::OverlayConfig);
} }
Ok(()) Ok(())

View File

@ -212,9 +212,9 @@ pub(super) fn posef_to_transform(pose: &xr::Posef) -> Affine3A {
Affine3A::from_rotation_translation(rotation, translation) 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 { let Some(monado) = app.monado_state.as_ref() else {
return; return false;
}; };
let params = &app.session.config.chroma_key_params; let params = &app.session.config.chroma_key_params;
@ -226,6 +226,10 @@ pub(super) fn reconfigure_chroma_key(app: &AppState) {
params.curve, params.curve,
params.despill, 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
} }

View File

@ -17,7 +17,7 @@ use crate::{
backend::{ backend::{
BackendError, XrBackend, BackendError, XrBackend,
input::interact, 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}, task::{OpenXrTask, OverlayTask, TaskType},
}, },
config::{save_settings, save_state}, config::{save_settings, save_state},
@ -94,8 +94,6 @@ pub fn openxr_run(show_by_default: bool, headless: bool) -> Result<(), BackendEr
.ok() .ok()
}); });
reconfigure_chroma_key(&app);
let mut blocker = app let mut blocker = app
.monado_state .monado_state
.as_ref() .as_ref()
@ -482,7 +480,7 @@ pub fn openxr_run(show_by_default: bool, headless: bool) -> Result<(), BackendEr
} }
} }
TaskType::OpenXR(task) => { TaskType::OpenXR(task) => {
if matches!(task, OpenXrTask::SettingsChanged) { if matches!(task, OpenXrTask::EnvironmentChanged) {
reconfigure_environment_blend( reconfigure_environment_blend(
&app, &app,
&xr_state, &xr_state,
@ -491,7 +489,6 @@ pub fn openxr_run(show_by_default: bool, headless: bool) -> Result<(), BackendEr
&mut environment_blend_mode, &mut environment_blend_mode,
main_session_visible, main_session_visible,
); );
reconfigure_chroma_key(&app);
} }
} }
#[cfg(feature = "openvr")] #[cfg(feature = "openvr")]
@ -532,6 +529,9 @@ pub(super) enum CompositionLayer<'a> {
Equirect2(xr::CompositionLayerEquirect2KHR<'a, xr::Vulkan>), 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( fn reconfigure_environment_blend(
app: &AppState, app: &AppState,
xr_state: &XrState, xr_state: &XrState,
@ -540,9 +540,11 @@ fn reconfigure_environment_blend(
environment_blend_mode: &mut xr::EnvironmentBlendMode, environment_blend_mode: &mut xr::EnvironmentBlendMode,
main_session_visible: bool, main_session_visible: bool,
) { ) {
let has_chroma_key = try_apply_chroma_key(app);
*environment_blend_mode = { *environment_blend_mode = {
if modes.contains(&xr::EnvironmentBlendMode::ALPHA_BLEND) if modes.contains(&xr::EnvironmentBlendMode::ALPHA_BLEND)
&& app.session.config.use_passthrough && (app.session.config.use_passthrough || has_chroma_key)
{ {
xr::EnvironmentBlendMode::ALPHA_BLEND xr::EnvironmentBlendMode::ALPHA_BLEND
} else { } else {
@ -554,13 +556,14 @@ fn reconfigure_environment_blend(
&& app.session.config.use_skybox && app.session.config.use_skybox
&& !main_session_visible; && !main_session_visible;
if want_skybox == skybox.is_some() {
return;
}
if want_skybox { if want_skybox {
log::debug!("Allocating skybox."); if let Some(curr_skybox) = skybox.as_ref() {
*skybox = create_skybox(xr_state, app); if curr_skybox.needs_recreate(app) {
*skybox = None;
log::debug!("Allocating skybox.");
*skybox = create_skybox(xr_state, app);
}
}
} else { } else {
log::debug!("Destroying skybox."); log::debug!("Destroying skybox.");
*skybox = None; *skybox = None;

View File

@ -29,6 +29,7 @@ pub(super) struct Skybox {
grid: Option<WlxSwapchain>, grid: Option<WlxSwapchain>,
grid_pose: xr::Posef, grid_pose: xr::Posef,
grid_color_scale_bias_khr: Option<Box<xr::sys::CompositionLayerColorScaleBiasKHR>>, grid_color_scale_bias_khr: Option<Box<xr::sys::CompositionLayerColorScaleBiasKHR>>,
current_skybox: Arc<str>,
} }
impl Skybox { 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() { if maybe_image.is_none() {
let p = include_bytes!("../../res/table_mountain_2.dds"); let p = include_bytes!("../../res/table_mountain_2.dds");
maybe_image = Some(command_buffer.upload_image_dds(p.as_slice())?); maybe_image = Some(command_buffer.upload_image_dds(p.as_slice())?);
@ -99,9 +106,14 @@ impl Skybox {
grid: None, grid: None,
grid_pose: translation_rotation_to_posef(Vec3A::ZERO, Quat::from_rotation_x(PI * -0.5)), grid_pose: translation_rotation_to_posef(Vec3A::ZERO, Quat::from_rotation_x(PI * -0.5)),
grid_color_scale_bias_khr, 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>( fn prepare_sky<'a>(
&'a mut self, &'a mut self,
xr: &'a XrState, xr: &'a XrState,

View File

@ -56,7 +56,7 @@ pub enum OpenVrTask {
#[cfg(feature = "openxr")] #[cfg(feature = "openxr")]
pub enum OpenXrTask { pub enum OpenXrTask {
SettingsChanged, EnvironmentChanged,
} }
pub enum PlayspaceTask { pub enum PlayspaceTask {

View File

@ -16,7 +16,7 @@ use wgui::{
widget::EventResult, widget::EventResult,
}; };
use wlx_common::{ use wlx_common::{
dash_interface::{self, DashInterface, RecenterMode}, dash_interface::{self, ConfigChangeKind, DashInterface, RecenterMode},
locale::WayVRLangProvider, locale::WayVRLangProvider,
overlays::{BackendAttrib, BackendAttribValue}, overlays::{BackendAttrib, BackendAttribValue},
}; };
@ -444,16 +444,22 @@ impl DashInterface<AppState> for DashInterfaceLive {
&mut data.session.config &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; data.session.config_dirty = true;
#[cfg(feature = "openxr")]
{ match kind {
use crate::backend::task::OpenXrTask; ConfigChangeKind::OverlayConfig => data
data.tasks .tasks
.enqueue(TaskType::OpenXR(OpenXrTask::SettingsChanged)); .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) { fn restart(&mut self, _data: &mut AppState) {

View File

@ -65,9 +65,15 @@ pub trait DashInterface<T> {
fn recenter_playspace(&mut self, data: &mut T, mode: RecenterMode) -> anyhow::Result<()>; 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 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 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 restart(&mut self, data: &mut T);
fn toggle_dashboard(&mut self, data: &mut T); fn toggle_dashboard(&mut self, data: &mut T);
} }
#[derive(Clone, Copy)]
pub enum ConfigChangeKind {
OverlayConfig,
EnvironmentBlend,
}
pub type BoxDashInterface<T> = Box<dyn DashInterface<T>>; pub type BoxDashInterface<T> = Box<dyn DashInterface<T>>;

View File

@ -5,7 +5,7 @@ use wayvr_ipc::{
use crate::{ use crate::{
config::GeneralConfig, config::GeneralConfig,
dash_interface::{self, DashInterface, RecenterMode}, dash_interface::{self, ConfigChangeKind, DashInterface, RecenterMode},
desktop_finder::DesktopFinder, desktop_finder::DesktopFinder,
gen_id, gen_id,
}; };
@ -230,7 +230,7 @@ impl DashInterface<()> for DashInterfaceEmulated {
&mut self.general_config &mut self.general_config
} }
fn config_changed(&mut self, _: &mut ()) {} fn config_changed(&mut self, _: &mut (), _: ConfigChangeKind) {}
fn restart(&mut self, _data: &mut ()) {} fn restart(&mut self, _data: &mut ()) {}