Chapter 4

Building a Scene


  • Handling a scene with multiple objects
  • Classifying objects based on their material properties
  • Mixing solid, alpha tested, and transparent objects and rendering them correctly
  • Creating and using Uber Shaders
  • Handling double-sided semitransparent objects, and other alpha tricks
  • Implementing per-pixel lighting inside your fragment shaders

So far you have been rendering single objects. Whether it is in 2D or in 3D, it has been pretty straightforward until now. In this chapter, you will learn how to handle a scene with multiple objects of different types, including how to sort and draw these objects using a correct rendering sequence.

You will progressively go through each aspect of rendering a complex scene. And you’ll fix each and every drawing issue as you go in order to end up with a perfectly rendered scene.

This chapter will also show you how to move the lighting calculation from the vertex to the fragment shader in order to obtain a more realistic lighting effect.

You will also learn about the Uber Shader concept, which allows you to have multiple effects contained inside one giant vertex and fragment shader file. And you’ll discover how to make full use of this popular technique inside you own games and 3D apps.


Until now, you have been handling only a single object. Whether it’s a simple quad or a furry monkey, it’s still just one set of vertex data drawn over and over again. In this chapter, you ...

Get Game and Graphics Programming for iOS and Android® with OpenGL® ES 2.0 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.