Skip to content

Commit

Permalink
blend outlines among each other in linear space
Browse files Browse the repository at this point in the history
  • Loading branch information
Wumpf committed Mar 9, 2023
1 parent 3916a58 commit 4c3ea36
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions crates/re_renderer/shader/outlines/outlines_from_voronoi.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,22 @@ fn main(in: FragmentInput) -> @location(0) Vec4 {
let resolution = Vec2(textureDimensions(voronoi_texture).xy);
let pixel_coordinates = resolution * in.texcoord;
let closest_positions = textureSample(voronoi_texture, nearest_sampler, in.texcoord);
let to_closest_a_and_b = (closest_positions - pixel_coordinates.xyxy);
let distance_pixel_a = length(to_closest_a_and_b.xy);
let distance_pixel_b = length(to_closest_a_and_b.zw);

let distance_pixel_a = distance(pixel_coordinates, closest_positions.xy);
let distance_pixel_b = distance(pixel_coordinates, closest_positions.zw);

let sharpness = 1.0; // Fun to play around with, but not exposed yet.
let outline_a = saturate((uniforms.outline_radius_pixel - distance_pixel_a) * sharpness);
let outline_b = saturate((uniforms.outline_radius_pixel - distance_pixel_b) * sharpness);

// We're going directly to an srgb-gamma target without automatic conversion.
let color_a = srgba_from_linear(outline_a * uniforms.color_layer_a);
let color_b = srgba_from_linear(outline_b * uniforms.color_layer_b);
let color_a = outline_a * uniforms.color_layer_a;
let color_b = outline_b * uniforms.color_layer_b;

// Blend B over A.
let color = color_a * (1.0 - color_b.a) + color_b;
return color;

// We're going directly to an srgb-gamma target without automatic conversion.
return srgba_from_linear(color);

// Show only the outline. Useful for debugging.
//return Vec4(color.rgb, 1.0);
Expand Down

0 comments on commit 4c3ea36

Please sign in to comment.