Search Unity

CommandBuffer: built-in render texture type 3 not found while executing Fill Color & Depth

Discussion in 'Editor & General Support' started by Hi_ImTemmy, Mar 16, 2021.

  1. Hi_ImTemmy

    Hi_ImTemmy

    Joined:
    Jul 8, 2015
    Posts:
    174
    Unity Ver: 2019.4.18f1

    Hello,

    I'm getting the following warning in some scenes of my game:



    I have a camera script (below) that basically creates a low-res pixelation camera, and a high res camera which is merged together so the result is things like world text can still be sharp and readable in a scene while everything else like geometry is pixelated.

    Should I be concerned about this warning? The camera appears to function as expected so it doesn't appear to affect anything, but I'm always eager for a nice clean console.

    I didn't write the script I'm using. It was courtesy of @bgolus:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Rendering;
    5.  
    6. [RequireComponent(typeof(Camera))]
    7. public class LowResCam : MonoBehaviour
    8. {
    9.  
    10.     public int lowResHeight = 160;
    11.     public int highResMult = 2;
    12.  
    13.     public LayerMask offscreenLayers;
    14.     public Shader depthFillShader;
    15.  
    16.  
    17.     private Material depthCopyMat;
    18.     private Material depthFillMat;
    19.     private Material compositeMat;
    20.  
    21.     // private new Camera camera;
    22.     private Camera newCamera;
    23.     private Camera lowCamera;
    24.     private Camera highCamera;
    25.  
    26.     private CommandBuffer mainCameraDepthCopy;
    27.     private CommandBuffer highFill;
    28.  
    29.     private RenderTexture lowRT;
    30.     private RenderTexture highRT;
    31.  
    32.     void Awake()
    33.     {
    34.         newCamera = GetComponent<Camera>();
    35.  
    36.         lowCamera = new GameObject("Offscreen Camera Low", typeof(Camera)).GetComponent<Camera>();
    37.         lowCamera.enabled = false;
    38.         lowCamera.transform.SetParent(newCamera.transform, false);
    39.         lowCamera.CopyFrom(newCamera);
    40.         lowCamera.renderingPath = RenderingPath.Forward;
    41.         lowCamera.cullingMask ^= offscreenLayers;
    42.         lowCamera.depthTextureMode |= DepthTextureMode.Depth;
    43.  
    44.         depthFillMat = new Material(depthFillShader);
    45.  
    46.         mainCameraDepthCopy = new CommandBuffer();
    47.         mainCameraDepthCopy.name = "Copy Depth Texture from Main Camera";
    48.         mainCameraDepthCopy.SetGlobalTexture("_MainCameraDepthTexture", BuiltinRenderTextureType.Depth);
    49.  
    50.         lowCamera.AddCommandBuffer(CameraEvent.BeforeForwardOpaque, mainCameraDepthCopy);
    51.  
    52.         highCamera = new GameObject("Offscreen Camera High", typeof(Camera)).GetComponent<Camera>();
    53.         highCamera.enabled = false;
    54.         highCamera.transform.SetParent(newCamera.transform, false);
    55.         highCamera.CopyFrom(newCamera);
    56.         highCamera.renderingPath = RenderingPath.Forward;
    57.         highCamera.cullingMask = offscreenLayers;
    58.         highCamera.depthTextureMode = DepthTextureMode.None;
    59.         highCamera.useOcclusionCulling = false;
    60.         highCamera.backgroundColor = Color.clear;
    61.         highCamera.clearFlags = CameraClearFlags.Nothing;
    62.  
    63.         highFill = new CommandBuffer();
    64.         highFill.name = "Fill Color & Depth";
    65.         highCamera.AddCommandBuffer(CameraEvent.BeforeForwardOpaque, highFill);
    66.  
    67.         newCamera.cullingMask = 0;
    68.     }
    69.  
    70.     void OnEnable()
    71.     {
    72.         float ratio = (float)Screen.width / (float)Screen.height;
    73.  
    74.         int lowResWidth = Mathf.RoundToInt((float)lowResHeight * ratio);
    75.         int highResWidth = Mathf.Min(Screen.width, lowResWidth * highResMult);
    76.         int highResHeight = Mathf.Min(Screen.height, lowResHeight * highResMult);
    77.  
    78.         lowRT = new RenderTexture(lowResWidth, lowResHeight, 24);
    79.         lowRT.filterMode = FilterMode.Point;
    80.         lowRT.Create();
    81.  
    82.         highRT = new RenderTexture(highResWidth, highResHeight, 24);
    83.         highRT.filterMode = FilterMode.Point;
    84.         highRT.Create();
    85.  
    86.         highFill.Clear();
    87.         highFill.Blit(lowRT, BuiltinRenderTextureType.CurrentActive);
    88.         highFill.Blit(BuiltinRenderTextureType.Depth, BuiltinRenderTextureType.CurrentActive, depthFillMat);
    89.     }
    90.  
    91.     void OnDisable()
    92.     {
    93.         Destroy(lowRT);
    94.         Destroy(highRT);
    95.     }
    96.  
    97.     void OnPreRender()
    98.     {
    99.         lowCamera.projectionMatrix = newCamera.projectionMatrix;
    100.         highCamera.projectionMatrix = newCamera.projectionMatrix;
    101.  
    102.         lowCamera.targetTexture = lowRT;
    103.         highCamera.targetTexture = highRT;
    104.     }
    105.  
    106.     void OnRenderImage(RenderTexture src, RenderTexture dst)
    107.     {
    108.         lowCamera.Render();
    109.         highCamera.Render();
    110.         Graphics.Blit(highRT, dst);
    111.     }
    112. }
     
    Last edited: Jun 30, 2021
  2. Hi_ImTemmy

    Hi_ImTemmy

    Joined:
    Jul 8, 2015
    Posts:
    174
    Does anybody have any ideas for the above?