googlevr / gvr-android-sdk

Google VR SDK for Android
http://developers.google.com/vr/android/
Other
3.28k stars 1.28k forks source link

Google VR double image on top of the screen bug #354

Closed yoavya closed 6 years ago

yoavya commented 7 years ago

I am using Google VR SDK to show an image on the screen. I am encountering a strange bug when displaying the objects without distortion although it happens only on large screens (namely 5.5 inch or larger). To disable distortion I am using gvrView.setDistortionCorrectionEnabled(false) The result looks like this: double image example You can see that there is a cut part at the top of the screen that shows some of the objects again.

When I use distortion the problem seems to disappear. distortion on no problem example

I will give the relevant code here for reference:

public class MainActivity extends GvrActivity {

    private GLSurfaceView mGLSurfaceView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fpv_activity_layout);
        initGvrView();
    }

    private void initGvrView() {
        GvrView gvrView = (GvrView) findViewById(R.id.gvr_view);
        gvrView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);

        // Associate a GvrView.StereoRenderer with gvrView.
        gvrView.setRenderer(new FpvRenderer(this));

        AndroidCompat.setSustainedPerformanceMode(this, true);

        gvrView.setDistortionCorrectionEnabled(false);

        setGvrView(gvrView);
    }
}

The XML file:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:orientation="vertical"
          android:layout_width="match_parent"
          android:layout_height="match_parent">

    <com.google.vr.sdk.base.GvrView
        android:id="@+id/gvr_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true" />

</RelativeLayout>

I am using this function to load the textures:

public static int loadTexture(final Context context, final int resourceId) {
    final int[] textureHandle = new int[1];

    GLES20.glGenTextures(1, textureHandle, 0);

    if (textureHandle[0] != 0) {
        final BitmapFactory.Options options = new BitmapFactory.Options();
        options.inScaled = false;    // No pre-scaling

        // Read in the resource
        final Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), resourceId, options);

        // Bind to the texture in OpenGL
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0]);

        // Set filtering
        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);

        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);

        // Load the bitmap into the bound texture.
        GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);

        // Recycle the bitmap, since its data has been loaded into OpenGL.
        bitmap.recycle();
    }

    if (textureHandle[0] == 0) {
        throw new RuntimeException("Error loading texture.");
    }

    return textureHandle[0];
}

Has anyone encountered this, have any idea why this is happening and how to resolve it ?

I appreciate the help.

I also asked this question on stackoverflow

sigmaxipi commented 7 years ago

The root of the issue is that without distortion, the undistorted texture is mapped 1-to-1 to the screen. If the texture is smaller than the screen, you will see it repeated on the edges. Is this repetition visible in your viewer?

yoavya commented 7 years ago

When in the cardboard the edges are not visible however I would like to avoid this issue from accruing at all. I can't display the texture on the entire screen because my requirements demand that i present them at a fixed size. How can I solve this?

sigmaxipi commented 7 years ago

What are your requirements for this app? Normally, you shouldn't disable distortion correction unless you're running on a very low-power device.

yoavya commented 7 years ago

Honestly it's just a cosmetic requirement by my client. The images I am presenting are 2D so there is no real need for distortion (although it doesn't harm anything). Is there a way to solve this issue without enabling the distortion correction ?

sigmaxipi commented 7 years ago

Two workarounds I can think of:

  1. Add a custom view to the layout that's black and covers the top of the 3D view.
  2. Use https://vr.google.com/cardboard/viewerprofilegenerator/ to create a fake viewer profile with 0.0 distortion. Enabling distortion correction with this viewer profile should be similar tto disabling distortion with a normal viewer profile.
jdduke commented 6 years ago

Closing per the suggested workarounds.