13.07.2015 Views

Mali GPU User Interface Engine Application Development Guide

Mali GPU User Interface Engine Application Development Guide

Mali GPU User Interface Engine Application Development Guide

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Tutorial on Drawing 3D Shapescube_reflection_mapping.vertThe vertex code in Example 4-44 calculates the view vector based on thenormal and the camera view:Example 4-44 cube_reflection_mapping.vert shader for cube mappinguniform mat4 WORLD_VIEW_PROJECTION;uniform mat3 WORLD;uniform vec3 CAMERA_POSITION;attribute vec4 POSITION;attribute vec3 NORMAL;varying vec3 vNormal;varying vec3 vViewVector;void main(void){gl_Position = WORLD_VIEW_PROJECTION * POSITION;// multiply the normal by the model matrix so that the teapot can// be rotatedvNormal = WORLD * NORMAL;vViewVector = CAMERA_POSITION - (WORLD * POSITION.xyz);}cube_reflection_mapping.fragThe code in Example 4-45 uses the normal vector to copy the cube map valuesto the teapot surface. This creates a mirror effect.Example 4-45 cube_reflection_mapping.frag shader for cube mappinguniform samplerCube environmentCubeMap;varying vec3 vNormal;varying vec3 vViewVector;void main(void){// normalize the normals as the interpolation changes their lengthvec3 normal = normalize(vNormal);vec3 viewVector = normalize(vViewVector);vec3 reflectionVector = reflect(-viewVector, normal);gl_FragColor = textureCube(environmentCubeMap,reflectionVector.xyz);}4. Example 4-46 shows the vertexDeclaration code. The coordinates for the skybox areentered manually:Example 4-46 Load the assets and set the skybox parameters...// Set up position data and index data of the skybox manuallyGLfloat vertexData[] ={-0.5f, -0.5f, -0.5f, // 00.5f, -0.5f, -0.5f, // 1ARM DUI 0527A-02a Copyright © 2010 ARM. All rights reserved. 4-36ID070710Non-Confidential - Draft - Beta

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!