Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,11 @@ enum Colormap: byte {
/// This is a perceptually uniform colormap which is robust to color blindness.
/// It interpolates from dark purple to green to yellow.
Viridis,

/// Rasmusgo's Cyan to Yellow colormap
///
/// This is a perceptually uniform colormap which is robust to color blindness.
/// It is especially suited for visualizing signed values.
/// It interpolates from cyan to blue to dark gray to brass to yellow.
CyanToYellow,
}
18 changes: 16 additions & 2 deletions crates/store/re_types/src/components/colormap.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 25 additions & 6 deletions crates/viewer/re_renderer/shader/colormap.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
#import <./utils/srgb.wgsl>

// NOTE: Keep in sync with `colormap.rs`!
const COLORMAP_GRAYSCALE: u32 = 1u; // sRGB gradient = perceptually even
const COLORMAP_INFERNO: u32 = 2u;
const COLORMAP_MAGMA: u32 = 3u;
const COLORMAP_PLASMA: u32 = 4u;
const COLORMAP_TURBO: u32 = 5u;
const COLORMAP_VIRIDIS: u32 = 6u;
const COLORMAP_GRAYSCALE: u32 = 1u; // sRGB gradient = perceptually even
const COLORMAP_INFERNO: u32 = 2u;
const COLORMAP_MAGMA: u32 = 3u;
const COLORMAP_PLASMA: u32 = 4u;
const COLORMAP_TURBO: u32 = 5u;
const COLORMAP_VIRIDIS: u32 = 6u;
const COLORMAP_CYAN_TO_YELLOW: u32 = 7u;

/// Returns a gamma-space sRGB in 0-1 range.
///
Expand All @@ -28,6 +29,8 @@ fn colormap_srgb(which: u32, t_unsaturated: f32) -> vec3f {
return colormap_turbo_srgb(t);
} else if which == COLORMAP_VIRIDIS {
return colormap_viridis_srgb(t);
} else if which == COLORMAP_CYAN_TO_YELLOW {
return colormap_cyan_to_yellow_srgb(t);
} else {
return ERROR_RGBA.rgb;
}
Expand Down Expand Up @@ -143,3 +146,19 @@ fn colormap_inferno_srgb(t: f32) -> vec3f {
let c6 = vec3f(25.13112622477341, -12.24266895238567, -23.07032500287172);
return c0 + t * (c1 + t * (c2 + t * (c3 + t * (c4 + t * (c5 + t * c6)))));
}

// --- rasmusgo's color maps ---

// Designed by Rasmus Brönnegård (rasmusgo) adapted from https://www.shadertoy.com/view/lfByRh.
//
// License CC0 (public domain)
// https://creativecommons.org/share-your-work/public-domain/cc0/

/// Returns a gamma-space sRGB in 0-1 range.
/// This is a perceptually uniform colormap which is robust to color blindness.
/// It is especially suited for visualizing signed values.
/// It interpolates from cyan to blue to dark gray to brass to yellow.
fn colormap_cyan_to_yellow_srgb(t: f32) -> vec3f {
let u = t * 2. - 1.;
return saturate(vec3f(1. + 3. * u, (1. + 3. * u * u) , 1. - 3. * u) / 4.);
}
27 changes: 26 additions & 1 deletion crates/viewer/re_renderer/src/colormap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@ pub enum Colormap {
Plasma = 4,
Turbo = 5,
Viridis = 6,
CyanToYellow = 7,
}

impl Colormap {
pub const ALL: [Self; 6] = [
pub const ALL: [Self; 7] = [
Self::Grayscale,
Self::Inferno,
Self::Magma,
Self::Plasma,
Self::Turbo,
Self::Viridis,
Self::CyanToYellow,
];
}

Expand All @@ -40,6 +42,7 @@ impl std::fmt::Display for Colormap {
Self::Plasma => write!(f, "Plasma"),
Self::Turbo => write!(f, "Turbo"),
Self::Viridis => write!(f, "Viridis"),
Self::CyanToYellow => write!(f, "CyanToYellow"),
}
}
}
Expand All @@ -52,6 +55,7 @@ pub fn colormap_srgb(which: Colormap, t: f32) -> [u8; 4] {
Colormap::Plasma => colormap_plasma_srgb(t),
Colormap::Magma => colormap_magma_srgb(t),
Colormap::Inferno => colormap_inferno_srgb(t),
Colormap::CyanToYellow => colormap_cyan_to_yellow_srgb(t),
}
}

Expand Down Expand Up @@ -185,3 +189,24 @@ pub fn colormap_inferno_srgb(t: f32) -> [u8; 4] {
let c = c * 255.0;
[c.x as u8, c.y as u8, c.z as u8, 255]
}

// --- rasmusgo's color maps ---

// Designed by Rasmus Brönnegård (rasmusgo) adapted from https://www.shadertoy.com/view/lfByRh.
//
// License CC0 (public domain)
// https://creativecommons.org/share-your-work/public-domain/cc0/

/// Returns a gamma-space sRGB in 0-255 range.
/// This is a perceptually uniform colormap which is robust to color blindness.
/// It is especially suited for visualizing signed values.
/// It interpolates from cyan to blue to dark gray to brass to yellow.
pub fn colormap_cyan_to_yellow_srgb(t: f32) -> [u8; 4] {
let t = t * 2. - 1.;
[
((1. + 3. * t) * (255. / 4.)).max(0.) as u8,
((1. + 3. * t * t) * (255. / 4.)) as u8,
((1. - 3. * t) * (255. / 4.)).max(0.) as u8,
255,
]
}
4 changes: 2 additions & 2 deletions crates/viewer/re_renderer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ use allocator::GpuReadbackBuffer;
pub use allocator::{CpuWriteGpuReadError, GpuReadbackIdentifier};
pub use color::Rgba32Unmul;
pub use colormap::{
colormap_inferno_srgb, colormap_magma_srgb, colormap_plasma_srgb, colormap_srgb,
colormap_turbo_srgb, colormap_viridis_srgb, grayscale_srgb, Colormap,
colormap_cyan_to_yellow_srgb, colormap_inferno_srgb, colormap_magma_srgb, colormap_plasma_srgb,
colormap_srgb, colormap_turbo_srgb, colormap_viridis_srgb, grayscale_srgb, Colormap,
};
pub use context::{adapter_info_summary, RenderContext, RenderContextError};
pub use debug_label::DebugLabel;
Expand Down
1 change: 1 addition & 0 deletions crates/viewer/re_viewer_context/src/gpu_bridge/colormap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,6 @@ pub fn colormap_to_re_renderer(colormap: re_types::components::Colormap) -> re_r
re_types::components::Colormap::Plasma => re_renderer::Colormap::Plasma,
re_types::components::Colormap::Turbo => re_renderer::Colormap::Turbo,
re_types::components::Colormap::Viridis => re_renderer::Colormap::Viridis,
re_types::components::Colormap::CyanToYellow => re_renderer::Colormap::CyanToYellow,
}
}
1 change: 1 addition & 0 deletions docs/content/reference/types/components/colormap.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rerun_cpp/src/rerun/components/colormap.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions rerun_cpp/src/rerun/components/colormap.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions rerun_py/rerun_sdk/rerun/components/colormap.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.