Rendering realistic images using shaders on mobile devices
Published at 11:06:18, August 12, 2021

Qualcomm products mentioned in this post are owned by Qualcomm technologiesandProvided by its subsidiaries.

Realism in the game is through the implementation of lighting and shadowsPhysical propertyParticle systems, and moisture effects, andMotion blurBump map, and distortion. By perfecting these on today's GPU hardware, you can make your game so realistic that players have to look carefully to determine whether they see computer images or real things. Very simple, these images look like magic on the screen!

utilizeShadersAll these effects can be achieved. These small programs running on the graphics processor provide developers with a programmable rendering pipeline, which can achieve dynamic rendering effects during the running process.

Shader 101

Writing shader programs requires advancedShader Language 。 Common examples includeOpenGL Shading Language (glsl)andDirectX advanced shading language (HLSL), both shading languages elevate hardware abstraction to advanced 2D and 3D rendering constructs. Once implemented, shaders are usually compiled into low-level shading languages, such asARB assembly languageorDirectX shader assembly languageTo optimize and execute on a given platform.

In 1988, asRenderMan interface specificationAs part of Pixar Animation, the shader was introduced for the first time and quickly eliminated withFixed functionVarious rendering pipelines. Since then, graphics processors have evolved to include a variety of hardware accelerated programmable shading capabilities to support an increasing number of shading types, including:

  • Pixel Shader (aka fragment shader): calculate the color of each pixel to render according to the specific effects that the developer is trying to achieve (e.g. lighting, bump map, etc.).
  • Vertex Shader : convert each vertex from 3D space to viewing cone space to achieve rasterization and finally used for projection on the screen.
  • geometry shader : generates a new element (for example, a triangle). It can be used for various procedural effects, such as procedural vegetation, surface damage, particle effect, etc.
  • Subdivision surface shader: subdivides the mesh into finer grained meshes. It can be used for dynamic adjustment of level of detail.

Shaders make up the current dynamic / programmablerendering pipeline The foundation of; Typically, individual shaders arelinkTogether, the output of one shader becomes the input of another shader. Each pipeline can then ensure multiple effects / types of processing before final rendering on the screen.

Over time, the types of shaders and their related instruction sets have expanded, and the number of shaders supported by graphics processors has also increased. Pixel shaders and vertex shaders are among the most commonly used shadersUnified Shader modelModelThe introduction of can ensure that any shader can handle both types of data. By unifying the functions and instruction sets of different shaders, the graphics processor can now balance shader tasks when some shaders are idle.

In general, shaders look like standard C programs. For example, shaders typically have data structures for storing data such as vectors or coordinates, called by the graphics processormainFunctions, and for platform specific resources (for example, targetsArithmetic logic unit(ALU). The following is a small example of pixel shader implemented in OpenGL es, taken fromQDNupperBurning flames using a graphics processorExamples ofproject

#version 300 es
in vec2 TexCoords;
in vec4 ParticleColor;
out vec4 color;
uniform sampler2D sprite;
void main()
{
 #if 1
  color = (texture(sprite, TexCoords) * ParticleColor);
 #else
  color = ParticleColor;
 #endif
}

This is about shaders  hello worldExample, because it shows several single line codes for setting pixel colors. In the first case, the shader drags a pixel from a specific texture coordinate and modifies the value based on some particle color to set the color of the pixel. In the second case, the shader simply assigns the color of the particles to the pixel color.

Shaders on Adreno

Shaders continue to evolve and play a key role in today's cutting-edge mobile graphics processors, including in the company'sSnapdragon ® Mobile platformAvailable onQualcomm ® Adreno ™ Graphics Processing Unit

Starting from the Adreno 2XX series, the company incorporated shader support into Adreno by using the unified shader architecture including pixel shader and vertex shader. Taking four as a group and processing vertices and pixels as vectors, Adreno can balance the load of pixel shader and vertex shader within its arithmetic logic unit, as shown in Fig. 1.

Attached Fig. 1  Conceptual diagram showing how the Adreno unified shader architecture balances vertex and pixel shaders within its arithmetic logic unit

Starting with Adreno 3xx, vertex shaders, pixel shaders, and general graphics processor processing can also share the same arithmetic logic unit andGet resources。 For example, vertex shaders have direct access to the graphics processor texture cache, enabling vertex texture algorithms to be implemented in a relatively simple way (for example:Displacement mapping)。

Adreno 3xx adopts a multi-threaded architecture, which means that if one shader stalls (for example, due to texture acquisition), execution can be passed to another shader. Adreno 3xx also supports scalars, which means that pixel shaders running on Adreno with 16 bit floating-point values can provide twice the function and performance improvement compared with other vector based mobile graphics processors. The best part is that this is handled automatically by the Adreno graphics processor, ensuring that developers are free to focus on writing shader logic.

The company's latest version of snapdragon, includingSnapdragon 888 5g mobile platformandSnapdragon 865 5g mobile platform, supportVariable rate shading (VRS)。 With variable rate shading, developers can control the granularity of pixel shader execution to shade one or more pixels at a time. With variable rate shading, programmers can control the number of shaded pixels in a given area according to the level of detail of the scene, which helps to reduce processing power and power consumption.

Adreno graphics processor supportOpenGL ESVulkanandDirectX, mobile device developers who develop games and image applications for snapdragon have a wealth of software development kits to choose from. In addition, many mobile game developers also use itUnityandUnreal EngineThird party game engine. These two engines provide developers with a mechanism to create shaders in their ecosystem by performing additional abstract processing on the color language, which is helpful for porting to various platforms.

Are you ready to accept a more realistic picture?

Developers interested in learning more should download itAdreno software development kit, for demonstrations and samples of various common shader and shading techniques, and visitGame developer's GuideFor more in-depth recommendations and guidance on creating the best experience on the snapdragon platform. For more information on specific shaders, visit the following sections:

  • Shader support
  • Shader best practices

Be sure to check the of the software development kit/Developer / assets / samples / shaders directory, which includes many shaders written in OpenGL Shading Language and DirectX advanced shading language. Similarly, inQDNupperBurning flames using a graphics processorExamples ofproject, which contains a vertex and pixel shader.

SnapdragonandQualcomm AdrenoIt is a product of Qualcomm technologies, Inc. and its subsidiaries.

CSDN official wechat
Scan the two-dimensional code, make complaints about CSDN.
Micro signal: csdnnews
Microblog attention
[Disclaimer: CSDN publishes information in this column to disseminate more information and enrich network culture. The manuscript only represents the author's personal views and has nothing to do with CSDN. Its originality and the text and content stated in the text have not been confirmed by this website. This website does not make any guarantee or commitment to the authenticity, integrity and timeliness of this article and all or part of its content and text. Please readers only for reference, and please verify the relevant content by yourself. If you have any doubts or doubts about the manuscript, please contact CSDN immediately, and we will respond to you and deal with it quickly.]