Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 1 of 1

Thread: comparing GLSL loop index with uniform int

  1. #1
    Newbie Newbie
    Join Date
    Dec 2018
    Posts
    1

    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.
    Code :
    gl.uniform1i(program.uniformLocations.pickedSphereLoc, pickedSphere);
    Comparing that index with the loop index in the fragment shader crashes webGL.
    Code :
    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
    Code :
    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?
    Last edited by Fourier; 12-19-2018 at 01:05 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •