Skip to content
Open
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
13 changes: 11 additions & 2 deletions assets/shaders/custom_stencil.wgsl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! A shader showing how to use the vertex position data to output the
//! A shader showing how to use the vertex position data to output the
//! stencil in the right position

// First we import everything we need from bevy_pbr
Expand All @@ -14,7 +14,11 @@ struct Vertex {
@builtin(instance_index) instance_index: u32,
// Like we defined for the vertex layout
// position is at location 0
#ifdef VERTEX_POSITIONS_COMPRESSED
@location(0) position: vec4<f32>,
#else
@location(0) position: vec3<f32>,
#endif
};

// This is the output of the vertex shader and we also use it as the input for the fragment shader
Expand All @@ -29,7 +33,12 @@ fn vertex(vertex: Vertex) -> VertexOutput {
// This is how bevy computes the world position
// The vertex.instance_index is very important. Especially if you are using batching and gpu preprocessing
var world_from_local = mesh_functions::get_world_from_local(vertex.instance_index);
out.world_position = mesh_functions::mesh_position_local_to_world(world_from_local, vec4(vertex.position, 1.0));
#ifdef VERTEX_POSITIONS_COMPRESSED
let vertex_position = mesh_functions::decompress_vertex_position(vertex.instance_index, vertex.position);
#else
let vertex_position = vertex.position;
#endif
out.world_position = mesh_functions::mesh_position_local_to_world(world_from_local, vec4(vertex_position, 1.0));
out.clip_position = position_world_to_clip(out.world_position.xyz);
return out;
}
Expand Down
11 changes: 10 additions & 1 deletion assets/shaders/specialized_mesh_pipeline.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ struct Vertex {
@builtin(instance_index) instance_index: u32,
// Like we defined for the vertex layout
// position is at location 0
#ifdef VERTEX_POSITIONS_COMPRESSED
@location(0) position: vec4<f32>,
#else
@location(0) position: vec3<f32>,
#endif
// and color at location 1
@location(1) color: vec4<f32>,
};
Expand All @@ -32,7 +36,12 @@ fn vertex(vertex: Vertex) -> VertexOutput {
// This is how bevy computes the world position
// The vertex.instance_index is very important. Especially if you are using batching and gpu preprocessing
var world_from_local = mesh_functions::get_world_from_local(vertex.instance_index);
out.world_position = mesh_functions::mesh_position_local_to_world(world_from_local, vec4(vertex.position, 1.0));
#ifdef VERTEX_POSITIONS_COMPRESSED
let vertex_position = mesh_functions::decompress_vertex_position(vertex.instance_index, vertex.position);
#else
let vertex_position = vertex.position;
#endif
out.world_position = mesh_functions::mesh_position_local_to_world(world_from_local, vec4(vertex_position, 1.0));
out.clip_position = position_world_to_clip(out.world_position.xyz);

// We just use the raw vertex color
Expand Down
4 changes: 3 additions & 1 deletion crates/bevy_gltf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ bevy_image = { path = "../bevy_image", version = "0.18.0-dev" }
bevy_light = { path = "../bevy_light", version = "0.18.0-dev" }
bevy_camera = { path = "../bevy_camera", version = "0.18.0-dev" }
bevy_math = { path = "../bevy_math", version = "0.18.0-dev" }
bevy_mesh = { path = "../bevy_mesh", version = "0.18.0-dev" }
bevy_mesh = { path = "../bevy_mesh", version = "0.18.0-dev", features = [
"serialize",
] }
bevy_pbr = { path = "../bevy_pbr", version = "0.18.0-dev" }
bevy_reflect = { path = "../bevy_reflect", version = "0.18.0-dev" }
bevy_render = { path = "../bevy_render", version = "0.18.0-dev" }
Expand Down
7 changes: 5 additions & 2 deletions crates/bevy_gltf/src/loader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use bevy_math::{Mat4, Vec3};
use bevy_mesh::{
morph::{MeshMorphWeights, MorphAttributes, MorphTargetImage, MorphWeights},
skinning::{SkinnedMesh, SkinnedMeshInverseBindposes},
Indices, Mesh, Mesh3d, MeshVertexAttribute, PrimitiveTopology,
Indices, Mesh, Mesh3d, MeshAttributeCompressionFlags, MeshVertexAttribute, PrimitiveTopology,
};
#[cfg(feature = "pbr_transmission_textures")]
use bevy_pbr::UvChannel;
Expand Down Expand Up @@ -185,6 +185,8 @@ pub struct GltfLoaderSettings {
///
/// Otherwise, nodes will be loaded and retained in RAM/VRAM according to the active flags.
pub load_meshes: RenderAssetUsages,
/// Mesh attribute compression flags for the loaded meshes.
pub mesh_attribute_compression: MeshAttributeCompressionFlags,
/// If empty, the gltf materials will be skipped.
///
/// Otherwise, materials will be loaded and retained in RAM/VRAM according to the active flags.
Expand Down Expand Up @@ -232,6 +234,7 @@ impl Default for GltfLoaderSettings {
default_sampler: None,
override_sampler: false,
use_model_forward_direction: None,
mesh_attribute_compression: MeshAttributeCompressionFlags::default(),
}
}
}
Expand Down Expand Up @@ -678,7 +681,7 @@ impl GltfLoader {
let primitive_topology = primitive_topology(primitive.mode())?;

let mut mesh = Mesh::new(primitive_topology, settings.load_meshes);

mesh.attribute_compression = settings.mesh_attribute_compression;
// Read vertex attributes
for (semantic, accessor) in primitive.attributes() {
if [Semantic::Joints(0), Semantic::Weights(0)].contains(&semantic) {
Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_mesh/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ hexasphere = "16.0"
thiserror = { version = "2", default-features = false }
tracing = { version = "0.1", default-features = false, features = ["std"] }
derive_more = { version = "2", default-features = false, features = ["from"] }
half = { version = "2.4.1", features = ["bytemuck"] }

[dev-dependencies]
serde_json = "1.0.140"

[features]
default = []
## Adds serialization support through `serde`.
serialize = ["dep:serde", "wgpu-types/serde"]
serialize = ["dep:serde", "wgpu-types/serde", "half/serde"]
morph = ["dep:bevy_image"]

[lints]
Expand Down
Loading
Loading