Ray-caster: adjust opacity of highlighting

This commit is contained in:
Aaron Fenyes 2024-08-24 11:00:50 -07:00
parent e3df765f16
commit 25da6ca062

View File

@ -75,6 +75,7 @@ fn main() {
let radius_x = create_signal(1.0); let radius_x = create_signal(1.0);
let radius_y = create_signal(1.0); let radius_y = create_signal(1.0);
let opacity = create_signal(0.5); let opacity = create_signal(0.5);
let highlight = create_signal(0.2);
let layer_threshold = create_signal(0.0); let layer_threshold = create_signal(0.0);
let display = create_node_ref(); let display = create_node_ref();
@ -120,6 +121,7 @@ fn main() {
uniform vec2 ctrl; uniform vec2 ctrl;
uniform vec2 radius; uniform vec2 radius;
uniform float opacity; uniform float opacity;
uniform float highlight;
uniform int layer_threshold; uniform int layer_threshold;
// light and camera // light and camera
@ -273,14 +275,14 @@ fn main() {
abs(dot(frag1.normal, disp)), abs(dot(frag1.normal, disp)),
abs(dot(frag0.normal, disp)) abs(dot(frag0.normal, disp))
) / ixn_sin; ) / ixn_sin;
float ixn_highlight = 1. - smoothstep(2./3.*ixn_threshold, 1.5*ixn_threshold, ixn_dist); float ixn_highlight = 0.5 * highlight * (1. - smoothstep(2./3.*ixn_threshold, 1.5*ixn_threshold, ixn_dist));
frags_by_depth[i].color = mix(frags_by_depth[i].color, vec4(1.), ixn_highlight); frags_by_depth[i].color = mix(frags_by_depth[i].color, vec4(1.), ixn_highlight);
frags_by_depth[i-1].color = mix(frags_by_depth[i-1].color, vec4(1.), ixn_highlight); frags_by_depth[i-1].color = mix(frags_by_depth[i-1].color, vec4(1.), ixn_highlight);
// cusps // cusps
float cusp_cos = abs(dot(dir, frag0.normal)); float cusp_cos = abs(dot(dir, frag0.normal));
float cusp_threshold = 2.*sqrt(ixn_threshold * v[frag0.id].lt.s); float cusp_threshold = 2.*sqrt(ixn_threshold * v[frag0.id].lt.s);
float cusp_highlight = 1. - smoothstep(2./3.*cusp_threshold, 1.5*cusp_threshold, cusp_cos); float cusp_highlight = highlight * (1. - smoothstep(2./3.*cusp_threshold, 1.5*cusp_threshold, cusp_cos));
frags_by_depth[i].color = mix(frags_by_depth[i].color, vec4(1.), cusp_highlight); frags_by_depth[i].color = mix(frags_by_depth[i].color, vec4(1.), cusp_highlight);
} }
@ -319,6 +321,7 @@ fn main() {
let ctrl_loc = ctx.get_uniform_location(&program, "ctrl"); let ctrl_loc = ctx.get_uniform_location(&program, "ctrl");
let radius_loc = ctx.get_uniform_location(&program, "radius"); let radius_loc = ctx.get_uniform_location(&program, "radius");
let opacity_loc = ctx.get_uniform_location(&program, "opacity"); let opacity_loc = ctx.get_uniform_location(&program, "opacity");
let highlight_loc = ctx.get_uniform_location(&program, "highlight");
let layer_threshold_loc = ctx.get_uniform_location(&program, "layer_threshold"); let layer_threshold_loc = ctx.get_uniform_location(&program, "layer_threshold");
// create a vertex array and bind it to the graphics context // create a vertex array and bind it to the graphics context
@ -351,6 +354,7 @@ fn main() {
ctx.uniform2f(ctrl_loc.as_ref(), ctrl_x.get() as f32, ctrl_y.get() as f32); ctx.uniform2f(ctrl_loc.as_ref(), ctrl_x.get() as f32, ctrl_y.get() as f32);
ctx.uniform2f(radius_loc.as_ref(), radius_x.get() as f32, radius_y.get() as f32); ctx.uniform2f(radius_loc.as_ref(), radius_x.get() as f32, radius_y.get() as f32);
ctx.uniform1f(opacity_loc.as_ref(), opacity.get() as f32); ctx.uniform1f(opacity_loc.as_ref(), opacity.get() as f32);
ctx.uniform1f(highlight_loc.as_ref(), highlight.get() as f32);
ctx.uniform1i(layer_threshold_loc.as_ref(), layer_threshold.get() as i32); ctx.uniform1i(layer_threshold_loc.as_ref(), layer_threshold.get() as i32);
// clear the screen and draw the scene // clear the screen and draw the scene
@ -397,6 +401,12 @@ fn main() {
step=0.001, step=0.001,
bind:valueAsNumber=opacity bind:valueAsNumber=opacity
) )
input(
type="range",
max=1.0,
step=0.001,
bind:valueAsNumber=highlight
)
input( input(
type="range", type="range",
max=3.0, max=3.0,