1 camera with multiple render textures?

Is it possible to have multiple render textures for just 1 camera? I’m trying to make a menu using the Unity GUI system and I want to display purchasable items in the menu as 3D meshes. I think the only way to do this is to use a render target. But I think having a camera for each item would be very resource intensive.

For anyone who has done something like this, how did you do it?

Multiple Render Targets (MRT) approach requires specialized shaders that output a struct of COLOR semantic values, instead of standard float4 or fixed4 color per fragment. Unity does not come with such shaders by default and you have to write them on your own, because they’re very application specific.

That said, this is a very wrong approach to such a problem :smiley:

Displaying 3D objects on your UI is no different than displaying 2D objects, simply make a 3D object belong in the “UI” layer (or whatever layer you have your UI setup in), and the camera will pick it up.

Simply instantiate the grid of 3D objects as needed to display your items. Beware though, they do go through UI elements like you would expect them to, so make sure they’re a bit closer to the camera than your canvas or it’s UI elements.

EDIT - I forgot to mention, this implies you are using a Camera space or World space UI setup. Screen Space setup does not have a camera to add to it, I am not sure how you’d make your object show there but I believe that again, simply setting the correct layer should do it. Do take care of the scale, as default Screen space setup is huge and your object needs to be visible in it.

I don’t quite understand the use case, but you can blit the output of a camera to as many rendertextures as you want…

RenderTexture[] renderTextures;

void OnRenderImage(RenderTexture src, RenderTexture dest) {

  // This is the default "passthrough" output of the camera
  Graphics.Blit(src, dest);

  // Also copy output to any additional rendertextures
  for(int i=0; i< renderTextures.Length; i++) {
    Graphics.Blit(null, renderTextures*);*

}
}

You can use this code to get a 2d texture and set it to your GUI RawImage.

Texture2D SnapshotImage(Camera cam) { // The camera must has a renderTexture target
    RenderTexture currentRT = RenderTexture.active;
    RenderTexture.active = cam.targetTexture;
    cam.Render();
    Texture2D image = new Texture2D(cam.targetTexture.width, cam.targetTexture.height);
    image.ReadPixels(new Rect(0, 0, cam.targetTexture.width, cam.targetTexture.height), 0, 0);
    image.Apply();
    RenderTexture.active = currentRT;
    return image;
}

Hello Homer_3, I try to do exactly the same thing, how did you finally manage to do it ?
Regards

Hello homer_3,
I try to do exactly the same thing, how did you finally manage to do that ?
Regards