#Struggling to perfectly map camera view from one scene to world space canvas in another scene

1 messages · Page 1 of 1 (latest)

harsh geode
#

Completely default Unity 6.2 project, didn’t tweak anything in lighting or any other settings. Project is in linear color space. Disclaimer: I don’t know what I’m doing, I don’t know what all the possible settings relating to cameras and render textures do, so this might be a dumb question.

I have a default settings camera in scene A, I want to take a 100% identical snapshot of what it sees to a world space canvas with a raw image in scene B.

So far I tried additively loading scene A from a main menu scene, which is completely empty, rendering scene A’s camera to render texture, ReadPixels from that render texture to a Texture2D and store it in a static dictionary so scene B can access it easily.

Then scene A unloads, scene B loads, and sets raw image texture as the render texture from the static dictionary. I’m using a dictionary because I’ll want to load snapshots from many scenes into scene B.

Now this works, but it’s not a perfect “snapshot”, viewing render texture in inspector it perfectly matches the camera view, but the Texture2D is brighter (oddly only the game objects, the skybox seems identical to camera view). I need it to be (nearly) indistinguishable, is this possible?

#
public static Dictionary<string, Texture2D> PaintingTextures = new();

    private IEnumerator Start()
    {
        DontDestroyOnLoad(gameObject);

        foreach (var sceneAsset in levelScenes)
        {
            var scenePath = AssetDatabase.GetAssetPath(sceneAsset);
            var sceneName = System.IO.Path.GetFileNameWithoutExtension(scenePath);
            SceneManager.LoadScene(sceneName, LoadSceneMode.Additive);
            yield return null;
    
            var paintingCamera = GameObject.FindWithTag("PaintingCamera").GetComponent<Camera>();
            var renderTexture = new RenderTexture(1920, 1080, 24, RenderTextureFormat.ARGBFloat);
            paintingCamera.targetTexture = renderTexture;
            paintingCamera.Render();

            yield return new WaitForEndOfFrame();
    
            RenderTexture.active = renderTexture;
            var texture = new Texture2D(renderTexture.width, renderTexture.height, TextureFormat.RGBA32, false, true);
            texture.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0);
            texture.Apply();
            RenderTexture.active = null;
    
            PaintingTextures.Add(sceneName, texture);
    
            paintingCamera.targetTexture = null;
            renderTexture.Release();
            SceneManager.UnloadSceneAsync(sceneName);
            yield return null;
        }
    }