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 Shadersvec3 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;POSITION is a element offset into a Vertex Buffer Object. The attribute POSITION passed to theshader is an interpolated value based on the vertex positions.The calculated vectors vLightVector and vCameraVector are passed to the fragment shader.6.3.4 TexturesA texture is typically based on a bit-mapped graphic. The code in Example 6-10 loads a texturefrom a bitmap and passes a sampler to the fragment shader:Example 6-10 Passing a texture sampler to the fragment shaderProgram *texturingProgram =proxy.getProgram("shaders/texturing.vert;shaders/texturing.frag");Texture2D *texture = proxy.getTexture2D("data/rock_t.png");texture->setFilterMode(GL_NEAREST, GL_NEAREST);context->setProgram(texturingProgram);context->setUniformSampler("texture", static_cast(texture));The uniform is passed to the shader as shown in Example 6-11:Example 6-11 Using the texture data in the fragment shaderuniform sampler2D texture;varying vec2 vTexCoord;void main(void){gl_FragColor = texture2D(texture, vTexCoord);}vTexCoord is a calculated texture coordinate passed from the vertex shader. gl_FragColor is theoutput color that is rendered to the display.ARM DUI 0527A-02a Copyright © 2010 ARM. All rights reserved. 6-11ID070710Non-Confidential - Draft - Beta

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

Saved successfully!

Ooh no, something went wrong!