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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Tutorial on Drawing 3D Shapesvarying vec3 vLightVector;varying vec3 vCameraVector;void main(void){// set the global that indicates this fragment positiongl_Position = WORLD_VIEW_PROJECTION * POSITION;// set the value to look up from the image bitmapvTexCoord = TEXCOORD0.st;// calculate the vector that identifies this point in the world projectionvec3 pos = WORLD * POSITION.xyz;// calculate the normals for the point on the shapemat3 TBN = WORLD *mat3(normalize(TANGENT), normalize(BINORMAL), normalize(NORMAL));// No point in normalizing before the fragment shader as the normalization will// be offset by the interpolation anyway.}// calculate the light vector for the point and multiply it b the world transformvLightVector = (LIGHT_POSITION - pos) * TBN;// calculate the camera vector for the point and multiply it b the world transformvCameraVector = (CAMERA_POSITION - pos) * TBN;6. The fragment shader uses the contents of the rock_n.png file to compute the reflection asshown in Example 4-36:Example 4-36 bumpmapping.frag contents#ifdef GL_ESprecision mediump float;#endif// constant values for the primitive shapeuniform mat3 M_MATRIX;uniform sampler2D diffuseTexture;uniform sampler2D normalMap;uniform vec3 AMBIENT_LIGHT;uniform vec3 DIFFUSE_LIGHT;uniform vec3 SPECULAR_LIGHT;uniform float DIFFUSE_CONTRIBUTION;uniform float SPECULAR_CONTRIBUTION;uniform float AMBIENT;// passed from the vertex shadervarying vec2 vTexCoord;varying vec3 vLightVector;varying vec3 vCameraVector;void main(void){// An optimization would be to assume that the precomputed normals in the normalMap// is already of a length of 1.0. That way the normalization would be unnecessary.vec3 normal = normalize(texture2D(normalMap, vTexCoord).rgb * 2.0 - 1.0);vec4 color = texture2D(diffuseTexture, vTexCoord);// what is the contribution of the diffuse light based on the relative// angle between the light and the normal read from the bitmap filevec3 lightVector = normalize(vLightVector);ARM DUI 0527A-02a Copyright © 2010 ARM. All rights reserved. 4-27ID070710Non-Confidential - Draft - Beta

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

Saved successfully!

Ooh no, something went wrong!