Compare commits

...

2 commits

Author SHA1 Message Date
2805861d16 Update Rust crate rusqlite to 0.34.0 2025-03-10 12:02:31 +00:00
Michael Huebner
5ec618feae Get image rotation for skybox right 2025-03-10 12:34:38 +01:00
7 changed files with 107 additions and 79 deletions

View file

@ -2,9 +2,8 @@
resolver = "2"
members = [
"config_handler",
"networking",
"asset",
"config_handler",
"context",
"controllable_thread",
"engine",
@ -14,6 +13,7 @@ members = [
"loading-screen",
"lua-wrapper",
"math",
"networking",
"presentation",
"promise",
"ring_buffer",
@ -32,7 +32,7 @@ chrono = { version = "0.4.35", features = ["serde"] }
anyhow = { version = "1.0.86", features = ["backtrace"] }
indexmap = { version = "2.2.6", features = ["rayon"] }
shaderc = { version = "0.8.3", features = ["build-from-source"] }
rusqlite = { version = "0.33.0", features = ["bundled"] }
rusqlite = { version = "0.34.0", features = ["bundled"] }
cgmath = "0.18.0"
http = "1.1.0"
iterchunks = "0.5.0"
@ -55,7 +55,6 @@ syn = { version = "2.0.67", features = ["extra-traits", "full"] }
quote = "1.0.35"
proc-macro2 = "1.0.86"
downcast-rs = "2.0.0"
plexus = { version = "0.0.11", default-features = false }
utilities = { git = "https://gavania.de/hodasemi/utilities.git" }
vulkan-rs = { git = "https://gavania.de/hodasemi/vulkan_lib.git" }

View file

@ -2,8 +2,6 @@ use cgmath::{Vector3, Zero};
use utilities::{impl_reprc, prelude::*};
use vulkan_rs::prelude::*;
use std::mem;
impl_reprc!(
#[derive(Copy, Debug)]
pub struct PositionOnly {
@ -34,19 +32,11 @@ impl Default for PositionOnly {
}
impl VertexInputDescription for PositionOnly {
fn bindings() -> Vec<VkVertexInputBindingDescription> {
vec![VkVertexInputBindingDescription {
binding: 0,
stride: mem::size_of::<Self>() as u32,
inputRate: VK_VERTEX_INPUT_RATE_VERTEX,
}]
}
fn attributes() -> Vec<VkVertexInputAttributeDescription> {
vec![VkVertexInputAttributeDescription {
location: 0,
binding: 0,
format: VK_FORMAT_R32G32B32A32_SFLOAT,
format: VK_FORMAT_R32G32B32_SFLOAT,
offset: 0,
}]
}

View file

@ -17,8 +17,8 @@ fn main() -> Result<()> {
world_builder.add_system(GameState::update);
world_builder.resources.insert(GameState::default());
// let dir = Path::new("C:/Users/M.Huebner/Downloads/Space Skybox Generator/Export");
let dir = Path::new("/home/michaelh/Sync/skybox_labeled");
let dir = Path::new("C:/Users/M.Huebner/Downloads/skybox");
// let dir = Path::new("/home/michaelh/Sync/skybox_labeled");
SkyBox::new(
&mut world_builder,
[
@ -88,7 +88,7 @@ impl Game {
let diff = now.as_secs_f32() - self.start.as_secs_f32();
camera.set_eye_dir(
Matrix3::from_angle_z(Deg(diff * 36.0))
* Matrix3::from_angle_x(Deg(diff.sin() * 45.0))
* Matrix3::from_angle_x(Deg(diff.sin() * 30.0))
* Vector3::unit_y(),
);
view.update_buffer()?;

View file

@ -6,7 +6,6 @@ edition = "2024"
[dependencies]
anyhow.workspace = true
plexus.workspace = true
utilities.workspace = true
ecs.workspace = true

84
skybox/src/cube.rs Normal file
View file

@ -0,0 +1,84 @@
use engine::prelude::{cgmath::*, *};
pub struct CubeCorners(pub [PositionOnly; 8]);
impl CubeCorners {
pub fn new(offset: Vector3<f32>, extent: Vector3<f32>) -> Self {
Self([
// 0 - left bottom front
PositionOnly::new(vec3(offset.x, offset.y, offset.z)),
// 1 - right bottom front
PositionOnly::new(vec3(offset.x + extent.x, offset.y, offset.z)),
// 2 - right top front
PositionOnly::new(vec3(offset.x + extent.x, offset.y + extent.y, offset.z)),
// 3 - left top front
PositionOnly::new(vec3(offset.x, offset.y + extent.y, offset.z)),
// 4 - left bottom back
PositionOnly::new(vec3(offset.x, offset.y, offset.z + extent.z)),
// 5 - right bottom back
PositionOnly::new(vec3(offset.x + extent.x, offset.y, offset.z + extent.z)),
// 6 - right top back
PositionOnly::new(vec3(
offset.x + extent.x,
offset.y + extent.y,
offset.z + extent.z,
)),
// 7 - left top back
PositionOnly::new(vec3(offset.x, offset.y + extent.y, offset.z + extent.z)),
])
}
}
pub struct Plane([PositionOnly; 4]);
impl Plane {
pub fn triangulate(self) -> [PositionOnly; 6] {
[
self.0[0], self.0[1], self.0[2], self.0[2], self.0[3], self.0[0],
]
}
}
impl<'a> From<(&'a CubeCorners, usize, usize, usize, usize)> for Plane {
fn from((corners, i1, i2, i3, i4): (&'a CubeCorners, usize, usize, usize, usize)) -> Self {
Self([corners.0[i1], corners.0[i2], corners.0[i3], corners.0[i4]])
}
}
pub struct Cube {
pub left: Plane,
pub right: Plane,
pub front: Plane,
pub back: Plane,
pub top: Plane,
pub bottom: Plane,
}
impl Cube {
pub fn triangulate(self) -> [PositionOnly; 36] {
[
self.front.triangulate(),
self.left.triangulate(),
self.right.triangulate(),
self.back.triangulate(),
self.top.triangulate(),
self.bottom.triangulate(),
]
.concat()
.try_into()
.unwrap()
}
}
impl From<CubeCorners> for Cube {
fn from(corners: CubeCorners) -> Self {
Self {
left: Plane::from((&corners, 0, 3, 4, 7)),
right: Plane::from((&corners, 2, 1, 6, 5)),
front: Plane::from((&corners, 0, 1, 2, 3)),
back: Plane::from((&corners, 5, 4, 7, 6)),
top: Plane::from((&corners, 3, 2, 6, 7)),
bottom: Plane::from((&corners, 5, 4, 0, 1)),
}
}
}

View file

@ -1,16 +1,11 @@
mod vertex;
mod cube;
use std::{path::PathBuf, sync::Arc, time::Duration};
use anyhow::Result;
use cube::{Cube, CubeCorners};
use ecs::*;
use engine::prelude::{shader_type::*, *};
use plexus::primitive::{
cube::{Bounds, Cube},
decompose::Triangulate,
generate::PolygonsWithPosition,
};
use vertex::VertexPoint;
use engine::prelude::{cgmath::*, shader_type::*, *};
pub struct SkyBoxImages {
left: PathBuf,
@ -40,7 +35,7 @@ pub struct SkyBox {
enabled: bool,
_cube_map: Arc<Image>,
cube_buffer: Arc<Buffer<VertexPoint>>,
cube_buffer: Arc<Buffer<PositionOnly>>,
vertex_shader: Arc<ShaderModule<Vertex>>,
fragment_shader: Arc<ShaderModule<Fragment>>,
@ -63,12 +58,15 @@ impl SkyBox {
let images = images.into();
let cube_map = Image::cube_map([
images.left.try_into()?,
images.right.try_into()?,
images.front.try_into()?,
images.back.try_into()?,
images.top.try_into()?,
images.bottom.try_into()?,
(
images.front.try_into()?,
vec![ImageModifier::Rotate90, ImageModifier::FlipH],
),
(images.left.try_into()?, vec![ImageModifier::Rotate90]),
(images.right.try_into()?, vec![ImageModifier::Rotate270]),
(images.back.try_into()?, vec![ImageModifier::FlipH]),
(images.top.try_into()?, vec![ImageModifier::None]),
(images.bottom.try_into()?, vec![ImageModifier::None]),
])?
.format(VK_FORMAT_R8G8B8A8_UNORM)
.max_mip_map_levels()
@ -128,19 +126,8 @@ impl SkyBox {
DescriptorWrite::combined_samplers(1, &[&cube_map]),
])?;
let cube_mesh = Cube::new()
.polygons_with_position_from(Bounds::unit_radius())
.triangulate()
.map(|d| {
vec![
[d.a.0.into_inner(), d.a.1.into_inner(), d.a.2.into_inner()],
[d.b.0.into_inner(), d.b.1.into_inner(), d.b.2.into_inner()],
[d.c.0.into_inner(), d.c.1.into_inner(), d.c.2.into_inner()],
]
})
.flatten()
.map(|t| VertexPoint::new(t[0] as f32, t[1] as f32, t[2] as f32))
.collect::<Vec<_>>();
let cube: Cube = CubeCorners::new(vec3(-1.0, -1.0, -1.0), vec3(2.0, 2.0, 2.0)).into();
let cube_mesh = cube.triangulate();
let command_buffer = CommandBuffer::new_primary()
.build(context.device().clone(), context.queue().clone())?;
@ -243,7 +230,7 @@ impl SkyBox {
) -> Result<TargetMode<Arc<Pipeline>>> {
render_target.execute(|render_target| {
Pipeline::new_graphics()
.set_vertex_shader::<VertexPoint>(vertex_shader.clone())
.set_vertex_shader::<PositionOnly>(vertex_shader.clone())
.set_fragment_shader(fragment_shader.clone())
.input_assembly(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, false)
.default_multisample(sample_count)

View file

@ -1,31 +0,0 @@
use engine::prelude::*;
use utilities::impl_reprc;
impl_reprc!(
pub struct VertexPoint {
#[assume_reprc]
v: [f32; 4],
}
);
impl VertexPoint {
pub fn new(x: impl Into<f32>, y: impl Into<f32>, z: impl Into<f32>) -> Self {
VertexPoint {
v: [x.into(), y.into(), z.into(), 1.0],
}
}
}
impl VertexInputDescription for VertexPoint {
fn attributes() -> Vec<VkVertexInputAttributeDescription> {
vec![
// position
VkVertexInputAttributeDescription {
location: 0,
binding: 0,
format: VK_FORMAT_R32G32B32_SFLOAT,
offset: 0,
},
]
}
}