Overlay camera

Hi,

I have a problem.
I have 2 cameras in my scene. One overlays the Main Camera with the same scene. Main Camera films Objects with the layer A. And the second camera films objects with the layer B.

The main camera has a “Skybox” and the second is with “Depth Only”. Thanks to that i can see the 2 layers on the same screen without occlusions and with the same scale.

But I would like to see just a part what the second camera sees. Like a minimap. And i want to control the size of this aera. I don’t realy know how to do. I have tried with a canvas, raw image, mask and rendertexture but failed with keeping the same scale between Main Camera and 2nd Camera.

Could you help me ?

I don’t know if this is the proper way to create a minimap, but mess with these properties on the camera you want as a minimap.

Thank you but it’s not a minimap that i would like.

It’s more this effect :
3044270--228172--cZ226fk.png

Render one camera to a render texture, and then use an image effect shader (with a mask texture for example) to compose the images together.

Ok, that’s what i did :
3044305--228173--pbCamA12.PNG

But I don’t understant how to do to have the same scale between the MainCamera and the 2nd Camera. As you can see, the green cube has not the same size.

Did you mess with the viewport rect? It should be 0,0 and 1,1 for this.

No. Below is what i have :


And for the raw img :
3044344--228183--pbCam2-1.PNG

And for the 2nd Camera :

Do you see the problem ?
I just want that the red cube (filmed by the AR_Cam) overlays everything of what the MainCamera is filming.

You probably want to set the canvas to scale with screen size, and set the images rect transform to fill its parent.

1 Like

Yes, that’s exactly what i want. I didn’t have the words :slight_smile:

1 Like

Great! Did you figure out how to do it, or do you need help with that as well?

Just in case, set the canvas scaler on your canvas to scale with screen size, and set it to track height. On the rect transform, click the pivot preset gizmo and set it to stretch in all directions.

Ok no,

I learn by my mistakes.

You were right for one point, the canvas has to scale with screen size.
For that it’s ok. I set the “RenderMode” on “SreenSpace - Overlay” and the UI scaler on “Scale withe the Screen Size” (i don’t care about the “Reference Resolution” ?)

For the second point, the images of the 2nd Camera has to stay at the same size what ever the ScreenResolution. And this size must ensure that objects of the MainCamera and the 2nd Camera appear with the same size/scale.
I don’t know really how to do. I tried to set the RenderTexture at the same size than the window of the screen and change the size of the RawImage to match with it. But I never had the same size of objects between the 2 cameras (i compare 2 cubes 1x1x1).

Do you need it to be a UI element on a canvas? As I said before, this can easily be done with an image effect shader.

It should work with a UI canvas as well, but I’m not sure at this point which of your settings could be wrong.

No it doesn’t need.
It is just I have never used the shader yet.
I found informations about the canvas that’s why I tried it.
I check on internet for shaders

Seems it was a bit more work to get it to display correctly on a canvas than I thought, but take a look at the attached example, I think this works as you want?

But if it doesn’t need to be on a canvas, I would still recommend using a shader. It will be more performant and probably look better. This would be a starting point https://docs.unity3d.com/Manual/PostProcessingWritingEffects.html

3045706–228321–camtocanvas.unitypackage (41.8 KB)

1 Like

Thank you,
Yesterday I had almost the same results that with what you did.
But yours works better than me :smile:.

As I need perf and really perfect good looking results I think I will do it in a shader as you say.

I notice that you have the same strange visual pb :
3045734--228322--PackSteego.PNG
With the same position, the 2 cubes don’t look identical. One seems smaller. I hope I will fix it with the shader.

You can try to change the render texture to point filtering and disable mipmaps, that might help with that.

With a shader you shouldn’t have this problem.

Ok it’s all good now.

I’m using a shader with Zwrite Ztest and i play with the render queue (RQ).
The green cube (CubeA) has a RQ = 1990.
The red cube (CubeB) has a RQ = 2010 and will overlay every time the CubeA.
I create a plane evry frame wich has the size of the camera and its Matrix4x4 is the same than the camera (+ a transform little bit bigger than the clipping plane). Its RQ = 2000.
The shader is on the plane. I force the depth of every pixel of the plane at the infinite with z.value to clean the depth buffer.
Thanks to that the CubeB will always appear in front of the CubeA whatever its position in the scene.

1 Like