Now, we will check whether the color obtained from the offscreen framebuffer matches any of the objects in our scene. Remember here that we are using colors as object labels. If the color matches one of the objects, then we call it a hit. If it does not, we call it a miss.
When looking for hits, we compare each object's diffuse color with the label obtained from the offscreen framebuffer. There is, however, an additional step to consider: each color channel comes back in a [0, 255] range while the object diffuse colors are in a [0, 1] range. We need to update this before we check for any possible hits. We can do so with a compare function:
function compare(readout, color) {
return (
Math.abs(Math.round(color[0] * 255) - readout[0]) <= 1 &&
Math.abs(Math.round(color[1] * 255) - readout[1]) <= 1 &&
Math.abs(Math.round(color...