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. This way, the objects will look the same when they are rendered on screen but every time we render them into the offscreen framebuffer, their colors will be unique. This is something that we will do later on in this chapter.

For now, let's assume that the objects in our scene have unique diffuse colors as shown in the following diagram:

Assigning one color per object in the scene

Let's see how to render the scene offscreen using the framebuffer that we just set up.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.70.203