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 Constructing Custom Shadersmat4 world = mat4::identity();// create the transformation matrixmat4 wvpMatrix = proj * view * world;// define a light position that will be used with specular reflectionsvec3 lightPosition(75.0f, 75.0f, 0.0f);...// Initialize the uniformscontext->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);...2. The vertex shader code in Example 6-32 is similar to the code in Example 6-27 onpage 6-21, except that the WORLD uniform is also passed to the shader:Example 6-32 Lighting initialization in bump map application code...// Enable depth test and start drawing loopglEnable(GL_DEPTH_TEST);do{// use keyboard input to rotate the camera or the object...wvpMatrix = proj * view * world;// set uniforms that have changed since the last drawcontext->setUniformMatrix("WORLD_VIEW_PROJECTION", wvpMatrix);context->setUniformMatrix("WORLD", world.toMat3());// Clear the screen and draw cube_asset with lightingglClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );// call the assets own draw method to render the primitivescube_asset->draw();}while ( context->update() );...3. The vertex shader code in Example 6-33 calculates the position of a fragment based onthe interpolated POSITION value and a world view projection:Example 6-33 Lighting calculation in bump map vertex shaderuniform mat4 WORLD_VIEW_PROJECTION;uniform mat3 WORLD;uniform vec3 LIGHT_POSITION;uniform vec3 CAMERA_POSITION;attribute vec4 POSITION;attribute vec3 NORMAL;attribute vec3 TANGENT;ARM DUI 0527A-02a Copyright © 2010 ARM. All rights reserved. 6-24ID070710Non-Confidential - Draft - Beta

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

Saved successfully!

Ooh no, something went wrong!