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 Shapesvec3 pos = WORLD * POSITION.xyz;vec3 lightVector = normalize(LIGHT_POSITION - pos);float nDotL = max(dot(normal, lightVector), 0.0);vDiffuse = DIFFUSE_LIGHT * nDotL;// No point in calculating specular reflections from the backside of vertices.float specPow = 0.0;if (nDotL > 0.0){vec3 cameraVector = normalize(CAMERA_POSITION - pos);}vec3 reflectVector = reflect(-cameraVector, normal);specPow = pow(max(dot(reflectVector, lightVector), 0.0), 4.0);}vSpecular = SPECULAR_LIGHT * specPow;Fragment lighting programper_fragment_lighting.vert for the vertex shader andper_fragment_lighting.frag for the fragment shader. Theper_fragment_lighting.frag fragment shader uses the data in the normalbitmap to calculate the reflections as shown in Example 4-21:Example 4-21 per_fragment_lighting.frag#ifdef GL_ESprecision mediump float;#endifuniform vec3 AMBIENT_LIGHT;uniform vec3 DIFFUSE_LIGHT;uniform vec3 SPECULAR_LIGHT;uniform vec4 COLOR;varying vec3 vNormal;varying vec3 vLightVector;varying vec3 vCameraVector;void main(void){vec3 normal = normalize(vNormal);vec3 lightVector = normalize(vLightVector);float nDotL = max(dot(normal, lightVector), 0.0);vec3 diffuse = DIFFUSE_LIGHT * nDotL;float specPow = 0.0;if (nDotL > 0.0){vec3 cameraVector = normalize(vCameraVector);}vec3 reflectVector = reflect(-cameraVector, normal);specPow = pow(max(dot(reflectVector, lightVector), 0.0), 16.0);vec3 specular = SPECULAR_LIGHT * specPow;gl_FragColor = vec4(AMBIENT_LIGHT, 1.0) * COLOR +ARM DUI 0527A-02a Copyright © 2010 ARM. All rights reserved. 4-17ID070710Non-Confidential - Draft - Beta

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

Saved successfully!

Ooh no, something went wrong!