From a2a99617d22493235b85d7ddfbc099b386a43951 Mon Sep 17 00:00:00 2001 From: Jeremy Leibs Date: Wed, 26 Apr 2023 00:27:42 +0200 Subject: [PATCH] Round to nearest color_index when doing color mapping --- crates/re_renderer/shader/rectangle_fs.wgsl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/re_renderer/shader/rectangle_fs.wgsl b/crates/re_renderer/shader/rectangle_fs.wgsl index 468f9c20f202..62f65952fe21 100644 --- a/crates/re_renderer/shader/rectangle_fs.wgsl +++ b/crates/re_renderer/shader/rectangle_fs.wgsl @@ -86,7 +86,9 @@ fn fs_main(in: VertexOut) -> @location(0) Vec4 { let colormap_size = textureDimensions(colormap_texture).xy; let color_index = normalized_value.r * f32(colormap_size.x * colormap_size.y); // TODO(emilk): interpolate between neighboring colors for non-integral color indices - let color_index_u32 = u32(color_index); + // It's important to round here since otherwise numerical instability can push us to the adjacent class-id + // See: https://github.com/rerun-io/rerun/issues/1968 + let color_index_u32 = u32(round(color_index)); let x = color_index_u32 % colormap_size.x; let y = color_index_u32 / colormap_size.x; texture_color = textureLoad(colormap_texture, UVec2(x, y), 0);