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
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:
var quad = EntityManager.Instantiate(SystemAPI.GetSingleton<Config>().QuadPrefab);
var hybridRenderer = World.GetExistingSystemManaged<EntitiesGraphicsSystem>();
var screenShotMaterial = new Material(Shader.Find("HDRP/Unlit"));
screenShotMaterial.mainTexture = UnityEngine.ScreenCapture.CaptureScreenshotAsTexture();
var materialID = hybridRenderer.RegisterMaterial(screenShotMaterial);
var mmi = EntityManager.GetComponentData<MaterialMeshInfo>(quad);
mmi.MaterialID = materialID;
var quadRma = EntityManager.GetSharedComponentManaged<RenderMeshArray>(quad);
var rmaMatList = quadRma.Materials.ToList();
rmaMatList.Add(screenShotMaterial);
var rma = new RenderMeshArray(rmaMatList.ToArray(), quadRma.Meshes);
var rmd = new RenderMeshDescription(UnityEngine.Rendering.ShadowCastingMode.Off, false);
RenderMeshUtility.AddComponents(quad, EntityManager, rmd, rma, mmi);