Hello ! I'm kinda new at Unity and i'm trying to do a segmentation on images coming from the main camera. I got a code which works absolutely fine ... except with trees.
public void OnSceneChange(bool grayscale=false)
{
var renderers = Object.FindObjectsOfType();
var mpb = new MaterialPropertyBlock();
foreach (var r in renderers)
{
var id = r.gameObject.GetInstanceID();
var layer = r.gameObject.layer;
var tag = r.gameObject.tag;
if(r.GetComponent()!=null)
{
Debug.Log(layer);
mpb.SetColor("_ObjectColor", ColorEncoding.EncodeIDAsColor(id));
mpb.SetColor("_CategoryColor", ColorEncoding.EncodeLayerAsColor(layer, grayscale));
r.GetComponent().SetPropertyBlock(mpb);
}
}
}
![alt text][1]
The code uses the layer of the gameobject. The code print the layer i gave to my trees in the console.
There is no errors in the console so i guess it gets a renderer for my trees prefabs but my thoughts is that it doesn't setPropertyBlock(mpb) on the right component.
Do anyone have a solution to this problem ?
[1]: /storage/temp/195659-ssegmentationtree.png
↧