Question by
AzThunder · Apr 28 at 09:32 AM ·
renderertreematerialpropertyblock
Tree Segmentation (SetPropertyBlock)
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<GameObject>();
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<Renderer>()!=null)
{
Debug.Log(layer);
mpb.SetColor("_ObjectColor", ColorEncoding.EncodeIDAsColor(id));
mpb.SetColor("_CategoryColor", ColorEncoding.EncodeLayerAsColor(layer, grayscale));
r.GetComponent<Renderer>().SetPropertyBlock(mpb);
}
}
}
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 ?
ssegmentationtree.png
(208.7 kB)
Comment
Your answer
Follow this Question
Related Questions
Add or Set in MaterialPropertyBlock? 0 Answers
Access CanvasRenderer render buffer? 0 Answers
Model not rendering//no textures. 0 Answers
Octane Renderer 0 Answers