Graphics Reference
In-Depth Information
supported by the tile). This not only lowers the amount of computations to
perform, it also diminishes the number of texture fetches as well as the number
of interpolators being used.
The rendering phase uses a single static vertex buffer object (VBO) and per-
forms a draw call for each non empty tile to be rendered.
By first sorting the tiles by the number of aggregated layers (1 to 8), we also
minimize the number of glUseProgram() calls.
1. Sort tiles by number of layers being used.
2. For i =1to8,
(a) enable program corresponding to i blended layers;
(b) for each tile,
i. set uniforms,
ii. bind textures,
iii. render tile quad.
The uniforms being used by the program are the following as follows:
uPositionTransform :A vec4 containing the scaling and offset to apply to
the positions in the VBO to properly position the tile on screen.
uCoordinateTransformX/Y : Two tables of eight vec3 , each pair representing
a3
2 matrix (2D rotation followed by a translation) used to transform
the tile “unit” texture coordinates into layer coordinates.
×
The vertex shader is shown in Listing 5.1 and uses the aforementioned uni-
forms to transform the (static) attributes of the VBO and pass them as varyings
to the fragment shader. A preprocessor define directive is used to ease the man-
agement of the multiple programs; each program is compiled with LAYER_COUNT
being defined to a value ranging from 1 to 8. 4
The fragment shader shown in Listing 5.2 is not a lot more complex. It
basically samples all textures, carefully avoiding dependent texture reads by not
using .zw components to fetch texture data [Imagination Technologies 12], and
performs the blending manually. This manual blending offers the possibility, if
desired, to implement more exotic blending modes than the regular lerp.
Again, LAYER_COUNT is used for controlling the number of layers blended by
the program.
You might have noticed that the blending formula assumes premultiplied al-
pha. Premultiplied textures provide lots of desirable properties (e.g., blending
4 To keep reasonable performances on the iPhone 4S (iOS 6.0.1), we had to unroll the frag-
ment shader loop manually.
Search WWH ::




Custom Search