我正在使用 Qt。我有多个着色器在工作,但是传递统一数组似乎总是将全部设置为零。预期的结果是在纹理顶部绘制随机圆圈(或者由于圆圈太多而只是透明纹理)。我得到的是右下角的单个粒子圆圈。
if (program->isLinked()) {
QVector3D hitPoints[40];
for (int k = 0; k < 40; k++) {
hitPoints[k] = QVector3D((float)rand()/(float)RAND_MAX, (float)rand()/(float)RAND_MAX, (float)rand()/(float)RAND_MAX);
}
program->setUniformValueArray("hitPoints", hitPoints, 40);
program->bind();
}
片段着色器:
uniform sampler2D color_texture;
uniform vec3 hitPoints[40];
void main()
{
float dist = 0.3;
vec2 texcoord = vec2(gl_TexCoord[0]);
for (int i = 0; i < 40; i++) {
float close = sqrt(pow(hitPoints[i].y - texcoord.y, 2) + pow(hitPoints[i].x - texcoord.x, 2));
if (close < dist) {
gl_FragColor = vec4(0,0,0,texture2D(color_texture, texcoord).a);
return;
}
}
gl_FragColor = texture2D(color_texture, texcoord);
}