Skip to content

Commit 7e2e357

Browse files
committed
feat: rasterize position
1 parent 8be87d7 commit 7e2e357

File tree

7 files changed

+35
-2
lines changed

7 files changed

+35
-2
lines changed

src/gaussian/settings.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@ pub enum RasterizeMode {
8888
#[default]
8989
Color,
9090
Depth,
91-
OpticalFlow,
9291
Normal,
92+
OpticalFlow,
93+
Position,
9394
Velocity,
9495
}
9596

src/material/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use bevy::prelude::*;
33
pub mod classification;
44
pub mod depth;
55
pub mod optical_flow;
6+
pub mod position;
67
pub mod spherical_harmonics;
78
pub mod spherindrical_harmonics;
89

@@ -23,6 +24,7 @@ impl Plugin for MaterialPlugin {
2324
classification::ClassificationMaterialPlugin,
2425
depth::DepthMaterialPlugin,
2526
optical_flow::OpticalFlowMaterialPlugin,
27+
position::PositionMaterialPlugin,
2628
spherical_harmonics::SphericalHarmonicCoefficientsPlugin,
2729
spherindrical_harmonics::SpherindricalHarmonicCoefficientsPlugin,
2830
));

src/material/position.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use bevy::{
2+
prelude::*,
3+
asset::load_internal_asset,
4+
};
5+
6+
7+
const POSITION_SHADER_HANDLE: Handle<Shader> = Handle::weak_from_u128(62346645534);
8+
9+
10+
pub struct PositionMaterialPlugin;
11+
12+
impl Plugin for PositionMaterialPlugin {
13+
fn build(&self, app: &mut App) {
14+
load_internal_asset!(
15+
app,
16+
POSITION_SHADER_HANDLE,
17+
"position.wgsl",
18+
Shader::from_wgsl
19+
);
20+
}
21+
}

src/material/position.wgsl

Whitespace-only changes.

src/render/bindings.wgsl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ struct GaussianUniforms {
1919
time_start: f32,
2020
time_stop: f32,
2121
num_classes: u32,
22+
min: vec4<f32>,
23+
max: vec4<f32>,
2224
};
2325
@group(1) @binding(0) var<uniform> gaussian_uniforms: GaussianUniforms;
2426

src/render/gaussian.wgsl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,8 @@ fn vs_points(
359359
);
360360

361361
rgb = optical_flow_to_rgb(motion_vector);
362+
#else ifdef RASTERIZE_POSITION
363+
rgb = (transformed_position - gaussian_uniforms.min.xyz) / (gaussian_uniforms.max.xyz - gaussian_uniforms.min.xyz);
362364
#else ifdef RASTERIZE_VELOCITY
363365
let time_delta = 1e-3;
364366
let future_gaussian_4d = conditional_cov3d(

src/render/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,8 +687,9 @@ pub fn shader_defs(
687687
RasterizeMode::Classification => shader_defs.push("RASTERIZE_CLASSIFICATION".into()),
688688
RasterizeMode::Color => shader_defs.push("RASTERIZE_COLOR".into()),
689689
RasterizeMode::Depth => shader_defs.push("RASTERIZE_DEPTH".into()),
690-
RasterizeMode::OpticalFlow => shader_defs.push("RASTERIZE_OPTICAL_FLOW".into()),
691690
RasterizeMode::Normal => shader_defs.push("RASTERIZE_NORMAL".into()),
691+
RasterizeMode::OpticalFlow => shader_defs.push("RASTERIZE_OPTICAL_FLOW".into()),
692+
RasterizeMode::Position => shader_defs.push("RASTERIZE_POSITION".into()),
692693
RasterizeMode::Velocity => shader_defs.push("RASTERIZE_VELOCITY".into()),
693694
}
694695

@@ -807,6 +808,8 @@ pub struct CloudUniform {
807808
pub time_start: f32,
808809
pub time_stop: f32,
809810
pub num_classes: u32,
811+
pub min: Vec4,
812+
pub max: Vec4,
810813
}
811814

812815
#[allow(clippy::type_complexity)]
@@ -870,6 +873,8 @@ pub fn extract_gaussians<R: PlanarStorage>(
870873
time_start: settings.time_start,
871874
time_stop: settings.time_stop,
872875
num_classes: settings.num_classes as u32,
876+
min: aabb.min().extend(1.0),
877+
max: aabb.max().extend(1.0),
873878
};
874879

875880
commands_list.push((

0 commit comments

Comments
 (0)