diff --git a/src/main.rs b/src/main.rs index e205e0d..171f361 100644 --- a/src/main.rs +++ b/src/main.rs @@ -51,8 +51,8 @@ use nodes::drawable::model::ModelNodePlugin; use nodes::drawable::text::TextNodePlugin; use nodes::spatial::SpatialNodePlugin; use objects::input::mouse_pointer::FlatscreenInputPlugin; -use objects::input::sk_controller::ControllerPlugin; -use objects::input::sk_hand::HandPlugin; +use objects::input::oxr_controller::ControllerPlugin; +use objects::input::oxr_hand::HandPlugin; use objects::play_space::PlaySpacePlugin; use openxr::{EnvironmentBlendMode, ReferenceSpaceType}; use session::{launch_start, save_session}; @@ -101,10 +101,6 @@ struct CliArgs { /// Restore the session with the given ID (or `latest`), ignoring the startup script. Sessions are stored in directories at `~/.local/state/stardust/`. #[clap(id = "SESSION_ID", long = "restore", action)] restore: Option, - /// this should fix nvidia issues, it'll only help on driver 565+ - /// and only if running under wayland, probably - #[clap(long)] - nvidia: bool, } pub type BevyMaterial = StandardMaterial; @@ -142,20 +138,6 @@ async fn main() -> Result { let cli_args = CliArgs::parse(); - if cli_args.nvidia && !cli_args.flatscreen { - // Only call this while singlethreaded since it can/will cause raceconditions with other - // functions reading or writing from the env - unsafe { - std::env::set_var("__GLX_VENDOR_LIBRARY_NAME", "mesa"); - std::env::set_var( - "__EGL_VENDOR_LIBRARY_FILENAMES", - "/usr/share/glvnd/egl_vendor.d/50_mesa.json", - ); - std::env::set_var("MESA_LOADER_DRIVER_OVERRIDE", "zink"); - std::env::set_var("GALLIUM_DRIVER", "zink"); - } - } - let socket_path = server::get_free_socket_path().expect("Unable to find a free stardust socket path"); STARDUST_INSTANCE.set(socket_path.file_name().unwrap().to_string_lossy().into_owned()).expect("Someone hasn't done their job, yell at Nova because how is this set multiple times what the hell"); diff --git a/src/nodes/drawable/assets/shaders/shader_unlit_gamma.hlsl.sks b/src/nodes/drawable/assets/shaders/shader_unlit_gamma.hlsl.sks deleted file mode 100644 index a38499d..0000000 Binary files a/src/nodes/drawable/assets/shaders/shader_unlit_gamma.hlsl.sks and /dev/null differ diff --git a/src/nodes/drawable/assets/shaders/shader_unlit_simula.hlsl.sks b/src/nodes/drawable/assets/shaders/shader_unlit_simula.hlsl.sks deleted file mode 100644 index 707dfed..0000000 Binary files a/src/nodes/drawable/assets/shaders/shader_unlit_simula.hlsl.sks and /dev/null differ diff --git a/src/nodes/drawable/mod.rs b/src/nodes/drawable/mod.rs index 2d36859..5c250d0 100644 --- a/src/nodes/drawable/mod.rs +++ b/src/nodes/drawable/mod.rs @@ -1,6 +1,5 @@ pub mod lines; pub mod model; -// pub mod shaders; pub mod text; use self::{lines::Lines, model::Model, text::Text}; diff --git a/src/nodes/drawable/shaders.rs b/src/nodes/drawable/shaders.rs deleted file mode 100644 index 2021453..0000000 --- a/src/nodes/drawable/shaders.rs +++ /dev/null @@ -1,5 +0,0 @@ -// Simula shader with fancy lanzcos sampling -pub const UNLIT_SHADER_BYTES: &[u8] = include_bytes!("assets/shaders/shader_unlit_gamma.hlsl.sks"); - -// Simula shader with fancy lanzcos sampling -pub const PANEL_SHADER_BYTES: &[u8] = include_bytes!("assets/shaders/shader_unlit_simula.hlsl.sks"); diff --git a/src/nodes/drawable/shaders_src/shader_unlit_gamma.hlsl b/src/nodes/drawable/shaders_src/shader_unlit_gamma.hlsl deleted file mode 100644 index 3e63104..0000000 --- a/src/nodes/drawable/shaders_src/shader_unlit_gamma.hlsl +++ /dev/null @@ -1,39 +0,0 @@ -#include "stereokit.hlsli" - -//--name = sk/unlit -//--diffuse = white -//--uv_offset = 0.0, 0.0 -//--uv_scale = 1.0, 1.0 -Texture2D diffuse : register(t0); -SamplerState diffuse_s : register(s0); -float2 uv_scale; -float2 uv_offset; - -struct vsIn { - float4 pos : SV_Position; - float3 norm : NORMAL0; - float2 uv : TEXCOORD0; -}; -struct psIn { - float4 pos : SV_POSITION; - float2 uv : TEXCOORD0; - uint view_id : SV_RenderTargetArrayIndex; -}; - -psIn vs(vsIn input, uint id : SV_InstanceID) { - psIn o; - o.view_id = id % sk_view_count; - id = id / sk_view_count; - - float3 world = mul(float4(input.pos.xyz, 1), sk_inst[id].world).xyz; - o.pos = mul(float4(world, 1), sk_viewproj[o.view_id]); - - o.uv = (input.uv + uv_offset) * uv_scale; - return o; -} -float4 ps(psIn input) : SV_TARGET { - float4 col = diffuse.Sample(diffuse_s, input.uv); - col.rgb = pow(col.rgb, float3(2.2)); - - return col; -} diff --git a/src/nodes/drawable/shaders_src/shader_unlit_simula.hlsl b/src/nodes/drawable/shaders_src/shader_unlit_simula.hlsl deleted file mode 100644 index f68a4ba..0000000 --- a/src/nodes/drawable/shaders_src/shader_unlit_simula.hlsl +++ /dev/null @@ -1,119 +0,0 @@ -#include "stereokit.hlsli" - -// Port of https://github.com/SimulaVR/Simula/blob/master/addons/godot-haskell-plugin/TextShader.tres to StereoKit and HLSL. - -//--name = stardust/text_shader -//--diffuse = white -//--uv_offset = 0.0, 0.0 -//--uv_scale = 1.0, 1.0 -//--fcFactor = 1.0 -//--ripple = 4.0 -//--alpha_min = 0.0 -//--alpha_max = 1.0 -Texture2D diffuse : register(t0); -SamplerState diffuse_s : register(s0); -float4 diffuse_i; -float2 uv_scale; -float2 uv_offset; -float fcFactor; -float ripple; -float alpha_min; -float alpha_max; - -struct vsIn { - float4 pos : SV_Position; - float3 norm : NORMAL0; - float2 uv : TEXCOORD0; -}; -struct psIn { - float4 pos : SV_POSITION; - float2 uv : TEXCOORD0; - uint view_id : SV_RenderTargetArrayIndex; -}; - -psIn vs(vsIn input, uint id : SV_InstanceID) { - psIn o; - o.view_id = id % sk_view_count; - id = id / sk_view_count; - - float3 world = mul(float4(input.pos.xyz, 1), sk_inst[id].world).xyz; - o.pos = mul(float4(world, 1), sk_viewproj[o.view_id]); - - o.uv = (input.uv + uv_offset) * uv_scale; - return o; -} - -float map(float value, float min1, float max1, float min2, float max2) { - return min2 + (value - min1) * (max2 - min2) / (max1 - min1); -} - -// float gaussian(float x, float t) { -// float PI = 3.14159265358; -// return exp(-x*x/(2.0 * t*t))/(sqrt(2.0*PI)*t); -// } - -float besselI0(float x) { - return 1.0 + pow(x, 2.0) * (0.25 + pow(x, 2.0) * (0.015625 + pow(x, 2.0) * (0.000434028 + pow(x, 2.0) * (6.78168e-6 + pow(x, 2.0) * (6.78168e-8 + pow(x, 2.0) * (4.7095e-10 + pow(x, 2.0) * (2.40281e-12 + pow(x, 2.0) * (9.38597e-15 + pow(x, 2.0) * (2.8969e-17 + 7.24226e-20 * pow(x, 2.0)))))))))); -} - -float kaiser(float x, float alpha) { - if (x > 1.0) { - return 0.0; - } - return besselI0(alpha * sqrt(1.0-x*x)); -} - -float4 lowpassFilter(Texture2D tex, sampler2D texSampler, float2 uv, float alpha) { - float PI = 3.14159265358; - - float4 q = float4(0.0); - - float2 dx_uv = ddx(uv); - float2 dy_uv = ddy(uv); - //float width = sqrt(max(dot(dx_uv, dx_uv), dot(dy_uv, dy_uv))); - float2 width = abs(float2(dx_uv.x, dy_uv.y)); - - float2 pixelWidth = floor(width * diffuse_i.xy); - float2 aspectRatio = normalize(pixelWidth); - - float2 xyf = uv * diffuse_i.xy; - int2 xy = int2(xyf); - - pixelWidth = clamp(pixelWidth, float2(1.0), float2(2.0)); - - int2 start = xy - int2(pixelWidth); - int2 end = xy + int2(pixelWidth); - - float4 outColor = float4(0.0); - - float qSum = 0.0; - - for (int v = start.y; v <= end.y; v++) { - for (int u = start.x; u <= end.x; u++) { - float kx = fcFactor * (xyf.x - float(u))/pixelWidth.x; - float ky = fcFactor * (xyf.y - float(v))/pixelWidth.y; - - //float lanczosValue = gaussian(kx, fcx); - float lanczosValue = kaiser(sqrt(kx*kx + ky*ky), alpha); - - q += tex.Sample(texSampler, (float2(u, v)+float2(0.5))/diffuse_i.xy) * lanczosValue; - // q += tex.Load(int3(u, v, 0)) * lanczosValue; - qSum += lanczosValue; - } - } - - return q/qSum; -} - -float4 ps(psIn input) : SV_TARGET { - float gamma = 2.2; - // float4 col = diffuse.Sample(diffuse_s, input.uv); - - // float4 col = lowpassFilter(diffuse, diffuse_s, diffuse_i.xy, float2(1.0 - input.uv.x, input.uv.y), ripple); - float4 col = lowpassFilter(diffuse, diffuse_s, input.uv, ripple); - // float4 col = diffuse.Sample(diffuse_s, input.uv); - col.rgb = pow(col.rgb, float3(gamma)); - col.a = map(col.a, 0, 1, alpha_min, alpha_max); - - return col; -} diff --git a/src/objects/input/mod.rs b/src/objects/input/mod.rs index a94542e..d481506 100644 --- a/src/objects/input/mod.rs +++ b/src/objects/input/mod.rs @@ -1,7 +1,7 @@ pub mod eye_pointer; pub mod mouse_pointer; -pub mod sk_controller; -pub mod sk_hand; +pub mod oxr_controller; +pub mod oxr_hand; use crate::nodes::{ fields::{Field, FieldTrait, Ray}, diff --git a/src/objects/input/sk_controller.rs b/src/objects/input/oxr_controller.rs similarity index 97% rename from src/objects/input/sk_controller.rs rename to src/objects/input/oxr_controller.rs index 0ed9104..eceeefe 100644 --- a/src/objects/input/sk_controller.rs +++ b/src/objects/input/oxr_controller.rs @@ -229,8 +229,8 @@ fn setup(instance: Res, connection: Res, mut cmds: set, }; let controllers = Controllers { - left: SkController::new(&connection, HandSide::Left).unwrap(), - right: SkController::new(&connection, HandSide::Right).unwrap(), + left: OxrControllerInput::new(&connection, HandSide::Left).unwrap(), + right: OxrControllerInput::new(&connection, HandSide::Right).unwrap(), }; cmds.insert_resource(controllers); cmds.insert_resource(actions); @@ -256,11 +256,11 @@ struct Actions { } #[derive(Resource)] struct Controllers { - left: SkController, - right: SkController, + left: OxrControllerInput, + right: OxrControllerInput, } -pub struct SkController { +pub struct OxrControllerInput { object_handle: ObjectHandle, input: Arc, side: HandSide, @@ -271,7 +271,7 @@ pub struct SkController { tracked: ObjectHandle, space: Option, } -impl SkController { +impl OxrControllerInput { fn new(connection: &Connection, side: HandSide) -> Result { let path = "/org/stardustxr/Controller/".to_string() + match side { @@ -290,7 +290,7 @@ impl SkController { tip, Datamap::from_typed(ControllerDatamap::default())?, )?; - Ok(SkController { + Ok(OxrControllerInput { object_handle, input, side, diff --git a/src/objects/input/sk_hand.rs b/src/objects/input/oxr_hand.rs similarity index 97% rename from src/objects/input/sk_hand.rs rename to src/objects/input/oxr_hand.rs index 0292da8..ba695d7 100644 --- a/src/objects/input/sk_hand.rs +++ b/src/objects/input/oxr_hand.rs @@ -62,7 +62,7 @@ fn update_hands( }); return; }; - let get_joints = |hand: &mut SkHand| -> Option { + let get_joints = |hand: &mut OxrHandInput| -> Option { let Some(tracker) = hand.tracker.as_ref() else { hand.input.spatial.node().unwrap().set_enabled(false); let handle = hand.tracked.clone(); @@ -148,8 +148,8 @@ fn setup( } }); cmds.insert_resource(Hands { - left: SkHand::new(&connection, HandSide::Left, &mut materials).unwrap(), - right: SkHand::new(&connection, HandSide::Right, &mut materials).unwrap(), + left: OxrHandInput::new(&connection, HandSide::Left, &mut materials).unwrap(), + right: OxrHandInput::new(&connection, HandSide::Right, &mut materials).unwrap(), }); } @@ -164,8 +164,8 @@ fn convert_joint(joint: HandJointLocation) -> Joint { #[derive(Resource)] struct Hands { - left: SkHand, - right: SkHand, + left: OxrHandInput, + right: OxrHandInput, } #[derive(Default, Deserialize, Serialize)] @@ -174,7 +174,7 @@ struct HandDatamap { grab_strength: f32, } -pub struct SkHand { +pub struct OxrHandInput { _node: OwnedNode, palm_spatial: Arc, palm_object: ObjectHandle, @@ -187,7 +187,7 @@ pub struct SkHand { captured: bool, material: Handle, } -impl SkHand { +impl OxrHandInput { pub fn new( connection: &Connection, side: HandSide, @@ -225,7 +225,7 @@ impl SkHand { perceptual_roughness: 1.0, ..default() }); - Ok(SkHand { + Ok(OxrHandInput { _node: node, palm_spatial, palm_object, diff --git a/src/objects/mod.rs b/src/objects/mod.rs index ed0bab6..6c9ecae 100644 --- a/src/objects/mod.rs +++ b/src/objects/mod.rs @@ -10,8 +10,8 @@ use crate::{ }; use glam::{Mat4, vec3}; use input::{ - eye_pointer::EyePointer, mouse_pointer::MousePointer, sk_controller::SkController, - sk_hand::SkHand, + eye_pointer::EyePointer, mouse_pointer::MousePointer, oxr_controller::OxrControllerInput, + oxr_hand::OxrHandInput, }; use parking_lot::RwLock; use play_space::PlaySpaceBounds;