public override void SetupMaterialProperties(
            MaterialPropertyBlock mpb, Renderer renderer, Labeling labeling, uint instanceId)
        {
            var found = InstanceIdToColorMapping.TryGetColorFromInstanceId(instanceId, out var color);

            if (!found)
            {
                Debug.LogError($"Could not get a unique color for {instanceId}");
            }

            mpb.SetVector(k_SegmentationIdProperty, (Color)color);
#if PERCEPTION_DEBUG
            Debug.Log($"Assigning id. Frame {Time.frameCount} id {id}");
#endif
        }
        public override void SetupMaterialProperties(
            MaterialPropertyBlock mpb, Renderer renderer, Labeling labeling, uint instanceId)
        {
            var entry = new SemanticSegmentationLabelEntry();
            var found = false;

            foreach (var l in m_LabelConfig.labelEntries)
            {
                if (labeling.labels.Contains(l.label))
                {
                    entry = l;
                    found = true;
                    break;
                }
            }

            // Set the labeling ID so that it can be accessed in ClassSemanticSegmentationPass.shader
            mpb.SetVector(k_LabelingId, found ? entry.color : Color.black);
        }
示例#3
0
        /// <summary>
        /// Attempts to find the matching index in <see cref="LabelEntries"/> for the given <see cref="Labeling"/>.
        /// </summary>
        /// <remarks>
        /// The matching index is the first class name in the given Labeling which matches an entry in <see cref="LabelEntries"/>.
        /// </remarks>
        /// <param name="labeling">The <see cref="Labeling"/> to match </param>
        /// <param name="labelEntry">When this method returns, contains the matching <see cref="LabelEntry"/>, or <code>default</code> if no match was found.</param>
        /// <param name="labelEntryIndex">When this method returns, contains the index of the matching <see cref="LabelEntry"/>, or <code>-1</code> if no match was found.</param>
        /// <returns>Returns true if a match was found. False if not.</returns>
        public bool TryGetMatchingConfigurationEntry(Labeling labeling, out LabelEntry labelEntry, out int labelEntryIndex)
        {
            foreach (var labelingClass in labeling.labels)
            {
                for (var i = 0; i < LabelEntries.Count; i++)
                {
                    var entry = LabelEntries[i];
                    if (string.Equals(entry.label, labelingClass))
                    {
                        labelEntry      = entry;
                        labelEntryIndex = i;
                        return(true);
                    }
                }
            }

            labelEntryIndex = -1;
            labelEntry      = default;
            return(false);
        }
