Display: highlight selected elements

This commit is contained in:
Aaron Fenyes 2024-09-16 15:46:45 -07:00
parent a60624884a
commit 96afad0c97
2 changed files with 20 additions and 8 deletions

View file

@ -18,6 +18,7 @@ const int SPHERE_MAX = 200;
uniform int sphere_cnt;
uniform vecInv sphere_list[SPHERE_MAX];
uniform vec3 color_list[SPHERE_MAX];
uniform float highlight_list[SPHERE_MAX];
// view
uniform vec2 resolution;
@ -25,7 +26,6 @@ uniform float shortdim;
// controls
uniform float opacity;
uniform float highlight;
uniform int layer_threshold;
uniform bool debug_mode;
@ -66,6 +66,7 @@ vec3 sRGB(vec3 color) {
struct taggedFrag {
int id;
vec4 color;
float highlight;
vec3 pt;
vec3 normal;
};
@ -82,7 +83,7 @@ taggedFrag[2] sort(taggedFrag a, taggedFrag b) {
return result;
}
taggedFrag sphere_shading(vecInv v, vec3 pt, vec3 base_color, int id) {
taggedFrag sphere_shading(vecInv v, vec3 pt, vec3 base_color, float highlight, int id) {
// 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
@ -92,7 +93,7 @@ taggedFrag sphere_shading(vecInv v, vec3 pt, vec3 base_color, int id) {
float incidence = dot(normal, light_dir);
float illum = mix(0.4, 1.0, max(incidence, 0.0));
return taggedFrag(id, vec4(illum * base_color, opacity), pt, normal);
return taggedFrag(id, vec4(illum * base_color, opacity), highlight, pt, normal);
}
// --- ray-casting ---
@ -158,6 +159,7 @@ void main() {
sphere_list[id],
hit_depths[side] * dir,
dimming * color_list[id],
highlight_list[id],
id
);
}
@ -203,13 +205,15 @@ void main() {
abs(dot(frag1.normal, disp)),
abs(dot(frag0.normal, disp))
) / ixn_sin;
float ixn_highlight = 0.5 * highlight * (1. - smoothstep(2./3.*ixn_threshold, 1.5*ixn_threshold, ixn_dist));
float max_highlight = max(frags[i].highlight, frags[i-1].highlight);
float ixn_highlight = 0.5 * max_highlight * (1. - smoothstep(2./3.*ixn_threshold, 1.5*ixn_threshold, ixn_dist));
frags[i].color = mix(frags[i].color, vec4(1.), ixn_highlight);
frags[i-1].color = mix(frags[i-1].color, vec4(1.), ixn_highlight);
// cusps
float cusp_cos = abs(dot(dir, frag0.normal));
float cusp_threshold = 2.*sqrt(ixn_threshold * sphere_list[frag0.id].lt.s);
float highlight = frags[i].highlight;
float cusp_highlight = highlight * (1. - smoothstep(2./3.*cusp_threshold, 1.5*cusp_threshold, cusp_cos));
frags[i].color = mix(frags[i].color, vec4(1.), cusp_highlight);
}