Fun with Pseudocolor

Screen Shot 2015-03-17 at 10.14.36 AM

A shader experiment gone horribly, beautifully wrong.

I was tinkering with some GLSL shaders in Processing, and I needed a way to visualize a value that smoothly changes from 0 to 1, showing a lot more than the 256 levels of gray that you’d normally see. So I wrote a little pseudocolor function that spirals through colorspace from black to white, hitting various hues along the way. It’s fun, and pretty, and very rungy-chungy, so I thought I’d post it here.

vec4 pseudo3(float val) {

    float reps = 20.0;
    float pi = 3.14159256;
    float bright = val;
    float con = 0.25 - 0.20 * cos(val * pi * 2.0);
    float sat = 0.66 - 0.25 * cos(val * pi * 2.0);

    return vec4(sin(val*pi*reps)*con+bright,
                sin(val*pi*reps - pi*0.663 * sat)*con+bright,
                sin(val*pi*reps - pi*1.333 * sat)*con+bright,
                1.0);
}

Here's the path the above function traces through the RGB cube of colorspace.
Here’s the path the above function traces through the RGB cube of colorspace.

3 thoughts on “Fun with Pseudocolor”

  1. Fun! I was considering something somewhat like this when I was displaying height field data and the details were mostly getting lost. I’ll keep this in mind!

Comments are closed.