Ejemplo n.º 1
0
        /// <summary>
        /// </summary>
        void Setup()
        {
            this._all_renders = FindObjectsOfType <Renderer>();

            this._camera = this.GetComponent <Camera>();
            SynthesisUtilities.SetupCapturePassesReplacementShader(this._camera,
                                                                   this.segmentation_shader,
                                                                   ref this._capture_passes);

            this.ColorsDictGameObject = new Dictionary <Material, Color>();
            this.CheckBlock();
            foreach (var r in this._all_renders)
            {
                r.GetPropertyBlock(this._block);
                var sm = r.sharedMaterial;
                if (sm)
                {
                    var id    = sm.GetInstanceID();
                    var color = ColorEncoding.EncodeIdAsColor(id);
                    if (!this.ColorsDictGameObject.ContainsKey(sm))
                    {
                        this.ColorsDictGameObject.Add(sm, color);
                    }

                    this._block.SetColor(SynthesisUtilities._Shader_MaterialId_Color_Name, color);
                    r.SetPropertyBlock(this._block);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// </summary>
        void Setup()
        {
            this._camera = this.GetComponent <Camera>();
            SynthesisUtilities.SetupCapturePassesReplacementShader(this._camera,
                                                                   this.segmentation_shader,
                                                                   ref this._capture_passes);
            this.ColorsDictGameObject = new Dictionary <GameObject, Color>();
            this._all_renders         = FindObjectsOfType <Renderer>();
            this.CheckBlock();
            foreach (var r in this._all_renders)
            {
                r.GetPropertyBlock(this._block);
                var game_object = r.gameObject;
                var id          = game_object.GetInstanceID();
                var layer       = game_object.layer;
                var go_tag      = game_object.tag;

                if (!this.ColorsDictGameObject.ContainsKey(game_object))
                {
                    this.ColorsDictGameObject.Add(game_object, ColorEncoding.EncodeIdAsColor(id));
                }
                else
                {
          #if NEODROID_DEBUG
                    if (true)
                    {
                        Debug.LogWarning($"ColorDict Duplicate {game_object}");
                    }
          #endif
                }

                this._block.SetColor(SynthesisUtilities._Shader_ObjectId_Color_Name,
                                     ColorEncoding.EncodeIdAsColor(id));

/*
 * this._block?.SetInt(SynthesisUtils._Shader_OutputMode_Name,(int) SynthesisUtils.ReplacementModes
 *                                                                        .Object_id_);
 */
                //this._block.SetColor("_CategoryIdColor", ColorEncoding.EncodeLayerAsColor(layer));
                //this._block.SetColor("_MaterialIdColor", ColorEncoding.EncodeIdAsColor(id));
                //this._block.SetColor("_CategoryColor", ColorEncoding.EncodeTagHashCodeAsColor(go_tag));
                r.SetPropertyBlock(this._block);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// </summary>
        void Setup()
        {
            if (!this.gui_style)
            {
                this.gui_style = Resources.FindObjectsOfTypeAll <GUISkin>().First(a => a.name == "BoundingBox");
            }

            this._all_renders = FindObjectsOfType <Renderer>();
            if (this._capture_passes == null || this._capture_passes.Length == 0 || this.always_re)
            {
                this._capture_passes = new[] {
                    new CapturePassMaterial(CameraEvent.AfterDepthTexture,
                                            BuiltinRenderTextureType.Depth)
                    {
                        _SupportsAntialiasing
                            = false,
                        _RenderTexture
                            = this
                              .depthRenderTexture
                    },
                    new CapturePassMaterial(CameraEvent.AfterForwardAlpha,
                                            BuiltinRenderTextureType.MotionVectors)
                    {
                        _SupportsAntialiasing
                            = false,
                        _RenderTexture
                            = this
                              .flowRenderTexture
                    },
                    new CapturePassMaterial(CameraEvent.AfterForwardAlpha,
                                            BuiltinRenderTextureType.None)
                    {
                        _SupportsAntialiasing
                            = false,
                        _RenderTexture
                            = this
                              .objectIdRenderTexture,
                        _TextureId
                            = Shader
                              .PropertyToID("_TmpFrameBuffer")
                    },
                    new CapturePassMaterial(CameraEvent.AfterDepthTexture,
                                            BuiltinRenderTextureType.None)
                    {
                        _SupportsAntialiasing
                            = false,
                        _RenderTexture
                            = this
                              .tagIdRenderTexture,
                        _TextureId
                            = Shader
                              .PropertyToID("_CameraDepthTexture")
                    }
                };
            }

            if (this.m_quad == null)
            {
                this.m_quad = CreateFullscreenQuad();
            }

            this._camera = this.GetComponent <Camera>();
            //this._camera.SetReplacementShader(this.uberMaterial.shader,"");

            this._camera.RemoveAllCommandBuffers(); // cleanup capturing camera

            this._camera.depthTextureMode = DepthTextureMode.Depth | DepthTextureMode.MotionVectors;

            foreach (var capture_pass in this._capture_passes)
            {
                var cb = new CommandBuffer {
                    name = capture_pass.Source.ToString()
                };

                cb.Clear();

                if (capture_pass._Material)
                {
                    cb.GetTemporaryRT(capture_pass._TextureId,
                                      -1,
                                      -1,
                                      0,
                                      FilterMode.Point);
                    //cb.Blit(capture_pass.Source, capture_pass._RenderTexture, capture_pass._Material);
                    cb.Blit(capture_pass.Source, capture_pass._TextureId);
                    cb.SetRenderTarget(new RenderTargetIdentifier[] { capture_pass._RenderTexture },
                                       capture_pass._RenderTexture);
                    cb.DrawMesh(this.m_quad,
                                Matrix4x4.identity,
                                capture_pass._Material,
                                0,
                                0);
                    cb.ReleaseTemporaryRT(capture_pass._TextureId);
                }
                else
                {
                    cb.Blit(capture_pass.Source, capture_pass._RenderTexture);
                }

                this._camera.AddCommandBuffer(capture_pass.When, cb);
            }

            this.CheckBlock();
            foreach (var r in this._all_renders)
            {
                r.GetPropertyBlock(this._block);
                var sm = r.sharedMaterial;
                if (sm)
                {
                    var id    = sm.GetInstanceID();
                    var color = ColorEncoding.EncodeIdAsColor(id);

                    this._block.SetColor(SynthesisUtilities._Shader_MaterialId_Color_Name, color);
                    r.SetPropertyBlock(this._block);
                }
            }
        }