Ejemplo n.º 1
0
        private void OnEnable()
        {
            if (link.targetCam == null)
            {
                link.targetCam = GetComponent <Camera>();
            }

            manualCam = new ManuallyRenderCamera(link.targetCam);
            commander = new CameraEventRetention(manualCam.Camera);

            cmd      = new CommandBuffer();
            cap      = new DepthCapture();
            depthTex = new ResizableRenderTexture(new FormatRT()
            {
                textureFormat = RenderTextureFormat.Depth,
                depth         = 24
            });
            depthColorTex = new ResizableRenderTexture(new FormatRT()
            {
                textureFormat = RenderTextureFormat.ARGBHalf,
                readWrite     = RenderTextureReadWrite.Linear,
                depth         = 0,
            });

            pip = new PIPTexture();

            currCamData = default;
            validator.Reset();
            validator.SetCheckers(() => currCamData.Equals(link.targetCam));
            validator.Validation += () => {
                currCamData = link.targetCam;

                cmd.Clear();

                var size = link.targetCam.Size();
                depthTex.Size      = size;
                depthColorTex.Size = size;

                cmd.Clear();
                cap.StepThreashold = tuner.stepThreashold;
                cap.Capture(cmd, depthColorTex, tuner.depthOutputMode);
                commander.Set(tuner.captureEvent, cmd);

                pip.CurrTuner = tuner.pip;
                pip.TargetCam = link.targetCam;
            };
            manualCam.AfterCopyFrom += v => {
                manualCam.Camera.depthTextureMode = DepthTextureMode.Depth;
                manualCam.Camera.cullingMask      = tuner.CullingMask();
            };

            validator.Validate();

            depthTex.AfterCreateTexture      += v => validator.Invalidate();
            depthColorTex.AfterCreateTexture += v => {
                using (new RenderTextureActivator(depthColorTex))
                    GL.Clear(true, true, Color.white);
                validator.Invalidate();
            };
        }
Ejemplo n.º 2
0
 private void OnDisable()
 {
     if (commander != null)
     {
         commander.Reset();
         commander = null;
     }
     if (manualCam != null)
     {
         manualCam.Dispose();
         manualCam = null;
     }
     if (cap != null)
     {
         cap.Dispose();
         cap = null;
     }
     if (cmd != null)
     {
         cmd.Dispose();
         cmd = null;
     }
     if (depthTex != null)
     {
         depthTex.Dispose();
         depthTex = null;
     }
     if (depthColorTex != null)
     {
         depthColorTex.Dispose();
         depthColorTex = null;
     }
     if (pip != null)
     {
         pip.Dispose();
         pip = null;
     }
 }