Skip to content

Commit de4864c

Browse files
committed
Factor out unnecessary traits, replace with permutate conditionals
1 parent 9e7a0b0 commit de4864c

16 files changed

+222
-826
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bevy-pbr-rust"
3-
version = "0.1.0"
3+
version = "0.2.0"
44
edition = "2021"
55

66
[lib]
@@ -9,5 +9,5 @@ crate_type = ["dylib", "rlib"]
99
[dependencies]
1010
bitflags = "1.3.2"
1111
spirv-std = { version = "0.5.0", features = ["glam"] }
12-
permutate-macro = { git = "https://github.com/Bevy-Rust-GPU/permutate-macro", tag = "v0.3.0" }
12+
permutate-macro = { git = "https://github.com/Bevy-Rust-GPU/permutate-macro", tag = "v0.4.0" }
1313
rust-gpu-bridge = { git = "https://github.com/Bevy-Rust-GPU/rust-gpu-bridge", tag = "v0.2.0", features = ["spirv-std"] }

src/mesh/base_material_normal_map.rs

Lines changed: 0 additions & 75 deletions
This file was deleted.

src/mesh/entry_points.rs

Lines changed: 27 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ use spirv_std::{
55

66
use permutate_macro::permutate;
77

8-
use crate::prelude::{Mesh, Skinning, VertexNormal, VertexPosition, VertexTangent, View};
8+
use crate::{
9+
prelude::{Mesh, View},
10+
skinning::skin_normals,
11+
};
12+
13+
use super::mesh_position_local_to_world;
914

1015
#[spirv(vertex)]
1116
#[allow(non_snake_case)]
@@ -16,6 +21,8 @@ use crate::prelude::{Mesh, Skinning, VertexNormal, VertexPosition, VertexTangent
1621
skinned: some | none
1722
},
1823
permutations = [
24+
(none, none, none),
25+
(some, some, some),
1926
file("../../entry_points.json", "mesh::entry_points"),
2027
env("BEVY_PBR_RUST_MESH_VERTEX_PERMUTATIONS", "mesh::entry_points")
2128
]
@@ -52,29 +59,25 @@ pub fn vertex(
5259
#[permutate(tangent = some)]
5360
let mut in_tangent = in_tangent;
5461

55-
vertex_impl(
56-
view,
57-
mesh,
58-
&mut in_position,
59-
&mut in_normal,
60-
#[permutate(tangent = some)]
61-
&mut in_tangent,
62-
#[permutate(tangent = none)]
63-
&mut (),
64-
#[permutate(skinned = some)]
65-
joint_matrices,
66-
#[permutate(skinned = none)]
67-
&(),
68-
#[permutate(skinned = some)]
69-
in_joint_indices,
70-
#[permutate(skinned = none)]
71-
(),
72-
#[permutate(skinned = some)]
73-
in_joint_weights,
74-
#[permutate(skinned = none)]
75-
(),
76-
out_clip_position,
77-
);
62+
#[permutate(skinned = some)]
63+
let model = in_joint_weights.x * joint_matrices.data[in_joint_indices.x as usize]
64+
+ in_joint_weights.y * joint_matrices.data[in_joint_indices.y as usize]
65+
+ in_joint_weights.z * joint_matrices.data[in_joint_indices.z as usize]
66+
+ in_joint_weights.w * joint_matrices.data[in_joint_indices.w as usize];
67+
68+
#[permutate(skinned = none)]
69+
let model = mesh.model;
70+
71+
#[permutate(skinned = some)]
72+
in_normal = skin_normals(model, in_normal);
73+
#[permutate(skinned = none)]
74+
in_normal = mesh.mesh_normal_local_to_world(in_normal);
75+
76+
in_position = mesh_position_local_to_world(model, in_position);
77+
*out_clip_position = view.mesh_position_world_to_clip(in_position);
78+
79+
#[permutate(tangent = some)]
80+
in_tangent = mesh.mesh_tangent_local_to_world(model, in_tangent);
7881

7982
*out_world_position = in_position;
8083
*out_world_normal = in_normal;
@@ -87,24 +90,6 @@ pub fn vertex(
8790
*out_color = in_color;
8891
}
8992

90-
pub fn vertex_impl<P: VertexPosition, N: VertexNormal, T: VertexTangent, SM: Skinning>(
91-
view: &View,
92-
mesh: &Mesh,
93-
vertex_position: &mut P,
94-
vertex_normal: &mut N,
95-
vertex_tangent: &mut T,
96-
joint_matrices: &SM,
97-
in_joint_indices: SM::JointIndices,
98-
in_joint_weights: SM::JointWeights,
99-
out_clip_position: &mut Vec4,
100-
) {
101-
let model = joint_matrices.skin_model(mesh, in_joint_indices, in_joint_weights);
102-
103-
vertex_normal.skin_normals::<SM>(mesh, model);
104-
vertex_position.transform_position(view, mesh, model, out_clip_position);
105-
vertex_tangent.transform_tangent(mesh, model);
106-
}
107-
10893
#[spirv(fragment)]
10994
#[allow(unused_variables)]
11095
pub fn fragment(

src/mesh/mod.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
1-
pub mod base_material_normal_map;
21
pub mod bindings;
32
pub mod entry_points;
43
pub mod skinned_mesh;
5-
pub mod skinning;
6-
pub mod vertex_color;
7-
pub mod vertex_normal;
8-
pub mod vertex_position;
9-
pub mod vertex_tangent;
10-
pub mod vertex_uv;
114

125
use spirv_std::glam::{Mat3, Mat4, Vec3, Vec4};
136

src/mesh/skinned_mesh.rs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,6 @@
1-
use spirv_std::glam::{Mat4, UVec4, Vec3, Vec4};
2-
3-
use crate::skinning::skin_normals;
4-
5-
use crate::prelude::Skinning;
6-
7-
use super::Mesh;
1+
use spirv_std::glam::Mat4;
82

93
#[repr(C)]
104
pub struct SkinnedMesh {
115
pub data: [Mat4; 256],
126
}
13-
14-
impl Skinning for SkinnedMesh {
15-
type JointIndices = UVec4;
16-
type JointWeights = Vec4;
17-
18-
fn skin_model(&self, _: &Mesh, indexes: UVec4, weights: Vec4) -> Mat4 {
19-
weights.x * self.data[indexes.x as usize]
20-
+ weights.y * self.data[indexes.y as usize]
21-
+ weights.z * self.data[indexes.z as usize]
22-
+ weights.w * self.data[indexes.w as usize]
23-
}
24-
25-
fn skin_normals(_: &Mesh, model: Mat4, normal: Vec3) -> Vec3 {
26-
skin_normals(model, normal)
27-
}
28-
}
29-

src/mesh/skinning.rs

Lines changed: 0 additions & 32 deletions
This file was deleted.

src/mesh/vertex_color.rs

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/mesh/vertex_normal.rs

Lines changed: 0 additions & 82 deletions
This file was deleted.

0 commit comments

Comments
 (0)