Unity-Technologies / arfoundation-samples

Example content for Unity projects based on AR Foundation
Other
2.99k stars 1.11k forks source link

How to get arcamera RenderTexture contain ARObjects. #1022

Closed Sjaeseok closed 1 year ago

Sjaeseok commented 1 year ago

i tried this code

` Graphics.Blit(null, renderTexture, m_ARCameraBackground.material); var activeRenderTexture = RenderTexture.active; RenderTexture.active = renderTexture;

    if (m_LastCameraTexture == null)
        m_LastCameraTexture = new Texture2D(renderTexture.width, renderTexture.height, TextureFormat.ARGB32, true);

    m_LastCameraTexture.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0);
    m_LastCameraTexture.Apply();
    RenderTexture.active = activeRenderTexture;
    // Write to file
    var bytes = m_LastCameraTexture.EncodeToPNG();
    var path = Application.persistentDataPath + "/camera_texture.png";
    File.WriteAllBytes(path, bytes);`

but i cant get texture contain ar objects. how can i get the texture contain ar obejcts?

nextechar-hardik commented 1 year ago

AR camera also work like normal camera component in Unity so, i haven't try this. but this should work

  1. Create a new Render Texture in you Project Folder
  2. Assign that render texture in main camera "Target Texture" Field.
  3. Assign same render texture in material or Canvas Raw Texture
  4. done

You can see All Thing in render texture what camera see....

Sjaeseok commented 1 year ago

AR camera also work like normal camera component in Unity so, i haven't try this. but this should work

  1. Create a new Render Texture in you Project Folder
  2. Assign that render texture in main camera "Target Texture" Field.
  3. Assign same render texture in material or Canvas Raw Texture
  4. done

You can see All Thing in render texture what camera see....

Thanks reply. I tried that way. ARCamera not showing display after assign render texture in 'AR Camera'. but only could just show render texture and without ARObject. Is there another way?

DavidMohrhardt commented 1 year ago

You may want to perform a Graphics.Blit(yourRenderTexture, null); after all rendering has completed for a given frame to write the render texture to the back buffer.