separate the objects in layers


For my application, I’d link to separate my world in layers and to put all my objects to draw in these layers. The aim is to sort what gives its color to the pixels at the end of the rendering.

For example, I have a back ground, particles, animals, ghosts and text, and I want the text to never be hidden by the ghosts, the ghosts to never be hidden by the animals, the animals to never be hidden by the particles and the particles to never be hidden by the background. So I would put all objects of the same kind in the same layer and I would sort the layers, so the layer of the background is at the very bottom and the layer of the text is at the very top.

For the background, I can use the skybox technique.

Do you have an idea to implement the other layers?


Render the farthest layer with the depth buffer on, clear your depth buffer, render the next layer, clear your depth buffer, etc.

What strattonbrazil said. Though it could be even simpler if each layer has no overlapping objects (requiring hidden surface). In that case you could turn off depth buffering entirely, and simply draw the layers back to front.

Thanks! I’d like to rephrase this to be sure I understand well what you propose and what would be going on in the video card:

  • At the beginning, the depth buffer is equal to 1.
  • I draw the objects of the farthest layer => an object gives its color to the pixels of the color buffer and its distance to the depth buffer if the current distance in the depth buffer is greater that the one of the objet.
  • “clear the depth buffer”: all the depth buffer is set to 1
  • I draw the objects of the next layer => They are drawn over the objects of the first layer because all their distance are greater than 1.

Did I made a mistake somewhere?

No mistake, you have perfectly understood :slight_smile: