Forums - How to import flame scene which is written by shader into adreno sdk

1 post / 0 new
How to import flame scene which is written by shader into adreno sdk
Join Date: 12 Oct 17
Posts: 3
Posted: Tue, 2019-04-16 19:43

      I studied the adreno sdk-linux-5_0/Development/Tutorials/ in the Adreno GPU SDK and referred to the 03_DrawTriangle code inside,

       in order  to change the demo of the triangle to the flame and display the frame rate of the current page.

      Focus on scene.cpp in adrenosdk-linux-5_0/Development/Tutorials/OpenGLES/03_DrawTriangle, we found that the triangle is mainly implemented 

      by BOOL CSample::InitShaders() and VOID CSample::Render(). Inside the InitShaders function g_strVSProgram receives the model data passed to it by the system, 

     and then processes these into the data we need later (but at least the location information of these vertices) for output. Other output data such as the UV coordinates of 

     the texture and other data that needs to be passed to g_strFSProgram.Then, the system interpolates the vertex data output by g_strVSProgram and 

     passes the interpolation result to g_strFSProgram. Finally, g_strFSProgram calculates the pixel color on the final screen based on these interpolation results.

The InitShaders function in Scene.cpp is as follows:

BOOL CSample::InitShaders()
    g_strVSProgram = 
    "attribute vec4 g_vVertex;                                             \n"
    "attribute vec4 g_vColor;                                             \n"
    "varying   vec4 g_vVSColor;                                          \n"
    "                                                                     \n"
    "void main()                                                         \n"
    "{                                                                     \n"
    "    gl_Position  = vec4( g_vVertex.x, g_vVertex.y,                  \n"
    "                         g_vVertex.z, g_vVertex.w );                \n"
    "    g_vVSColor = g_vColor;                                          \n"
    "}                                                                     \n";

    g_strFSProgram = 
    "#ifdef GL_FRAGMENT_PRECISION_HIGH                                     \n"
    "   precision highp float;                                             \n"
    "#else                                                                 \n"
    "   precision mediump float;                                         \n"
    "#endif                                                                 \n"
    "                                                                     \n"
    "varying   vec4 g_vVSColor;                                          \n"
    "                                                                     \n"
    "void main()                                                         \n"
    "{                                                                     \n"
    "    gl_FragColor = g_vVSColor;                                      \n"
    "}                                                                     \n";
    return TRUE;

  We have the flame shader code as follows, which are the vertexShader and fragmentShader parts. 

  The current problem is to replace the following vertexShader and fragmentShader code into g_strVSProgram and 

  g_strFSProgram of BOOL CSample::InitShaders() function respectively, compile and generate apk push. Into the phone, 

  the app will flash directly after opening the app, but no abnormal information is found in the log. 

  We studied and found no related documents for shader import.

  Please help to point the direction of the debug, and how the shader code imports the adrenosdk process.


vertexShader: `
        uniform float elapsedTime;
        uniform float numParticles;
        uniform float gravity;
        uniform vec3 up;
        uniform float sparkLifecycle;
        uniform float sparkDistanceScale;
        uniform float sparkStartSize;
        uniform float sparkEndSize;
        uniform float flameMaxHeight;
        uniform float flameMinHeight;
        uniform float flamePeriod;
        uniform float windStrength;
        uniform float windFrequency;

        attribute vec3 direction;
        attribute float uniqueness;
        attribute float particleIndex;

        #define PI 3.141592653589793238462643383279

        varying float vTime;

        void main( void ) {
          // unique duration
          float duration = sparkLifecycle + sparkLifecycle * uniqueness;

          // make time loop
          float particleOffset = (particleIndex / numParticles * duration);
          float time = mod(elapsedTime + particleOffset, duration);

          // store time as 0-1 for fragment shader
          vTime = time / duration;

          // apply "gravity" to fire
          vec3 vGravity = up * gravity * pow(vTime, 2.0);

          // move in direction based on elapsed time
          float flameHeight = mix(flameMinHeight, flameMaxHeight, uniqueness); 
          vec3 vDistance = flameHeight * direction * vTime;

          // close flame at top (0.5 is fully closed)
          vDistance.xz *= cos(mix(0.0, PI * flamePeriod, vTime));

          // apply some random horizonal wind
          vec3 vWind = sin((elapsedTime + vTime * uniqueness) * windFrequency * uniqueness) * cross(up, direction) * windStrength * uniqueness * vTime;

          // add all forces to get final position for this frame
          vec3 pos = position + vDistance + vGravity + vWind;

          // Set size based on frame and distance
          vec4 mvPosition = modelViewMatrix * vec4( pos, 1.0 );
          gl_PointSize = mix(sparkStartSize, sparkEndSize, vTime);
                  gl_PointSize = gl_PointSize * (sparkDistanceScale / length(;
          // project position on screen
          gl_Position = projectionMatrix * modelViewMatrix * vec4(pos, 1.0);

fragmentShader: `
        uniform vec3 color;
        uniform vec3 endColor;
        uniform float opacity;
        uniform sampler2D texture;

        varying float vTime;
        void main() {
          vec4 texColor = texture2D(texture, gl_PointCoord);
          vec4 startColor = vec4(color, opacity);
          vec4 endColor = vec4(endColor, 0.0);
          gl_FragColor = texColor * mix(startColor, endColor, vTime);

  • Up0
  • Down0

Opinions expressed in the content posted here are the personal opinions of the original authors, and do not necessarily reflect those of Qualcomm Incorporated or its subsidiaries (“Qualcomm”). The content is provided for informational purposes only and is not meant to be an endorsement or representation by Qualcomm or any other party. This site may also provide links or references to non-Qualcomm sites and resources. Qualcomm makes no representations, warranties, or other commitments whatsoever about any non-Qualcomm sites or third-party resources that may be referenced, accessible from, or linked to this site.