PDA

View Full Version : Portable way to create a histogram.



Foxbat
11-17-2006, 07:50 AM
I would like my shader to create a histogram at a mid-stage of the shader. ( The final gl_FragColor is not part of the histogram. ) The obvious way would be to have the histogram as a uniform array that the shader can update. However, at least on my nvidia hw, array indexing using computed values is not allowed. So...

int index;

index = (int)( clamp( color.r * ( histogram_length - 1 ), 0.0, histogram_length - 1 ) );

histogram_array[ index ] += 1;

This fails to link with the complaint that only texcoords can be indexed and then only with loop counters.

So I'm looking for ideas on how to proceed.

On a related note ... why is there no integer version of "clamp" ?

Relic
11-17-2006, 08:36 AM
"The obvious way would be to have the histogram as a uniform array that the shader can update."

Shaders can not _write_ into uniforms.

And you can also not write to arbitrary pixel locations inside a fragment shader, which means you can't store the histogramm into a color buffer (e.g. 256 * 1 pixels FP32) in one pass.

Humus
11-17-2006, 09:23 AM
One way to create a histogram is to use occlusion queries and do as many fullscreen passes as you have buckets, and simply discard fragments in the fragment shader that doesn't fall into the current bucket.

Foxbat
11-17-2006, 06:52 PM
Originally posted by Relic:
"The obvious way would be to have the histogram as a uniform array that the shader can update."

Shaders can not _write_ into uniforms.

And you can also not write to arbitrary pixel locations inside a fragment shader, which means you can't store the histogramm into a color buffer (e.g. 256 * 1 pixels FP32) in one pass. Well there you go. Not just SOL but SOB (brains) too!