-
Notifications
You must be signed in to change notification settings - Fork 808
Expand file tree
/
Copy pathtextured_rect.rs
More file actions
72 lines (64 loc) · 2.85 KB
/
Copy pathtextured_rect.rs
File metadata and controls
72 lines (64 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use glam::Vec3;
use re_log_types::EntityPath;
use re_renderer::renderer;
use re_sdk_types::ArchetypeName;
use re_viewer_context::{ColormapWithRange, ImageInfo, ImageStatsCache, ViewerContext, gpu_bridge};
use crate::contexts::SpatialSceneEntityContext;
pub fn textured_rect_from_image(
ctx: &ViewerContext<'_>,
ent_path: &EntityPath,
ent_context: &SpatialSceneEntityContext<'_>,
image: &ImageInfo,
colormap: Option<&ColormapWithRange>,
multiplicative_tint: egui::Rgba,
archetype_name: ArchetypeName,
) -> anyhow::Result<renderer::TexturedRect> {
let debug_name = ent_path.to_string();
let tensor_stats = ctx
.store_context
.caches
.entry(|c: &mut ImageStatsCache| c.entry(image));
gpu_bridge::image_to_gpu(
ctx.render_ctx(),
&debug_name,
image,
&tensor_stats,
&ent_context.annotations,
colormap,
)
.map(|colormapped_texture| {
// TODO(emilk): let users pick texture filtering.
// Always use nearest for magnification: let users see crisp individual pixels when they zoom
let texture_filter_magnification = renderer::TextureFilterMag::Nearest;
// For minimization: we want a smooth linear (ideally mipmapped) filter for color images.
// Note that this filtering is done BEFORE applying the color map!
// For labeled/annotated/class_Id images we want nearest, because interpolating classes makes no sense.
// Interpolating depth images _can_ make sense, but can also produce weird artifacts when there are big jumps (0.1m -> 100m),
// so it's usually safer to turn off.
// The best heuristic is this: if there is a color map being applied, use nearest.
// TODO(emilk): apply filtering _after_ the color map?
let texture_filter_minification = if colormapped_texture.color_mapper.is_on() {
renderer::TextureFilterMin::Nearest
} else {
renderer::TextureFilterMin::Linear
};
let world_from_entity = ent_context
.transform_info
.single_transform_required_for_entity(ent_path, archetype_name)
.as_affine3a();
renderer::TexturedRect {
top_left_corner_position: world_from_entity.transform_point3(Vec3::ZERO),
extent_u: world_from_entity.transform_vector3(Vec3::X * image.width() as f32),
extent_v: world_from_entity.transform_vector3(Vec3::Y * image.height() as f32),
colormapped_texture,
options: renderer::RectangleOptions {
texture_filter_magnification,
texture_filter_minification,
multiplicative_tint,
force_draw_with_transparency: false,
depth_offset: ent_context.depth_offset,
outline_mask: ent_context.highlight.overall,
},
}
})
}