Comparing GLSL loop index with uniform int

I wrote a small mouse picker for a GLSL ray tracer using webGL.
The index of the selected object (only spheres) gets sent to the fragment shader as a uniform int.


gl.uniform1i(program.uniformLocations.pickedSphereLoc, pickedSphere);

Comparing that index with the loop index in the fragment shader crashes webGL.


uniform int pickedSphere;
for(int j = 0; j < 8; j++){
if( j - pickedSphere == 0 ){
    color = vec3(0.2 , 0.2, 0.2);
    }
}

However casting everything to floats works


uniform int pickedSphere;
for(int j = 0; j < 8; j++){
    if( float(j) - float(pickedSphere) == 0.0 ){
        color = vec3(0.2 , 0.2, 0.2);
    }
}

Can anyone explain why that is?

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.