Graphics Programs Reference
In-Depth Information
+ "attribute vec2 aCoord; \n"
+ "varying vec2 vCoord; \n"
+ "uniform mat4 uMVP; \n"
+ "void main() { \n"
+ " gl_Position = uMVP * aPosition; \n"
+ " vCoord = aCoord; \n"
+ "} \n";
private final String _planeFragmentShaderCode =
"#ifdef GL_FRAGMENT_PRECISION_HIGH \n"
+ "precision highp float; \n"
+ "#else \n"
+ "precision mediump float; \n"
+ "#endif \n"
+ "varying vec2 vCoord; \n"
+ "uniform sampler2D uSampler1; \n"
+ "uniform sampler2D uSampler2; \n"
+ "void main() { \n"
+ " vec4 textureColor1,textureColor2; \n"
+ " textureColor1 = texture2D(uSampler1,vCoord); \n"
+ " textureColor2 = texture2D(uSampler2,vCoord); \n"
+ " gl_FragColor = textureColor1 * textureColor2; \n"
+ "} \n";
Because the texture2D function returns a vec4 texture color, there is no re-
striction as to how you combine the texture colors. You can perform any operation
between the texture colors, and finally set the resultant color as the fragment color.
As shown in Listing 5-12 , texture colors textureColor1 and textureColor2
are multiplied, and the resultant color is set as the fragment color:
gl_FragColor = textureColor1 * textureColor2;
When using multiple 2D textures, you must generate texture objects for each texture
to be used. Please note that, although a cubemap texture uses six 2D textures, a cube-
map texture is a separate type of texture in ES 2.0, which explains why it only re-
quires a single texture object.
Search WWH ::




Custom Search