diff --git a/crates/re_renderer/shader/rectangle_fs.wgsl b/crates/re_renderer/shader/rectangle_fs.wgsl index 0d1a35cad961..071b093f2877 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_i32 = i32(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_i32 = i32(round(color_index)); let x = color_index_i32 % colormap_size.x; let y = color_index_i32 / colormap_size.x; texture_color = textureLoad(colormap_texture, IVec2(x, y), 0);