Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Get the ARCamera image to a RenderTexture, ReadPixels from the RenderTexture then set to a RawImage , flickers color ??? #985

Closed
hasionerin opened this issue Jun 14, 2022 · 3 comments
Labels
bug A bug in an ARFoundation-related package

Comments

@hasionerin
Copy link

hasionerin commented Jun 14, 2022

Unity Version : Unity2020.3.18
ARFoundation Version : 4.2.1
ARCore XR Plugin 4.2.1
Platform : Android

I Get the ARCamera Image Real-time, Render to a RenderTexture, then ReadPixels from the RenderTexture ,and set to a RawImage , unfortunately, the RawImage flickers color .

follow is my code:

`

public Camera cam; 
public RawImage img;

private Texture2D renderResult = null;

public RenderTexture camRT;

#region GPU 

private RenderTexture mRenderTexture;

private void Update()
{
    if (mRenderTexture == null)
    {
        RenderTextureDescriptor renderTextureDes = new RenderTextureDescriptor(480, 640, RenderTextureFormat.BGRA32);

        mRenderTexture = RenderTexture.GetTemporary(renderTextureDes);
    }

    cam.targetTexture = mRenderTexture;
    cam.Render();

    RenderTexture.active = mRenderTexture;

    if (renderResult == null)
        renderResult = new Texture2D(480, 640, TextureFormat.RGB24, false);

    renderResult.ReadPixels(new Rect(0, 0, mRenderTexture.width, mRenderTexture.height), 0, 0);
    renderResult.Apply();

    img.texture = renderResult;

    cam.targetTexture = null;
    RenderTexture.active = null;

}

#endregion`

it like flicker every few frames . It's too strange . and it works fine on ios devices. just error on android devices . has anyone had this problem? and how to solve this problem?

i take some photos :

微信图片_20220614155737

微信图片_20220614155745
微信图片_20220614155754

@hasionerin hasionerin added the bug A bug in an ARFoundation-related package label Jun 14, 2022
@hasionerin
Copy link
Author

@tdmowrer please helps me . This problem has puzzled me for a long time. thanks a lot !

@hasionerin hasionerin changed the title [Bug]Render the ARCamera screen to a RenderTexture, Set RenderTexture to a RawImage , flickers color [Bug] Get the ARCamera image to a RenderTexture, ReadPixels from the RenderTexture then set to a RawImage , flickers color ??? Jun 14, 2022
@DavidMohrhardt
Copy link
Collaborator

DavidMohrhardt commented Jun 14, 2022

I can't help but wonder if this might be a timing issue.

To validate it's not can you try just using Graphics.Blit or use a blit command buffer and add it to the CameraEvent.AfterEverything event like so:

commandBuffer.clear();
commandBuffer.ClearRenderTarget(true, false, Color.clear);
commandBuffer.Blit(null, myRenderTarget, material);
Camera.main.AddCommandBuffer(CameraEvent.AfterEverything, commandBuffer);

then read the texture OnPostRender.

@andyb-unity
Copy link
Collaborator

Closing due to inactivity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug in an ARFoundation-related package
Projects
None yet
Development

No branches or pull requests

3 participants