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);