Work with graphic objects in Android


    By clicking the “Next” button, you will find a translation of four small training materials on various techniques for processing and generating images in Android; three of them have source code for test programs and reference material for it. In our opinion, these manuals can be useful to everyone involved in the development of applications and games for Android.
    Under the cut are the following articles:
    • Clustered shading example in Android
    • Introducing RenderScript. Tutorial
    • Introducing OpenCL for Android. Tutorial
    • Tessellation for OpenGL ES 3.1 on Android

    Clustered shading example in Android

    In this example for Android, several shading techniques for scenes containing many light sources are implemented and compared. The full source code is available on GitHub , it can also be downloaded via a direct link . The most effective method shown in the example is the clustered shading described in this document . This example is a more advanced version of Windows ported to Android, available for download from here .
    The following methods are used in the example:
    • Direct rendering. In this method, the scene is rendered as usual, and the fragment shader passes through the entire list of light sources, applying the corresponding to each fragment to be shaded.
    • Deferred shading. In this method, the scene is first rendered into the G-buffer, and the illumination is calculated during post-processing. The fragment shader runs through the entire list of light sources for each fragment.
    • Shading with quadrangles. This is also a delayed technique, but unlike the previous one, each light source is rendered as a quadrangle, each contribution is summed into the buffer.
    • Clustered shading. In this mode, all light sources are first clustered on a three-dimensional grid. Next, the scene is rasterized. The fragment shader first determines which mesh cell the given fragment falls into and then goes through the list of light sources associated with this element, summing up the influence of each.
    • CS cells. This method combines delayed shading and clustering of light. Lighting is calculated by a shader of calculations, which summarizes the contribution of each source. Note that this technique only works if OpenGLES 3.1 is available .

    In our example, the following picture is generated:



    In the examples folder there are two solutions for Visual Studio:
    • ClusteredShadingWindows.sln is a Windows solution that can be built as a regular Windows application
    • ClusteredShadingAndroid.sln is a solution for Android. To build it, you need the Visual GDB plugin for Visual Studio. It can be downloaded from visualgdb.com .

    If you do not want to install Visual GDB, follow the instructions in the readme.txt file from the examples folder to assemble it manually.
    Original article.

    Introducing RenderScript. Tutorial

    The RenderScript Android Tutorial covers the basics of using RenderScript in developing an application for Android 4.2.2 and higher.
    The focus of the tutorial is on RenderScript, its base language and Java API. Since the manual uses only Java, although there are native C / C ++ analogues for the RenderScript API, and since RenderScript uses the dynamic compilation method (JIT), the resulting compiled application can be run on any device with the correct version of Android.
    The training application has a minimalistic graphical interface that displays the results of calculations and statistics. It implements a simple full-screen image processing algorithm that can be interacted with by touch.
    Target platform:Emulators and devices with Android 4.2.2 and higher
    Development platform: Any
    Difficulty level: Novice



    For more information about the example, refer to the user manual located inside the test archive.
    Download source code / documentation .
    Original article

    Introducing OpenCL for Android. Tutorial

    The OpenCL Tutorial for Android introduces you to the basic principles of using OpenCL in Android applications. The training application is an interactive image processing tool.
    The main focus of the tutorial is on how to use OpenCL in an Android application, where to start writing OpenCL code and how to link to OpenCL runtime. The tutorial shows a typical sequence of OpenCL API calls and the usual procedure for creating a simple animation handler for an OpenCL device. More advanced topics, such as efficient data sharing or OpenCL performance issues for Android, are not covered in this tutorial.
    Difficulty level: Beginner
    Development platform: Any
    Target platform: Devices with Android 4.2.2 and higher
    Target device: GPU device on an Android device
    Note. Android emulator does not support GPU OpenCL device. To run the sample code on the emulator, change the target GPU to the CPU by replacing CL_DEVICE_TYPE_GPU with CL_DEVICE_TYPE_CPU on line 451 of the jni / step.cpp file.



    For more information about the example, refer to the user manual located inside the test archive.
    Download source code / documentation .
    Original article

    Tessellation for OpenGL ES 3.1 on Android

    This article discusses how to implement and use tessellation in OpenGL ES 3 on Android. Tessellation is a hardware tool that allows the graphics processor (GPU) to dynamically subdivide primitives. It also allows you to control the placement of new vertices.
    The usual use of tessellation is to dynamically scale the level of detail of the area depending on the distance to the camera. Thus, the high definition of a densely triangulated area is combined with good performance.
    To support this technique, tessellation shaders are currently added in DirectX 11 and OpenGL 4.0. OpenGL ES does not yet have tessellation shaders, however, the Intel Bay Trail platform has an extension that allows tessellation to be used in OpenGL ES 3.0.
    The following steps show how the GPU uses tessellation to dynamically scale the terrain. The starting area consists of a low-resolution grid and a high-resolution elevation map texture.
    1. The tessellation control shader calculates the distance between the current triangle and the camera and sets the tessellation level depending on the calculated value. The closer the camera is to the triangle, the higher the tessellation level.
    2. The tessellation calculation shader adds new vertices of the triangles and moves them up or down depending on the values ​​of the high-resolution height map.

    As a result, tessellation triangles close to the camera refine the height map with finer details and add small indentations and bulges where the camera can see them.


    Tessellation off


    Tessellation on

    OpenGL ES Tessellation
    Original article.

    Also popular now: