A simple lighting and shading system for use in shader-based OpenGL rendering.


@interface GLKBaseEffect : NSObject


The GLKBaseEffect class provides shaders that mimic many of the behaviors provided by the OpenGL ES 1.1 lighting and shading model, including materials, lighting and texturing. The base effect allows up to three lights and two textures to be applied to a scene.

At initialization time, your application first creates a compatible OpenGL or OpenGL ES context and makes it current. Then, it allocates and initializes a new effect object, configures its properties, and calls its prepareToDraw method. Binding an effect causes a shader to be compiled and bound to the current context. The base effect also requires vertex data to be supplied by your application. To supply vertex data, create one or more vertex array objects. For each attribute required by the shader, the vertex array object should enable the attribute and point to data stored in a vertex buffer object.

At rendering time, your application calls the effect’s prepareToDraw method to prepare the effect. Then, it binds a vertex array object and submits one or more drawing commands.

Lighting calculations for the base effect are done in eye-space coordinates.  The light0, light1 and light2 properties hold the position and spot direction of the base effect’s lights. The transform property contains the model view matrix assigned to the scene. When a light is assigned a new position or spot direction, those values are immediately modified by the current model view matrix. Thus, it is important to sequence changes to the model view matrix and changes to the lights to achieve the desired light positioning.  Light positions that need to be transformed in a manner similar to scene geometry should be set after the model view matrix is updated.


Although this class can be subclassed, there are no methods your subclass can use to directly override the underlying shader generation. Instead, your subclass should implement its functionality by changing the values of existing properties declared by the base class.


Naming the Effect


A string used to name your effect.

Configuring the Modelview Transform


The modelview, projection and texture transformations applied to the vertex data when the effect is bound.

Configuring Lights


The strategy the effect uses to calculate light values at each fragment. See GLKLightingType.


A Boolean value that indicates whether lighting is calculated for both sides of a primitive.


The material properties used when calculating the light values for a rendered primitive.


The ambient color applied to all primitives rendered by the effect.


The lighting properties for the first light in the scene.


The lighting properties for the second light in the scene.


The lighting properties for the third light in the scene.

Configuring Textures


The properties for the first texture.


The properties for the second texture.


The order in which textures are applied to rendered primitives.

Configuring Fog


The fog properties to apply to the scene.

Configuring Color Information


A Boolean value that indicates whether or not to use the color vertex attribute when calculating the light’s interaction with the material.


A Boolean value that indicates whether or not to use the constant color.


A constant color, used when per-vertex color data is not provided.

Preparing the Effect for Drawing

- prepareToDraw

Prepares an effect for rendering.


Inherits From

Conforms To

See Also

Shader-Based Rendering Effects


A standard interface for objects that provide shader-based OpenGL rendering effects.


A lighting and shading system that supports reflection mapping for use in shader-based OpenGL rendering.


A simple skybox visual effect for use in shader-based OpenGL rendering.