Draw a camera at a resolution independent of Screen.currentResolution

I would like to have a resolution setting for the gameplay camera that is independent of the game resolution (Screen.currentResolution) so that the UI stays crisp even if the gameplay camera is set to a low resolution.

My thought was I could just render the camera to a RenderTexture that has a smaller resolution and then draw it back to the screen:

void OnPreRender()
{
    renderTexture = RenderTexture.GetTemporary(1080, 1920, 16);
    cam.targetTexture = renderTexture;
}

void OnPostRender()
{
    cam.targetTexture = null;
    Graphics.Blit(renderTexture, null as RenderTexture);
    RenderTexture.ReleaseTemporary(renderTexture);
}

Unfortunately (if I’ve gone about this the right way) that doubles the rendering time so it seems using RenderTextures to accomplish this is not going to work.

Are there any other options? Am I missing something with the RenderTexture approach?

Is there a way to set the resolution that specific camera draws at? Changing the Camera viewport width and height does this but then it obviously gets draw only to a small portion of the screen.

The way you’re doing it is the best way, as far as I’m aware.

It doesn’t quite double the rendering time because a camera has to loop through every object it sees, sending the shaders and textures to the GPU and rendering each object before it can move on. Once you’ve already rendered every object to a RenderTexture, using Blit to copy that texture to the screen is nearly as simple as rendering 1 quad with 1 texture (your RenderTexture).

The biggest hit here is that you are probably rendering that texture full-screen, which means drawing to every pixel in your game’s final resolution. I believe this is very unlikely to cause problems unless you have a GPU with a terrible “fill rate” and a high game resolution.

Well, I guess that’s my problem. Im using this for a mobile game. Being able to render the camera at a lower resolution would save me from some of those fill rate issues but, rendertextures make those problems worse. The code above makes my frame rate go from 26fps to 16fps negating any beneift of lower resolutions. If only there were a way to modify the camera render resolution without using a rendertexture…

Is there really no other option?

I’m not sure of the performance hit when calling “RenderTexture.GetTemporary()”, so maybe you could use a RenderTexture you create ahead of time in your assets folder.

There is also an alternative to using “OnPreRender()” and “OnPostRender()”, but I’m not sure if it will improve performance much. Basically you’ll want to create a quad that covers the full screen on the low-res camera, and set your quad to use a material that renders your RenderTexture with an unlit shader. With this approach, I recommend avoiding setting camera or material values in functions that are repeatedly called, such as “OnPreRender()”, “OnPostRender()”, and “Update()” to limit your CPU-to-GPU interactions.

This approach will probably not reduce hit to fill rate, unfortunately.

Best of luck!