我想在我的android应用中用opengl es实现一个直方图均衡滤镜.我遍历我的fragment shader中的所有纹理坐标来找出映射数组.但似乎这些数组中的所有值都是1,这导致了错误的输出片段颜色.有人知道为什么吗?
precision mediump float;
uniform sampler2D inputTexture;
uniform float texelWidth;
uniform float texelHeight;
uniform int width;
uniform int height;
in mediump vec2 textureCoordinate;
out vec4 fragColor;
float sR[256];
float sG[256];
float sB[256];
void main() {
if(textureCoordinate.xy==vec2(0.,0.)){
int nR[256];
int nG[256];
int nB[256];
int i,j;
for (i=0;i<=height;i++){
float currentHeight=texelHeight*float(i);
for(j=0;j<=width;j++){
vec3 current=texture(inputTexture,vec2(texelWidth*float(j),currentHeight)).rgb;
int r=int(round(current.r*255.));
int g=int(round(current.g*255.));
int b=int(round(current.b*255.));
nR[r]+=1;
nG[g]+=1;
nB[b]+=1;
}
}
/*
calculateS(nR,sR);
calculateS(nG,sG);
calculateS(nB,sB);*/
int k,nSum;
for(k=0,nSum=0;k<256;k++){
nSum+=nR[k];
}
float p[256];
for(k=0;k<256;k++){
p[k]=float(nR[k])/float(nSum);
}
int l;
for(k=0;k<256;k++){
sR[k]=0.;
for(l=0;l<=k;l++){
sR[k]+=p[l];
}
}
//
for(k=0,nSum=0;k<256;k++){
nSum+=nG[k];
}
float q[256];
for(k=0;k<256;k++){
q[k]=float(nG[k])/float(nSum);
}
for(k=0;k<256;k++){
sG[k]=0.;
for(l=0;l<=k;l++){
sG[k]+=q[l];
}
}
//
for(k=0,nSum=0;k<256;k++){
nSum+=nB[k];
}
float h[256];
for(k=0;k<256;k++){
h[k]=float(nB[k])/float(nSum);
}
for(k=0;k<256;k++){
sB[k]=0.;
for(l=0;l<=k;l++){
sB[k]+=h[l];
}
}
}
vec3 current=texture(inputTexture,textureCoordinate.xy).rgb;
int r=int(round(current.r*255.));
int g=int(round(current.g*255.));
int b=int(round(current.b*255.));
fragColor=vec4(sR[r],sG[g],sB[b],1.);
}