Пример #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);
                }
            }
        }
Пример #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);
            }
        }
Пример #3
0
        /// <summary>
        /// </summary>
        void Setup()
        {
            if (this._colors_by_category != null && this._colors_by_category.Length > 0)
            {
                foreach (var tag_color in this._colors_by_category)
                {
                    if (!this.ColorsDictGameObject.ContainsKey(tag_color._Category_Name))
                    {
                        this.ColorsDictGameObject.Add(tag_color._Category_Name, tag_color._Color);
                    }
                }
            }

            if (this._segmentation_preset)
            {
                var segmentation_color_by_tags = this._segmentation_preset._color_by_categories;
                if (segmentation_color_by_tags != null)
                {
                    foreach (var tag_color in segmentation_color_by_tags)
                    {
                        if (!this.ColorsDictGameObject.ContainsKey(tag_color._Category_Name))
                        {
                            this.ColorsDictGameObject.Add(tag_color._Category_Name, tag_color._Color);
                        }
                    }
                }
            }

            this._all_renders = FindObjectsOfType <Renderer>();
            if (!this._camera)
            {
                this._camera = this.GetComponent <Camera>();
            }

            if (this.ColorsDictGameObject == null)
            {
                this.ColorsDictGameObject = new Dictionary <string, Color>();
            }

            switch (this._segmentation_mode)
            {
            case SegmentationMode.Tag_:
                this._capture_passes = new[] {
                    new SynthesisUtilities.CapturePass {
                        _Name            = "_tag_id",
                        _ReplacementMode =
                            SynthesisUtilities.ReplacementModes
                            .Tag_id_,
                        _SupportsAntialiasing =
                            false
                    }
                };
                break;

            case SegmentationMode.Layer_:
                this._capture_passes = new[] {
                    new SynthesisUtilities.CapturePass {
                        _Name            = "_layer_id",
                        _ReplacementMode =
                            SynthesisUtilities.ReplacementModes
                            .Layer_id_,
                        _SupportsAntialiasing =
                            false
                    }
                };
                break;

            default: throw new ArgumentOutOfRangeException();
            }

            SynthesisUtilities.SetupCapturePassesReplacementShader(this._camera,
                                                                   this.segmentation_shader,
                                                                   ref this._capture_passes);

            this.CheckBlock();
            foreach (var a_renderer in this._all_renders)
            {
                a_renderer.GetPropertyBlock(this._block);
                string category_name;
                var    category_int = 0;
                Color  color;
                string shader_data_name;
                switch (this._segmentation_mode)
                {
                case SegmentationMode.Tag_:
                    category_name    = a_renderer.tag;
                    shader_data_name = SynthesisUtilities._Shader_Tag_Color_Name;
                    break;

                case SegmentationMode.Layer_:
                    category_int     = a_renderer.gameObject.layer;
                    category_name    = LayerMask.LayerToName(category_int);
                    shader_data_name = SynthesisUtilities._Shader_Layer_Color_Name;
                    break;

                default: throw new ArgumentOutOfRangeException();
                }

                if (!this.ColorsDictGameObject.ContainsKey(category_name))
                {
                    if (!this._Replace_Untagged_Color)
                    {
                        switch (this._segmentation_mode)
                        {
                        case SegmentationMode.Tag_:
                            category_int = category_name.GetHashCode();
                            color        = ColorEncoding.EncodeTagHashCodeAsColor(category_int);
                            //color = ColorEncoding.EncodeIdAsColor(category_int);
                            break;

                        case SegmentationMode.Layer_:
                            color = ColorEncoding.EncodeLayerAsColor(category_int);
                            break;

                        default:
                            //color = ColorEncoding.EncodeIdAsColor(category_int);
                            throw new ArgumentOutOfRangeException();
                        }
                    }
                    else
                    {
                        color = this._Untagged_Color;
                    }

                    this.ColorsDictGameObject.Add(category_name, color);
                }
                else
                {
                    color = this.ColorsDictGameObject[category_name];
                }

                this._block.SetColor(shader_data_name, color);

                a_renderer.SetPropertyBlock(this._block);
            }
        }