Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ScreenshotTool : MonoBehaviour, IAfterRender
- {
- private GrabPass grabPass;
- public ScriptableRenderPass GetPassToEnqueue()
- {
- if (grabPass == null)
- grabPass = new GrabPass();
- return grabPass;
- }
- }
- public class GrabPass : ScriptableRenderPass
- {
- public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData)
- {
- CommandBuffer buffer = new CommandBuffer();
- Camera camera = renderingData.cameraData.camera;
- using (new ProfilingSample(buffer, "test"))
- {
- RenderTextureDescriptor desc = ScriptableRenderer.CreateRenderTextureDescriptor(ref renderingData.cameraData);
- RenderTexture rt = new RenderTexture(desc);
- Texture2D tex = new Texture2D(camera.pixelWidth, camera.pixelHeight);
- RenderTexture.active = rt;
- tex.ReadPixels(new Rect(0, 0, camera.pixelWidth, camera.pixelHeight), 0, 0);
- tex.Apply();
- File.WriteAllBytes(Path.Combine(Application.persistentDataPath, $"screenshot.jpg"), tex.EncodeToJPG());
- Object.DestroyImmediate(tex);
- }
- context.ExecuteCommandBuffer(buffer);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement