feat(flatscreen): add option to make flatscreen window transparent

Signed-off-by: Schmarni <marnistromer@gmail.com>
This commit is contained in:
Schmarni
2025-08-13 05:16:21 +02:00
parent 127641064a
commit c8d9af5217
3 changed files with 81 additions and 59 deletions

4
Cargo.lock generated
View File

@@ -1108,7 +1108,7 @@ dependencies = [
[[package]] [[package]]
name = "bevy_mod_openxr" name = "bevy_mod_openxr"
version = "0.3.0" version = "0.3.0"
source = "git+https://github.com/Schmarni-Dev/bevy_openxr?branch=vk_exts#a60db3da6cfa48afb3345c3c370fa26578bda341" source = "git+https://github.com/awtterpip/bevy_oxr#a988d731875072b0b56cf0e644b274d8de5051f4"
dependencies = [ dependencies = [
"android_system_properties", "android_system_properties",
"ash", "ash",
@@ -1126,7 +1126,7 @@ dependencies = [
[[package]] [[package]]
name = "bevy_mod_xr" name = "bevy_mod_xr"
version = "0.3.0" version = "0.3.0"
source = "git+https://github.com/Schmarni-Dev/bevy_openxr?branch=vk_exts#a60db3da6cfa48afb3345c3c370fa26578bda341" source = "git+https://github.com/awtterpip/bevy_oxr#a988d731875072b0b56cf0e644b274d8de5051f4"
dependencies = [ dependencies = [
"bevy", "bevy",
] ]

View File

@@ -51,8 +51,8 @@ opt-level = 3
opt-level = 3 opt-level = 3
[patch.crates-io] [patch.crates-io]
bevy_mod_openxr = { git = "https://github.com/Schmarni-Dev/bevy_openxr", branch = "vk_exts" } bevy_mod_openxr = { git = "https://github.com/awtterpip/bevy_oxr" }
bevy_mod_xr = { git = "https://github.com/Schmarni-Dev/bevy_openxr", branch = "vk_exts" } bevy_mod_xr = { git = "https://github.com/awtterpip/bevy_oxr" }
bevy_gltf = { git = "https://github.com/Schmarni-Dev/bevy", branch = "gltf_backport" } bevy_gltf = { git = "https://github.com/Schmarni-Dev/bevy", branch = "gltf_backport" }
# TODO: figure out how to not need this horrifing patch # TODO: figure out how to not need this horrifing patch
wgpu = { git = "https://github.com/Schmarni-Dev/wgpu", branch = "bad_dmabuf_workaround" } wgpu = { git = "https://github.com/Schmarni-Dev/wgpu", branch = "bad_dmabuf_workaround" }

View File

@@ -27,6 +27,7 @@ use bevy::pbr::PbrPlugin;
use bevy::render::settings::{Backends, RenderCreation, WgpuSettings}; use bevy::render::settings::{Backends, RenderCreation, WgpuSettings};
use bevy::render::{RenderDebugFlags, RenderPlugin}; use bevy::render::{RenderDebugFlags, RenderPlugin};
use bevy::scene::ScenePlugin; use bevy::scene::ScenePlugin;
use bevy::window::{CompositeAlphaMode, PresentMode};
use bevy::winit::{WakeUp, WinitPlugin}; use bevy::winit::{WakeUp, WinitPlugin};
use bevy_dmabuf::import::DmabufImportPlugin; use bevy_dmabuf::import::DmabufImportPlugin;
use bevy_mod_openxr::action_set_attaching::OxrActionAttachingPlugin; use bevy_mod_openxr::action_set_attaching::OxrActionAttachingPlugin;
@@ -34,7 +35,6 @@ use bevy_mod_openxr::action_set_syncing::OxrActionSyncingPlugin;
use bevy_mod_openxr::add_xr_plugins; use bevy_mod_openxr::add_xr_plugins;
use bevy_mod_openxr::exts::OxrExtensions; use bevy_mod_openxr::exts::OxrExtensions;
use bevy_mod_openxr::features::overlay::OxrOverlaySettings; use bevy_mod_openxr::features::overlay::OxrOverlaySettings;
use bevy_mod_openxr::features::passthrough::OxrPassthroughPlugin;
use bevy_mod_openxr::graphics::{GraphicsBackend, OxrManualGraphicsConfig}; use bevy_mod_openxr::graphics::{GraphicsBackend, OxrManualGraphicsConfig};
use bevy_mod_openxr::init::{OxrInitPlugin, should_run_frame_loop}; use bevy_mod_openxr::init::{OxrInitPlugin, should_run_frame_loop};
use bevy_mod_openxr::reference_space::OxrReferenceSpacePlugin; use bevy_mod_openxr::reference_space::OxrReferenceSpacePlugin;
@@ -86,6 +86,10 @@ struct CliArgs {
#[clap(short, long, action)] #[clap(short, long, action)]
flatscreen: bool, flatscreen: bool,
/// Creates a transparent window fot the flatscreen mode
#[clap(short, long, action)]
transparent_flatscreen: bool,
/// If monado insists on emulating them, set this flag...we want the raw input /// If monado insists on emulating them, set this flag...we want the raw input
#[clap(long)] #[clap(long)]
disable_controllers: bool, disable_controllers: bool,
@@ -323,7 +327,8 @@ fn bevy_loop(
.disable::<ScheduleRunnerPlugin>() .disable::<ScheduleRunnerPlugin>()
.add(FlatscreenInputPlugin); .add(FlatscreenInputPlugin);
} }
app.add_plugins(if !args.flatscreen { app.add_plugins(
if !args.flatscreen {
add_xr_plugins(plugins) add_xr_plugins(plugins)
.set(OxrInitPlugin { .set(OxrInitPlugin {
app_info: AppInfo { app_info: AppInfo {
@@ -350,8 +355,6 @@ fn bevy_loop(
default_primary_ref_space: ReferenceSpaceType::LOCAL, default_primary_ref_space: ReferenceSpaceType::LOCAL,
}) })
// Disable a bunch of unneeded plugins // Disable a bunch of unneeded plugins
// this plugin uses the fb extention, blend mode still works
.disable::<OxrPassthroughPlugin>()
// we don't do any action stuff that needs to integrate with the ecosystem // we don't do any action stuff that needs to integrate with the ecosystem
.disable::<OxrActionAttachingPlugin>() .disable::<OxrActionAttachingPlugin>()
.disable::<OxrActionSyncingPlugin>() .disable::<OxrActionSyncingPlugin>()
@@ -359,11 +362,26 @@ fn bevy_loop(
// enable a event // enable a event
plugins = plugins.add(XrSessionPlugin { auto_handle: false }); plugins = plugins.add(XrSessionPlugin { auto_handle: false });
bevy_dmabuf::wgpu_init::add_dmabuf_init_plugin(plugins) bevy_dmabuf::wgpu_init::add_dmabuf_init_plugin(plugins)
}); }
.set(WindowPlugin {
primary_window: Some(Window {
transparent: args.transparent_flatscreen,
present_mode: PresentMode::AutoNoVsync,
composite_alpha_mode: if args.transparent_flatscreen {
CompositeAlphaMode::PreMultiplied
} else {
CompositeAlphaMode::Inherit
},
title: "StardustXR server flatscreen mode".to_string(),
..default()
}),
..default()
}),
);
app.add_plugins(bevy_sk::hand::HandPlugin); app.add_plugins(bevy_sk::hand::HandPlugin);
// app.add_plugins(HandGizmosPlugin); // app.add_plugins(HandGizmosPlugin);
app.world_mut().resource_mut::<AmbientLight>().brightness = 2000.0; app.world_mut().resource_mut::<AmbientLight>().brightness = 1000.0;
if let Some(priority) = args.overlay_priority { if let Some(priority) = args.overlay_priority {
app.insert_resource(OxrOverlaySettings { app.insert_resource(OxrOverlaySettings {
session_layer_placement: priority, session_layer_placement: priority,
@@ -371,11 +389,11 @@ fn bevy_loop(
}); });
} }
app.insert_resource(OxrSessionConfig { app.insert_resource(OxrSessionConfig {
blend_modes: Some(vec![ blend_mode_preference: vec![
EnvironmentBlendMode::ALPHA_BLEND, EnvironmentBlendMode::ALPHA_BLEND,
EnvironmentBlendMode::ADDITIVE, EnvironmentBlendMode::ADDITIVE,
EnvironmentBlendMode::OPAQUE, EnvironmentBlendMode::OPAQUE,
]), ],
..default() ..default()
}); });
let mut pre_frame_wait = Schedule::new(PreFrameWait); let mut pre_frame_wait = Schedule::new(PreFrameWait);
@@ -406,7 +424,7 @@ fn bevy_loop(
app.add_systems(PostStartup, move || { app.add_systems(PostStartup, move || {
ready_notifier.notify_waiters(); ready_notifier.notify_waiters();
}); });
app.add_systems(Update, (add_oit, update_cameras)); app.add_observer(cam_observer);
app.add_systems( app.add_systems(
XrFirst, XrFirst,
xr_step xr_step
@@ -416,13 +434,18 @@ fn bevy_loop(
app.run() app.run()
} }
fn update_cameras(mut camera: Query<&mut Projection, (With<Camera3d>,)>) {
for mut projection in &mut camera { fn cam_observer(
trigger: Trigger<OnAdd, Camera3d>,
mut query: Query<(&mut Projection, &mut Msaa), With<Camera3d>>,
) {
let Ok((mut projection, mut msaa)) = query.get_mut(trigger.target()) else {
return;
};
info!("modifying cam");
match projection.deref_mut() { match projection.deref_mut() {
Projection::Perspective(perspective_projection) => perspective_projection.near = 0.003, Projection::Perspective(perspective_projection) => perspective_projection.near = 0.003,
Projection::Orthographic(orthographic_projection) => { Projection::Orthographic(orthographic_projection) => orthographic_projection.near = 0.003,
orthographic_projection.near = 0.003
}
Projection::Custom(custom_projection) => { Projection::Custom(custom_projection) => {
if let Some(xr) = custom_projection.get_mut::<XrProjection>() { if let Some(xr) = custom_projection.get_mut::<XrProjection>() {
xr.near = 0.003 xr.near = 0.003
@@ -431,7 +454,7 @@ fn update_cameras(mut camera: Query<&mut Projection, (With<Camera3d>,)>) {
} }
} }
} }
} *msaa = Msaa::Off;
} }
fn add_oit( fn add_oit(
@@ -450,8 +473,7 @@ fn add_oit(
.insert(OrderIndependentTransparencySettings { .insert(OrderIndependentTransparencySettings {
layer_count: 4, layer_count: 4,
alpha_threshold: 0.00, alpha_threshold: 0.00,
}) });
.insert(Msaa::Off);
} }
} }