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.
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.
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.
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).
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?
Thank you,
Yesterday I had almost the same results that with what you did.
But yours works better than me .
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 :
With the same position, the 2 cubes don’t look identical. One seems smaller. I hope I will fix it with the shader.
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.