Search Unity

Camera.SetTargetBuffers() not working with stencil buffer (UI masks)

Discussion in 'UGUI & TextMesh Pro' started by CorruptScanline, Sep 9, 2014.

  1. CorruptScanline

    CorruptScanline

    Joined:
    Mar 26, 2009
    Posts:
    217
    It seems that for some reason when using Camera.SetTargetBuffers(RenderBuffer[] colorBuffers, RenderBuffer depthBuffer), only the first color buffer gets the proper color from things within a UI mask. Things outside of masks render fine into both color buffers.

    Heres how the buffers are set.

    Code (CSharp):
    1. theCamera.SetTargetBuffers(new RenderBuffer[] { rt0.colorBuffer, rt1.colorBuffer }, rt0.depthBuffer);

    Both buffers are declared like this.

    Code (CSharp):
    1. new RenderTexture(Screen.width, Screen.height, 24, RenderTextureFormat.ARGB32);

    Heres an example of the results, the shaders write the same color info to both buffers. Top left is the second render buffer with masking enabled, top right is first render buffer with masking enabled, bottom left is second render buffer with masking disabled, bottom right is first render buffer with masking disabled. The difference between the bottom ones is expected due to some elements not having shaders that write to 2 color outputs. The top 2 show that the second color buffer is not getting color from things within side the mask, and that it seems that somehow it is failing the stencil test, even though the writing is happening within the same fragment program.


    The frag program in the shaders look like this. The stencil settings are copied out of the default UI shaders.

    Code (CSharp):
    1. struct f2s {
    2.     fixed4 col0 : COLOR0;
    3.     fixed4 col1 : COLOR1;
    4. };
    5.  
    6. f2s frag(v2f IN)
    7. {
    8.     half4 color = tex2D(_MainTex, IN.texcoord) * IN.color;
    9.                
    10.     f2s output;
    11.     output.col0 = color;
    12.     output.col1 = color;
    13.     return output;
    14. }
     
  2. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,206
    Could you report a bug so we can get the right people looking at this.
     
unityunity