O'Reilly logo

WebGL Beginner's Guide by Brandon Jones, Diego Cantor

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Assigning one color per object in the scene

We will pick an object based on its color. If the object has shiny reflections or shadows, then the color throughout it will not be uniform. Therefore, to pick an object based on its color we need to make sure that the color is constant per object and that each object has a different color.

We achieve constant coloring by telling the fragment shader to use only the material diffuse property to set the ESSL gl_FragColor variable. Here we are assuming that each object has a unique diffuse property.

When there are objects sharing the same diffuse color, then we need to create a new ESSL uniform to store the picking color and make it unique for every object that is rendered into the offscreen framebuffer. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required