Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Copying a screenshot onto a quad in an ISystem

Discussion in 'General Graphics' started by xindexer2, Aug 2, 2023.

  1. xindexer2

    xindexer2

    Joined:
    Nov 30, 2013
    Posts:
    78
    I need to copy a screenshot onto a quad and I’d prefer to do it all in an ISystem (or SystemBase) if able.

    I have a version that works in mono using screenCapture.capturescreenshotastexture, however I have read and I’m seeing that it sometimes doesn’t work.

    ideally I’d like to do it all on the GPU.

    How do i get the screen as my source And how do I assign the texture to the quad?

    Thank you
     
  2. xindexer2

    xindexer2

    Joined:
    Nov 30, 2013
    Posts:
    78
    I have been working on this one for a while - finally got something that works, if somebody comes across this in the future here's what I did:
    Code (CSharp):
    1. var quad = EntityManager.Instantiate(SystemAPI.GetSingleton<Config>().QuadPrefab);
    2. var hybridRenderer = World.GetExistingSystemManaged<EntitiesGraphicsSystem>();
    3. var screenShotMaterial = new Material(Shader.Find("HDRP/Unlit"));
    4. screenShotMaterial.mainTexture = UnityEngine.ScreenCapture.CaptureScreenshotAsTexture();
    5. var materialID = hybridRenderer.RegisterMaterial(screenShotMaterial);
    6. var mmi = EntityManager.GetComponentData<MaterialMeshInfo>(quad);
    7. mmi.MaterialID = materialID;
    8. var quadRma = EntityManager.GetSharedComponentManaged<RenderMeshArray>(quad);
    9. var rmaMatList = quadRma.Materials.ToList();
    10. rmaMatList.Add(screenShotMaterial);
    11. var rma = new RenderMeshArray(rmaMatList.ToArray(), quadRma.Meshes);
    12. var rmd = new RenderMeshDescription(UnityEngine.Rendering.ShadowCastingMode.Off, false);
    13. RenderMeshUtility.AddComponents(quad, EntityManager, rmd, rma, mmi);