Ejemplo n.º 1
0
    private void SetSegmentationEffect()
    {
        var renderers = FindObjectsOfType <Renderer>();
        var mpb       = new MaterialPropertyBlock();

        foreach (var r in renderers)
        {
            var theTag = r.gameObject.tag;
            var id     = getTheId(theTag);
            Debug.Log("object name :" + theTag + "object ID :" + id);
            mpb.SetColor("_ObjectColor", ColorEncoding.EncodeIDAsColor(id, theTag));
            mpb.SetColor("_CategoryColor", ColorEncoding.EncodeTagAsColor(theTag));//give a color by name
            r.SetPropertyBlock(mpb);
        }
    }
Ejemplo n.º 2
0
        public void OnSceneChange()
        {
            var renderers = Object.FindObjectsOfType <Renderer>();
            var mpb       = new MaterialPropertyBlock();

            foreach (var r in renderers)
            {
                var id    = r.gameObject.GetInstanceID();
                var layer = r.gameObject.layer;
                var tag   = r.gameObject.tag;

                mpb.SetColor("_ObjectColor", ColorEncoding.EncodeIDAsColor(id));
                mpb.SetColor("_CategoryColor", ColorEncoding.EncodeLayerAsColor(layer));
                r.SetPropertyBlock(mpb);
            }
        }
Ejemplo n.º 3
0
        private void SetSegmentationEffect()
        {
            var renderers = FindObjectsOfType <Renderer>();
            var mpb       = new MaterialPropertyBlock();

            foreach (var r in renderers)
            {
                var id = r.gameObject.GetInstanceID();
                segmentationIds.TryGetValue(r.gameObject.name, out id);
                var layer = r.gameObject.layer;

                mpb.SetColor("_ObjectColor", ColorEncoding.EncodeIDAsColor(id));
                mpb.SetColor("_CategoryColor", ColorEncoding.EncodeLayerAsColor(layer));
                r.SetPropertyBlock(mpb);
            }

            myCamera.renderingPath = RenderingPath.Forward;
            SetupCameraWithReplacementShader(0, Color.gray);
        }
Ejemplo n.º 4
0
        private void Start()
        {
            myCamera = GetComponent <Camera>();
            var renderers = FindObjectsOfType <Renderer>();
            var mpb       = new MaterialPropertyBlock();

            foreach (var r in renderers)
            {
                var id    = r.gameObject.GetInstanceID();
                var layer = r.gameObject.layer;

                mpb.SetColor("_ObjectColor", ColorEncoding.EncodeIDAsColor(id));
                mpb.SetColor("_CategoryColor", ColorEncoding.EncodeLayerAsColor(layer));
                r.SetPropertyBlock(mpb);
                var objectName = r.gameObject.name;
                if (!segmentationIds.ContainsKey(objectName))
                {
                    segmentationIds.Add(r.gameObject.name, id);
                }
            }
            UpdateCameraEffect();
        }