Search Unity

Critical UI Artifacts

Discussion in 'General Graphics' started by neroziros, Mar 11, 2016.

  1. neroziros

    neroziros

    Joined:
    Aug 25, 2012
    Posts:
    129
    Hello there! I was wondering if anyone has experienced this same problem:

    http://screencast-o-matic.com/watch/cDeXhQ1bJx

    I have been trying to implement a multi deferred camera setup to no avail. Even though I managed to get the desired visual effect using several cameras with different screen effects I'm getting horrible artifacts when there is player interaction with the UI elements.

    This is the guide I've been following:

    http://forum.unity3d.com/threads/postprocessing-issues-with-several-cameras.313903/

    And this is the script I'm using to merge the multiple RT. (In the previous example I was using a single camera and the problem persisted)

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4.  
    5. [ExecuteInEditMode]
    6. public class PostProcessFilter : MonoBehaviour {
    7.  
    8.     public Material PostProcessMaterial;
    9.  
    10.     // Camera list
    11.     public List<Camera> Cameras;
    12.  
    13.     // Control parameters
    14.     private RenderTexture mainRenderTexture;
    15.  
    16.     private int width;
    17.     private int height;
    18.    
    19.     // Use this for initialization
    20.     void OnEnable()
    21.     {
    22.         this.GenerateRT    ();
    23.     }
    24.  
    25.     void Update()
    26.     {
    27.         if (width != Screen.width || height != Screen.height)
    28.         {
    29.             this.GenerateRT();
    30.         }
    31.     }
    32.  
    33.     void GenerateRT()
    34.     {
    35.         width = Screen.width;
    36.         height = Screen.height;
    37.  
    38.         if (this.mainRenderTexture != null)
    39.         {
    40.             foreach (var camera in Cameras)
    41.                 camera.targetTexture = null;
    42.             this.mainRenderTexture.Release();
    43.             DestroyImmediate(this.mainRenderTexture);
    44.         }
    45.  
    46.         Debug.Log("NEW RT GENERATED WITH DIMENSIONS: "+ Screen.width + " " + Screen.height);
    47.  
    48.         mainRenderTexture = new RenderTexture(Screen.width, Screen.height, 16, RenderTextureFormat.DefaultHDR);
    49.         mainRenderTexture.Create();
    50.         foreach (var camera in Cameras)
    51.             camera.targetTexture = mainRenderTexture;
    52.     }
    53.  
    54.     void OnPostRender()
    55.     {
    56.         if (this.PostProcessMaterial == null) return;
    57.             Graphics.Blit(mainRenderTexture, PostProcessMaterial);
    58.     }
    59. }
    60.