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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Tutorial on Constructing Custom Shaders4. The vertex shader listed in Example 6-21 performs the following actions:• It calculates the output position, gl_Position, based on a world view projection andthe current value of POSITION.This position calculation in Example 6-21 is a simple matrix multiplication toenable viewing the object from different angles, but more complex transformationscan be performed in the vertex shader.• It assigns the current of TEXCOORD0 to the varying vTexCoord.The fragment shader does not have access to TEXCOORD0, so the vertex shader mustcreate a variable to pass the value to the fragment shader. In Example 6-21, thevertex coordinate is just directly copied, but the vertex shader can also modify thecoordinate before passing it to the fragment shader.Example 6-21 Calculating gl_Position in the vertex shaderuniform mat4 WORLD_VIEW_PROJECTION;attribute vec4 POSITION;attribute vec2 TEXCOORD0;varying vec2 vTexCoord;void main(void){// calculate the actual position based on the interpolated POSITION attribute// and the uniform WORLD_VIEW_PROJECTIONgl_Position = WORLD_VIEW_PROJECTION * POSITION;// the texture coordinate is interpolated as passed as the TEXTCOORD0 attributevTexCoord = TEXCOORD0;}5. When the fragment shader receives the texture coordinate from the vertex shader, itassigns a value from the bitmap sampler to gl_FragColor as shown in Example 6-22:Example 6-22 Fragment shader code to read the texture value#ifdef GL_ESprecision mediump float;#endif // GL_ES// texture uniform was set up by the applicationuniform sampler2D texture;// the texture coordinate was passed from the vertex shadervarying vec2 vTexCoord;void main(void){// assign color by looking at the specified coordinate in the texturegl_FragColor = texture2D(texture, vTexCoord);}ARM DUI 0527A-02a Copyright © 2010 ARM. All rights reserved. 6-17ID070710Non-Confidential - Draft - Beta

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

Saved successfully!

Ooh no, something went wrong!