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 Shaders6.4 Minimal shader programsThe shaders are not required to use all of the available uniforms and attributes. Example 6-12shows a simple vertex shader that assigns the interpolated value in the POSITION attribute to theglobal position variable gl_Position:Example 6-12 Identity vertex shaderattribute vec4 POSITION;void main(void){gl_Position = POSITION;};Example 6-13 shows a simple fragment shader that always outputs red as the fragment color:Example 6-13 Fixed-color fragment shaderprecision mediump float;void main(void){gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);};6.4.1 Adding vertex coloringThe vertex shader can define a varying col and use it to pass the interpolated vertex color, COLOR,to the fragment shader. The varying col variable is shared with the fragment shader. SeeExample 6-14:Example 6-14 Vertex shader passes interpolated color to fragment shaderattribute vec4 POSITION;attribute vec4 COLOR;varying vec4 col;void main(void){col = COLOR;gl_Position = POSITION;};Example 6-15 shows that the actual assignment to the gl_FragColor global color variable is donein the fragment shader:Example 6-15 Assignment of the color in the fragment shaderprecision mediump float;varying vec4 col;void main(void)ARM DUI 0527A-02a Copyright © 2010 ARM. All rights reserved. 6-12ID070710Non-Confidential - Draft - Beta

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

Saved successfully!

Ooh no, something went wrong!