Graphics Programs Reference
In-Depth Information
0, img2, 0);
samplerCube Uniform Variable
The fragment shader code for a cubemap texture uses samplerCube uniform in
place of sampler2D ( Listing 5-6 ) uniform. Listing 5-11 shows the fragment shader
code from the GL CUBEMAP TEXTURE application. It uses the built-in function
textureCube to fetch from the cubemap texture. This function is almost identical
to the texture2D function. The only difference is that the texture coordinate is a
vec3 , instead of vec2 and the sampler* type must be samplerCube .
Listing 5-11. GL CUBEMAP TEXTURE/src/com/apress/android/glcubemaptex-
ture/GLES20Renderer.java
private final String _cubeFragmentShaderCode =
"#ifdef GL_FRAGMENT_PRECISION_HIGH \n"
+ "precision highp float; \n"
+ "#else \n"
+ "precision mediump float; \n"
+ "#endif \n"
+ "varying vec3 vCoord; \n"
+ "uniform samplerCube uSampler; \n"
+ "void main() { \n"
+ " gl_FragColor = textureCube(uSampler,vCoord); \n"
+ "} \n";
Multi-Texturing
You can also extend the GL TEXTURE application to use more than one texture
for the rendered object. Use of two textures ( Figure 5-6 ) with the rendered object
is demonstrated in the GL MULTI TEXTURE application ( Chapter5/glmulti-
texture.zip ) with output as seen in Figure 5-7 .
 
 
 
 
Search WWH ::




Custom Search