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 Drawing 3D ShapesExample 4-18 Shaders...// Loading programsProgram* perVertexLightingProgram =proxy.getProgram("../shaders/per_vertex_lighting.vert;../shaders/per_vertex_lighting.frag");Program* perFragmentLightingProgram =proxy.getProgram("../shaders/per_fragment_lighting.vert;../shaders/per_fragment_lighting.frag");There are two lighting programs, and each program has a fragment shader and a vertexshader:Vertex lighting programThe per_vertex_lighting.frag fragment shader is based on the ambient,diffuse, and specular lighting as shown in Example 4-19:Example 4-19 per_vertex_lighting.frag#ifdef GL_ESprecision mediump float;#endifuniform vec3 AMBIENT_LIGHT;uniform vec4 COLOR;varying vec3 vDiffuse;varying vec3 vSpecular;void main(void){gl_FragColor = vec4(AMBIENT_LIGHT, 1.0) * COLOR +vec4(vDiffuse, 1.0) * COLOR +vec4(vSpecular, 1.0);}The per_vertex_lighting.vert vertex shader is listed in Example 4-20:Example 4-20 per_vertex_lighting.vertuniform mat4 WORLD_VIEW_PROJECTION;uniform mat3 WORLD;uniform vec3 LIGHT_POSITION;uniform vec3 CAMERA_POSITION;uniform vec3 DIFFUSE_LIGHT;uniform vec3 SPECULAR_LIGHT;attribute vec4 POSITION;attribute vec3 NORMAL;varying vec3 vDiffuse;varying vec3 vSpecular;void main(void){gl_Position = WORLD_VIEW_PROJECTION * POSITION;vec3 normal = normalize(WORLD * NORMAL);ARM DUI 0527A-02a Copyright © 2010 ARM. All rights reserved. 4-16ID070710Non-Confidential - Draft - Beta

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

Saved successfully!

Ooh no, something went wrong!