示例#4
0
 void IGroundTruthGenerator.SetupMaterialProperties(MaterialPropertyBlock mpb, Renderer renderer, Labeling labeling, uint instanceId)
 {
     if (m_IdLabelConfig.TryGetMatchingConfigurationEntry(labeling, out _, out var index))
     {
         if (m_InstanceIdToLabelEntryIndexLookup.Length <= instanceId)
         {
             m_InstanceIdToLabelEntryIndexLookup.Resize((int)instanceId + 1, NativeArrayOptions.ClearMemory);
         }
         m_InstanceIdToLabelEntryIndexLookup[(int)instanceId] = (ushort)index;
     }
 }
 /// <summary>
 /// Unregisters a labeling component
 /// </summary>
 /// <param name="labeling">the component to unregister</param>
 internal void Unregister(Labeling labeling)
 {
     m_LabelsPendingRegistration.Remove(labeling);
     m_RegisteredLabels.Remove(labeling);
 }
        /// <summary>
        /// Recursively initializes Renderer components on GameObjects with Labeling components
        /// </summary>
        /// <param name="gameObject">The parent GameObject being initialized</param>
        /// <param name="mpb">A reusable material property block</param>
        /// <param name="labeling">The labeling component attached to the current gameObject</param>
        /// <param name="instanceId">The perception specific instanceId assigned to the current gameObject</param>
        void RecursivelyInitializeGameObjects(
            GameObject gameObject, MaterialPropertyBlock mpb, Labeling labeling, uint instanceId)
        {
            var terrain = gameObject.GetComponent <Terrain>();

            if (terrain != null)
            {
                terrain.GetSplatMaterialPropertyBlock(mpb);
                foreach (var pass in m_ActiveGenerators)
                {
                    if (labeling.enabled)
                    {
                        pass.SetupMaterialProperties(mpb, null, labeling, instanceId);
                    }
                    else
                    {
                        pass.ClearMaterialProperties(mpb, null, labeling, instanceId);
                    }
                }

                terrain.SetSplatMaterialPropertyBlock(mpb);
            }

            var renderer = gameObject.GetComponent <Renderer>();

            if (renderer != null)
            {
                renderer.GetPropertyBlock(mpb);
                foreach (var pass in m_ActiveGenerators)
                {
                    if (labeling.enabled)
                    {
                        pass.SetupMaterialProperties(mpb, renderer, labeling, instanceId);
                    }
                    else
                    {
                        pass.ClearMaterialProperties(mpb, renderer, labeling, instanceId);
                    }
                }

                renderer.SetPropertyBlock(mpb);

                var materialCount = renderer.materials.Length;
                for (var i = 0; i < materialCount; i++)
                {
                    renderer.GetPropertyBlock(mpb, i);
                    //Only apply to individual materials if there is already a MaterialPropertyBlock on it
                    if (!mpb.isEmpty)
                    {
                        foreach (var pass in m_ActiveGenerators)
                        {
                            if (labeling.enabled)
                            {
                                pass.SetupMaterialProperties(mpb, renderer, labeling, instanceId);
                            }
                            else
                            {
                                pass.ClearMaterialProperties(mpb, renderer, labeling, instanceId);
                            }
                        }

                        renderer.SetPropertyBlock(mpb, i);
                    }
                }
            }

            for (var i = 0; i < gameObject.transform.childCount; i++)
            {
                var child = gameObject.transform.GetChild(i).gameObject;
                if (child.GetComponent <Labeling>() != null)
                {
                    continue;
                }

                RecursivelyInitializeGameObjects(child, mpb, labeling, instanceId);
            }
        }
 /// <summary>
 /// Refresh ground truth generation for the labeling of a particular GameObject. This is necessary when the
 /// list of labels changes or when renderers or materials change on objects in the hierarchy.
 /// </summary>
 /// <param name="labeling">the component to refresh</param>
 internal void RefreshLabeling(Labeling labeling)
 {
     m_RegisteredLabels.Remove(labeling);
     m_LabelsPendingRegistration.Add(labeling);
 }
 public abstract void SetupMaterialProperties(MaterialPropertyBlock mpb, Renderer meshRenderer, Labeling labeling, uint instanceId);
 /// <inheritdoc/>
 void IGroundTruthGenerator.ClearMaterialProperties(MaterialPropertyBlock mpb, Renderer renderer, Labeling labeling, uint instanceId)
 {
     if (m_InstanceIdToLabelEntryIndexLookup.Length > instanceId)
     {
         m_InstanceIdToLabelEntryIndexLookup[(int)instanceId] = k_DefaultValue;
     }
 }
示例#10
0
        void IGroundTruthGenerator.SetupMaterialProperties(MaterialPropertyBlock mpb, Renderer renderer, Labeling labeling, uint instanceId)
        {
            if (m_IdLabelConfig.TryGetMatchingConfigurationEntry(labeling, out _, out var index))
            {
                m_DefaultValue = ushort.MaxValue;
                Debug.Assert(index < m_DefaultValue, "Too many entries in the label config");
                if (m_InstanceIdToLabelEntryIndexLookup.Length <= instanceId)
                {
                    var oldLength = m_InstanceIdToLabelEntryIndexLookup.Length;
                    m_InstanceIdToLabelEntryIndexLookup.Resize((int)instanceId + 1, NativeArrayOptions.ClearMemory);

                    for (int i = oldLength; i < instanceId; i++)
                    {
                        m_InstanceIdToLabelEntryIndexLookup[i] = m_DefaultValue;
                    }
                }
                m_InstanceIdToLabelEntryIndexLookup[(int)instanceId] = (ushort)index;
            }
        }
 public override void ClearMaterialProperties(MaterialPropertyBlock mpb, Renderer renderer, Labeling labeling, uint instanceId)
 {
     mpb.SetVector(k_SegmentationIdProperty, (Color)InstanceIdToColorMapping.invalidColor);
 }
