Image histogram via ofShaders?

Hello,
Has anyone done a color histogram for an ofImage/ofFbo using the ofShaders? I’m wondering if I’d be able to figure out this as a technique

S

I’ve got a little way with this; using the ideas outlined here: stack overflow

The idea is to sample texture rgb.s in the vertex shader, then set an x-coordinate for the gl_Position based on the hsv equivalent for that rgb. Then in the frag shader to add an alpha dot to that location. Back on the cpu side, sample the pixels of the fbo created, using the alpha channel totals to edit poly line coords.

I have basic frag and vertex shaders written, and have checked the cpu side sampling. I think there may be an issue with what I’m writing in the vertex shader. Can anyone give advice?

Vertex shader:

void main(){

// get the texture coordinates
float dx = 0.001953125;
float dy = 0.001953125;
vec2 tiny = vec2(dx,dy);
texCoordVarying = gl_MultiTexCoord0.xy - tiny;

vec4 position = ftransform();
    
// grab incoming colour values
vec3 rgb;
rgb.r = texture2DRect(tex0, texCoordVarying).r;
rgb.g = texture2DRect(tex0, texCoordVarying).g;
rgb.b = texture2DRect(tex0, texCoordVarying).b;

//extract the HSV values
vec3 hsv = rgb2hsv(rgb);

// map Hue to the X position
// Hue goes from 0 to 1 intitially
// scale up by the dims of the histograph
position.x = hsv.x;
position.x *= dims.x;
position.y = 100;

position.x -= centre.x;
position.y -= centre.y;

//fix for screen wierdness
position.x *= 1.0844;
position.y *= 1.73;

gl_Position = position;
}

Frag shader is basic:

void main(){

// Spot a pixel value of 1 to the alpha channel
gl_FragColor = vec4(1,0,0,0.0442809);

}

On the CPU side I’m less sure I’m doing it right (spectrum is an FBO with coloured pixels made elsewhere):

histoGram.begin();
ofClear(255,255,255,0);
histoShader.begin();

histoShader.setUniform2f("dims", graphDims);
histoShader.setUniform2f("centre", centre);

spectrum.draw(0,0);

histoShader.end();
histoGram.end();