Introduce ghost mode for elements #85

Merged
glen merged 4 commits from Vectornaut/dyna3:ghost-mode into main 2025-06-02 15:56:08 +00:00
2 changed files with 14 additions and 10 deletions
Showing only changes of commit ba1d87812f - Show all commits

View file

@ -469,7 +469,6 @@ pub fn Display() -> View {
);
let resolution_loc = ctx.get_uniform_location(&sphere_program, "resolution");
let shortdim_loc = ctx.get_uniform_location(&sphere_program, "shortdim");
let opacity_loc = ctx.get_uniform_location(&sphere_program, "opacity");
let layer_threshold_loc = ctx.get_uniform_location(&sphere_program, "layer_threshold");
let debug_mode_loc = ctx.get_uniform_location(&sphere_program, "debug_mode");
@ -646,6 +645,11 @@ pub fn Display() -> View {
ctx.uniform1i(sphere_cnt_loc.as_ref(), sphere_cnt);
for n in 0..sphere_reps_world.len() {
let v = &sphere_reps_world[n];
let sphere_color = &mut [0.0; 4];
sphere_color[..3].copy_from_slice(&scene.spheres.colors[n]);
sphere_color[3] = OPACITY;
ctx.uniform3fv_with_f32_array(
sphere_sp_locs[n].as_ref(),
v.rows(0, 3).as_slice()
@ -654,9 +658,9 @@ pub fn Display() -> View {
sphere_lt_locs[n].as_ref(),
v.rows(3, 2).as_slice()
);
ctx.uniform3fv_with_f32_array(
ctx.uniform4fv_with_f32_array(
sphere_color_locs[n].as_ref(),
&scene.spheres.colors[n]
sphere_color
);
ctx.uniform1f(
sphere_highlight_locs[n].as_ref(),
@ -665,7 +669,6 @@ pub fn Display() -> View {
}
// pass the display parameters
ctx.uniform1f(opacity_loc.as_ref(), OPACITY);
ctx.uniform1i(layer_threshold_loc.as_ref(), LAYER_THRESHOLD);
ctx.uniform1i(debug_mode_loc.as_ref(), DEBUG_MODE);

View file

@ -17,7 +17,7 @@ struct vecInv {
const int SPHERE_MAX = 200;
uniform int sphere_cnt;
uniform vecInv sphere_list[SPHERE_MAX];
uniform vec3 color_list[SPHERE_MAX];
uniform vec4 color_list[SPHERE_MAX];
uniform float highlight_list[SPHERE_MAX];
// view
@ -25,7 +25,6 @@ uniform vec2 resolution;
uniform float shortdim;
// controls
uniform float opacity;
uniform int layer_threshold;
uniform bool debug_mode;
@ -69,7 +68,7 @@ struct Fragment {
vec4 color;
};
Fragment sphere_shading(vecInv v, vec3 pt, vec3 base_color) {
Fragment sphere_shading(vecInv v, vec3 pt, vec4 base_color) {
// the expression for normal needs to be checked. it's supposed to give the
// negative gradient of the lorentz product between the impact point vector
// and the sphere vector with respect to the coordinates of the impact
@ -79,7 +78,7 @@ Fragment sphere_shading(vecInv v, vec3 pt, vec3 base_color) {
float incidence = dot(normal, light_dir);
float illum = mix(0.4, 1.0, max(incidence, 0.0));
return Fragment(pt, normal, vec4(illum * base_color, opacity));
return Fragment(pt, normal, vec4(illum * base_color.rgb, base_color.a));
}
float intersection_dist(Fragment a, Fragment b) {
@ -192,10 +191,11 @@ void main() {
vec3 color = vec3(0.);
int layer = layer_cnt - 1;
TaggedDepth hit = top_hits[layer];
vec4 sphere_color = color_list[hit.id];
Fragment frag_next = sphere_shading(
sphere_list[hit.id],
hit.depth * dir,
hit.dimming * color_list[hit.id]
vec4(hit.dimming * sphere_color.rgb, sphere_color.a)
);
float highlight_next = highlight_list[hit.id];
--layer;
@ -206,10 +206,11 @@ void main() {
// shade the next fragment
hit = top_hits[layer];
sphere_color = color_list[hit.id];
frag_next = sphere_shading(
sphere_list[hit.id],
hit.depth * dir,
hit.dimming * color_list[hit.id]
vec4(hit.dimming * sphere_color.rgb, sphere_color.a)
);
highlight_next = highlight_list[hit.id];