Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Enable depth texture for editor camera?

Discussion in 'General Graphics' started by Pyronious2, Apr 16, 2015.

  1. Pyronious2

    Pyronious2

    Joined:
    Aug 21, 2014
    Posts:
    2
    I can enable the depth texture for in-game cameras using the instructions here:

    http://docs.unity3d.com/Manual/SL-CameraDepthTexture.html

    However I don't know how to enable the depth texture for the editor's scene camera. This means I can't see the shader I'm working on (which requires a depth texture) unless I'm running the game. Is there a way to specify that the editor camera should generate a depth texture?

    Thanks!

    PM
     
  2. iSinner

    iSinner

    Joined:
    Dec 5, 2013
    Posts:
    201
    From release notes.
    Scene view camera renders the depth texture if you set the game view camera to render it, so the reason why you don't see your shader might be something else.
     
  3. Pyronious2

    Pyronious2

    Joined:
    Aug 21, 2014
    Posts:
    2
    Thanks for the info. At the moment the game camera only has a depth texture when the game is running (the code that enables it is in the Start() function). How would I go about enabling it in editor mode?
     
  4. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,663
    Bumping this to add this script to make depth texture mode set in edit mode (and runtime also):

    Code (CSharp):
    1. using UnityEngine;
    2. [ExecuteInEditMode]
    3. public class EnableDepthTexture : MonoBehaviour
    4. {
    5.     void Start()
    6.     {
    7.         Camera.main.depthTextureMode = DepthTextureMode.Depth;
    8.     }
    9. }
    Attach to any object in the scene, and it should work.
     
    manurocker95 and mahdi1375unity like this.
  5. Gigabitten_Gaming

    Gigabitten_Gaming

    Joined:
    Jul 10, 2017
    Posts:
    13
    Derp. I know this is three years too late, but Start() functions don't work in the editor using [ExecuteAlways] or [ExecuteInEditMode].

    So this is a wrong solution.
     
  6. Gigabitten_Gaming

    Gigabitten_Gaming

    Joined:
    Jul 10, 2017
    Posts:
    13
    Five years later and there is still no solution to this? Very irritating, this is.
     
  7. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,208
    Swap
    Start()
    with
    OnEnable()
    .
     
    st-VALVe and DrJBN like this.
  8. CGDever

    CGDever

    Joined:
    Dec 17, 2014
    Posts:
    154
    Bump with this problem too.
    I have editor camera, I used Camera.main.depthTextureMode = DepthTextureMode.Depth; in OnEnable(), I use _CameraDepthTexture and the shader result is visible only in GameView :/ Editor's camera doesn't render anything.
    I have being trying to start\stop game simulation - no success, editor's camera doesn't show anything.