render to texture with effects

hi all!
I have my camera that contains some effects like Antialiasing, DoF, Bloom, etc…
I wish make a shot using render to texture, 'cause I wish the shot bigger than the real camera size…
I used this code:

RenderTexture rt = new RenderTexture(resWidth, resHeight, 24);
Camera.main.targetTexture = rt;
Texture2D screenShot = new Texture2D(resWidth, resHeight, TextureFormat.ARGB32, false);
Camera.main.Render();
RenderTexture.active = rt;
screenShot.ReadPixels(new Rect(0, 0, resWidth, resHeight), 0, 0);
Camera.main.targetTexture = null;
RenderTexture.active = null;
Destroy(rt);
byte[] bytes = screenShot.EncodeToPNG();
string filename = @"c:\temp.png";
           
System.IO.File.WriteAllBytes(filename, bytes);
Debug.Log(string.Format("Took screenshot to: {0}", filename));

and it works, but all the effects that I’ve added are not present, and also the UI…

how can I do? thanks

I guess you gotta call this code very late after the camera renders?

1 Like

so I need to do in

void LateUpdate()

?

You should put it into OnPostRender()
Unity - Scripting API: Texture2D.ReadPixels contains an example

1 Like

thanks @mholub :roll_eyes:

Alternatively you could just use Application.CaptureScreenshot
It has a ‘supersize’ option that can scale the size of your screenshot.

1 Like