feat(selection): highlight opacity and extra width (#1823)

Options > Selection gains "Selection highlight opacity" and "Selection
highlight extra width". Below full opacity the object's own colour
shows through the highlight. The selection overlay draws with its own
copy of the frame uniforms: transparency on, and every line widened by
the extra width. Drawings opened at startup now get the selection
colour settings too; they used to keep the defaults until a setting
changed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Hakan SevenandClaude Opus 5.5 committed 2026-10-16 01:07:23 +03:00
1 parent 977135fbbd
commit 38d81bf838
38 files changed
+247 -89

No files matched your search

+3
View File
@@ -2204,6 +2204,8 @@ pub struct Scene {
pub selection_color: [f32; 4],
/// Whether selection visual effect (glow/highlight) is enabled (SELECTIONEFFECT).
pub selection_effect: bool,
/// Extra screen pixels the selection highlight is drawn wider.
pub selection_widen: f32,
/// Whether entity transparency is honoured on screen. When false the
/// wire shader forces every line opaque (a uniform toggle, no retessellate).
pub transparency_display: bool,
@@ -2827,6 +2829,7 @@ impl Scene {
constraint_hover_refs: Vec::new(),
constraint_hover_wires: Vec::new(),
selection_color: crate::scene::model::wire_model::WireModel::SELECTED,
selection_widen: 0.0,
selection_effect: true,
transparency_display: true,
model_lineweight_scale: 1.0,
+73 -71
View File
@@ -182,6 +182,10 @@ pub struct Pipeline {
uniform_buffer: wgpu::Buffer,
frame_bgl: wgpu::BindGroupLayout,
uniform_bind_group: wgpu::BindGroup,
/// The selection overlay's copy of the frame uniforms: transparency on,
/// so a translucent highlight colour shows, and lines widened.
selection_uniform_buffer: wgpu::Buffer,
selection_uniform_bind_group: wgpu::BindGroup,
shadow_uniform_bind_group: wgpu::BindGroup,
background_texture: wgpu::Texture,
environment_texture: wgpu::Texture,
@@ -414,6 +418,37 @@ pub struct Pipeline {
pub slot_id: u64,
}
/// The views and samplers the frame bind group carries beside its uniforms.
struct FrameViews<'a> {
background: &'a wgpu::TextureView,
environment: &'a wgpu::TextureView,
background_sampler: &'a wgpu::Sampler,
shadow: &'a wgpu::TextureView,
shadow_sampler: &'a wgpu::Sampler,
}
fn frame_bind_group(
device: &wgpu::Device,
layout: &wgpu::BindGroupLayout,
uniforms: &wgpu::Buffer,
views: &FrameViews<'_>,
) -> wgpu::BindGroup {
let entry = |binding, resource| wgpu::BindGroupEntry { binding, resource };
device.create_bind_group(&wgpu::BindGroupDescriptor {
label: Some("viewer.bind_group"),
layout,
entries: &[
entry(0, uniforms.as_entire_binding()),
entry(1, wgpu::BindingResource::TextureView(views.background)),
entry(2, wgpu::BindingResource::Sampler(views.background_sampler)),
entry(3, wgpu::BindingResource::TextureView(views.environment)),
entry(4, wgpu::BindingResource::Sampler(views.background_sampler)),
entry(5, wgpu::BindingResource::TextureView(views.shadow)),
entry(6, wgpu::BindingResource::Sampler(views.shadow_sampler)),
],
})
}
impl Pipeline {
pub fn new(device: &wgpu::Device, queue: &wgpu::Queue, format: wgpu::TextureFormat) -> Self {
// ── Shared frame uniform buffer (view_proj etc.) ───────────────────
@@ -423,6 +458,12 @@ impl Pipeline {
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
mapped_at_creation: false,
});
let selection_uniform_buffer = device.create_buffer(&wgpu::BufferDescriptor {
label: Some("viewer.selection_uniform_buffer"),
size: std::mem::size_of::<Uniforms>() as u64,
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
mapped_at_creation: false,
});
// Bind group layout 0 — shared by wire and hatch pipelines.
let frame_bgl = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
@@ -563,40 +604,17 @@ impl Pipeline {
background_texture.create_view(&wgpu::TextureViewDescriptor::default());
let environment_view =
environment_texture.create_view(&wgpu::TextureViewDescriptor::default());
let uniform_bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
label: Some("viewer.bind_group"),
layout: &frame_bgl,
entries: &[
wgpu::BindGroupEntry {
binding: 0,
resource: uniform_buffer.as_entire_binding(),
},
wgpu::BindGroupEntry {
binding: 1,
resource: wgpu::BindingResource::TextureView(&background_view),
},
wgpu::BindGroupEntry {
binding: 2,
resource: wgpu::BindingResource::Sampler(&background_sampler),
},
wgpu::BindGroupEntry {
binding: 3,
resource: wgpu::BindingResource::TextureView(&environment_view),
},
wgpu::BindGroupEntry {
binding: 4,
resource: wgpu::BindingResource::Sampler(&background_sampler),
},
wgpu::BindGroupEntry {
binding: 5,
resource: wgpu::BindingResource::TextureView(&shadow_fallback_view),
},
wgpu::BindGroupEntry {
binding: 6,
resource: wgpu::BindingResource::Sampler(&shadow_sampler),
},
],
});
let frame_views = FrameViews {
background: &background_view,
environment: &environment_view,
background_sampler: &background_sampler,
shadow: &shadow_fallback_view,
shadow_sampler: &shadow_sampler,
};
let uniform_bind_group =
frame_bind_group(device, &frame_bgl, &uniform_buffer, &frame_views);
let selection_uniform_bind_group =
frame_bind_group(device, &frame_bgl, &selection_uniform_buffer, &frame_views);
let shadow_uniform_bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
label: Some("shadow.frame_bind_group"),
layout: &shadow_frame_bgl,
@@ -2390,6 +2408,8 @@ impl Pipeline {
uniform_buffer,
frame_bgl,
uniform_bind_group,
selection_uniform_buffer,
selection_uniform_bind_group,
shadow_uniform_bind_group,
background_texture,
environment_texture,
@@ -3926,40 +3946,18 @@ analytic={:.1} regular={:.1} blocks={:.1}",
let environment_view = self
.environment_texture
.create_view(&wgpu::TextureViewDescriptor::default());
self.uniform_bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
label: Some("viewer.bind_group"),
layout: &self.frame_bgl,
entries: &[
wgpu::BindGroupEntry {
binding: 0,
resource: self.uniform_buffer.as_entire_binding(),
},
wgpu::BindGroupEntry {
binding: 1,
resource: wgpu::BindingResource::TextureView(&background_view),
},
wgpu::BindGroupEntry {
binding: 2,
resource: wgpu::BindingResource::Sampler(&self.background_sampler),
},
wgpu::BindGroupEntry {
binding: 3,
resource: wgpu::BindingResource::TextureView(&environment_view),
},
wgpu::BindGroupEntry {
binding: 4,
resource: wgpu::BindingResource::Sampler(&self.background_sampler),
},
wgpu::BindGroupEntry {
binding: 5,
resource: wgpu::BindingResource::TextureView(self.shadow_view()),
},
wgpu::BindGroupEntry {
binding: 6,
resource: wgpu::BindingResource::Sampler(&self.shadow_sampler),
},
],
});
let views = FrameViews {
background: &background_view,
environment: &environment_view,
background_sampler: &self.background_sampler,
shadow: self.shadow_view(),
shadow_sampler: &self.shadow_sampler,
};
let frame = frame_bind_group(device, &self.frame_bgl, &self.uniform_buffer, &views);
let selection =
frame_bind_group(device, &self.frame_bgl, &self.selection_uniform_buffer, &views);
self.uniform_bind_group = frame;
self.selection_uniform_bind_group = selection;
}
/// Allocate or drop the shadow target to match `shadow_enabled`.
@@ -3995,7 +3993,11 @@ analytic={:.1} regular={:.1} blocks={:.1}",
if self.shadow_full.is_none() {
uniforms.shadow_params[0] = 0.0;
}
let mut selection = uniforms;
selection.transparency_enable = 1.0;
uniforms.highlight_widen = 0.0;
queue.write_buffer(&self.uniform_buffer, 0, bytemuck::bytes_of(&uniforms));
queue.write_buffer(&self.selection_uniform_buffer, 0, bytemuck::bytes_of(&selection));
}
pub fn upload_background_images(
@@ -5120,7 +5122,7 @@ analytic={:.1} regular={:.1} blocks={:.1}",
multiview_mask: None,
});
pass.set_viewport(raster.x, raster.y, raster.width, raster.height, 0.0, 1.0);
pass.set_bind_group(0, &self.uniform_bind_group, &[]);
pass.set_bind_group(0, &self.selection_uniform_bind_group, &[]);
pass.set_stencil_reference(stencil_ref);
if !self.gpu_selected_wires.is_empty() {
pass.set_pipeline(if occluded {
@@ -5160,7 +5162,7 @@ analytic={:.1} regular={:.1} blocks={:.1}",
} else {
&self.circle_xray_pipeline
});
pass.set_bind_group(0, &self.uniform_bind_group, &[]);
pass.set_bind_group(0, &self.selection_uniform_bind_group, &[]);
for cg in &self.gpu_selected_circles {
if cg.instance_count > 0 {
pass.set_vertex_buffer(0, cg.instance_buffer.slice(..));
@@ -5174,7 +5176,7 @@ analytic={:.1} regular={:.1} blocks={:.1}",
} else {
&self.ellipse_xray_pipeline
});
pass.set_bind_group(0, &self.uniform_bind_group, &[]);
pass.set_bind_group(0, &self.selection_uniform_bind_group, &[]);
for eg in &self.gpu_selected_ellipses {
if eg.instance_count > 0 {
pass.set_vertex_buffer(0, eg.instance_buffer.slice(..));
+4 -2
View File
@@ -39,7 +39,9 @@ pub struct Uniforms {
// jitter.
pub view_rot: glam::Mat4,
pub eye_high: [f32; 3],
pub _pad_eh: f32,
/// Extra screen pixels added to every line width. Only the selection
/// overlay pass sees a non-zero value (`Pipeline::upload_uniforms`).
pub highlight_widen: f32,
pub eye_low: [f32; 3],
pub _pad_el: f32,
@@ -121,7 +123,7 @@ impl Uniforms {
lineweight_scale: 1.0,
view_rot: camera.view_proj_rte(bounds),
eye_high,
_pad_eh: 0.0,
highlight_widen: 0.0,
eye_low,
_pad_el: 0.0,
light_position_type: [[0.0; 4]; 4],
+6
View File
@@ -270,6 +270,8 @@ pub struct Primitive {
pub(in crate::scene) selection_color: [f32; 4],
/// Whether selection visual effect (glow/highlight) is enabled.
pub(in crate::scene) selection_effect: bool,
/// Extra screen pixels the selection highlight is drawn wider.
pub(in crate::scene) selection_widen: f32,
/// One input-to-render sample, carried only when PERF tracing is enabled.
pub(in crate::scene) nav_perf: Option<NavPerfSample>,
}
@@ -4298,6 +4300,7 @@ impl Scene {
viewcube_text_color,
selection_color: self.selection_color,
selection_effect: self.selection_effect,
selection_widen: self.selection_widen,
nav_perf: perf_nav,
}
}
@@ -4330,6 +4333,7 @@ impl Scene {
viewcube_text_color,
selection_color: self.selection_color,
selection_effect: self.selection_effect,
selection_widen: self.selection_widen,
nav_perf: None,
};
};
@@ -4392,6 +4396,7 @@ impl Scene {
viewcube_text_color,
selection_color: self.selection_color,
selection_effect: self.selection_effect,
selection_widen: self.selection_widen,
nav_perf: perf_nav,
}
}
@@ -4688,6 +4693,7 @@ impl Scene {
uniforms.viewport_size = [visible_w, visible_h];
uniforms.flat_shade = if flags.flat_shade { 1.0 } else { 0.0 };
uniforms.transparency_enable = if self.transparency_display { 1.0 } else { 0.0 };
uniforms.highlight_widen = self.selection_widen;
uniforms.viewport_background = display.background.base;
uniforms.view_tone = [display.brightness, display.contrast, 0.0, 0.0];
uniforms.background_top = display.background.colors[0];