Skip to content

Commit 1aa96a2

Browse files
committed
Improve READMEs and examples
1 parent c812d23 commit 1aa96a2

File tree

15 files changed

+115
-126
lines changed

15 files changed

+115
-126
lines changed

.github/images/examples/brdf.png

1.18 MB
Loading

.github/images/examples/suzanne.png

140 KB
Loading
33.1 KB
Loading

README.md

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,44 +11,48 @@ The goal is to build a somewhat usable game engine and a demo using it. While we
1111
## Features
1212

1313
Currently implemented features are:
14-
- Scene comprised of Entities and Components
15-
- Debug UI Layer with Frame stats, Scene Graph, Component Inspectors and Profiler
16-
- BRDF shading
17-
- Deferred rendering
14+
15+
- A scene graph with entities and components
16+
- Vulkan rendering
17+
- BRDF shading and lighting
18+
- Deferred rendering and post-processing effects
19+
- Debug UI Layer with frame stats, scene graph and component inspectors
1820
- `.obj` parser
1921
- Runs on both Linux and Windows
2022

2123
## Screenshots
2224

2325
BRDF testing:
2426

25-
![brdf testing](./.github/images/examples/brdf.png)
27+
![brdf testing](/.github/images/examples/brdf.png)
2628

2729
Debug UI:
2830

29-
![debug ui](./.github/images/examples/debug-ui.png)
31+
![debug ui](/.github/images/examples/debug-ui.png)
32+
33+
Custom meshes:
34+
![custom meshes](/.github/images/examples/suzanne.png)
3035

3136
## Workspace
3237

3338
| Folder | Description | Readme |
3439
| ---- | ----------- | - |
35-
| [crates/engine](crates/engine) | Main engine library | This one |
36-
| [crates/ve_asset](crates/ve_asset) | Utility that converts files into our custom format | [here](./crates/ve_asset/README.md) |
37-
| [crates/ve_format](crates/ve_format) | Stores some shared structs | [here](./crates/ve_format/README.md) |
38-
| [crates/ve_shader_reflect](crates/ve_shader_reflect) | Retrieves metadata from compiled shaders to feed into the material pipeline | [here](./crates/ve_shader_reflect/README.md) |
39-
40+
| [crates/engine](/crates/engine) | Main engine library | This one |
41+
| [crates/ve_asset](/crates/ve_asset) | Utility that converts files into our custom format | [here](./crates/ve_asset/README.md) |
42+
| [crates/ve_format](/crates/ve_format) | Stores some shared structs | [here](./crates/ve_format/README.md) |
43+
| [crates/ve_shader_reflect](/crates/ve_shader_reflect) | Retrieves metadata from compiled shaders to feed into the material pipeline | [here](/crates/ve_shader_reflect/README.md) |
4044

4145

4246
## Examples
4347

4448
Examples are in the [crates/engine/examples](crates/engine/examples) folder. They can be run with `cargo +nightly run --example <name>`.
4549
| Name | Description |
4650
| ---- | ----------- |
47-
| minimal | Displays a triangle using vertex colors |
48-
| brdf | Renders a couple of spheres using physically-based rendering |
49-
| mesh | Loads and renders a custom mesh |
50-
| textured_material | Creates a texture at runtime and renders it onto a quad |
51-
| components | Shows off the engine's component system |
51+
| [minimal](/crates/engine/examples/minimal/) | Displays a triangle using vertex colors |
52+
| [brdf](/crates/engine/examples/brdf/) | Renders a couple of spheres using physically-based rendering |
53+
| [mesh](/crates/engine/examples/mesh/) | Loads and renders a custom mesh |
54+
| [textured_material](/crates/engine/examples/textured_material/) | Creates a texture at runtime and renders it onto a quad |
55+
| [components](/crates/engine/examples/components/) | Shows off the engine's component system |
5256

5357
## Building
5458

assets/models/donut.vem

-185 KB
Binary file not shown.

assets/models/suzanne.vem

33.2 KB
Binary file not shown.

crates/engine/examples/brdf/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Mesh Example
1+
# BRDF Example
22

3-
This example renders a custom mesh loaded from a `.obj` file.
3+
This example renders a few spheres with different material properties using physically-based rendering.
44

5-
![triangle](/.github/images/examples/mesh.png)
5+
![brdf](/.github/images/examples/brdf.png)

