Graphics Reference
In-Depth Information
multiple_draw_call_VS
]
attribute vec2
Position
,
TextureCoordinates
;
uniform mediump vec4
uPositionTransform
;
uniform mediump vec3
uCoordinateTransformX
[
LAYER_COUNT
],
uCoordinateTransformY
[
LAYER_COUNT
];
varying mediump vec2
vTextureCoordinates
[
LAYER_COUNT
];
void
main
()
{
gl_Position
.
xy
=
Position
.
xy
uPositionTransform
.
xy
+
uPositionTransform
.
zw
;
gl_Position
.
zw
=
vec2
( 0.0, 1.0 );
mediump vec3 texcoord
=
vec3
(
TextureCoordinates
,1.0);
for
(
int
i
=0;
i
<
LAYER_COUNT
;
i
++ )
{
vTextureCoordinates
[
i
].
x
=
dot
(
uCoordinateTransformX
[
i
],
texcoord
);
vTextureCoordinates
[
i
].
y
=
dot
(
uCoordinateTransformY
[
i
],
texcoord
);
}
}
Listing 5.1.
The vertex shader.
associativity) [Forsyth 06], but care must still be taken to preserve transparency
order. The previous shader assumes that we have sorted the transparent layers
back to front.
varying mediump vec2
vTextureCoordinates
[
LAYER_COUNT
];
uniform sampler2D
Textures
[
LAYER_COUNT
];
void
main
()
{
mediump vec4 result
=
vec4
( 0.0 , 0.0, 0.0 , 0.0 ) ;
for
(
int
i
=0;
i
<
LAYER_COUNT
;
i
++ )
{
mediump vec4 contribution
=
texture2D
(
Textures
[
i
],
vTextureCoordinates
[
i
]);
result
=
contribution
+(1.0
−
contribution
.
a
)
result
;
}
gl_FragColor
=
result
;
}
Listing 5.2.
Multiple draw call fragment shader.