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 Drawing 3D ShapesoLight0Dir = light0position - oPos;tLight0Dir = oLight0Dir * tangentSpace;oLight1Dir = light1position - oPos;tLight1Dir = oLight1Dir * tangentSpace;}tViewDir = oViewDir * tangentSpace;7. Example 4-64 shows the fragment shader code for the environment:Example 4-64 Environment fragment shader lightshow.frag...varying vec3 oPos;varying vec3 tViewDir;varying vec2 outTexcoord;varying vec3 oLight0Dir;varying vec3 tLight0Dir;varying vec3 oLight1Dir;varying vec3 tLight1Dir;uniform sampler2D diffuseMap;uniform sampler2D normalMap;uniform sampler2D glossMap;uniform vec3 cameraPosition;uniform vec3 light0color;uniform vec3 light1color;uniform vec3 light2color;uniform vec3 light0position;const float pi = 3.1415;uniform vec3 shadow_info[2];const float soft_shadow_eps = 0.015;// calculate how the light source intersects the columnfloat intersectRayCylinder(vec2 ray_origin, vec3 shadow_info){const float scale_factor = (0.5/pi);float offset = shadow_info.x;float light_dist = shadow_info.y;float limit = shadow_info.z;vec2 light_pixel = ray_origin.xy - light0position.xy;float angle = fract(atan(light_pixel.y, light_pixel.x)*scale_factor - offset);float adjusted_angle = abs(angle - 0.5);}return smoothstep(limit, limit+soft_shadow_eps, adjusted_angle) *float(light_dist < length(light_pixel));// is this point in shadowfloat getShadow(vec2 oPos){float shadow = 0.0;shadow = max(shadow, intersectRayCylinder(oPos, shadow_info[0]));shadow = max(shadow, intersectRayCylinder(oPos, shadow_info[1]));ARM DUI 0527A-02a Copyright © 2010 ARM. All rights reserved. 4-52ID070710Non-Confidential - Draft - Beta

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

Saved successfully!

Ooh no, something went wrong!