Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vehicle example #98

Merged
merged 4 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion blade-graphics/src/vulkan/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ impl super::CommandEncoder {

pub fn present(&mut self, frame: super::Frame) {
assert_eq!(self.present, None);
let wa = &self.device.workarounds;
self.present = Some(super::Presentation {
image_index: frame.image_index,
acquire_semaphore: frame.acquire_semaphore,
Expand All @@ -313,12 +314,13 @@ impl super::CommandEncoder {
base_array_layer: 0,
layer_count: 1,
})
.src_access_mask(vk::AccessFlags::MEMORY_WRITE | wa.extra_sync_src_access)
.build();
unsafe {
self.device.core.cmd_pipeline_barrier(
self.buffers[0].raw,
vk::PipelineStageFlags::TOP_OF_PIPE,
vk::PipelineStageFlags::ALL_COMMANDS,
vk::PipelineStageFlags::BOTTOM_OF_PIPE,
vk::DependencyFlags::empty(),
&[],
&[],
Expand Down
17 changes: 8 additions & 9 deletions blade-graphics/src/vulkan/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ struct AdapterCapabilities {
shader_info: bool,
}

#[derive(Debug)]
struct SystemBugs {
/// https://gitlab.freedesktop.org/mesa/mesa/-/issues/4688
intel_unable_to_present_on_xorg: bool,
intel_unable_to_present: bool,
}

// See https://github.com/canonical/nvidia-prime/blob/587c5012be9dddcc17ab4d958f10a24fa3342b4d/prime-select#L56
Expand Down Expand Up @@ -110,8 +111,7 @@ unsafe fn inspect_adapter(
log::warn!("Rejected for not presenting to the window surface");
return None;
}
if bugs.intel_unable_to_present_on_xorg
&& properties2_khr.properties.vendor_id == db::intel::VENDOR
if bugs.intel_unable_to_present && properties2_khr.properties.vendor_id == db::intel::VENDOR
{
log::warn!("Rejecting Intel for not presenting when Nvidia is present (on Linux)");
return None;
Expand Down Expand Up @@ -341,14 +341,13 @@ impl super::Context {
entry.create_instance(&create_info, None).unwrap()
};

let is_xorg = match surface_handles {
Some((_, raw_window_handle::RawDisplayHandle::Xlib(_))) => true,
Some((_, raw_window_handle::RawDisplayHandle::Xcb(_))) => true,
_ => false,
};
let bugs = SystemBugs {
intel_unable_to_present_on_xorg: is_xorg && is_nvidia_prime_forced(),
//Note: this is somewhat broad across X11/Wayland and different drivers.
// It could be narrower, but at the end of the day if the user forced Prime
// for GLX it should be safe to assume they want it for Vulkan as well.
intel_unable_to_present: is_nvidia_prime_forced(),
};
log::debug!("Bugs {:#?}", bugs);

let vk_surface = surface_handles.map(|(rwh, rdh)| {
ash_window::create_surface(&entry, &core_instance, rdh, rwh, None).unwrap()
Expand Down
3 changes: 2 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ Blade is an innovative rendering solution for Rust. It starts with a lean [low-l
## Examples

![scene editor](../blade-egui/etc/scene-editor.jpg)
![particles example](../blade-graphics/etc/particles.png)
![particle example](../blade-graphics/etc/particles.png)
![vehicle example](vehicle-colliders.jpg)
![sponza scene](../blade-render/etc/sponza.jpg)

## Instructions
Expand Down
Binary file added docs/raycraft-colliders.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 8 additions & 7 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Blade Examples

| Example | graphics | macros | egui | asset | render | lib |
| --------- | ----------- | ------ | ------ | ------ | ------ | --- |
| mini | :star: | | | | | |
| init | :star: | :star: | | | | |
| ray-query | :star: (RT) | :star: | | | | |
| particle | :star: | :star: | :star: | | | |
| scene | :star: (RT) | :star: | :star: | :star: | :star: | |
| Example | graphics | macros | egui | asset | render | lib |
| --------- | ----------- | ------ | ------ | ------ | ------ | ------ |
| mini | :star: | | | | | |
| init | :star: | :star: | | | | |
| ray-query | :star: (RT) | :star: | | | | |
| particle | :star: | :star: | :star: | | | |
| scene | :star: (RT) | :star: | :star: | :star: | :star: | |
| vehicle | | | | | | :star: |
71 changes: 71 additions & 0 deletions examples/vehicle/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#[derive(serde::Deserialize)]
pub struct Body {
pub visual: blade::config::Visual,
pub collider: blade::config::Collider,
}

#[derive(serde::Deserialize)]
pub struct Wheel {
pub visual: blade::config::Visual,
pub collider: blade::config::Collider,
}

#[derive(Default, serde::Deserialize)]
pub struct Motor {
pub limit: f32,
pub stiffness: f32,
pub damping: f32,
}

#[derive(serde::Deserialize)]
pub struct Axle {
/// Side offset for each wheel.
pub x_wheels: Vec<f32>,
/// Height offset from the body.
pub y: f32,
/// Forward offset from the body.
pub z: f32,
#[serde(default)]
pub suspension: Motor,
#[serde(default)]
pub steering: Motor,
}

fn default_additional_mass() -> blade::config::AdditionalMass {
blade::config::AdditionalMass {
density: 0.0,
shape: blade::config::Shape::Ball { radius: 0.0 },
}
}

#[derive(serde::Deserialize)]
pub struct Vehicle {
pub body: Body,
pub wheel: Wheel,
#[serde(default = "default_additional_mass")]
pub suspender: blade::config::AdditionalMass,
pub drive_factor: f32,
pub jump_impulse: f32,
pub roll_impulse: f32,
pub axles: Vec<Axle>,
}

#[derive(serde::Deserialize)]
pub struct Level {
#[serde(default)]
pub environment: String,
pub gravity: f32,
pub average_luminocity: f32,
pub spawn_pos: [f32; 3],
pub ground: blade::config::Object,
}

#[derive(serde::Deserialize)]
pub struct Camera {
pub azimuth: f32,
pub altitude: f32,
pub distance: f32,
pub speed: f32,
pub target: [f32; 3],
pub fov: f32,
}
Binary file added examples/vehicle/data/ground.glb
Binary file not shown.
25 changes: 25 additions & 0 deletions examples/vehicle/data/level.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
(
environment: "",
gravity: 9.81,
average_luminocity: 0.1,
spawn_pos: (0, 2, 0),
ground: (
name: "ground",
visuals: [
(
model: "ground.glb",
pos: (0, 1, 0),
scale: 60,
),
],
colliders: [
(
density: 1.0,
friction: 1.0,
shape: Cuboid(
half: (1000, 1.0, 1000),
),
),
],
),
)
Binary file added examples/vehicle/data/raceFuture-body.glb
Binary file not shown.
65 changes: 65 additions & 0 deletions examples/vehicle/data/raceFuture.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
(
body: (
visual: (
model: "raceFuture-body.glb",
pos: (0, -0.3, 0.1),
rot: (0, 180, 0),
),
collider: (
density: 100.0,
shape: Cuboid(
half: (0.65, 0.2, 1.2),
),
),
),
wheel: (
visual: (
model: "wheelRacing.glb",
),
collider: (
density: 100.0,
friction: 1.0,
rot: (0, 0, 90),
shape: Cylinder(
half_height: 0.1,
radius: 0.28,
),
),
),
suspender: (
density: 100.0,
shape: Ball(
radius: 0.28,
),
),
drive_factor: 100.0,
jump_impulse: 10,
roll_impulse: 10,
axles: [
(
x_wheels: [-0.5, 0.5],
y: -0.1,
z: 0.7,
suspension: (
limit: 0.02,
stiffness: 100000,
damping: 10000,
),
steering: (
limit: 30,
stiffness: 100000,
damping: 10000,
),
),
(
x_wheels: [-0.5, 0.5],
y: -0.1,
z: -0.8,
suspension: (
limit: 0.03,
stiffness: 100000,
damping: 10000,
),
),
],
)
Binary file added examples/vehicle/data/wheelRacing.glb
Binary file not shown.
Loading
Loading