Make points more transparent in ghost mode

This commit is contained in:
Aaron Fenyes 2025-05-19 00:06:21 -07:00
parent fc230e4993
commit 592f327e62
3 changed files with 24 additions and 12 deletions

View file

@ -22,6 +22,9 @@ use crate::{
// --- scene data ---
const COLOR_SIZE: usize = 3;
type ColorWithOpacity = [f32; COLOR_SIZE + 1];
struct SceneSpheres {
representations: Vec<DVector<f64>>,
colors: Vec<ElementColor>,
@ -53,7 +56,7 @@ impl SceneSpheres {
struct ScenePoints {
representations: Vec<DVector<f64>>,
colors: Vec<ElementColor>,
colors_with_opacity: Vec<ColorWithOpacity>,
highlights: Vec<f32>,
selections: Vec<f32>
}
@ -62,15 +65,19 @@ impl ScenePoints {
fn new() -> ScenePoints {
ScenePoints {
representations: Vec::new(),
colors: Vec::new(),
colors_with_opacity: Vec::new(),
highlights: Vec::new(),
selections: Vec::new()
}
}
fn push(&mut self, representation: DVector<f64>, color: ElementColor, highlight: f32, selected: bool) {
fn push(&mut self, representation: DVector<f64>, color: ElementColor, opacity: f32, highlight: f32, selected: bool) {
let mut color_with_opacity = [0.0; COLOR_SIZE + 1];
color_with_opacity[..COLOR_SIZE].copy_from_slice(&color);
color_with_opacity[COLOR_SIZE] = opacity;
self.representations.push(representation);
self.colors.push(color);
self.colors_with_opacity.push(color_with_opacity);
self.highlights.push(highlight);
self.selections.push(if selected { 1.0 } else { 0.0 });
}
@ -156,11 +163,15 @@ impl DisplayItem for Sphere {
impl DisplayItem for Point {
fn show(&self, scene: &mut Scene, selected: bool) {
const HIGHLIGHT: f32 = 0.5; /* SCAFFOLDING */
/* SCAFFOLDING */
const GHOST_OPACITY: f32 = 0.4;
const HIGHLIGHT: f32 = 0.5;
let representation = self.representation.get_clone_untracked();
let color = if selected { self.color.map(|channel| 0.2 + 0.8*channel) } else { self.color };
let opacity = if self.ghost.get() { GHOST_OPACITY } else { 1.0 };
let highlight = if selected { 1.0 } else { HIGHLIGHT };
scene.points.push(representation, color, highlight, selected);
scene.points.push(representation, color, opacity, highlight, selected);
}
/* SCAFFOLDING */
@ -714,7 +725,7 @@ pub fn Display() -> View {
// bind them to the corresponding attributes in the vertex
// shader
bind_new_buffer_to_attribute(&ctx, point_position_attr, SPACE_DIM as i32, point_positions.as_slice());
bind_new_buffer_to_attribute(&ctx, point_color_attr, COLOR_SIZE as i32, scene.points.colors.concat().as_slice());
bind_new_buffer_to_attribute(&ctx, point_color_attr, (COLOR_SIZE + 1) as i32, scene.points.colors_with_opacity.concat().as_slice());
bind_new_buffer_to_attribute(&ctx, point_highlight_attr, 1 as i32, scene.points.highlights.as_slice());
bind_new_buffer_to_attribute(&ctx, point_selection_attr, 1 as i32, scene.points.selections.as_slice());

View file

@ -2,7 +2,7 @@
precision highp float;
in vec3 point_color;
in vec4 point_color;
in float point_highlight;
in float total_radius;
@ -13,6 +13,7 @@ void main() {
const float POINT_RADIUS = 4.;
float border = smoothstep(POINT_RADIUS - 1., POINT_RADIUS, r);
vec3 color = mix(point_color, vec3(1.), border * point_highlight);
outColor = vec4(color, 1. - smoothstep(total_radius - 1., total_radius, r));
float disk = 1. - smoothstep(total_radius - 1., total_radius, r);
vec4 color = mix(point_color, vec4(1.), border * point_highlight);
outColor = vec4(vec3(1.), disk) * color;
}

View file

@ -1,11 +1,11 @@
#version 300 es
in vec4 position;
in vec3 color;
in vec4 color;
in float highlight;
in float selected;
out vec3 point_color;
out vec4 point_color;
out float point_highlight;
out float total_radius;