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.
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:
Now let’s move to the right so that the field of view mesh can expand:
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):
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.
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?
@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.
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.
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.
@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.