How to set up a camera so that it doesn't clear the color buffer?

Hello,

I’m using Unity 2019.3.3f and the latest Universal RP 7.2.1. I have a camera stack set up - the base camera renders my level (layer Default), and the overlay camera renders the “field of view” mesh that I’m generating on the fly (it’s on a separate layer called “Mask”.)

Now when I use the stack and combine the outputs of those two cameras, it works correctly, i.e. I can see the rendered field of view mesh overlaid on the base camera’s output. But my aim is to have the field of view to unveil the map, so all areas that have already been visited by the player should be visible, and the remaining ones not.

I think the problem is that the overlay camera clears its color buffer everytime it renders, because it only renders the current “state” of the field of view mesh.

How do I set up the stack so that I can achieve what I’m looking for?

If you need any more information, please let me know.

Thank you,
Patryk

I decided to try a different setup and show you guys the approach that I’m currently taking.

Here’s my minimap camera. It basically follows the player (that’s why it has a script attached to it, background type is set to ‘Uninitialized’):

Here’s the renderer configuration that it uses:

And now let’s run the game and see what happens. As you can see, it correctly renders the view mesh. I know that it might look bad in the picture, but believe that it’s the expected result:
5537647--569443--RT_1.PNG

Now let’s move to the right so that the field of view mesh can expand:
5537647--569446--RT_2.PNG

As you can see, the little fragment at the very start is now gone and the current state of the field view mesh is now rendered to the texture. What I would like to achieve is this (this picture’s been done in Photoshop):
5537647--569449--RT_Desired.PNG

The above effect should be easily achieved if the render texture didn’t clear every frame, I believe.

Do you think my setup is wrong somewhere, something is missing, or is that a bug in Unity? Also, if you have a different idea on how to do that “uncovering map” effect, I’m open to learn about them.

Thank you,
Patryk

Another observation is that if I set the camera’s solid color to some value and then set it back to Uninitialized, I can still see that color in the render texture.

Seriously, am I missing some really obvious stuff here or is it clearly a bug?

You are using the API as intended. I quickly checked the code and it seems like this is behavior that you might experience only in editor. That’s a bug. Could you submit I bug report so we keep track of it and I’ll push a fix asap?

Sure, how do I do that? :slight_smile: And what exactly is the problem?

@phil_lira I think that you only want to fix the problem with the editor still showing the camera color in the preview, but the problem is (I think) in the render texture being cleared every frame, even though I don’t really want to do that, because I explicitly set ‘Background Type’ to ‘Uninitialized’.

I didn’t say how I’m going to fix the problem. Behavior should be if you set to Uninitialized it should not clear, not matter the platform or the render target. :slight_smile:
I just said that I cans see already something is wrong with Editor, it might be that there’s more things wrong but I’ll find out when we triage the bug.

Perfect, let me report it for you!

@phil_lira The tracking link is here: http://fogbugz.unity3d.com/default.asp?1224369_7mrk4u7mtf10ar0u

Thanks,
Patryk

1 Like

@phil_lira Do you happen to know if there’s any progress on this issue? Do you guys need more information from me?

Regards,
Patryk

@phil_lira Could you tell me if you guys fixed the bug, please?

Hey Patryk, I apologize we haven’t started worked on the fix for this issue yet. We plan to fix it and backport to 2019 LTS but I can’t give you an ETA yet.

@phil_lira Sorry for bugging you guys, but I’m just curious whether there’s any progress on this issue. If it’s fixed in whichever 2020 version, it’s fine, I can upgrade.

Hey @pateman , I’ll see if we can get an update on this for you!

@Shaunyowns Perfect, I’m waiting for your reply. :slight_smile:

@Shaunyowns , any news?

Hey @pateman , sorry for the delay, I’ll see if I can get this looked at again!

@Shaunyowns Thank you! Please get back to me as soon as possible, I’d really love to have it resolved. I don’t mind upgrading to a newer version as long as the issue’s gone.

I was also curious about this one, and I made attempts to capture the screen buffer using a blit to a RenderTexture at the end of the render pipeline. I planned to blit the texture at the start of the next frame, as to simulate having Clear Flags: Don’t Clear (or what Background Type: Uninitialized could be). I was able to achieve this in a couple of different ways, but it felt like a mess.

But in the process, I discovered an interesting solution.

If you use the Blit/pass scripts from Universal Rendering Examples, you can set up a blit feature in your renderer. If you specify a material using the Sprites/Default shader, Event: Before Rendering Prepasses, Destination: Color, it will cause it to behave as if it has Clear Flags: Don’t Clear.

I have no clue why this works, but it really seems to do the trick.

Wow, cool! I’ll check it out soon :slight_smile: