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 Shadersattribute vec3 BINORMAL;attribute vec3 TEXCOORD0;varying vec2 vTexCoord;varying vec3 vLightVector;varying vec3 vCameraVector;void main(void){gl_Position = WORLD_VIEW_PROJECTION * POSITION;vTexCoord = TEXCOORD0.st;vec3 pos = WORLD * POSITION.xyz;mat3 TBN = WORLD * mat3(normalize(TANGENT), normalize(BINORMAL),normalize(NORMAL));}// No point in normalizing before the fragment shader as the normalization will// be offset by the interpolation anyway.vLightVector = (LIGHT_POSITION - pos) * TBN;vCameraVector = (CAMERA_POSITION - pos) * TBN;4. Example 6-34 shows the fragment shader combining the light sources:Example 6-34 Summing light values in bump map fragment shaderuniform mat3 M_MATRIX;uniform sampler2D diffuseTexture;uniform sampler2D normalMap;uniform vec3 AMBIENT_LIGHT;uniform vec3 DIFFUSE_LIGHT;uniform vec3 SPECULAR_LIGHT;uniform float DIFFUSE_CONTRIBUTION;uniform float SPECULAR_CONTRIBUTION;uniform float AMBIENT;varying vec2 vTexCoord;varying vec3 vLightVector;varying vec3 vCameraVector;void main(void){// read the normal value for this point from the texturevec3 normal = normalize(texture2D(normalMap, vTexCoord).rgb * 2.0 - 1.0);// read the color for this point from the texturevec4 color = texture2D(diffuseTexture, vTexCoord);// calculate the intensity of the diffuse light reflected off the pointvec3 lightVector = normalize(vLightVector);float nDotL = max(dot(normal, lightVector), 0.0);vec3 diffuse = DIFFUSE_LIGHT * nDotL;// calculate the multiplier for the specular reflectionfloat specPow = 0.0; // was 0// if the nDotL value is less than 0, use 0.0 for the specular multiplierif (nDotL > 0.0){vec3 cameraVector = normalize(vCameraVector);// what is the reflection based on the normal and the camera viewvec3 reflectVector = reflect(-cameraVector, normal);ARM DUI 0527A-02a Copyright © 2010 ARM. All rights reserved. 6-25ID070710Non-Confidential - Draft - Beta

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

Saved successfully!

Ooh no, something went wrong!