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 Shapesfloat nDotL = max(dot(normal, lightVector), 0.0);vec3 diffuse = DIFFUSE_LIGHT * nDotL;float specPow = 0.0;if (nDotL > 0.0) // are there any specular reflections?{vec3 cameraVector = normalize(vCameraVector);// calculate how much specular light will be reflectedvec3 reflectVector = reflect(-cameraVector, normal);specPow = pow(max(dot(reflectVector, lightVector), 0.0), 4.0);}// calculate the specular light based on the light value and the reflection valuevec3 specular = SPECULAR_LIGHT * specPow;}// sum all of the light sources togethergl_FragColor = vec4(AMBIENT_LIGHT, 1.0) * color +vec4(diffuse, 1.0) * color +vec4(specular, 1.0);7. Example 4-37 shows setting the light and position values and passing them to the shaders:Example 4-37 Set the camera, projection, view, and world...float cameraAngle = 0.0f;vec3 camPos = calculateCamPos(75.0f, cameraAngle);vec3 camTarget = vec3(0.0f, 0.0f, 0.0f);vec3 upVector = vec3(0.0f, 0.0f, 1.0f);// Set up the view, projection and world matrices and multiply them to get the// modelviewprojection and modelview matrices.mat4 view = mat4::lookAt(camPos, camTarget, upVector);mat4 proj = mat4::perspective(60.0f, 4.0f/3.0f, 1.0f, 500.0f);mat4 world = mat4::identity();mat4 wvpMatrix = proj * view * world;vec3 lightPosition(75.0f, 75.0f, 0.0f);// Set the program to use and initialize the uniformscontext->setProgram(perVertexLightingProgram);context->setUniform("LIGHT_POSITION", lightPosition);context->setUniform("CAMERA_POSITION", camPos);context->setUniform("AMBIENT_LIGHT", AMBIENT_LIGHT);context->setUniform("DIFFUSE_LIGHT", DIFFUSE_LIGHT);context->setUniform("SPECULAR_LIGHT", SPECULAR_LIGHT);context->setUniformSampler("diffuseTexture", diffuseTexture);context->setUniformSampler("normalMap", normalMap);...// Enable depth test and start drawing loopglEnable(GL_DEPTH_TEST);8. Example 4-38 on page 4-29 shows the part of the draw loop that reacts to keyboard inputto change the camera, view, and lighting:ARM DUI 0527A-02a Copyright © 2010 ARM. All rights reserved. 4-28ID070710Non-Confidential - Draft - Beta

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

Saved successfully!

Ooh no, something went wrong!