Skip to content

Commit

Permalink
dev (#9)
Browse files Browse the repository at this point in the history
- **started scene implementation**
- **scene pipeline wip**
- **temporary silences scene, toolchain update**
  • Loading branch information
VladasZ authored Nov 12, 2024
2 parents 7b06eb5 + 7def1e7 commit 595ab6d
Show file tree
Hide file tree
Showing 30 changed files with 486 additions and 219 deletions.
335 changes: 168 additions & 167 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ convert_case = "0.6"
dirs = "5.0"
educe = "0.6.0"
env_logger = "0.11"
fake = "2.9.2"
fake = "3.0.1"
home = "0.5"
image = "0.25"
log = "0.4"
Expand All @@ -39,9 +39,10 @@ rapier2d = { version = "0.22.0", features = ["simd-nightly"] }
#rapier2d = { version = "0.20.0", features = ["enhanced-determinism"] }
# rapier2d = { version = "0.20.0", features = ["parallel", "simd-stable"] }
aes-gcm = "0.10.3"
cgmath = "0.18"
indexmap = "2.2"
lyon = "1.0"
rodio = "0.19.0"
rodio = "0.20.1"
rust_decimal = "1.35"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand All @@ -53,8 +54,8 @@ walkdir = "2.5"
web-time = "1.0.0"

glyph_brush = "0.7.8"
wgpu = "22.1.0"
wgpu_text = "0.9.0"
wgpu = "23.0.0"
wgpu_text = "0.9.1"
winit = "0.30.5"

jni = "0.21.1"
Expand All @@ -71,6 +72,7 @@ gm = { path = "deps/gm" }
image-proc = { path = "deps/wgpu-wrapper/image-proc" }
level = { path = "deps/level" }
level-proc = { path = "deps/level/level-proc" }
scene = { path = "deps/scene" }
store = { path = "deps/store" }
test-engine = { path = "test-engine" }
test-game = { path = "test-game" }
Expand Down
2 changes: 1 addition & 1 deletion build
Submodule build updated 1 files
+1 −1 build.sh
2 changes: 2 additions & 0 deletions deps/gm/src/flat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ mod process_points;
mod rect;
mod shape;
mod size;
mod vertex2d;

pub use point::{Direction, Point};
pub use points_path::*;
pub use process_points::*;
pub use rect::Rect;
pub use shape::Shape;
pub use size::*;
pub use vertex2d::Vertex2D;
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::flat::Point;

#[repr(C)]
#[derive(Copy, Clone, Default, Debug, Zeroable, Pod)]
pub struct Vertex {
pub struct Vertex2D {
pub pos: Point,
pub uv: Point,
}
8 changes: 4 additions & 4 deletions deps/gm/src/volume/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod gyro_data;
mod vector3;
mod vertex;
mod point3;
mod vertex3d;

pub use gyro_data::GyroData;
pub use vector3::Vector3;
pub use vertex::*;
pub use point3::Point3;
pub use vertex3d::Vertex3D;
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use bytemuck::{Pod, Zeroable};

#[repr(C)]
#[derive(Copy, Clone, Default, Debug, Zeroable, Pod)]
pub struct Vector3 {
pub struct Point3 {
pub x: f32,
pub y: f32,
pub z: f32,
}

impl Vector3 {
impl Point3 {
pub const fn new(x: f32, y: f32, z: f32) -> Self {
Self { x, y, z }
}
Expand Down
10 changes: 10 additions & 0 deletions deps/gm/src/volume/vertex3d.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use bytemuck::{Pod, Zeroable};

use crate::{flat::Point, volume::Point3};

#[repr(C)]
#[derive(Copy, Clone, Default, Debug, Zeroable, Pod)]
pub struct Vertex3D {
pub pos: Point3,
pub uv: Point,
}
13 changes: 13 additions & 0 deletions deps/scene/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
authors = ["Vladas Zakrevskis <[email protected]>"]
edition = "2021"
name = "scene"
version = "0.1.0"

[lib]
crate-type = ["rlib", "staticlib"]
name = "scene"

[dependencies]
cgmath = { workspace = true }
gm = { workspace = true }
29 changes: 29 additions & 0 deletions deps/scene/src/camera.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#[rustfmt::skip]
pub const OPENGL_TO_WGPU_MATRIX: cgmath::Matrix4<f32> = cgmath::Matrix4::new(
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 0.5, 0.5,
0.0, 0.0, 0.0, 1.0,
);

pub struct Camera {
pub eye: cgmath::Point3<f32>,
pub target: cgmath::Point3<f32>,
pub up: cgmath::Vector3<f32>,
pub aspect: f32,
pub fovy: f32,
pub znear: f32,
pub zfar: f32,
}

impl Camera {
pub fn build_view_projection_matrix(&self) -> cgmath::Matrix4<f32> {
// 1.
let view = cgmath::Matrix4::look_at_rh(self.eye, self.target, self.up);
// 2.
let proj = cgmath::perspective(cgmath::Deg(self.fovy), self.aspect, self.znear, self.zfar);

// 3.
OPENGL_TO_WGPU_MATRIX * proj * view
}
}
6 changes: 6 additions & 0 deletions deps/scene/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
mod camera;
mod object;
mod scene;

pub use camera::Camera;
pub use scene::Scene;
6 changes: 6 additions & 0 deletions deps/scene/src/object.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use gm::volume::Point3;

pub struct Object {
pub position: Point3,
pub vertices: Vec<Point3>,
}
35 changes: 35 additions & 0 deletions deps/scene/src/scene.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use gm::flat::Size;

use crate::{camera::Camera, object::Object};

pub struct Scene {
pub camera: Camera,
pub objects: Vec<Object>,
}

impl Scene {
pub fn set_aspect_ratio(&mut self, resolution: Size) {
self.camera.aspect = resolution.width / resolution.height;
}
}

impl Default for Scene {
fn default() -> Self {
Self {
camera: Camera {
// position the camera 1 unit up and 2 units back
// +z is out of the screen
eye: (0.0, 1.0, 2.0).into(),
// have it look at the origin
target: (0.0, 0.0, 0.0).into(),
// which way is "up"
up: cgmath::Vector3::unit_y(),
aspect: 1.0,
fovy: 45.0,
znear: 0.1,
zfar: 100.0,
},
objects: Vec::new(),
}
}
}
17 changes: 8 additions & 9 deletions deps/wgpu-wrapper/src/render/background_pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use std::ops::Range;
use bytemuck::{Pod, Zeroable};
use gm::{
checked_usize_to_u32,
flat::{Point, Size},
volume::Vertex,
flat::{Point, Size, Vertex2D},
};
use wgpu::{
BindGroup, Buffer, BufferUsages, PipelineLayoutDescriptor, PolygonMode, PrimitiveTopology, RenderPass,
Expand All @@ -21,28 +20,28 @@ use crate::{
const VAL: f32 = 100_000.0;
const UV: f32 = 500.0;

const fn image_vertices() -> [Vertex; 4] {
const fn image_vertices() -> [Vertex2D; 4] {
[
Vertex {
Vertex2D {
pos: Point::new(-VAL, VAL),
uv: Point::new(-UV, -UV),
},
Vertex {
Vertex2D {
pos: Point::new(-VAL, -VAL),
uv: Point::new(-UV, UV),
},
Vertex {
Vertex2D {
pos: Point::new(VAL, VAL),
uv: Point::new(UV, -UV),
},
Vertex {
Vertex2D {
pos: Point::new(VAL, -VAL),
uv: Point::new(UV, UV),
},
]
}

const VERTICES: [Vertex; 4] = image_vertices();
const VERTICES: [Vertex2D; 4] = image_vertices();

const RANGE: Range<u32> = 0..checked_usize_to_u32(VERTICES.len());

Expand Down Expand Up @@ -83,7 +82,7 @@ impl Default for BackgroundPipeline {
&shader,
PolygonMode::Fill,
PrimitiveTopology::TriangleStrip,
&[Vertex::VERTEX_LAYOUT],
&[Vertex2D::VERTEX_LAYOUT],
);

let view = BackgroundView {
Expand Down
17 changes: 8 additions & 9 deletions deps/wgpu-wrapper/src/render/image_drawer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use std::ops::Range;

use gm::{
checked_usize_to_u32,
flat::{Point, Rect},
volume::Vertex,
flat::{Point, Rect, Vertex2D},
};
use wgpu::{
BindGroupLayout, Buffer, BufferUsages, PolygonMode, PrimitiveTopology, RenderPipeline, ShaderStages,
Expand All @@ -19,28 +18,28 @@ use crate::{
WGPUApp,
};

pub const fn image_vertices_with_shrink(x: f32, y: f32, width: f32, height: f32) -> [Vertex; 4] {
pub const fn image_vertices_with_shrink(x: f32, y: f32, width: f32, height: f32) -> [Vertex2D; 4] {
[
Vertex {
Vertex2D {
pos: Point::new(-1.0, 1.0),
uv: Point::new(0.0 + x, 0.0 + y),
},
Vertex {
Vertex2D {
pos: Point::new(-1.0, -1.0),
uv: Point::new(0.0 + x, 1.0 * height + y),
},
Vertex {
Vertex2D {
pos: Point::new(1.0, 1.0),
uv: Point::new(1.0 * width + x, 0.0 + y),
},
Vertex {
Vertex2D {
pos: Point::new(1.0, -1.0),
uv: Point::new(1.0 * width + x, 1.0 * height + y),
},
]
}

const VERTICES: [Vertex; 4] = image_vertices_with_shrink(0.0, 0.0, 1.0, 1.0);
const VERTICES: [Vertex2D; 4] = image_vertices_with_shrink(0.0, 0.0, 1.0, 1.0);

const RANGE: Range<u32> = 0..checked_usize_to_u32(VERTICES.len());

Expand Down Expand Up @@ -70,7 +69,7 @@ impl Default for ImageDrawer {
&shader,
PolygonMode::Fill,
PrimitiveTopology::TriangleStrip,
&[Vertex::VERTEX_LAYOUT],
&[Vertex2D::VERTEX_LAYOUT],
);

Self {
Expand Down
1 change: 1 addition & 0 deletions deps/wgpu-wrapper/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub mod image_drawer;
pub mod path_data;
pub mod path_drawer;
pub mod rect_drawer;
pub mod scene_drawer;
pub mod sprite_drawer;
pub mod uniform;
mod vec_buffer;
Expand Down
1 change: 1 addition & 0 deletions deps/wgpu-wrapper/src/render/scene_drawer/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod scene_pipeline;
Loading

0 comments on commit 595ab6d

Please sign in to comment.