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 ShadersThe fragment shader outputs gl_FragColor which is the global color value for the fragment. Theshader might just assign a fixed color value to all fragments in the shape but it can also:• read uniform values passed to the fragment shader by the application• use a texture bitmap to locate the bitmap pixel to use as the color for the fragment• use the varying output values from the vertex shader to modify the fragment color• use local variables or functions to simplify complex calculations• use matrix transformations to calculate lighting effects to apply• use a stencil to return fragment color for points that fit the specified condition.Figure 6-2 shows the data paths between the application, shader programs, and global context:Vertex shader codeAttributesPOSITIONCOLOR...UniformsWORLD_VIEW_PROJECTIONCAMERA_POSITIONWORLDModelViewMatrix...Global variablesgl_Positiongl_Pointsizegl_PointCoordgl_FrontFacinggl_FragColor...UniformsDIFFUSE_LIGHTSPECULAR_LIGHTAMBIENTDIFFUSE_CONTRIBUTIONSPECULAR_CONTRIBUTION...gl_Positiongl_FragColorVertexshaderLocal variablesvTexCoordvLightVectorvCameraVectorVaryingsvTexCoordvLightVectorvCameraVectorvColorvViewVectorFragmentshaderLocal variablesnormalviewVectorreflectionVectorFragment shader codeTexture sampler(typically from a bitmap file)Figure 6-2 Simplified view of shader data flowThe fragment shader might also use matrix transformations to calculate the fragment colorbased on all of the lighting sources.To draw a geometric object, for example a chair:1. All vertices associated with the chair must be known. For 3D graphics, the vertices arerepresented by x, y, and z coordinates. (If not explicitly specified, the value of w isassumed to be 1 for points in 3D space.)2. The vertices must be grouped into geometric primitives.ARM DUI 0527A-02a Copyright © 2010 ARM. All rights reserved. 6-3ID070710Non-Confidential - Draft - Beta

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

Saved successfully!

Ooh no, something went wrong!