I’m attempting to perform an auto-gain process on a 2D image using CG Fragment Shader. Since I’m already am using a fragment program to perform 2D image processing, I want to modify it to recover the color (or grey scale) histogram. I am passing an hirtogram array as a parameter to my CG program which will be filled. All I need to do is get back the array once the rendering is complete. The pseudo-code is simple:
- Reset the histogram array to 0, and pass it to the CG program;
- Render the image;
- Recover the filled-in histogram array from the CG program;
However, when I call cgGLGetParameterArray1f() to recover the array, CG gives an error indicating the the array index is out-of-bounds. Here is a snipit of my code:
float4 PS_HistoProc( in float4 vColor : COLOR
, uniform float afHistogram[256]
) : COLOR
{
// Convert the color into an intensity level
float fIntensity = clamp( vColor.r*0.3086 + vColor.g*0.6094 + vColor.b*0.0820, 0.0f, 1.0f );
afHistogram[int( fIntensity * 255 )] += 1;
return vColor;
}
I have a feeling that arrays can only be inputs to a CG program. If so, then why is there a GET function?
Any help would be appreciated.