crates/engine/examples/brdf/main.rs

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ use vulkan_engine::{
1111
scene::{
1212
component::{
1313
camera_component::CameraComponent, debug_movement_component::DebugMovementComponent,
14-
light_component::LightComponent, renderer::RendererComponent, Component,
14+
light_component::LightComponent, renderer::RendererComponent,
15+
rotation_component::RotationComponent, Component,
1516
},
1617
entity::Entity,
1718
light::{DirectionalLight, PointLight},
@@ -193,42 +194,3 @@ fn setup(engine: &mut Engine) {
193194

194195
scene.load();
195196
}
196-
197-
#[derive(Debug)]
198-
struct RotationComponent {
199-
entity: Weak<Entity>,
200-
rotation_speed: Cell<f32>,
201-
}
202-
203-
impl Component for RotationComponent {
204-
fn create(entity: &Rc<Entity>) -> Rc<Self>
205-
where
206-
Self: Sized,
207-
{
208-
Rc::new(Self {
209-
entity: Rc::downgrade(entity),
210-
rotation_speed: Cell::new(30.0),
211-
})
212-
}
213-
214-
fn load(&self) {}
215-
216-
fn start(&self) {}
217-
218-
fn update(&self, _: &Input, delta: f32) {
219-
if let Some(entity) = self.entity.upgrade() {
220-
let mut transform = entity.transform.borrow_mut();
221-
222-
let mut rotation = transform.rotation;
223-
rotation = Quaternion::axis_angle(
224-
Vec3::new(0.0, 0.0, 1.0),
225-
self.rotation_speed.get().to_radians() * delta,
226-
) * rotation;
227-
transform.rotation = rotation;
228-
}
229-
}
230-
231-
fn inspector_name(&self) -> &'static str {
232-
"TimeOfDayComponent"
233-
}
234-
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Components Example
2+
3+
This example shows the component system in action.
4+
5+
![debug ui](/.github/images/examples/debug-ui.png)

crates/engine/examples/mesh/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# BRDF Example
1+
# Mesh Example
22

3-
This example renders a few spheres with different material properties using physically-based rendering.
3+
This example renders a custom mesh loaded from a `.vem` file. This file was generated from an `.obj` file using `ve_assets` and the following command: `ve_asset ".\suzanne.obj" -o .\assets\models\suzanne.vem`.
44

5-
![triangle](/.github/images/examples/brdf.png)
5+
![suzanne](/.github/images/examples/suzanne.png)

crates/engine/examples/mesh/main.rs

Lines changed: 16 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use vulkan_engine::{
88
component::{
99
camera_component::CameraComponent, debug_movement_component::DebugMovementComponent,
1010
light_component::LightComponent, renderer::RendererComponent,
11+
rotation_component::RotationComponent,
1112
},
1213
light::{DirectionalLight, PointLight},
1314
material::MaterialPipeline,
@@ -67,8 +68,8 @@ fn setup(engine: &mut Engine) {
6768
brdf_material0.set_float("metallic", 0.0).unwrap();
6869
brdf_material0.set_float("roughness", 0.1).unwrap();
6970

70-
let mesh_data = ve_format::mesh::MeshData::from_file(Path::new("./assets/models/cube.vem"))
71-
.expect("Model cube.vem not found!");
71+
let mesh_data = ve_format::mesh::MeshData::from_file(Path::new("./assets/models/suzanne.vem"))
72+
.expect("Model suzanne.vem not found!");
7273

7374
let mesh = Mesh::bake(
7475
mesh_data,
@@ -83,13 +84,19 @@ fn setup(engine: &mut Engine) {
8384
};
8485

8586
let entity = scene.new_entity_with_transform(
86-
"Cube".to_string(),
87+
"Suzanne".to_string(),
8788
Transform {
88-
position: Vec3::new(0.0, 0.0, 5.0),
89-
rotation: Quaternion::axis_angle(Vec3::new(1.0, 0.0, 0.0), 0.0f32.to_radians()),
89+
position: Vec3::new(0.0, 0.0, 0.0),
90+
rotation: Quaternion::axis_angle(Vec3::new(0.0, 1.0, 0.0), -180.0f32.to_radians()),
9091
scale: Vec3::new(1.0, 1.0, 1.0),
9192
},
9293
);
94+
95+
entity
96+
.new_component::<RotationComponent>()
97+
.axis
98+
.set(Vec3::new(0.0, 1.0, 0.0));
99+
93100
let comp = entity.new_component::<RendererComponent>();
94101
*comp.model.borrow_mut() = Some(Rc::new(model));
95102

@@ -109,7 +116,10 @@ fn setup(engine: &mut Engine) {
109116
"DirLight1".to_string(),
110117
Transform {
111118
position: Vec3::zero(),
112-
rotation: Quaternion::axis_angle(Vec3::new(1.0, 0.0, 0.0), -90.0f32.to_radians()),
119+
rotation: Quaternion::axis_angle(
120+
Vec3::new(-41.0, -20.0, 0.0),
121+
-90.0f32.to_radians(),
122+
),
113123
scale: Vec3::one(),
114124
},
115125
)
@@ -123,25 +133,6 @@ fn setup(engine: &mut Engine) {
123133
.into(),
124134
);
125135

126-
scene
127-
.new_entity_with_transform(
128-
"DirLight2".to_string(),
129-
Transform {
130-
position: Vec3::zero(),
131-
rotation: Quaternion::axis_angle(Vec3::new(1.0, 0.0, 0.0), 90.0f32.to_radians()),
132-
scale: Vec3::one(),
133-
},
134-
)
135-
.new_component::<LightComponent>()
136-
.light
137-
.set(
138-
DirectionalLight {
139-
direction: Vec4::zero(),
140-
illuminance: Vec4::new(1.6, 1.6, 1.6, 0.0),
141-
}
142-
.into(),
143-
);
144-
145136
scene
146137
.new_entity_with_transform(
147138
"PointLight White 1".to_string(),
@@ -196,43 +187,6 @@ fn setup(engine: &mut Engine) {
196187
}
197188
.into(),
198189
);
199-
scene
200-
.new_entity_with_transform(
201-
"PointLight White 4".to_string(),
202-
Transform {
203-
position: Vec3::new(0.1, -3.0, -3.0),
204-
rotation: Quaternion::identity(),
205-
scale: Vec3::one(),
206-
},
207-
)
208-
.new_component::<LightComponent>()
209-
.light
210-
.set(
211-
PointLight {
212-
position: Vec4::zero(),
213-
luminous_flux: Vec4::new(100.0, 100.0, 100.0, 0.0),
214-
}
215-
.into(),
216-
);
217-
218-
scene
219-
.new_entity_with_transform(
220-
"PointLight Red".to_string(),
221-
Transform {
222-
position: Vec3::new(0.0, 0.0, -3.0),
223-
rotation: Quaternion::identity(),
224-
scale: Vec3::one(),
225-
},
226-
)
227-
.new_component::<LightComponent>()
228-
.light
229-
.set(
230-
PointLight {
231-
position: Vec4::zero(),
232-
luminous_flux: Vec4::new(100.0, 0.0, 0.0, 0.0),
233-
}
234-
.into(),
235-
);
236190

237191
scene.load();
238192
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Textured Material Example
2+
3+
This example is a minimal working example that displays a textured triangle (the texture is created at runtime).
4+
5+
![textured material](/.github/images/examples/textured_material.png)

crates/engine/src/scene/component/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ pub mod camera_component;
22
pub mod debug_movement_component;
33
pub mod light_component;
44
pub mod renderer;
5+
pub mod rotation_component;
56

67
use std::{fmt::Debug, rc::Rc};
78

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
use std::{
2+
cell::Cell,
3+
rc::{Rc, Weak},
4+
};
5+
6+
use egui::Slider;
7+
use gfx_maths::{Quaternion, Vec3};
8+
9+
use crate::{core::input::Input, scene::entity::Entity};
10+
11+
use super::Component;
12+
13+
#[derive(Debug)]
14+
pub struct RotationComponent {
15+
entity: Weak<Entity>,
16+
pub rotation_speed: Cell<f32>,
17+
pub axis: Cell<Vec3>,
18+
}
19+
20+
impl Component for RotationComponent {
21+
fn create(entity: &Rc<Entity>) -> Rc<Self>
22+
where
23+
Self: Sized,
24+
{
25+
Rc::new(Self {
26+
entity: Rc::downgrade(entity),
27+
rotation_speed: Cell::new(30.0),
28+
axis: Cell::new(Vec3::new(0.0, 0.0, 1.0)),
29+
})
30+
}
31+
32+
fn load(&self) {}
33+
34+
fn start(&self) {}
35+
36+
fn update(&self, _: &Input, delta: f32) {
37+
if let Some(entity) = self.entity.upgrade() {
38+
let mut transform = entity.transform.borrow_mut();
39+
40+
let mut rotation = transform.rotation;
41+
rotation = Quaternion::axis_angle(
42+
self.axis.get(),
43+
self.rotation_speed.get().to_radians() * delta,
44+
) * rotation;
45+
transform.rotation = rotation;
46+
}
47+
}
48+
49+
fn inspector_name(&self) -> &'static str {
50+
"RotationComponent"
51+
}
52+
53+
fn render_inspector(&self, ui: &mut egui::Ui) {
54+
let mut rot_speed = self.rotation_speed.get();
55+
ui.add(Slider::new(&mut rot_speed, -360.0..=360.0).text("Rotation Speed"));
56+
self.rotation_speed.set(rot_speed);
57+
}
58+
}

crates/ve_asset/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ Currently, this utility supports the following file formats:
2626

2727
## Meta
2828

29-
Formats like `.obj` have to be parsed with different settings, e.g., depending on the software it was made with. These settings can be set in `.toml` files that are named the same as the corresponding file. These metadata can also be set for a whole folder in a `<file_extension>.toml` file.
29+
Formats like `.obj` have to be parsed with different settings, e.g., depending on the software it was made with. These settings can be set in `.toml` files that are named the same as the corresponding file. This metadata can also be set for a whole folder in a `<file_extension>.toml` file.
3030

31-
E.g. the meta-file for the `.obj` file type, looks like this:
31+
The meta-file for the `.obj` file type looks like this:
3232

3333
```toml
3434
calculate_normals = false

0 commit comments

Comments
 (0)