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 Constructing Custom Shadersvoid main(void){gl_Position = WORLD_VIEW_PROJECTION * POSITION;vColor = COLOR;// fragment shader assigns this to gl_FragColor}6.7.2 Example showing calculation of specular reflectionsThe application code in Example 6-23 on page 6-18 uses an interpolated vertex color for thefragment. The example in Example 6-26 calculates the light based on the vectors that specifythe different light sources:Example 6-26 Context initialization in lighting application code...// define constants for the light colorsstatic const vec3 AMBIENT_LIGHT = vec3 (0.1f, 0.1f, 0.1f);static const vec3 DIFFUSE_LIGHT = vec3(0.5f, 0.5f, 0.5f);static const vec3 SPECULAR_LIGHT = vec3(0.5f, 0.5f, 0.5f);static const vec4 COLOR = vec4(1.0f, 0.0f, 0.0f, 1.0f);...// define the calculateCamPos that returns a vec3 given an angle and radius// enables the camera to rotate about the scene object...// initialize the context and MDE classes...// load the shader code...// Loading scene from a <strong>Mali</strong> Binary Asset fileSceneAsset* scene = proxy.getSceneAsset("cube.mba");// get the asset from the mba file and assign it to the cube_asset variableGeometryAsset* cube_asset =static_cast(scene->getAsset(Asset::TYPE_GEOMETRY, 0));Texture2D *diffuseTexture =proxy.getTexture2DAsset("rock_t.png")->getTexture2D();Texture2D *normalMap =proxy.getTexture2DAsset("rock_n.png")->getTexture2D();// Initialize the camera position, target, and up vectorfloat 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();// create the transformation matrixmat4 wvpMatrix = proj * view * world;// define the light positionvec3 LightPosition(75.f, 75.f, 0.0f)...ARM DUI 0527A-02a Copyright © 2010 ARM. All rights reserved. 6-20ID070710Non-Confidential - Draft - Beta

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

Saved successfully!

Ooh no, something went wrong!