Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Litttlefish authored Oct 1, 2024
2 parents e2c1fe1 + 1df8238 commit 0b5b0d3
Show file tree
Hide file tree
Showing 276 changed files with 10,195 additions and 4,335 deletions.
43 changes: 38 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,17 @@ description = "Loads and renders a glTF file as a scene, including the gltf extr
category = "3D Rendering"
wasm = true

[[example]]
name = "query_gltf_primitives"
path = "examples/3d/query_gltf_primitives.rs"
doc-scrape-examples = true

[package.metadata.example.query_gltf_primitives]
name = "Query glTF primitives"
description = "Query primitives in a glTF scene"
category = "3D Rendering"
wasm = true

[[example]]
name = "motion_blur"
path = "examples/3d/motion_blur.rs"
Expand Down Expand Up @@ -1153,7 +1164,7 @@ setup = [
"curl",
"-o",
"assets/models/bunny.meshlet_mesh",
"https://raw.githubusercontent.com/JMS55/bevy_meshlet_asset/e3da1533b4c69fb967f233c817e9b0921134d317/bunny.meshlet_mesh",
"https://raw.githubusercontent.com/JMS55/bevy_meshlet_asset/854eb98353ad94aea1104f355fc24dbe4fda679d/bunny.meshlet_mesh",
],
]

Expand Down Expand Up @@ -2463,13 +2474,24 @@ category = "Shaders"
wasm = true

[[example]]
name = "shader_instancing"
path = "examples/shader/shader_instancing.rs"
name = "custom_shader_instancing"
path = "examples/shader/custom_shader_instancing.rs"
doc-scrape-examples = true

[package.metadata.example.shader_instancing]
[package.metadata.example.custom_shader_instancing]
name = "Instancing"
description = "A shader that renders a mesh multiple times in one draw call"
description = "A shader that renders a mesh multiple times in one draw call using low level rendering api"
category = "Shaders"
wasm = true

[[example]]
name = "automatic_instancing"
path = "examples/shader/automatic_instancing.rs"
doc-scrape-examples = true

[package.metadata.example.automatic_instancing]
name = "Instancing"
description = "Shows that multiple instances of a cube are automatically instanced in one draw call"
category = "Shaders"
wasm = true

Expand Down Expand Up @@ -3415,6 +3437,17 @@ description = "Demonstrates screen space reflections with water ripples"
category = "3D Rendering"
wasm = false

[[example]]
name = "camera_sub_view"
path = "examples/3d/camera_sub_view.rs"
doc-scrape-examples = true

[package.metadata.example.camera_sub_view]
name = "Camera sub view"
description = "Demonstrates using different sub view effects on a camera"
category = "3D Rendering"
wasm = true

[[example]]
name = "color_grading"
path = "examples/3d/color_grading.rs"
Expand Down
Binary file added assets/models/GltfPrimitives/gltf_primitives.glb
Binary file not shown.
3 changes: 3 additions & 0 deletions assets/shaders/gpu_readback.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@

// This is the data that lives in the gpu only buffer
@group(0) @binding(0) var<storage, read_write> data: array<u32>;
@group(0) @binding(1) var texture: texture_storage_2d<r32uint, write>;

@compute @workgroup_size(1)
fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
// We use the global_id to index the array to make sure we don't
// access data used in another workgroup
data[global_id.x] += 1u;
// Write the same data to the texture
textureStore(texture, vec2<i32>(i32(global_id.x), 0), vec4<u32>(data[global_id.x], 0, 0, 0));
}
86 changes: 2 additions & 84 deletions crates/bevy_animation/src/animatable.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Traits and type for interpolating between values.

use crate::{util, AnimationEvaluationError, Interpolation};
use crate::util;
use bevy_color::{Laba, LinearRgba, Oklaba, Srgba, Xyza};
use bevy_math::*;
use bevy_reflect::Reflect;
Expand Down Expand Up @@ -188,93 +188,11 @@ impl Animatable for Quat {
}
}

/// An abstraction over a list of keyframes.
///
/// Using this abstraction instead of `Vec<T>` enables more flexibility in how
/// keyframes are stored. In particular, morph weights use this trait in order
/// to flatten the keyframes for all morph weights into a single vector instead
/// of nesting vectors.
pub(crate) trait GetKeyframe {
/// The type of the property to be animated.
type Output;
/// Retrieves the value of the keyframe at the given index.
fn get_keyframe(&self, index: usize) -> Option<&Self::Output>;
}

/// Interpolates between keyframes and stores the result in `dest`.
///
/// This is factored out so that it can be shared between implementations of
/// [`crate::keyframes::Keyframes`].
pub(crate) fn interpolate_keyframes<T>(
dest: &mut T,
keyframes: &(impl GetKeyframe<Output = T> + ?Sized),
interpolation: Interpolation,
step_start: usize,
time: f32,
weight: f32,
duration: f32,
) -> Result<(), AnimationEvaluationError>
where
T: Animatable + Clone,
{
let value = match interpolation {
Interpolation::Step => {
let Some(start_keyframe) = keyframes.get_keyframe(step_start) else {
return Err(AnimationEvaluationError::KeyframeNotPresent(step_start));
};
(*start_keyframe).clone()
}

Interpolation::Linear => {
let (Some(start_keyframe), Some(end_keyframe)) = (
keyframes.get_keyframe(step_start),
keyframes.get_keyframe(step_start + 1),
) else {
return Err(AnimationEvaluationError::KeyframeNotPresent(step_start + 1));
};

T::interpolate(start_keyframe, end_keyframe, time)
}

Interpolation::CubicSpline => {
let (
Some(start_keyframe),
Some(start_tangent_keyframe),
Some(end_tangent_keyframe),
Some(end_keyframe),
) = (
keyframes.get_keyframe(step_start * 3 + 1),
keyframes.get_keyframe(step_start * 3 + 2),
keyframes.get_keyframe(step_start * 3 + 3),
keyframes.get_keyframe(step_start * 3 + 4),
)
else {
return Err(AnimationEvaluationError::KeyframeNotPresent(
step_start * 3 + 4,
));
};

interpolate_with_cubic_bezier(
start_keyframe,
start_tangent_keyframe,
end_tangent_keyframe,
end_keyframe,
time,
duration,
)
}
};

*dest = T::interpolate(dest, &value, weight);

Ok(())
}

/// Evaluates a cubic Bézier curve at a value `t`, given two endpoints and the
/// derivatives at those endpoints.
///
/// The derivatives are linearly scaled by `duration`.
fn interpolate_with_cubic_bezier<T>(p0: &T, d0: &T, d3: &T, p3: &T, t: f32, duration: f32) -> T
pub fn interpolate_with_cubic_bezier<T>(p0: &T, d0: &T, d3: &T, p3: &T, t: f32, duration: f32) -> T
where
T: Animatable + Clone,
{
Expand Down
Loading

0 comments on commit 0b5b0d3

Please sign in to comment.