GL LINES disappearflicker when rotating camera on Android with OpenGL ES 2.0

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

In my Android application I m using OpenGL ES 2.0, and i have need to show a grid in the center of the scene. I have also camera which can be rotated around scene center.

I m rendering grid using GL_LINES and simple shader program.

On some devices that i have, everything works fine, however on one device (specifically Galaxy Note 10.1 2014 edition) i have problem with grid lines disappearing/flickering when camera is rotated, i.e. at some camera angles lines are not visible.

Here is how problem looks:

<img src="https://i.stack.imgur.com/ji1i9.gif" alt="enter image description here">

And here is how it should work:

<img src="https://i.stack.imgur.com/FJ73y.gif" alt="enter image description here">

What i noticed, is that it looks like lines start to flicker at some camera angles, when their end points (or start points, not sure) appears behind near frustum plane of camera (i.e. behind camera). So there is no flickering when camera looks at grid from above, and no flickering when camera looks from two of four sides, or from far away.

I tried to search for solution or possible cause of this problem for few days, but found nothing so far. So i decided to ask you people. I would appreciate some help, suggestions. Maybe someone with OpenGL experience could guess what causes problem from this description.

There is also question, maybe it’s not problem in my code, but problem with specific device, with driver or etc? But i have no way to check this. I have only three Android devices on my hands, and it’s probably not enough to make such conclusion for sure.

It works fine on old Galaxy Tab 10.1, and on Lenovo P780 phone. However Galaxy Note 10.1 is more recent device and has very big resolution (2560 x 1600), so i also think, that maybe its not because device/GPU driver, but maybe because high resolution?

Other geometry (filled polygons not lines) renders fine.

Here is my code.

DrawFrame and project/view matrices setup:

    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

    GLES20.glLineWidth(1f);

    float screenRatio = (float)viewportWidth / (float)viewportHeight;

    Matrix.setIdentityM(matrixProjection, 0);
    MatrixHelper.perspectiveM(matrixProjection, 0, 90, screenRatio, 0.1f, 1000f);                

    Matrix.setIdentityM(matrixView, 0);

    Matrix.translateM(matrixView, 0, 0f, 0f, -10f);        

    rotationAngle = rotationAngle + (10f * deltaSec);

    Matrix.rotateM(matrixView, 0, 45f, 1f, 0f, 0f);
    Matrix.rotateM(matrixView, 0, rotationAngle, 0f, 1f, 0f);        


    GLES20.glUseProgram(shaderGrid.ShaderProgramId);

    GLES20.glUniformMatrix4fv(shaderGrid.vProjection, 1, false, matrixProjection, 0);
    GLES20.glUniformMatrix4fv(shaderGrid.vView, 1, false, matrixView, 0);

    renderGrid.Draw(shaderGrid, origin); //see code from this method below

Drawing lines:

    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, bufferIds[0]);                              
    GLES20.glVertexAttribPointer(shader.aPosition, 3, GLES20.GL_FLOAT, false, 0, 0);
    GLES20.glEnableVertexAttribArray(shader.aPosition);        

    float [] m = new float[16];

    Matrix.setIdentityM(m, 0);

    GLES20.glUniformMatrix4fv(shader.vModel, 1, false,  m, 0);            

    GLES20.glDrawArrays(GLES20.GL_LINES, 0,     10 * 2 * 4); 
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
    GLES20.glDisableVertexAttribArray(shader.aPosition);

Here is my shader code (sorry for such format =)):

    public String GetShaderFragmentCode()
    {        
        return
          "precision mediump float;" +
          "void main() " +
          "{" +
          "  gl_FragColor = vec4(0.7, 0.7, 0.7, 1.0);" +
          "}";            
    }

    public String GetShaderVertexCode()
    {
        return
          "uniform mat4 vProjection;" +
          "uniform mat4 vModel;" +
          "uniform mat4 vView;" +

          "attribute vec3 aPosition;" +

          "void main() " +
          "{" +
          "  gl_Position = (vProjection * vView * vModel) * vec4(aPosition.xyz, 1.0);" +
          "}";
     }

Here is minimal app to reproduce problem (wait until grid rotates completely):

https://dl.dropboxusercontent.com/u/5344890/GL_LINES_BUG/LinesProblemMinimal.apk https://dl.dropboxusercontent.com/u/5344890/GL_LINES_BUG/LinesProblemMinimal.apk

https://dl.dropboxusercontent.com/u/5344890/GL_LINES_BUG/LinesProblemMinimal.zip https://dl.dropboxusercontent.com/u/5344890/GL_LINES_BUG/LinesProblemMinimal.zip

I am not sure if its really helps, because it’s device specific, but I will also appreciate your feedback in case if you will have same problem on other devices. Or if you have other high resolution device that doesn t have this problem.

And here is random stuff I have tried to see if it will affect problem (but no luck, same result) so far:

    • disable/enable GL_CULL_FACE
    • explicitly set glLineWidth to 1f, or other values
    • use glDrawElements instead of glDrawArrays
    • change camera frustum zNear (from 0.1f to 100f)
    • change frustum zFar (from 10f to very big values)
    • change vec3 to vec4 for aPosition in shader code (and without converting using .xyz)
    • using GL_LINE_STRIP - to see what will happen, lines still disappear
    • using GL_TRIANGLE_STRIP etc - polygons doesn t disappear, so problem specifically with lines, but i need lines

I also noticed this artifact when i was preparing examples:

<img src="https://i.stack.imgur.com/4oqlN.png" alt="enter image description here">

It appears and then disappears very quickly when camera is rotated and lines flicker.

Answers

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/24530895/gl-lines-disappear-flicker-when-rotating-camera-on-android-with-opengl-es-2-0

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils