Skip to content

Commit

Permalink
fix: morph_particles feature
Browse files Browse the repository at this point in the history
  • Loading branch information
mosure committed May 27, 2024
1 parent c28ad9e commit 5084a9d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ default = [
"query_select",
# "query_sparse",

# "morph_particles",
"morph_particles",

# "sort_radix", # TODO: fix macos radix sort
"sort_rayon",
Expand Down
11 changes: 6 additions & 5 deletions src/morph/particle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ use bevy::{
NodeRunError,
RenderGraphApp,
RenderGraphContext,
RenderLabel,
},
Render,
RenderApp,
Expand Down Expand Up @@ -88,9 +89,9 @@ use crate::render::{


const PARTICLE_SHADER_HANDLE: Handle<Shader> = Handle::weak_from_u128(234553453455);
pub mod node {
pub const MORPH: &str = "gaussian_cloud_particle_behavior";
}

#[derive(Debug, Hash, PartialEq, Eq, Clone, RenderLabel)]
pub struct MorphLabel;


#[derive(Default)]
Expand All @@ -114,11 +115,11 @@ impl Plugin for ParticleBehaviorPlugin {
render_app
.add_render_graph_node::<ParticleBehaviorNode>(
Core3d,
node::MORPH,
MorphLabel,
)
.add_render_graph_edge(
Core3d,
node::MORPH,
MorphLabel,
Node3d::Prepass,
);

Expand Down
8 changes: 4 additions & 4 deletions src/morph/particle.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#import bevy_gaussian_splatting::bindings::{
gaussian_uniforms,
globals,
points,
position_visibility,
}
#import bevy_gaussian_splatting::spherical_harmonics::spherical_harmonics_lookup
#import bevy_gaussian_splatting::transform::{
Expand Down Expand Up @@ -31,15 +31,15 @@ fn apply_particle_behaviors(
let behavior = particle_behaviors[behavior_index];

let point_index = behavior.indicies.x;
let point = points[point_index];
let point = position_visibility[point_index];

// TODO: add gaussian attribute setters for 4d capability

let delta_position = behavior.velocity * globals.delta_time + 0.5 * behavior.acceleration * globals.delta_time * globals.delta_time + 1.0 / 6.0 * behavior.jerk * globals.delta_time * globals.delta_time * globals.delta_time;
let delta_velocity = behavior.acceleration * globals.delta_time + 0.5 * behavior.jerk * globals.delta_time * globals.delta_time;
let delta_acceleration = behavior.jerk * globals.delta_time;

let new_position = point.position_visibility + delta_position;
let new_position = point + delta_position;
let new_velocity = behavior.velocity + delta_velocity;
let new_acceleration = behavior.acceleration + delta_acceleration;

Expand All @@ -49,7 +49,7 @@ fn apply_particle_behaviors(
return;
}

points[point_index].position_visibility = new_position;
position_visibility[point_index] = new_position;
particle_behaviors[behavior_index].velocity = new_velocity;
particle_behaviors[behavior_index].acceleration = new_acceleration;
}
4 changes: 2 additions & 2 deletions src/render/planar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ pub fn get_bind_group_layout(
binding: 1,
visibility: ShaderStages::all(),
ty: BindingType::Buffer {
ty: BufferBindingType::Storage { read_only },
ty: BufferBindingType::Storage { read_only: true },
has_dynamic_offset: false,
min_binding_size: BufferSize::new(std::mem::size_of::<SphericalHarmonicCoefficients>() as u64),
},
Expand All @@ -173,7 +173,7 @@ pub fn get_bind_group_layout(
binding: 2,
visibility: ShaderStages::all(),
ty: BindingType::Buffer {
ty: BufferBindingType::Storage { read_only },
ty: BufferBindingType::Storage { read_only: true },
has_dynamic_offset: false,
min_binding_size: BufferSize::new(std::mem::size_of::<RotationScaleOpacityPacked128>() as u64),
},
Expand Down
10 changes: 6 additions & 4 deletions viewer/viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,13 @@ fn setup_particle_behavior(
mut commands: Commands,
gaussian_splatting_viewer: Res<GaussianSplattingViewer>,
mut particle_behavior_assets: ResMut<Assets<ParticleBehaviors>>,
gaussian_cloud: Query<(
Entity,
&Handle<GaussianCloud>,
gaussian_cloud: Query<
(
Entity,
&Handle<GaussianCloud>,
),
Without<Handle<ParticleBehaviors>>,
)>,
>,
) {
if gaussian_cloud.is_empty() {
return;
Expand Down

0 comments on commit 5084a9d

Please sign in to comment.