Skip to content

Commit

Permalink
Consistency: call it pixel_per_point everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Apr 24, 2024
1 parent 8682dde commit 89d594f
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion crates/re_renderer/src/global_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub struct FrameUniformBuffer {

/// How many pixels there are per point.
/// I.e. the UI zoom factor
pub pixels_from_point: f32,
pub pixels_per_point: f32,

/// (tan(fov_y / 2) * aspect_ratio, tan(fov_y /2)), i.e. half ratio of screen dimension to screen distance in x & y.
/// Both values are set to f32max for orthographic projection
Expand Down
6 changes: 3 additions & 3 deletions crates/re_renderer/src/view_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ pub struct TargetConfiguration {
/// I.e. the UI zoom factor.
/// Note that this does not affect any of the camera & projection properties and is only used
/// whenever point sizes were explicitly specified.
pub pixels_from_point: f32,
pub pixels_per_point: f32,

/// How [`Size::AUTO`] is interpreted.
pub auto_size_config: AutoSizeConfig,
Expand All @@ -263,7 +263,7 @@ impl Default for TargetConfiguration {
aspect_ratio: 1.0,
},
viewport_transformation: RectTransform::IDENTITY,
pixels_from_point: 1.0,
pixels_per_point: 1.0,
auto_size_config: Default::default(),
outline_config: None,
}
Expand Down Expand Up @@ -457,7 +457,7 @@ impl ViewBuilder {
camera_forward,
tan_half_fov: tan_half_fov.into(),
pixel_world_size_from_camera_distance,
pixels_from_point: config.pixels_from_point,
pixels_per_point: config.pixels_per_point,

auto_size_points: auto_size_points.0,
auto_size_lines: auto_size_lines.0,
Expand Down
6 changes: 3 additions & 3 deletions crates/re_renderer_examples/2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl framework::Example for Render2D {
re_ctx: &re_renderer::RenderContext,
resolution: [u32; 2],
time: &framework::Time,
pixels_from_point: f32,
pixels_per_point: f32,
) -> Vec<framework::ViewDrawResult> {
let splits = framework::split_resolution(resolution, 1, 2).collect::<Vec<_>>();

Expand Down Expand Up @@ -302,7 +302,7 @@ impl framework::Example for Render2D {
vertical_world_size: splits[0].resolution_in_pixel[1] as f32,
far_plane_distance: 1000.0,
},
pixels_from_point,
pixels_per_point,
..Default::default()
},
);
Expand Down Expand Up @@ -344,7 +344,7 @@ impl framework::Example for Render2D {
near_plane_distance: 0.01,
aspect_ratio: resolution[0] as f32 / resolution[1] as f32,
},
pixels_from_point,
pixels_per_point,
..Default::default()
},
);
Expand Down
14 changes: 7 additions & 7 deletions crates/re_renderer_examples/depth_cloud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl RenderDepthClouds {
fn draw_backprojected_point_cloud<FD, ID>(
&mut self,
re_ctx: &re_renderer::RenderContext,
pixels_from_point: f32,
pixels_per_point: f32,
resolution_in_pixel: [u32; 2],
target_location: glam::Vec2,
frame_draw_data: FD,
Expand Down Expand Up @@ -122,7 +122,7 @@ impl RenderDepthClouds {
near_plane_distance: 0.01,
aspect_ratio: resolution_in_pixel[0] as f32 / resolution_in_pixel[1] as f32,
},
pixels_from_point,
pixels_per_point,
..Default::default()
},
);
Expand All @@ -146,7 +146,7 @@ impl RenderDepthClouds {
fn draw_depth_cloud<FD, ID>(
&mut self,
re_ctx: &re_renderer::RenderContext,
pixels_from_point: f32,
pixels_per_point: f32,
resolution_in_pixel: [u32; 2],
target_location: glam::Vec2,
frame_draw_data: FD,
Expand Down Expand Up @@ -202,7 +202,7 @@ impl RenderDepthClouds {
near_plane_distance: 0.01,
aspect_ratio: resolution_in_pixel[0] as f32 / resolution_in_pixel[1] as f32,
},
pixels_from_point,
pixels_per_point,
..Default::default()
},
);
Expand Down Expand Up @@ -265,7 +265,7 @@ impl framework::Example for RenderDepthClouds {
re_ctx: &re_renderer::RenderContext,
resolution: [u32; 2],
time: &framework::Time,
pixels_from_point: f32,
pixels_per_point: f32,
) -> Vec<framework::ViewDrawResult> {
let Self {
albedo,
Expand Down Expand Up @@ -329,15 +329,15 @@ impl framework::Example for RenderDepthClouds {
vec![
self.draw_backprojected_point_cloud(
re_ctx,
pixels_from_point,
pixels_per_point,
splits[0].resolution_in_pixel,
splits[0].target_location,
frame_draw_data.clone(),
image_draw_data.clone(),
),
self.draw_depth_cloud(
re_ctx,
pixels_from_point,
pixels_per_point,
splits[1].resolution_in_pixel,
splits[1].target_location,
frame_draw_data,
Expand Down
4 changes: 2 additions & 2 deletions crates/re_renderer_examples/depth_offset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl framework::Example for Render2D {
re_ctx: &re_renderer::RenderContext,
resolution: [u32; 2],
_time: &framework::Time,
pixels_from_point: f32,
pixels_per_point: f32,
) -> Vec<framework::ViewDrawResult> {
let mut rectangles = Vec::new();

Expand Down Expand Up @@ -110,7 +110,7 @@ impl framework::Example for Render2D {
near_plane_distance: self.near_plane,
aspect_ratio: resolution[0] as f32 / resolution[1] as f32,
},
pixels_from_point,
pixels_per_point,
..Default::default()
},
);
Expand Down
2 changes: 1 addition & 1 deletion crates/re_renderer_examples/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub trait Example {
re_ctx: &RenderContext,
resolution: [u32; 2],
time: &Time,
pixels_from_point: f32,
pixels_per_point: f32,
) -> Vec<ViewDrawResult>;

fn on_key_event(&mut self, _event: winit::event::KeyEvent) {}
Expand Down
4 changes: 2 additions & 2 deletions crates/re_renderer_examples/multiview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ impl Example for Multiview {
re_ctx: &RenderContext,
resolution: [u32; 2],
time: &framework::Time,
pixels_from_point: f32,
pixels_per_point: f32,
) -> Vec<framework::ViewDrawResult> {
if matches!(self.camera_control, CameraControl::RotateAroundCenter) {
let seconds_since_startup = time.seconds_since_startup();
Expand Down Expand Up @@ -373,7 +373,7 @@ impl Example for Multiview {
resolution_in_pixel: splits[$n].resolution_in_pixel,
view_from_world,
projection_from_view: projection_from_view.clone(),
pixels_from_point,
pixels_per_point,
..Default::default()
},
skybox.clone(),
Expand Down
4 changes: 2 additions & 2 deletions crates/re_renderer_examples/outlines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl framework::Example for Outlines {
re_ctx: &re_renderer::RenderContext,
resolution: [u32; 2],
time: &framework::Time,
pixels_from_point: f32,
pixels_per_point: f32,
) -> Vec<framework::ViewDrawResult> {
if !self.is_paused {
self.seconds_since_startup += time.last_frame_duration.as_secs_f32();
Expand All @@ -65,7 +65,7 @@ impl framework::Example for Outlines {
near_plane_distance: 0.01,
aspect_ratio: resolution[0] as f32 / resolution[1] as f32,
},
pixels_from_point,
pixels_per_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),
Expand Down
4 changes: 2 additions & 2 deletions crates/re_renderer_examples/picking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl framework::Example for Picking {
re_ctx: &re_renderer::RenderContext,
resolution: [u32; 2],
_time: &framework::Time,
pixels_from_point: f32,
pixels_per_point: f32,
) -> Vec<framework::ViewDrawResult> {
while let Some(picking_result) =
PickingLayerProcessor::next_readback_result::<()>(re_ctx, READBACK_IDENTIFIER)
Expand Down Expand Up @@ -136,7 +136,7 @@ impl framework::Example for Picking {
near_plane_distance: 0.01,
aspect_ratio: resolution[0] as f32 / resolution[1] as f32,
},
pixels_from_point,
pixels_per_point,
outline_config: None,
..Default::default()
},
Expand Down
4 changes: 2 additions & 2 deletions crates/re_space_view_spatial/src/picking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ impl PickingContext {
pointer_in_ui: egui::Pos2,
space2d_from_ui: egui::emath::RectTransform,
ui_clip_rect: egui::Rect,
pixels_from_points: f32,
pixels_per_point: f32,
eye: &Eye,
) -> PickingContext {
let pointer_in_space2d = space2d_from_ui.transform_pos(pointer_in_ui);
let pointer_in_space2d = glam::vec2(pointer_in_space2d.x, pointer_in_space2d.y);
let pointer_in_pixel = (pointer_in_ui - ui_clip_rect.left_top()) * pixels_from_points;
let pointer_in_pixel = (pointer_in_ui - ui_clip_rect.left_top()) * pixels_per_point;

PickingContext {
pointer_in_space2d,
Expand Down
6 changes: 3 additions & 3 deletions crates/re_space_view_spatial/src/ui_2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,9 @@ fn setup_target_config(

// ----------------------

let pixels_from_point = egui_painter.ctx().pixels_per_point();
let pixels_per_point = egui_painter.ctx().pixels_per_point();
let resolution_in_pixel =
gpu_bridge::viewport_resolution_in_pixels(egui_painter.clip_rect(), pixels_from_point);
gpu_bridge::viewport_resolution_in_pixels(egui_painter.clip_rect(), pixels_per_point);
anyhow::ensure!(0 < resolution_in_pixel[0] && 0 < resolution_in_pixel[1]);

Ok({
Expand All @@ -394,7 +394,7 @@ fn setup_target_config(
view_from_world,
projection_from_view,
viewport_transformation,
pixels_from_point,
pixels_per_point,
auto_size_config,
outline_config: any_outlines.then(|| outline_config(egui_painter.ctx())),
}
Expand Down
2 changes: 1 addition & 1 deletion crates/re_space_view_spatial/src/ui_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ pub fn view_3d(
},
viewport_transformation: re_renderer::RectTransform::IDENTITY,

pixels_from_point: ui.ctx().pixels_per_point(),
pixels_per_point: ui.ctx().pixels_per_point(),
auto_size_config: state.auto_size_config(),

outline_config: query
Expand Down
12 changes: 6 additions & 6 deletions crates/re_viewer_context/src/gpu_bridge/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ pub fn tensor_decode_srgb_gamma_heuristic(

// ----------------------------------------------------------------------------

pub fn viewport_resolution_in_pixels(clip_rect: egui::Rect, pixels_from_point: f32) -> [u32; 2] {
let min = (clip_rect.min.to_vec2() * pixels_from_point).round();
let max = (clip_rect.max.to_vec2() * pixels_from_point).round();
pub fn viewport_resolution_in_pixels(clip_rect: egui::Rect, pixels_per_point: f32) -> [u32; 2] {
let min = (clip_rect.min.to_vec2() * pixels_per_point).round();
let max = (clip_rect.max.to_vec2() * pixels_per_point).round();
let resolution = max - min;
[resolution.x as u32, resolution.y as u32]
}
Expand Down Expand Up @@ -160,14 +160,14 @@ pub fn render_image(

// ------------------------------------------------------------------------

let pixels_from_points = egui_painter.ctx().pixels_per_point();
let pixels_per_point = egui_painter.ctx().pixels_per_point();
let ui_from_space = egui::emath::RectTransform::from_to(space_rect, image_rect_on_screen);
let space_from_ui = ui_from_space.inverse();
let space_from_points = space_from_ui.scale().y;
let points_from_pixels = 1.0 / egui_painter.ctx().pixels_per_point();
let space_from_pixel = space_from_points * points_from_pixels;

let resolution_in_pixel = viewport_resolution_in_pixels(viewport, pixels_from_points);
let resolution_in_pixel = viewport_resolution_in_pixels(viewport, pixels_per_point);
anyhow::ensure!(resolution_in_pixel[0] > 0 && resolution_in_pixel[1] > 0);

let camera_position_space = space_from_ui.transform_pos(viewport.min);
Expand All @@ -184,7 +184,7 @@ pub fn render_image(
far_plane_distance: 1000.0,
},
viewport_transformation: re_renderer::RectTransform::IDENTITY,
pixels_from_point: pixels_from_points,
pixels_per_point: pixels_per_point,
auto_size_config: Default::default(),
outline_config: None,
};
Expand Down

0 comments on commit 89d594f

Please sign in to comment.