Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPU tensor colormapping #1841

Merged
merged 27 commits into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
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: 7 additions & 6 deletions crates/re_data_store/src/entity_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,23 +143,24 @@ impl ExtraQueryHistory {
pub enum Colormap {
/// Perceptually even
Grayscale,

Inferno,
Magma,
Plasma,
#[default]
Turbo,
Viridis,
Plasma,
Magma,
Inferno,
}

impl std::fmt::Display for Colormap {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
Colormap::Grayscale => "Grayscale",
Colormap::Inferno => "Inferno",
Colormap::Magma => "Magma",
Colormap::Plasma => "Plasma",
Colormap::Turbo => "Turbo",
Colormap::Viridis => "Viridis",
Colormap::Plasma => "Plasma",
Colormap::Magma => "Magma",
Colormap::Inferno => "Inferno",
})
}
}
Expand Down
19 changes: 19 additions & 0 deletions crates/re_log_types/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,25 @@ impl TensorDataType {
}
}

#[inline]
pub fn min_value(&self) -> f64 {
match self {
Self::U8 => u8::MIN as _,
Self::U16 => u16::MIN as _,
Self::U32 => u32::MIN as _,
Self::U64 => u64::MIN as _,

Self::I8 => i8::MIN as _,
Self::I16 => i16::MIN as _,
Self::I32 => i32::MIN as _,
Self::I64 => i64::MIN as _,

Self::F16 => f16::MIN.into(),
Self::F32 => f32::MIN as _,
Self::F64 => f64::MIN,
}
}

