Search Unity

SetRenderTarget problem

Discussion in 'Shaders' started by SubPixelPerfect, Mar 2, 2017.

  1. SubPixelPerfect

    SubPixelPerfect

    Joined:
    Oct 14, 2015
    Posts:
    224
    Hi, I'm working on a post effect

    and for that i need to render set of meshes to texture with ZTest LEqual to create a mask
    mask.jpg
    here is a sphere rendered to separate texture

    so i'm creating new RenderTexture and setting it as active color buffer while leaving depth buffer unchanged
    rendering what i need and resetting render target

    and everything works perfect

    but when i'm enabling Direct3D in player settings and enabling anti-aliasing in quality settings
    i'm getting an error:
    here is my code:
    Code (CSharp):
    1. void OnRenderImageTest0(RenderTexture source, RenderTexture destination){
    2.         // create new render target
    3.         RenderTexture rt = RenderTexture.GetTemporary(_camera.pixelWidth, _camera.pixelHeight);
    4.         rt.Create();
    5.         RenderBuffer tmp = Graphics.activeColorBuffer;
    6.  
    7.         // change render target
    8.         Graphics.SetRenderTarget(rt.colorBuffer, Graphics.activeDepthBuffer);
    9.  
    10.         ...
    11.         // render meshes
    12.         ...
    13.  
    14.         // reset render target
    15.         Graphics.SetRenderTarget(tmp, Graphics.activeDepthBuffer);
    16.         rt.Release();
    17.     }
    18.  

    is it a bug or i'm doing something wrong?
    is there any way to do that on Direct3D with enabled anti-aliasing?
     
    Last edited: Mar 2, 2017
  2. SubPixelPerfect

    SubPixelPerfect

    Joined:
    Oct 14, 2015
    Posts:
    224
    here i've found that
    But in my case size is equal.

    unity documentation says:
    https://docs.unity3d.com/Manual/SL-CameraDepthTexture.html
    ok, I have ZWrite Off

    more from docs:
    https://docs.unity3d.com/Manual/SL-PlatformDifferences.html
    this is clear, but what i can do in my case?