示例#12
0
 public abstract void ClearMaterialProperties(
     MaterialPropertyBlock mpb, Renderer renderer, Labeling labeling, uint instanceId);
示例#13
0
        public override void SetupMaterialProperties(MaterialPropertyBlock mpb, MeshRenderer meshRenderer, Labeling labeling, uint instanceId)
        {
            var entry = new LabelEntry();

            foreach (var l in m_LabelingConfiguration.LabelEntries)
            {
                if (labeling.labels.Contains(l.label))
                {
                    entry = l;
                    break;
                }
            }

            //Set the labeling ID so that it can be accessed in ClassSemanticSegmentationPass.shader
            mpb.SetInt(k_LabelingId, entry.value);
        }
 public override void ClearMaterialProperties(MaterialPropertyBlock mpb, Renderer renderer, Labeling labeling, uint instanceId)
 {
     mpb.SetVector(k_LabelingId, Color.black);
 }
示例#15
0
        /// <inheritdoc/>
        public void SetupMaterialProperties(MaterialPropertyBlock mpb, MeshRenderer meshRenderer, Labeling labeling, uint instanceId)
        {
            if (m_LabelingConfiguration.TryGetMatchingConfigurationEntry(labeling, out var entry, out var index))
            {
                if (m_InstanceIdToLabelEntryIndexLookup.Length <= instanceId)
                {
                    m_InstanceIdToLabelEntryIndexLookup.Resize((int)instanceId + 1, NativeArrayOptions.ClearMemory);
                }

                m_InstanceIdToLabelEntryIndexLookup[(int)instanceId] = index;
            }
        }
 public override void ClearMaterialProperties(MaterialPropertyBlock mpb, Renderer renderer, Labeling labeling, uint instanceId)
 {
     SetLensDistortionShaderParameters();
 }
示例#17
0
 /// <summary>
 /// Attempts to find the matching index in <see cref="LabelEntries"/> for the given <see cref="Labeling"/>.
 /// </summary>
 /// <remarks>
 /// The matching index is the first class name in the given Labeling which matches an entry in <see cref="LabelEntries"/>.
 /// </remarks>
 /// <param name="labeling">The <see cref="Labeling"/> to match </param>
 /// <param name="labelEntry">When this method returns, contains the matching <see cref="LabelEntry"/>, or <code>default</code> if no match was found.</param>
 /// <returns>Returns true if a match was found. False if not.</returns>
 public bool TryGetMatchingConfigurationEntry(Labeling labeling, out LabelEntry labelEntry)
 {
     return(TryGetMatchingConfigurationEntry(labeling, out labelEntry, out int _));
 }
     public override void SetupMaterialProperties(MaterialPropertyBlock mpb, MeshRenderer meshRenderer, Labeling labeling, uint instanceId)
     {
         mpb.SetInt(k_SegmentationIdProperty, (int)instanceId);
 #if PERCEPTION_DEBUG
         Debug.Log($"Assigning id. Frame {Time.frameCount} id {id}");
 #endif
     }
 public override void SetupMaterialProperties(MaterialPropertyBlock mpb, MeshRenderer meshRenderer, Labeling labeling, uint instanceId)
 {
     if (!m_InstanceIdToLabelIndexLookup.IsCreated)
     {
         m_InstanceIdToLabelIndexLookup = new NativeList <int>(k_StartingObjectCount, Allocator.Persistent);
     }
     if (LabelingConfiguration.TryGetMatchingConfigurationEntry(labeling, out LabelEntry labelEntry, out var index))
     {
         if (m_InstanceIdToLabelIndexLookup.Length <= instanceId)
         {
             m_InstanceIdToLabelIndexLookup.Resize((int)instanceId + 1, NativeArrayOptions.ClearMemory);
         }
         m_IdBuffersNeedUpdating = true;
         m_InstanceIdToLabelIndexLookup[(int)instanceId] = index + 1;
     }
 }