How can I render a scene to a surface

Two cameras in different levels. Within camera B’s view you can see a plane. On that plane I want to render what camera A can see.

I’m not asking for code specifics, but really just pointers in the right direction/what to look for. If there are particular functions that help with specifically this, mentioning those would be appreciated. Cheers.

3 Answers

3

Just going to provide a working non-Unity-Pro solution for anyone else that comes across this.

It’s true that you can’t use RenderTexture() without Pro, but you don’t need it. What you can do instead is use a shader with a ColorMask of 0.

Create 2 cameras, and chuck an object in the view of Camera 2 and another object in the view of Camera 1. On Camera 2’s object place a material that has the following shader, and then render first Camera 1, then Camera 2. To do this, simply go to the Inspector and set Camera 1´s Depth to 1, and Camera 2´s Depth to 2.

Camera 2’s render will completely cover that of the Camera 1, except for where the object is, creating a functioning hole in the air that you can look through to see what’s in the view of Camera 1.

[10407-2013-04-25+image+005.png|10407]

Shader “DepthMask” {
SubShader
{
ColorMask 0 // Masks the object with no rendering to all colour
channels
Pass {} // Render the object, which in this case means disabling
} }

Thanks to Tenebraus for pointing this out.

Is there a download link for this project?

@jjxtra I recommend switching to unity 5. The free version has rendertextures. If you want to finish your project in 4, then see the posts below for step-by-step instructions (I dont have an example project). Unity 5 is amazing though and if you want real rendertextures without the side-effects of this workaround, upgrade.

I think this can help you to do what you want :

http://blog.almostlogical.com/2009/12/11/render-to-texture-unity3d/

Thanks. Totally bummed that you have to have Pro to use it. :(

I’m very sorry, but I can’t get this to work in Unity 4.0

Can someone please elaborate on this?

Can you email the scene to staakman@gmail.com ( maybe if it's big through http://www.wetransfer.com )? Would love to check what's going wrong. Thanks in advance.

Checking the scene about to send it to you, I noticed strange behaviour. Simply scaling an object was making the effect switch between functional and non-functional. So perhaps this is a Unity bug after all, and it might have something to do with this thread: http://forum.unity3d.com/threads/192467-Unity-4-2-submesh-draw-order

I would also appreciate if you could email me the scene as well. If either you or staakman could send it to gardnedn@miamioh.edu that would be very helpful. Thanks again!