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 Shadersvoid main(void){gl_FragColor = vec4(AMBIENT_LIGHT, 1.0) * COLOR +vec4(vDiffuse, 1.0) * COLOR +vec4(vSpecular, 1.0);}Lighting calculation in the fragment shaderThe vertex shader code in Example 6-29 passes more of the calculation to the fragment shader:Example 6-29 Specular lighting calculation in vertex shaderuniform mat4 WORLD_VIEW_PROJECTION;uniform mat3 WORLD;uniform vec3 LIGHT_POSITION;uniform vec3 CAMERA_POSITION;attribute vec4 POSITION;attribute vec3 NORMAL;varying vec3 vNormal;varying vec3 vLightVector;varying vec3 vCameraVector;void main(void){gl_Position = WORLD_VIEW_PROJECTION * POSITION;vec3 pos = WORLD * POSITION.xyz;}// No point in normalizing before the fragment shader as the normalization will// be offset by the interpolation anyway.vNormal = WORLD * NORMAL;vLightVector = LIGHT_POSITION - pos;vCameraVector = CAMERA_POSITION - pos;The fragment shader in Example 6-30 calculates the reflection vectors before combining thelight sources:Example 6-30 Fragment shader adds specular light to background lightuniform vec3 AMBIENT_LIGHT;uniform vec3 DIFFUSE_LIGHT;uniform vec3 SPECULAR_LIGHT;uniform vec4 COLOR;varying vec3 vNormal;varying vec3 vLightVector;varying vec3 vCameraVector;void main(void){vec3 normal = normalize(vNormal);ARM DUI 0527A-02a Copyright © 2010 ARM. All rights reserved. 6-22ID070710Non-Confidential - Draft - Beta

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

Saved successfully!

Ooh no, something went wrong!