A collection of GLSL fragment shaders to draw color map like this:
Each *.frag
shader sources provides a colormap
function, which takes an float
argument x
(x
should be: 0.0 <= x <= 1.0
). The colormap
function returns a vec4
value which represents an RGBA color.
vec4 colormap(float x);
void main() {
gl_FragColor = colormap(gl_TexCoord[0].x);
}
/* include "shaders/rainbow.frag" here, for example. */
This shader emulates gnuplot
's rgbformulae
, and the signature of colormap
is:
vec4 colormap(float x, int red_type, int green_type, int blue_type);
It takes additional 3 arguments, with same meanings to rgbformulae
's 3 arguments respectively.
#include <colormap/colormap.h>
#include <iostream>
int main()
{
using namespace colormap;
// Print RGB table of MATLAB::Jet colormap.
MATLAB::Jet jet;
std::cout << "category: " << jet.getCategory() << std::endl;
std::cout << "title: " << jet.getTitle() << std::endl;
int const size = 256;
for (int i = 0; i < size; ++i) {
float const x = i / (float)size;
Color c = jet.getColor(x);
std::cout << x << "\t" << c.r << "\t" << c.g << "\t" << c.b << std::endl;
}
// Dump category and title of all colormaps.
for (std::shared_ptr<Colormap const> const& c : ColormapList::getAll()) {
std::cout << c->getCategory() << " : " << c->getTitle() << std::endl;
}
return 0;
}
name | sample |
---|---|
MATLAB_autumn | |
MATLAB_bone | |
MATLAB_cool | |
MATLAB_copper | |
MATLAB_hot | |
MATLAB_hsv | |
MATLAB_jet | |
MATLAB_parula | |
MATLAB_pink | |
MATLAB_spring | |
MATLAB_summer | |
MATLAB_winter |
name | sample |
---|---|
rgbformulae(7, 5, 15) | |
rgbformulae(3, 11, 6) | |
rgbformulae(23, 28, 3) | |
rgbformulae(21, 22, 23) | |
rgbformulae(30, 31, 32) | |
rgbformulae(33, 13, 10) | |
rgbformulae(34, 35, 36) |
The MIT License. See 'LICENSE' file for detail.