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); } }
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); } }
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); }
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(); }