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 Shapesshadow = 1.0 - shadow;shadow = max(0.0, shadow);shadow = min(1.0, shadow);}return shadow;vec2 calcLight(vec3 tLightDir, vec3 oLightDir, vec3 oPos, vec3 tNormal,vec3 tRefViewDir, vec2 texcoord){float lightDist = length(tLightDir);tLightDir = normalize(tLightDir);float l_dot_n = max(dot(tNormal, tLightDir), 0.0);float h_dot_n = max(dot(tRefViewDir, tLightDir), 0.0);float attenuation = max(0.0, 120.0 - lightDist) / 90.0;attenuation *= attenuation;// use the shadow value to calculate the diffuse and specular lightfloat shadow = getShadow(oPos.xy) * attenuation;float diffuse = l_dot_n * shadow;float specular = pow(h_dot_n, 50.0) * shadow;}return vec2(diffuse, specular);void main(void){vec2 texcoord = outTexcoord.xy;vec3 tNormal = normalize((2.0*texture2D(normalMap, outTexcoord.xy).xyz)-1.0);vec3 tViewDirNorm = normalize(tViewDir);vec3 tRefViewDir = reflect(tViewDirNorm, tNormal);vec3 diffuseLight = vec3(0.0, 0,0);vec3 specularLight = vec3(0,0,0);{}vec3 lightColor = light0color;vec2 diffuseSpecular = calcLight(tLight0Dir, oLight0Dir, oPos, tNormal,tRefViewDir, texcoord);diffuseLight.xyz += lightColor * diffuseSpecular.x;specularLight.xyz += lightColor * diffuseSpecular.y * texture2D(glossMap,texcoord).x;}vec3 texDiffuse = texture2D(diffuseMap, outTexcoord.xy).xyz;gl_FragColor = vec4(diffuseLight*texDiffuse + specularLight,1);8. Example 4-65 shows the code that sets the uniforms for the flare and calls drawFlare():Example 4-65 Drawing the flare...glDepthMask(GL_FALSE);glEnable(GL_BLEND);glBlendFunc(GL_SRC_ALPHA, GL_ONE);ARM DUI 0527A-02a Copyright © 2010 ARM. All rights reserved. 4-53ID070710Non-Confidential - Draft - Beta

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

Saved successfully!

Ooh no, something went wrong!