2 using System.Collections.Generic;
6 namespace droid.Runtime.Utilities.GameObjects.NeodroidCamera.Segmentation {
14 Renderer[] _all_renders;
18 MaterialPropertyBlock _block;
20 [SerializeField] Shader segmentation_shader = null;
21 [SerializeField] Camera _camera;
25 public Dictionary<GameObject, Color> ColorsDictGameObject {
get;
set; } =
26 new Dictionary<GameObject, Color>();
30 public override Dictionary<String, Color> ColorsDict {
32 var colors =
new Dictionary<String, Color>();
33 foreach (var key_val
in this.ColorsDictGameObject) {
34 colors.Add(key_val.Key.GetInstanceID().ToString(), key_val.Value);
44 void Start() { this.Setup(); }
47 if (this._block == null) {
48 this._block =
new MaterialPropertyBlock();
52 SynthesisUtilities.CapturePass[] _capture_passes = {
53 new SynthesisUtilities.CapturePass {
68 this._camera = this.GetComponent<Camera>();
69 SynthesisUtilities.SetupCapturePassesReplacementShader(this._camera,
70 this.segmentation_shader,
71 ref this._capture_passes);
72 this.ColorsDictGameObject =
new Dictionary<GameObject, Color>();
73 this._all_renders = FindObjectsOfType<Renderer>();
75 foreach (var r
in this._all_renders) {
76 r.GetPropertyBlock(this._block);
77 var game_object = r.gameObject;
78 var
id = game_object.GetInstanceID();
79 var layer = game_object.layer;
80 var go_tag = game_object.tag;
82 if (!this.ColorsDictGameObject.ContainsKey(game_object)) {
83 this.ColorsDictGameObject.Add(game_object, ColorEncoding.EncodeIdAsColor(
id));
87 Debug.LogWarning($
"ColorDict Duplicate {game_object}");
92 this._block.SetColor(SynthesisUtilities._Shader_ObjectId_Color_Name,
93 ColorEncoding.EncodeIdAsColor(
id));
101 r.SetPropertyBlock(this._block);