Search Unity

Create Custom Render Texture with Depth Buffer?

Discussion in 'General Graphics' started by Koval331, Aug 27, 2019.

  1. Koval331

    Koval331

    Joined:
    Feb 3, 2019
    Posts:
    114
    How can I turn on the depth buffer in the Custom Render Texture? For now, on the left is how it is supposed to look, and on the right is what my Custom Render Texture sees:

    upload_2019-8-27_13-49-21.png upload_2019-8-27_13-49-3.png

    Here are the settings of my Custom Render Texture and there is no Depth Buffer field (unlike in regular Render Texture)

    upload_2019-8-27_13-50-42.png

    I also tried creating it from code, but the depth setting is reset back to 0 automatically:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEditor;
    5.  
    6. public class SetDepthBuffer : MonoBehaviour
    7. {
    8.     [SerializeField]
    9.     private CustomRenderTexture custom_render_texture;
    10.  
    11.     [ContextMenu("CreateNew")]
    12.     public void Create()
    13.     {
    14.         Debug.Log("Creating");
    15.         CustomRenderTexture new_custom_render_texture = new CustomRenderTexture(512, 512);
    16.         Debug.Log("Setting");
    17.         new_custom_render_texture.depth = 16;
    18.         Debug.Log("Creating Asset");
    19.  
    20.         AssetDatabase.CreateAsset(new_custom_render_texture, "Assets/Core/GUI/CustomRenderTexture/new_crt.asset");
    21.     }
    22.  
    23.     [ContextMenu("GetDepthBuffer")]
    24.     public void Get()
    25.     {
    26.         Debug.Log("getting custom_render_texture.depth: " + custom_render_texture.depth);
    27.     }
    28. }
    Here are the logs, after I ran Create and Get methods from Context Menu.

    upload_2019-8-27_13-52-47.png

    How do I make the depth buffer work in my Custom Render Texture?
     

    Attached Files:

  2. Binary42

    Binary42

    Joined:
    Aug 15, 2013
    Posts:
    207
    Did you find a solution?