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" ?

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" ?