#[inline]
pub fn max_value(&self) -> f64 {
match self {
Expand Down
72 changes: 33 additions & 39 deletions crates/re_renderer/examples/2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,25 +225,22 @@ impl framework::Example for Render2D {
vec![
// 2d view to the left
{
let mut view_builder = ViewBuilder::default();
view_builder
.setup_view(
re_ctx,
TargetConfiguration {
name: "2D".into(),
resolution_in_pixel: splits[0].resolution_in_pixel,
view_from_world: macaw::IsoTransform::IDENTITY,
projection_from_view: Projection::Orthographic {
camera_mode:
view_builder::OrthographicCameraMode::TopLeftCornerAndExtendZ,
vertical_world_size: splits[0].resolution_in_pixel[1] as f32,
far_plane_distance: 1000.0,
},
pixels_from_point,
..Default::default()
let mut view_builder = ViewBuilder::new(
re_ctx,
TargetConfiguration {
name: "2D".into(),
resolution_in_pixel: splits[0].resolution_in_pixel,
view_from_world: macaw::IsoTransform::IDENTITY,
projection_from_view: Projection::Orthographic {
camera_mode:
view_builder::OrthographicCameraMode::TopLeftCornerAndExtendZ,
vertical_world_size: splits[0].resolution_in_pixel[1] as f32,
far_plane_distance: 1000.0,
},
)
.unwrap();
pixels_from_point,
..Default::default()
},
);
view_builder.queue_draw(&line_strip_draw_data);
view_builder.queue_draw(&point_draw_data);
view_builder.queue_draw(&rectangle_draw_data);
Expand All @@ -258,7 +255,6 @@ impl framework::Example for Render2D {
},
// and 3d view of the same scene to the right
{
let mut view_builder = ViewBuilder::default();
let seconds_since_startup = time.seconds_since_startup();
let camera_rotation_center = screen_size.extend(0.0) * 0.5;
let camera_position = glam::vec3(
Expand All @@ -267,27 +263,25 @@ impl framework::Example for Render2D {
seconds_since_startup.cos(),
) * screen_size.x.max(screen_size.y)
+ camera_rotation_center;
view_builder
.setup_view(
re_ctx,
view_builder::TargetConfiguration {
name: "3D".into(),
resolution_in_pixel: splits[1].resolution_in_pixel,
view_from_world: macaw::IsoTransform::look_at_rh(
camera_position,
camera_rotation_center,
glam::Vec3::Y,
)
.unwrap(),
projection_from_view: Projection::Perspective {
vertical_fov: 70.0 * std::f32::consts::TAU / 360.0,
near_plane_distance: 0.01,
},
pixels_from_point,
..Default::default()
let mut view_builder = ViewBuilder::new(
re_ctx,
view_builder::TargetConfiguration {
name: "3D".into(),
resolution_in_pixel: splits[1].resolution_in_pixel,
view_from_world: macaw::IsoTransform::look_at_rh(
camera_position,
camera_rotation_center,
glam::Vec3::Y,
)
.unwrap(),
projection_from_view: Projection::Perspective {
vertical_fov: 70.0 * std::f32::consts::TAU / 360.0,
near_plane_distance: 0.01,
},
)
.unwrap();
pixels_from_point,
..Default::default()
},
);
let command_buffer = view_builder
.queue_draw(&line_strip_draw_data)
.queue_draw(&point_draw_data)
Expand Down
78 changes: 36 additions & 42 deletions crates/re_renderer/examples/depth_cloud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,28 +110,25 @@ impl RenderDepthClouds {
builder.to_draw_data(re_ctx).unwrap()
};

let mut view_builder = ViewBuilder::default();
view_builder
.setup_view(
re_ctx,
view_builder::TargetConfiguration {
name: "Point Cloud".into(),
resolution_in_pixel,
view_from_world: IsoTransform::look_at_rh(
self.camera_position,
Vec3::ZERO,
Vec3::Y,
)
.unwrap(),
projection_from_view: Projection::Perspective {
vertical_fov: 70.0 * std::f32::consts::TAU / 360.0,
near_plane_distance: 0.01,
},
pixels_from_point,
..Default::default()
let mut view_builder = ViewBuilder::new(
re_ctx,
view_builder::TargetConfiguration {
name: "Point Cloud".into(),
resolution_in_pixel,
view_from_world: IsoTransform::look_at_rh(
self.camera_position,
Vec3::ZERO,
Vec3::Y,
)
.unwrap(),
projection_from_view: Projection::Perspective {
vertical_fov: 70.0 * std::f32::consts::TAU / 360.0,
near_plane_distance: 0.01,
},
)
.unwrap();
pixels_from_point,
..Default::default()
},
);

let command_buffer = view_builder
.queue_draw(&GenericSkyboxDrawData::new(re_ctx))
Expand Down Expand Up @@ -191,28 +188,25 @@ impl RenderDepthClouds {
)
.unwrap();

let mut view_builder = ViewBuilder::default();
view_builder
.setup_view(
re_ctx,
view_builder::TargetConfiguration {
name: "Depth Cloud".into(),
resolution_in_pixel,
view_from_world: IsoTransform::look_at_rh(
self.camera_position,
Vec3::ZERO,
Vec3::Y,
)
.unwrap(),
projection_from_view: Projection::Perspective {
vertical_fov: 70.0 * std::f32::consts::TAU / 360.0,
near_plane_distance: 0.01,
},
pixels_from_point,
..Default::default()
let mut view_builder = ViewBuilder::new(
re_ctx,
view_builder::TargetConfiguration {
name: "Depth Cloud".into(),
resolution_in_pixel,
view_from_world: IsoTransform::look_at_rh(
self.camera_position,
Vec3::ZERO,
Vec3::Y,
)
.unwrap(),
projection_from_view: Projection::Perspective {
vertical_fov: 70.0 * std::f32::consts::TAU / 360.0,
near_plane_distance: 0.01,
},
)
.unwrap();
pixels_from_point,
..Default::default()
},
);

let command_buffer = view_builder
.queue_draw(&GenericSkyboxDrawData::new(re_ctx))
Expand Down
13 changes: 5 additions & 8 deletions crates/re_renderer/examples/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,14 +288,11 @@ impl<E: Example + 'static> Application<E> {
});

for draw_result in &draw_results {
draw_result
.view_builder
.composite(
&self.re_ctx,
&mut composite_pass,
draw_result.target_location,
)
.expect("Failed to composite view main surface");
draw_result.view_builder.composite(
&self.re_ctx,
&mut composite_pass,
draw_result.target_location,
);
}
};

Expand Down
3 changes: 1 addition & 2 deletions crates/re_renderer/examples/multiview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,7 @@ impl Multiview {
draw_data: &D,
index: u32,
) -> (ViewBuilder, wgpu::CommandBuffer) {
let mut view_builder = ViewBuilder::default();
view_builder.setup_view(re_ctx, target_cfg).unwrap();
let mut view_builder = ViewBuilder::new(re_ctx, target_cfg);

if self
.take_screenshot_next_frame_for_view
Expand Down
53 changes: 23 additions & 30 deletions crates/re_renderer/examples/outlines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,44 +40,37 @@ impl framework::Example for Outlines {
time: &framework::Time,
pixels_from_point: f32,
) -> Vec<framework::ViewDrawResult> {
let mut view_builder = ViewBuilder::default();

if !self.is_paused {
self.seconds_since_startup += time.last_frame_duration.as_secs_f32();
}
let seconds_since_startup = self.seconds_since_startup;
// TODO(#1426): unify camera logic between examples.
let camera_position = glam::vec3(1.0, 3.5, 7.0);

view_builder
.setup_view(
re_ctx,
TargetConfiguration {
name: "OutlinesDemo".into(),
resolution_in_pixel: resolution,
view_from_world: macaw::IsoTransform::look_at_rh(
camera_position,
glam::Vec3::ZERO,
glam::Vec3::Y,
)
.unwrap(),
projection_from_view: Projection::Perspective {
vertical_fov: 70.0 * std::f32::consts::TAU / 360.0,
near_plane_distance: 0.01,
},
pixels_from_point,
outline_config: Some(OutlineConfig {
outline_radius_pixel: (seconds_since_startup * 2.0).sin().abs() * 10.0
+ 2.0,
color_layer_a: re_renderer::Rgba::from_rgb(1.0, 0.6, 0.0),
color_layer_b: re_renderer::Rgba::from_rgba_unmultiplied(
0.25, 0.3, 1.0, 0.5,
),
}),
..Default::default()
let mut view_builder = ViewBuilder::new(
re_ctx,
TargetConfiguration {
name: "OutlinesDemo".into(),
resolution_in_pixel: resolution,
view_from_world: macaw::IsoTransform::look_at_rh(
camera_position,
glam::Vec3::ZERO,
glam::Vec3::Y,
)
.unwrap(),
projection_from_view: Projection::Perspective {
vertical_fov: 70.0 * std::f32::consts::TAU / 360.0,
near_plane_distance: 0.01,
},
)
.unwrap();
pixels_from_point,
outline_config: Some(OutlineConfig {
outline_radius_pixel: (seconds_since_startup * 2.0).sin().abs() * 10.0 + 2.0,
color_layer_a: re_renderer::Rgba::from_rgb(1.0, 0.6, 0.0),
color_layer_b: re_renderer::Rgba::from_rgba_unmultiplied(0.25, 0.3, 1.0, 0.5),
}),
..Default::default()
},
);

let outline_mask_large_mesh = match ((seconds_since_startup * 0.5) as u64) % 5 {
0 => OutlineMaskPreference::NONE,
Expand Down
42 changes: 19 additions & 23 deletions crates/re_renderer/examples/picking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,33 +118,29 @@ impl framework::Example for Picking {
}
}

let mut view_builder = ViewBuilder::default();

// TODO(#1426): unify camera logic between examples.
let camera_position = glam::vec3(1.0, 3.5, 7.0);

view_builder
.setup_view(
re_ctx,
TargetConfiguration {
name: "OutlinesDemo".into(),
resolution_in_pixel: resolution,
view_from_world: macaw::IsoTransform::look_at_rh(
camera_position,
glam::Vec3::ZERO,
glam::Vec3::Y,
)
.unwrap(),
projection_from_view: Projection::Perspective {
vertical_fov: 70.0 * std::f32::consts::TAU / 360.0,
near_plane_distance: 0.01,
},
pixels_from_point,
outline_config: None,
..Default::default()
let mut view_builder = ViewBuilder::new(
re_ctx,
TargetConfiguration {
name: "OutlinesDemo".into(),
resolution_in_pixel: resolution,
view_from_world: macaw::IsoTransform::look_at_rh(
camera_position,
glam::Vec3::ZERO,
glam::Vec3::Y,
)
.unwrap(),
projection_from_view: Projection::Perspective {
vertical_fov: 70.0 * std::f32::consts::TAU / 360.0,
near_plane_distance: 0.01,
},
)
.unwrap();
pixels_from_point,
outline_config: None,
..Default::default()
},
);

// Use an uneven number of pixels for the picking rect so that there is a clearly defined middle-pixel.
// (for this sample a size of 1 would be sufficient, but for a real application you'd want to use a larger size to allow snapping)
Expand Down
Loading