Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

GL.readpixels issue

Discussion in 'Android' started by dsurka, Sep 26, 2017.

  1. dsurka

    dsurka

    Joined:
    Sep 30, 2012
    Posts:
    7
    Hi, we're working on a cross platform android/ios project. iOS is working fine but Android, not so much.

    We’re rendering to a ARGB32 RenderTexture, and we need to read pixels of that texture in each frame. ReadPixels method is really slow, so we’re doing this in a native Android plugin. We’re getting a native pointer to the RenderTexture’s color buffer and sending this to the plugin. In each Unity frame, we notify the plugin to read the color buffer. So we create a new FrameBuffer with GLES2, attach the color buffer using the pointer, and then use glReadPixels to read that FrameBuffer.

    After reading pixels, we run an algorithm to transform color format to YUV.

    There is some blending between particles and UI elements going on in the RenderTexture camera. The issue appears to be some clamping happening over the pixels written by the alpha channel on some shaders.
    PIC A

    PIC B


    Picture A is on device, it can be applied to a RawTexture or Mesh and looks like this, like it should. Picture B is what Java gets, some pixels where alpha blending is happening are clamped to 1 on the color channel. Blend SrcAlpha OneMinusSrcAlpha in both cases. This does not happen with SpritesDefault shader. But can't use that one for text or particles.

    Thanks in advance!