Search Unity

Two cameras on rendertexture, one with depth of field

Discussion in 'Editor & General Support' started by stefanob, Apr 9, 2014.

  1. stefanob

    stefanob

    Joined:
    Nov 26, 2012
    Posts:
    68
    Hello,

    I have a scene with some objects and I want to apply depth of field to them. But there is also a background plane which shouldn't be affected by it.
    So I have one camera for the objects with "Clear Flags: depth only" and another camera for the background plane. Both render on one rendertexture:

    Code (csharp):
    1.  
    2. rt = new RenderTexture(1920, 1080, 24);
    3. rt.Create();
    4. sourceCam1.targetTexture = rt;
    5. sourceCam2.targetTexture = rt;
    6. var newMat = renderer.material;
    7. newMat.SetTexture("_MainTex", rt);
    8.  
    Everything renders fine without the dof effect. When I turn it on, I can see only the front camera rendering with it's black background (which should be transparent to see the second camera image).

    Any ideas?

    Thank you!