Skip to content

Commit

Permalink
feat: velocity rasterization mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mosure committed Dec 31, 2024
1 parent da02dc5 commit f0f7bdb
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 6 deletions.
8 changes: 8 additions & 0 deletions src/gaussian/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ pub enum GaussianMode {
Hash,
PartialEq,
Reflect,
Serialize,
Deserialize,
ValueEnum,
)]
pub enum PlaybackMode {
#[default]
Expand All @@ -74,12 +77,17 @@ pub enum PlaybackMode {
Hash,
PartialEq,
Reflect,
Serialize,
Deserialize,
ValueEnum,
)]
pub enum RasterizeMode {
#[default]
Color,
Depth,
Flow,
Normal,
Velocity,
}


Expand Down
33 changes: 32 additions & 1 deletion src/render/gaussian.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ fn vs_points(
let gaussian_4d = conditional_cov3d(
transformed_position,
splat_index,
gaussian_uniforms.time,
);

if !gaussian_4d.mask {
Expand Down Expand Up @@ -332,7 +333,37 @@ fn vs_points(
0.5 * (t.y + 1.0),
0.5 * (t.z + 1.0)
);
#else
#else ifdef RASTERIZE_FLOW
// TODO: optical flow rendering
rgb = vec3<f32>(1.0);
#else ifdef RASTERIZE_VELOCITY
let time_delta = 1e-3;
let future_gaussian_4d = conditional_cov3d(
transformed_position,
splat_index,
gaussian_uniforms.time + time_delta,
);
let position_delta = future_gaussian_4d.delta_mean - gaussian_4d.delta_mean;
let velocity = position_delta / time_delta;
let velocity_magnitude = length(velocity);
let velocity_normalized = normalize(velocity);

let min_magnitude = 1.0;
let max_magnitude = 2.0;

let scaled_mag = clamp(
(velocity_magnitude - min_magnitude) / (max_magnitude - min_magnitude),
0.0,
1.0
);

if scaled_mag < 1e-2 {
opacity = 0.0;
}

let base_color = 0.5 * (velocity_normalized + vec3<f32>(1.0, 1.0, 1.0));
rgb = base_color * scaled_mag;
#else ifdef RASTERIZE_COLOR
// TODO: verify color benefit for ray_direction computed at quad verticies instead of gaussian center (same as current complexity)
// TODO: why doesn't Transform rotation change SH color?
let ray_direction = normalize(transformed_position - view.world_position);
Expand Down
5 changes: 3 additions & 2 deletions src/render/gaussian_4d.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,20 @@ fn outer_product(
fn conditional_cov3d(
position: vec3<f32>,
index: u32,
time: f32,
) -> DecomposedGaussian4d {
let isotropic_rotations = get_isotropic_rotations(index);
let rotation = normalize(isotropic_rotations[0]);
let rotation_r = normalize(isotropic_rotations[1]);
let scale = get_scale(index);

let dt = gaussian_uniforms.time - get_timestamp(index);
let dt = time - get_timestamp(index);

let S = mat4x4<f32>(
gaussian_uniforms.global_scale * scale.x, 0.0, 0.0, 0.0,
0.0, gaussian_uniforms.global_scale * scale.y, 0.0, 0.0,
0.0, 0.0, gaussian_uniforms.global_scale * scale.z, 0.0,
0.0, 0.0, 0.0, gaussian_uniforms.global_scale * get_time_scale(index),
0.0, 0.0, 0.0, get_time_scale(index),
);

let a = rotation.x;
Expand Down
2 changes: 2 additions & 0 deletions src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,9 @@ pub fn shader_defs(
match key.rasterize_mode {
RasterizeMode::Color => shader_defs.push("RASTERIZE_COLOR".into()),
RasterizeMode::Depth => shader_defs.push("RASTERIZE_DEPTH".into()),
RasterizeMode::Flow => shader_defs.push("RASTERIZE_FLOW".into()),
RasterizeMode::Normal => shader_defs.push("RASTERIZE_NORMAL".into()),
RasterizeMode::Velocity => shader_defs.push("RASTERIZE_VELOCITY".into()),
}

match key.draw_mode {
Expand Down
14 changes: 13 additions & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ use bevy_args::{
Serialize,
};

use crate::gaussian::settings::GaussianMode;
use crate::gaussian::settings::{
GaussianMode,
PlaybackMode,
RasterizeMode,
};


#[derive(
Expand Down Expand Up @@ -50,6 +54,12 @@ pub struct GaussianSplattingViewer {
#[arg(long, value_enum, default_value_t = GaussianMode::Gaussian3d)]
pub gaussian_mode: GaussianMode,

#[arg(long, value_enum, default_value_t = PlaybackMode::Sin)]
pub playback_mode: PlaybackMode,

#[arg(long, value_enum, default_value_t = RasterizeMode::Color)]
pub rasterization_mode: RasterizeMode,

#[arg(long, default_value = "0")]
pub particle_count: usize,
}
Expand All @@ -68,6 +78,8 @@ impl Default for GaussianSplattingViewer {
input_file: "".to_string(),
gaussian_count: 0,
gaussian_mode: GaussianMode::Gaussian3d,
playback_mode: PlaybackMode::Sin,
rasterization_mode: RasterizeMode::Color,
particle_count: 0,
}
}
Expand Down
6 changes: 4 additions & 2 deletions viewer/viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ use bevy_gaussian_splatting::{
PlanarGaussian3dHandle,
PlanarGaussian4dHandle,
gaussian::interface::TestCloud,
gaussian::settings::PlaybackMode,
random_gaussians_3d,
random_gaussians_4d,
utils::{
Expand Down Expand Up @@ -88,6 +87,8 @@ fn setup_gaussian_cloud(
PlanarGaussian3dHandle(cloud),
CloudSettings {
gaussian_mode: args.gaussian_mode,
playback_mode: args.playback_mode,
rasterize_mode: args.rasterization_mode,
..default()
},
Name::new("gaussian_cloud_3d"),
Expand All @@ -109,7 +110,8 @@ fn setup_gaussian_cloud(
PlanarGaussian4dHandle(cloud),
CloudSettings {
gaussian_mode: args.gaussian_mode,
playback_mode: PlaybackMode::Sin,
playback_mode: args.playback_mode,
rasterize_mode: args.rasterization_mode,
..default()
},
Name::new("gaussian_cloud_4d"),
Expand Down

0 comments on commit f0f7bdb

Please sign in to comment.