Depth2.cs 761 B

123456789101112131415161718192021222324
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. [RequireComponent(typeof(Camera))]
  5. public class Depth2 : MonoBehaviour
  6. {
  7. //material that's applied when doing postprocessing
  8. [SerializeField]
  9. private Material postprocessMaterial;
  10. private void Start()
  11. {
  12. Camera camera = GetComponent<Camera>();
  13. camera.depthTextureMode = camera.depthTextureMode | DepthTextureMode.Depth;
  14. }
  15. //method which is automatically called by unity after the camera is done rendering
  16. void OnRenderImage(RenderTexture source, RenderTexture destination)
  17. {
  18. //draws the pixels from the source texture to the destination texture
  19. Graphics.Blit(source, destination, postprocessMaterial);
  20. }
  21. }