@group(1) @binding(0) var color_map_texture: texture_1d; @group(1) @binding(1) var color_map_sampler: sampler; @group(1) @binding(2) var color_map_params: ColorMapParams; struct ColorMapParams { color_count: u32, value_min: f32, value_max: f32, invalid_value: f32 } fn find_idx(ratio: f32) -> f32 { var sum = 0.0; var i = 0.0; let count = f32(color_map_params.color_count - 1); while (ratio > sum) { sum += textureSample(color_map_texture, color_map_sampler, i / count).r; i += 1.0; } return i / count; } fn linear_colormap(value: f32) -> vec4f { let v = clamp((value - color_map_params.value_min) / (color_map_params.value_max - color_map_params.value_min), 0.0, 1.0); let idx = find_idx(v); let c0 = textureSample(color_map_texture, color_map_sampler, idx).rgb; return vec4f(c0, 1.0); }