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 Shadersvec3 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 +vec4(diffuse, 1.0) * COLOR +vec4(specular, 1.0);6.7.3 Example showing calculation of bump-mapped reflectionsThe application code in Example 6-29 on page 6-22 uses an interpolated vertex color for thefragment. To use normal and diffuse texture samplers:1. The example in Example 6-31 uses normal and diffuse texture samplers from bitmaps tomodify the reflections:Example 6-31 Context initialization in bump map application code// initialize the context and MDE classes...// load the shader code...// Loading scene from a <strong>Mali</strong> Binary Asset file eliminates the requirement to// construct an arrow of primitive shapesSceneAsset* 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));// this bitmap creates a texture used with the diffuse light calculationTexture2D *diffuseTexture =proxy.getTexture2DAsset("rock_t.png")->getTexture2D();// this bitmap creates a texture used with the specular light calculationTexture2D *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);ARM DUI 0527A-02a Copyright © 2010 ARM. All rights reserved. 6-23ID070710Non-Confidential - Draft - Beta

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

Saved successfully!

Ooh no, something went wrong!